P
pablowski
Guest
So ive recently started using game maker studios and have been watching a few tutorials. I have been able to make my player power up and kill enemies by jumping on them but his sword swing attack doesn't work. Any help would be greatly appreciated. Here is the code ( and the code in /// is just code i tried that didn't work too).
///get the players input
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
key_jump = keyboard_check_pressed(vk_up);
//key_attack = keyboard_check_pressed(vk_space)
//react to inputs
//left and right
move = key_left + key_right;
hsp = move * movespeed;
if (vsp<10) vsp += grav;
//jump
if (place_meeting(x,y+1,obj_wll))
{
jumps = jumpmax;
}
if (key_jump) && (jumps > 0)
{
jumps -= 1;
vsp = -jumpspeed;
}
//attck
///if (key_attack)
///{
/// sprite_index = spr_plyr_attck;
/// hsp = 0;
/// if (image_index >=3) && (image_index <= 5)
/// {
/// with(instance_create(x,y,obj_hitbox))
/// {
/// image_xscale = other.image_xscale;
/// with(instance_place(x,y,par_enemy))
/// {
/// instance_destroy();
/// }
/// }
/// }
///}
//horizontal collision
if (place_meeting(x+hsp,y,obj_wll))
{
while(!place_meeting(x+sign(hsp),y,obj_wll))
{
x+= sign(hsp);
}
hsp = 0;
}
x += hsp;
//Vertical Collision
if (place_meeting(x,y+vsp,obj_wll))
{
while(!place_meeting(x,y+sign(vsp),obj_wll))
{
y += sign(vsp);
}
vsp = 0;
}
y += vsp;
// animation
if (alarm[0] <= 0)
{
if (move!=0) image_xscale = move;
///keyboard_check_pressed(vk_space) //or
if (keyboard_check_pressed(vk_space))
{
sprite_index = spr_plyr_attck;
image_speed = 0.1;
hsp = 0;
if (image_index >=3) && (image_index <= 5)
{
with(instance_create(x,y,obj_hitbox))
{
image_xscale = other.image_xscale;
with(instance_place(x,y,par_enemy))
{
instance_destroy();
}
}
}
}
if (place_meeting(x,y+1,obj_wll))
{
if (move!=0)
{
sprite_index = spr_plyr_wlk;
}
else sprite_index = spr_plyr;
}
else
{
if (vsp < 0) sprite_index = spr_plyr_jmp; else sprite_index = spr_plyr_fll;
}
}
//if powered up
if (alarm[0] > 0)
{
{
if (move!=0) image_xscale = move;
if (place_meeting(x,y+1,obj_wll))
{
if (move!=0)
{
sprite_index = spr_plyr_wlk_ghost;
image_speed = 0.25;
}
else sprite_index = spr_plyr_ghost;
}
else
{
if (vsp < 0) sprite_index = spr_plyr_jmp_ghost; else sprite_index = spr_plyr_fll_ghost;
}
}
}
///get the players input
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
key_jump = keyboard_check_pressed(vk_up);
//key_attack = keyboard_check_pressed(vk_space)
//react to inputs
//left and right
move = key_left + key_right;
hsp = move * movespeed;
if (vsp<10) vsp += grav;
//jump
if (place_meeting(x,y+1,obj_wll))
{
jumps = jumpmax;
}
if (key_jump) && (jumps > 0)
{
jumps -= 1;
vsp = -jumpspeed;
}
//attck
///if (key_attack)
///{
/// sprite_index = spr_plyr_attck;
/// hsp = 0;
/// if (image_index >=3) && (image_index <= 5)
/// {
/// with(instance_create(x,y,obj_hitbox))
/// {
/// image_xscale = other.image_xscale;
/// with(instance_place(x,y,par_enemy))
/// {
/// instance_destroy();
/// }
/// }
/// }
///}
//horizontal collision
if (place_meeting(x+hsp,y,obj_wll))
{
while(!place_meeting(x+sign(hsp),y,obj_wll))
{
x+= sign(hsp);
}
hsp = 0;
}
x += hsp;
//Vertical Collision
if (place_meeting(x,y+vsp,obj_wll))
{
while(!place_meeting(x,y+sign(vsp),obj_wll))
{
y += sign(vsp);
}
vsp = 0;
}
y += vsp;
// animation
if (alarm[0] <= 0)
{
if (move!=0) image_xscale = move;
///keyboard_check_pressed(vk_space) //or
if (keyboard_check_pressed(vk_space))
{
sprite_index = spr_plyr_attck;
image_speed = 0.1;
hsp = 0;
if (image_index >=3) && (image_index <= 5)
{
with(instance_create(x,y,obj_hitbox))
{
image_xscale = other.image_xscale;
with(instance_place(x,y,par_enemy))
{
instance_destroy();
}
}
}
}
if (place_meeting(x,y+1,obj_wll))
{
if (move!=0)
{
sprite_index = spr_plyr_wlk;
}
else sprite_index = spr_plyr;
}
else
{
if (vsp < 0) sprite_index = spr_plyr_jmp; else sprite_index = spr_plyr_fll;
}
}
//if powered up
if (alarm[0] > 0)
{
{
if (move!=0) image_xscale = move;
if (place_meeting(x,y+1,obj_wll))
{
if (move!=0)
{
sprite_index = spr_plyr_wlk_ghost;
image_speed = 0.25;
}
else sprite_index = spr_plyr_ghost;
}
else
{
if (vsp < 0) sprite_index = spr_plyr_jmp_ghost; else sprite_index = spr_plyr_fll_ghost;
}
}
}