Thu Jan 08, 2015 5:01 pm
if(player.x>monster.x){
monster.x+=1;
}
if(player.x<monster.x){
monster.x-=1;
}
if(player.y>monster.y){
monster.y+=1;
}
if(player.y<monster.y){
monster.y-=1;
}
Thu Jan 08, 2015 5:18 pm
Thu Jan 08, 2015 5:32 pm
Thu Jan 08, 2015 5:32 pm
if(player.y!=monster.y){
movement == 1;
}
if(player.x!=monster.x){
movement == 1;
}
if (movement == 1){
xoff == player.x - monster.x;
yoff == player.y - monster.y;
if yoff > xoff {
monster.y += 1;
}
if xoff > yoff {
monster.x += 1;
}
Thu Jan 08, 2015 5:37 pm
Thu Jan 08, 2015 6:36 pm
float monster.X = somewhere in the play area
float monster.Y = somewhere in the play area
monsterSpeed = speed in pixels per frame (can be a float or an integer)
Ydistance = player.Y - monster.Y
Xdistance = player.X - monster.X
Xdirection = -(Xdistance < 0) + (Xdistance > 0) // store the monster movement direction as -1, 0 or 1 (left, no movement, right)
Ydirection = -(Ydistance < 0) + (Ydistance > 0) // store the monster movement direction as -1, 0 or 1 (up, no movement, down)
Xdistance = abs(Xdistance)
Ydistance = abs(Ydistance) // get rid of direction, not needed anymore
if Xdistance > Ydistance {
difference = Ydistance / Xdistance
monster.X += monsterSpeed * Xdirection
monster.Y += difference * monsterSpeed * Ydirection
}
else {
difference = Xdistance / Ydistance
monster.Y += monsterSpeed * Ydirection
monster.X += difference * monsterSpeed * Xdirection
}
Thu Jan 08, 2015 6:56 pm
Tue Jan 13, 2015 7:17 pm
float angle;
float player.X;
float player.Y;
float monster.X;
float monster.Y;
angle = atan(monster.X-player.X)/(monster.Y-player.Y));
monster.X+=cos(angle);
monster.Y+=sin(angle);
gb.display.drawBitmap(int(monster.X),int(monster.Y),Zombie);
Tue Jan 13, 2015 7:27 pm
// Angles
angleStruct angles[NB_ANGLES] = {
{ 0.996194698092, 0.0871557427477 }, // 5 deg
{ 0.984807753012, 0.173648177667 }, // 10 deg
{ 0.965925826289, 0.258819045103 }, // 15 deg
{ 0.939692620786, 0.342020143326 },
{ 0.906307787037, 0.422618261741 },
{ 0.866025403784, 0.5 }, //30 deg
{ 0.819152044289, 0.573576436351 },
{ 0.766044443119, 0.642787609687 },
{ 0.707106781187, 0.707106781187 }, // 45deg
{ 0.642787609687, 0.766044443119 },
{ 0.573576436351, 0.819152044289 },
{ 0.5, 0.866025403784 }, // 60deg
{ 0.422618261741, 0.906307787037 },
{ 0.342020143326, 0.939692620786 },
{ 0.258819045103, 0.965925826289 }, // 75 deg
{ 0.173648177667, 0.984807753012 }, // 80deg
{ 0.0871557427477, 0.996194698092 }, // 85deg
};