/// @description Control player character
//Step Event
var k_left = keyboard_check(ord("A"));
var k_leftr = keyboard_check_released(ord("A"));
var k_right = keyboard_check(ord("D"));
var k_rightr = keyboard_check_released(ord("D"));
var k_jump = keyboard_check_pressed(vk_space);
var k_down = keyboard_check(ord("S"));
var k_downp = keyboard_check_pressed(ord("S"));
var k_downr = keyboard_check_released(ord("S"));
var k_dash = keyboard_check_pressed(vk_shift);
var k_punch = keyboard_check_pressed(ord("P"));
var k_knee = keyboard_check_pressed(ord("O"));
var k_kick = keyboard_check_pressed(ord("I"));
var spd_wanted = 0; //The wanted horizontal speed for this step
var haccl = 0 //Set horizontal acceleration
if(k_left && crouchstate == 0 && attackstate == 0 && dashstate == 0 && !k_down)
{
image_xscale = 1;
haccl -=0.25;
spd_wanted -= 2;
if (speed_x >= spd_wanted){
haccl +=0.25;
}
if (place_meeting(x,y+1,oWall) && !k_down){
image_speed = abs(speed_x)*0.85;
sprite_index = sJotaroWalk;
pstate = "walk";
}
}
if(k_right && crouchstate == 0 && attackstate == 0 && dashstate == 0 && !k_down)
{
image_xscale = -1;
haccl +=0.25;
spd_wanted += 2;
if (speed_x <= spd_wanted){
haccl -=0.25;
}
if (place_meeting(x,y+1,oWall) && !k_down){
image_speed = abs(speed_x)*0.85;
sprite_index = sJotaroWalk;
pstate = "walk";
}
}
if (k_downp && place_meeting(x,y+1,oWall) && dashstate = 0 && attackstate = 0){
image_index = 0;
}
if (k_down && place_meeting(x,y+1,oWall) && dashstate = 0 && sprite_index != sJotaroCrouchBackhand && attackstate = 0){
sprite_index = sJotaroCrouch
image_speed = 0.9;
crouchstate = 1;
haccl = 0;
spd_wanted = 0;
pstate = "crouch";
if (stam < maxstam){
stam += 0.5
}
}
if (k_downr && crouchstate == 1 && dashstate == 0 && attackstate == 0){
image_index = 0;
sprite_index = sJotaroStandUp;
}
if(k_dash && speed_x != 0 && dashstate == 0 && pstate != "dash" && attackstate = 0){
dashstate = 1;
image_index = 0;
}
if (dashstate == 1){
pstate = "dash";
stam -=2;
if(place_meeting(x,y+1,oWall)){
sprite_index = sJotaroDash;
image_speed = 1.05;
}
if(!place_meeting(x,y+1,oWall)){
sprite_index = sJotaroAirdash
image_speed = 1.05;
}
if (image_xscale == -1){
haccl = 0.8;
}
if (image_xscale == 1){
haccl = -0.8;
}
}
if (dashstate == 0){
pstate = "idle";
haccl = 0;
}
if (!k_right && !k_left && place_meeting(x,y+1,oWall) && !k_jump && dashstate = 0 && !k_down && sprite_index != sJotaroStandUp && sprite_index != sJotaroPunch && sprite_index != sJotaroKnee && sprite_index != sJotaroKick && sprite_index != sJotaroCrouchBackhand){
image_speed = 1;
sprite_index = sJotaroIdle;
pstate = "idle";
crouchstate = 0;
attackstate = 0;
}
if (k_punch && dashstate == 0 && place_meeting(x,y+1,oWall) && attackstate == 0 && crouchstate == 0){
attackstate = 1;
image_index = 0;
image_speed = 1.05;
sprite_index = sJotaroPunch;
instance_create_depth(x,y,0,oPunchHitbox);
}
if (k_knee && dashstate == 0 && place_meeting(x,y+1,oWall) && attackstate == 0){
attackstate = 1;
image_index = 0;
image_speed = 1.05;
sprite_index = sJotaroKnee;
instance_create_depth(x,y,0,oKneeHitbox);
}
if (k_kick && dashstate == 0 && place_meeting(x,y+1,oWall) && attackstate == 0){
attackstate = 1;
image_index = 0;
image_speed = 1.05;
sprite_index = sJotaroKick;
instance_create_depth(x,y,0,oKickHitbox);
}
if (k_punch && dashstate == 0 && place_meeting(x,y+1,oWall) && attackstate == 0 && crouchstate == 1){
attackstate = 1;
image_index = 0;
image_speed = 1.05;
sprite_index = sJotaroCrouchBackhand;
instance_create_depth(x,y,0,oBackhandHitbox);
}
if (!place_meeting(x,y+1,oWall) && sprite_index != sJotaroJump && dashstate = 0){
if (speed_y > 0){
image_speed = 1.05;
sprite_index = sJotaroFall;
}
if (speed_y <= 0){
image_speed = 1.05;
sprite_index = sJotaroAirborne;
}
crouchstate = 0;
}
speed_x += haccl; //Set the horizontal speed based on the wanted speed
speed_y += grav; //Apply gravity
if (dashstate = 0 && stam < maxstam){
stam +=1;
}
//Horizontal collision
if(place_meeting(x + speed_x, y, oWall))
{
while(!place_meeting(x + sign(speed_x), y, oWall))
{
x+=sign(speed_x);
}
speed_x = 0;
}
x += speed_x;
//Vertical collision
if(place_meeting(x, y + speed_y, oWall))
{
while(!place_meeting(x, y + sign(speed_y), oWall))
{
y+=sign(speed_y);
}
speed_y = 0;
}
y += speed_y;
/*var spd_wanted = 0; //The wanted horizontal speed for this step
*/
speed_x += (spd_wanted - speed_x) * 0.15; //Smoothly accelerate / decelerate to the wanted speed
var xsp = round(speed_x); //Turn the theoretical value into an integer for collision and movement
//Horizontal collision
if(place_meeting(x+xsp, y, oWall))
{
while(!place_meeting(x+sign(xsp), y, oWall))
{
x += sign(xsp);
}
xsp = 0;
speed_x = 0;
}
x += xsp;
speed_y += grav; //Apply gravity
if(k_jump && place_meeting(x, y + 1, oWall))
{
if(dashstate = 0) {
image_speed = 1.2/*speed_y*8*/;
image_index = 0;
sprite_index = sJotaroJump;
}
if (crouchstate = 1) {
crouchstate = 0;
speed_y = -8.5
pstate = "jump";
} else {
speed_y = -7;
pstate = "jump";
}
}
var ysp = round(speed_y); //Turn the theoretical value into an integer for collision and movement
//Vertical collision
if(place_meeting(x, y + ysp, oWall))
{
while(!place_meeting(x, y+sign(ysp), oWall))
{
y+=sign(ysp);
}
ysp = 0
speed_y = 0;
}
y += ysp;