A.I Programming
Posted: Wed Nov 27, 2013 11:48 pm
Hello everyone! , so, I've learning just for couple of days Love and Lua, great indeed, reading and stuff, so I did this little code trying to emulete some AI or something, just a guy walking forever in square, so I did everything with IF's statements and counters, obviously must be a better way to do the same using other stuff, so that's the question to the experts, What's the proper way to do this kind of events in Love and of course using Lua?
Waiting for suggestions.. thanks
here's the code and the .love:
Waiting for suggestions.. thanks
here's the code and the .love:
Code: Select all
if veces == 1 then
player2.x = player2.x + player2.speed * dt
elseif veces == 2 then
player2.x = player2.x - player2.speed * dt
elseif veces == 3 then
player2.y = player2.y - player2.speed * dt
elseif veces == 4 then
player2.y = player2.y + player2.speed * dt
end
if player2.x >= 600 and veces == 1 then
veces = 2
semaforo.tiempo = semaforo. tiempo + 1 --veces que llega a punto
player2.animation = player2.animations.left
elseif player2.x <= 400 and veces == 2 then
veces = 1
semaforo.tiempo = semaforo. tiempo + 1 --veces llega
player2.animation = player2.animations.right
end
--hero square walking
if semaforo.tiempo == 3 then
veces = 3
player2.animation = player2.animations.up
elseif semaforo.tiempo == 6 then
veces = 2
player2.animation = player2.animations.left
-- semaforo.tiempo = 0 --reset time
elseif semaforo.tiempo == 9 then
veces = 4
player2.animation = player2.animations.down
-- semaforo.tiempo = 2
elseif semaforo.tiempo == 12 then
veces = 1
player2.animation = player2.animations.right
semaforo.tiempo = 0
end
if player2.y <= 100 and veces == 3 then
veces = 4
semaforo.tiempo = semaforo. tiempo + 1 --veces que llega a punto
player2.animation = player2.animations.down
elseif player2.y >= 410 and veces == 4 then
veces = 3
semaforo.tiempo = semaforo. tiempo + 1 --veces que llega a punto
player2.animation = player2.animations.up
end