CREATE EVENT OF PLAYER
// Initialize variables
image_speed=1;
grav = 1;
hsp = 0;
vsp = 0;
move=0;
movefactor=1;
hpmax=100;
hpamount=hpmax;
state="idle";
facing=1;
weapon=0;
canattack=0;
wep="";
subimage=-1;
depth=-1;
STEP EVENT OF PLAYER
/// Movement Code
// Get player input
key_right = keyboard_check(ord("D"));
key_left = -keyboard_check(ord("A"));
key_jump = keyboard_check_pressed(ord("W"));
attack = mouse_check_button_pressed(mb_left);
wepselect = keyboard_check_pressed(ord("S"));
//React to inputs
move = key_right + key_left;
hsp = move * global.movespeed * movefactor;
//Gravity
if (vsp < 12)
vsp+=grav; //limits fall speed
//Jumping
if place_meeting(x,y+1,oBlock)
{
vsp = key_jump * -global.jumpspeed;
}
//Horizontal collisions
if place_meeting(x+hsp,y,oBlock)
{
while (!place_meeting(x+sign(hsp),y,oBlock))
{
x+= sign(hsp);
}
hsp=0;
}
x+=hsp;
//Vertical collisions
if place_meeting(x,y+vsp,oBlock)
{
while (!place_meeting(x,y+sign(vsp),oBlock))
{
y+= sign(vsp);
}
vsp=0;
}
y+=vsp;
//Special Block
// check collisions with block
if place_meeting(x,y,oSlow)
{
movefactor=.1;
}
else movefactor = 1;
// Hurt block
if place_meeting(x,y,oSpikes)
{
hpamount -= 1;
}
//Super Jump Code
if place_meeting(x,y,oJump) //super jump block code
{
vsp=-35;
oJump.subimage=-1;
}
///Change States
if move==1 && canattack==0
{
facing = key_right;
state="walk";
}
if move==-1 && canattack==0
{
facing = key_left;
state="walk";
}
//Animate character
switch state
{
case "walk":
sprite_index = sPlayerWalk;
image_xscale=facing;
subimage=-1;
break;
case "idle":
sprite_index = sPlayerIdle;
image_xscale=facing;
subimage=0;
break;
case "attackbow":
sprite_index = sPlayerBow;
image_xscale=facing;
subimage=-1;
break;
case "attackspear":
sprite_index = sPlayerSpear;
image_xscale=facing;
subimage=-1;
break;
case "attacksword":
sprite_index = sPlayerSword;
image_xscale=facing;
subimage=-1;
break;
}
//Attack Code
//Toggle weapon from
//0 Spear
//1 Bow
if wepselect == 1 weapon=!weapon;
if weapon == 0 wep="spear";
if weapon == 1 wep="bow";
if attack==1 canattack=1;
//Attack state
if canattack==1 && wep=="spear"
state = "attackspear";
if canattack==1 && wep=="bow"
state = "attackbow";
//Change States
if move==1 && canattack==0
{
facing=key_right;
state="walk";
}
if move==-1 && canattack==0
{
facing=key_left;
state="walk";
}
if move==0 && state!="attackspear" && state !="attackbow"
{
state="idle";
}
ANIMATION END EVENT OF PLAYER
switch state
{
case "attackbow":
//When you create the arrow
var ID;
ID = instance_create_layer(x,y,"Instances",oArrow);
with (ID)
{// makes arrow face same direction as you
image_xscale = other.image_xscale;
hspeed = other.image_xscale*15; //Sets the arrow's speed to 10 or -10
}
break;
case "attackspear":
break;
}
canattack=0;
state="idle";
DRAW EVENT OF PLAYER
//DRAW health bar:
draw_healthbar(x-32,y-sprite_height/2-10,x+32,y-sprite_height/2-5,hpamount,c_black,c_red,c_lime,0,1,1);
draw_sprite_ext(sprite_index,subimage,x,y,facing,1,0,c_white,1);