hdarren
Member
I have a enemy that bounces around the screen. I have been struggling with getting the bouncing to work when it hits a wall. I want it to bounce away when it hits a wall.
Is this the best way of doing it?
Is this the best way of doing it?
Code:
///move back out of wall
d = point_direction(x,y,xprevious,yprevious);
while place_meeting(x,y,Parent_Wall)
{
x += lengthdir_x(1,d);
y += lengthdir_y(1,d);
}
///inverse speed
if (hspeed > 0 and place_meeting(x+1,y,Parent_Wall))
or (hspeed < 0 and place_meeting(x-1,y,Parent_Wall))
{hspeed *= -1;}
if (vspeed > 0 and place_meeting(x,y+1,Parent_Wall))
or (vspeed < 0 and place_meeting(x,y-1,Parent_Wall))
{vspeed *= -1;}