Skip to content

Instantly share code, notes, and snippets.

@edprince
Last active August 29, 2015 14:01
Show Gist options
  • Save edprince/a7aabcf54ac2629cad84 to your computer and use it in GitHub Desktop.
Save edprince/a7aabcf54ac2629cad84 to your computer and use it in GitHub Desktop.
Getting enemy to switch costume and drop off screen when hit
//spr_EnemyDead is a speparate sprite that contains the image of the enemy rotated slightly.
//Trying to get enemy once hit, to switch to spr_EnemyDead and then fall off screen, at the moment, as soon
//as player bounces off head he switches back to alive sprite.
//Enemy Movement
hsp = dir * movespeed;
vsp += grav;
sprite_index = spr_enemy
//Horizontal Collision
if (place_meeting(x + hsp, y, obj_wall || obj_GravBlock))
{
while(!place_meeting(x + sign(hsp), y, obj_wall)) and sprite_index = spr_enemy
{
x += sign(hsp);
}
hsp = 0
dir *= -1
}
//Movement through lava
if (place_meeting(x, y, obj_lava))
{
vsp = (vsp / 1.1);
}
if (place_meeting(x, y, obj_lava))
{
hsp = (hsp / 3);
}
x += hsp;
//Vertical Collision
if (place_meeting(x, y + vsp, obj_wall || obj_GravBlock)) and sprite_index = spr_enemy
{
while(!place_meeting(x, y + sign(vsp), obj_wall))
{
y += sign(vsp);
}
vsp = 0
}
y += vsp;
//Enemy Collision
if (place_meeting(x, y, obj_player))
{
if (obj_player.y < y-16)
{
with (obj_player) vsp = -jumpspeed;
sprite_index = spr_EnemyDead;
}
else
{
game_restart();
}
}
else
{
sprite_index = spr_enemy;
}
if sprite_index = spr_EnemyDead
{
hsp = 0;
vsp = 2;
}
@danprince
Copy link

if (image_index != 1) and (move != 0) {
  if move = 1 then image_index = 0;
  if move = -1 then image_index = 2;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment