C
Choppa
Guest
Hello everyone! I am new around these parts, but I am currently making a 2D game. The problem that I am facing at the moment is with the AI mechanics. I have no clue how to flip the sprite that is moving.
Right now as it goes I have a sprite AI that moves left and right. Once it hits a wall it is suppose to turn around and walk the other way. Currently I have the sprite hit a wall and turn to go the other way, but I have no idea how to flip the sprite itself so it looks the other way. Can anyone help me out, or direct me in the path I need to go? Thank you for your time.
Right now as it goes I have a sprite AI that moves left and right. Once it hits a wall it is suppose to turn around and walk the other way. Currently I have the sprite hit a wall and turn to go the other way, but I have no idea how to flip the sprite itself so it looks the other way. Can anyone help me out, or direct me in the path I need to go? Thank you for your time.
Code:
///Initialize Variables
dir = -1; //Horizontal Variable
//Movement variables
movespeed = 3;
grav = 0.35;
hsp = 0;
vsp = 0;
Code:
hsp = dir * movespeed;
vsp += grav;
//Horizontal Collision
if (place_meeting(x+hsp,y,obj_grassblock1))
{
while(!place_meeting(x+sign(hsp),y,obj_grassblock1))
{
x += sign(hsp);
}
hsp = 0;
dir *= -1;
}
if (place_meeting(x+hsp,y,obj_grassblock2))
{
while(!place_meeting(x+sign(hsp),y,obj_grassblock2))
{
x += sign(hsp);
}
hsp = 0;
dir *= -1;
}
if (place_meeting(x+hsp,y,obj_aibar))
{
while(!place_meeting(x+sign(hsp),y,obj_aibar))
{
x += sign(hsp);
}
hsp = 0;
dir *= -1;
}
x += hsp;
//Vertical Collision
if (place_meeting(x,y+vsp,obj_grassblock1))
{
while(!place_meeting(x,y+vsp,obj_grassblock1))
{
y += sign(vsp);
}
vsp = 0;
}
if (place_meeting(x,y+vsp,obj_grassblock2))
{
while(!place_meeting(x,y+vsp,obj_grassblock2))
{
y += sign(vsp);
}
vsp = 0;
dir *= -1;
}
y += vsp;