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 15:10

>>10
First, I did write rewrite the State Monad when I was figuring out what they were, but I did it in Scheme. I used a list of key value pairs, but if I was doing it again I would use a more efficient tree structure.
Second, you are right, Haskell doesn't have a generic mixable type, but you could have the dictionary be either specialised by the data you were storing [(String,A)]. Presumably you could make a "sexp" data type that would have different constructors for strings, numbers, etc. although it wouldn't work for new user defined types.

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