Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Push a player back when he is hurt?

Name: Anonymous 2010-04-07 14:40

Hello programmers! I am having a tad bit of trouble with my lua code, I am trying to make the play go in the opposite direction (about 5 pixels back) when he is hurt by an enemy or sharp object.

basically like in the older snes and gameboy version of zelda.
The problem is that it keeps going and going until it goes off the screen into oblivion. Anyone know how to get this working correctly?

function playerDirection()
if Player[1].state == 2 and Player[1].hurt == 1 then
Player.x = Player.x + 5
local sound = hurt_01
voice = sound:play()
end
if Player[1].state == 3 and Player[1].hurt == 1 then
Player.x = Player.x - 5
local sound = hurt_01
voice = sound:play()
end
if Player[1].state == 1 and Player[1].hurt == 1 then
Player.y = Player.y + 5
local sound = hurt_01
voice = sound:play()
end
if Player[1].state == 0 and Player[1].hurt == 1 then
Player.y = Player.y - 5
local sound = hurt_01
voice = sound:play()
end
end

Name: Anonymous 2010-04-07 14:57

>>1
Look at all that repeated code and magic numbers, you should be ashamed of yourself.

The problem is that it keeps going and going until it goes off the screen into oblivion
Can you elaborate on this. I've noticed there aren't any edge checks in the code, are you just saying that it goes off screen or that it seems to loop infinitely?

>>4
Haskells State monad is pretty limited, I mean, is it that fucking difficult to have a key value table?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List