K
King Gryzz
Guest
Hello. I am having trouble with figuring out how to make my enemy sprites look right if they are going right etc. I am using Shaun Spaulding's code as a base for my sprites and when I use the dir variable to see whether it looks left or right it just spazzes out. Please help.
Code:
Create event
///Stats
dir = -1;
image_speed = 0.5;
gravsp = 0.5
msp = 6
vsp = 0
hsp = 0
jsp = 11
Code:
Step Event for movement
///Movement
hsp = dir * msp
vsp += gravsp
//Horiz
if (place_meeting(x+hsp,y,Obj_Solid))
{
while(!place_meeting(x+sign(hsp),y,Obj_Solid))
{
x += sign(hsp);
}
hsp = 0
}
if (place_meeting(x+hsp,y,Obj_Wall))
{
while(!place_meeting(x+sign(hsp),y,Obj_Wall))
{
x += sign(hsp);
}
hsp = 0
dir *= -1
}
if (place_meeting(x+hsp,y,Obj_EWall))
{
while(!place_meeting(x+sign(hsp),y,Obj_EWall))
{
x += sign(hsp);
}
hsp = 0
dir *= -1
}
//Vert
if (place_meeting(x,y+vsp,Obj_Solid))
{
while(!place_meeting(x,y+sign(vsp),Obj_Solid))
{
y += sign(vsp);
}
vsp = 0
}
if (place_meeting(x,y+vsp,Obj_Wall))
{
while(!place_meeting(x,y+sign(vsp),Obj_Wall))
{
y += sign(vsp);
}
vsp = 0
}
if (place_meeting(x,y+vsp,Obj_EWall))
{
while(!place_meeting(x,y+sign(vsp),Obj_EWall))
{
y += sign(vsp);
}
vsp = 0
}
x += hsp;
y += vsp;
x=clamp(x, 0, room_width);
y=clamp(y, 0, room_height);