R
Rew711
Guest
I'm pretty sure I might need to add some type of true/false statement but for now I'm kinda at a point where I don't know what to do. I'm hoping that someone can help because I've looked at online tutorials and they only talk about the full area around the enemy rather than just a specific point.
I'm also having trouble getting the enemy AI to go from what Case to another. I think it might have something to do with having a timer running in the code.
Step Event:
Begin Step:
End Step:
Its pretty simple code and its a mix of code from different sources but its mostly from a user who had previously helped me on this site. And most of the other code is from a guy who showed you a bit of code through an Amazon page tutorial but he never really finished.
I tried a lot of things with the code, moving each thing around and/or adding in something new but it always seems to do either nothing or just crash the game.
I hope that whatever it is, I can learn from it for future coding purposes.
I'm also having trouble getting the enemy AI to go from what Case to another. I think it might have something to do with having a timer running in the code.
Step Event:
Code:
//animation
frame_counter();
//state switch
switch currentState
{
case states.move:
if not instance_exists(oPlayer) break;
var distance_to_player = point_distance(x, y, oPlayer.x, oPlayer.y);
sprite = Frog_Hop;
last_image = (image_speed - 1);
image_speed = 0.1;
xPos = sign(oPlayer.x - x);
move_state(self.dir, self.movespeed);
if (image_index > last_image) and (distance_to_player < 128)
{
image_speed = 0;
pauseTimer = -1;
movespeed = 0;
currentState = states.attack;
}
if (image_index > last_image) and !(distance_to_player < 128)
{
image_speed = 0;
pauseTimer ++;
movespeed = 6.5;
if (pauseTimer >= Time_For_Jump)
{
image_index = 0;
movespeed = 0;
puaseTimer = 0;
}
if (pauseTimer = 40)
{
pauseTimer = 0;
}
}
break;
case states.attack:
if not instance_exists(oPlayer) break;
sprite = Frog_Attack;
var distance_to_player = point_distance(x, y, oPlayer.x, oPlayer.y);
xPos = sign(oPlayer.x - x);
dir = xPos;
movespeed = 0;
if !(image_index > sprite_get_number(sprite_index) - 1)
{
xPos = 1;
pauseTimer = -1;
currentState = states.attack;
}
else if (image_index > sprite_get_number(sprite_index) - 1)
{
xPos = -1;
pauseTimer = 1;
currentState = states.normal;
}
break;
case states.hit:
hit_state();
break;
}
//reset frame to 0 if sprite changes
if(lastSprite != sprite)
{
lastSprite = sprite;
frame = 0;
}
Code:
onGround = check_below();
if(onGround)
{
ySpeed = 0;
}
else
{
ySpeed += gSpeed;
}
Code:
xPos = x;
yPos = y;
//animation
frame_reset();
//hurtbox
with(hurtbox)
{
x = other.x + xOffset;
y = other.y + yOffset;
}
//get hit
if !(hit)
{
currentState = states.move
}
else if(hit)
{
squash_stretch(1.3,1.3);
xSpeed = hitBy.xHit;
hitStun = hitBy.hitStun;
facing = hitBy.owner.facing * -1;
hit = false;
currentState = states.hit;
dir *= -1;
facing = dir;
pauseTimer = 0;
image_index = 0;
}
//hitbox
if(hitbox != -1)
{
with(hitbox)
{
x = other.x + xOffset;
y = other.y + yOffset;
}
}
///collision
var h, v;
// Handle sub-pixel movement
xCounter += xSpeed;
yCounter += ySpeed;
h = round(xCounter);
v = round(yCounter);
xCounter -= h;
yCounter -= v;
repeat(abs(v))
{
if(ySpeed <= 0)
{
if(place_meeting(x,y+sign(v),oWall))
{
ySpeed = 0;
break;
}
else
{
y += sign(v);
}
}
else
if (check_below())
{
ySpeed = 0;
break;
}
else
{
y += sign(v);
}
}
repeat(abs(h))
{
if(place_meeting(x+sign(h),y,oWall))
{
xSpeed = 0;
dir *= -1;
facing = dir;
break;
}
else
{
x += sign(h);
}
}
I tried a lot of things with the code, moving each thing around and/or adding in something new but it always seems to do either nothing or just crash the game.
I hope that whatever it is, I can learn from it for future coding purposes.