1
SFML projects / Ultimate Zombie Fighters
« on: September 13, 2010, 09:21:46 pm »
Thanks for the reply! I hope the source code wil help me to learn Box2D =)
Thanks again and Good Luck! =D
Thanks again and Good Luck! =D
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
For avoiding objects just do something like:
Save the direction the sprite is moving,
Check if the enemy is colliding with any object.
(for example the sprite is colliding with an object and moved right-->)
Check if the player is higher or lower then the enemy. If the player is above move up, then right. If colliding move up again and then right. As long as you're not colliding anymore. Then you can go on normal movement
P
O
EO
O
O
O
EO P
O
O
OO
EO P
OO
R) If right is not blocked
move right
A) If right is blocked
move up(down) (choose randomly or depending on Player's position)
then make check and select R or B
B) If chosen up(down) blocked
try down(up)
then make check and select R or C
C) If both up and down are blocked
move left and move up(down)
then make check and select R or B
Repeat it until we can use R
OOO
O
OOO
EO P
OO
O
OO
if(X_Enemy > X_Player)
Enemy.Move(-Speed,0);
else
if(X_Enemy < X_Player)
Enemy.Move(Speed,0);
if(Y_Enemy > Y_Player)
Enemy.Move(0,-Speed);
else
if(Y_Enemy < Y_Player)
Enemy.Move(0,Speed);
if(needToMoveCloser)
{
angle=getAngle(Enemy, Player);
Enemy.move(speed*time*cos(angle), speed*time*sin(angle));
}