Monsters!

posted in r1ckparker's Journal for project Psy
Published May 11, 2011
Advertisement
It was surprisingly easy to get the monsters in and animated, and facing the correct direction in relation to the player. Basically the player has one of 4 directions (0, 1, 2 and 3) and the monster has 1 of 4 directions (0, 1, 2 and 3) and you subtract the monsters direction from the players direction to give you which sprite to plot. If the result is less than 0 you add 4.

E.g. if player is facing East (1) and enemy facing South (2)

1-2 = -1
-1+4 = 3

Plot monster sprite 3. Repeat!

Previous Entry Combat
Next Entry Pathfinding
0 likes 5 comments

Comments

sanch3x
(Md - Pd) % 4 if you want to avoid the extra check. :P
May 11, 2011 08:48 PM
Spencer Bowers
Looking good! Also, I believe Gazillion's optimization should be more like ((Pd - Md) + 4) % 4.
May 12, 2011 12:56 AM
r1ckparker
Thanks for the advice guys, I am going to need all the shortcuts I can get!
May 12, 2011 06:23 PM
sanch3x
Sorry I mixed up the two parameters, I meant (Md - Pd) % 4 which will give you the same results as adding +4 to negative numbers and leave the positive ones unchanged.

[s]Player Monster Pd-Md%4 0 0 0 0 1 3 0 2 2 0 3 1 1 0 1 1 1 0 1 2 3 1 3 2 2 0 2 2 1 1 2 2 0 2 3 3 3 0 3 3 1 2 3 2 1 3 3 0[/s]

Looks like the editor doesn't like me pasting from excel, but the math is good (or am I really that tired? :P)[s]
[/s]
May 12, 2011 09:06 PM
a_insomniac
Coolness
May 12, 2011 09:48 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement