Untitled
//Get inputs var _keyRight = keyboard_check(ord("D")) var _keyLeft = keyboard_check(ord("A")) var _keyJump = keyboard_check_pressed(ord("W")) var _keyDown = keyboard_check_pressed(ord("S")) var dash = keyboard_check_pressed(vk_shift); // all movement sprites animations //Standing Still if (hsp == 0) { show_debug_message("1") if (dir == 0) { sprite_index = spr_StandingStillRight } if (dir == 1) { sprite_index = spr_StandingStillLeft } } if (keyboard_check(ord("D"))) { show_debug_message("2") dir = 0 sprite_index = spr_WalkingCycleRight } if (keyboard_check(ord("A"))) { show_debug_message("3") dir = 1 sprite_index = spr_WalkingCycleLeft } if keyboard_check(ord("A")) & dash { dir = 1 sprite_index = spr_DashLeft } if keyboard_check(ord("D")) & dash { dir = 0 sprite_index = spr_DashRight } // player movement calculation horizontally hsp = (_keyRight - _keyLeft) * hspWalk; // simple dash if dash { hsp = (_keyRight - _keyLeft) * dsp } // player movement calculation vertically vsp = vsp + grv; // player movement jumping if (vsp == grv) && (_keyJump) { vsp = vspJump; jumpDuration = 30; } if (vsp == grv) && (_keyDown) { downDuration = 30; } // X collision to check when player collides with the platforms if (place_meeting(x + hsp, y, collidewith)) { while (abs(hsp) > 0.1) { hsp *= 0.5; if (!place_meeting(x + hsp, y, collidewith)) { x += hsp; } } hsp = 0; } // Y collision to check when player collides with the platforms if (place_meeting(x, y + vsp, collidewith)) { while (abs(vsp) > 0.1) { vsp *= 0.5; if (!place_meeting(x, y + vsp, collidewith)) { y += vsp; } } vsp = 0; } // X collision check when player collides with the crate if (place_meeting(x + hsp, y, obj_crate)) { obj_crate.hsp = hsp * 1.5; } // Y collision check when player collides with the crate if (position_meeting(x, y + vsp, obj_crate) && (jumpDuration == 0 && downDuration == 0)) { while (abs(vsp) > 0.1) { vsp *= 0.5; if (!position_meeting(x, y + vsp, obj_crate)) { y += vsp; } } vsp = 0; } // Y collision check when player collides with moving platform (top only) if (position_meeting(x, y + vsp, obj_moving_platform) && (jumpDuration == 0 && downDuration == 0)) { var platform = instance_position(x, y + vsp, obj_moving_platform); while (abs(vsp) > 0.1) { vsp *= 0.25; if (!position_meeting(x, y + vsp, obj_moving_platform)) { y += vsp; } } vsp = 0; hsp += platform.hsp; if (hsp == platform.hsp) { if (dir == 0) { sprite_index = spr_StandingStillRight } if (dir == 1) { sprite_index = spr_StandingStillLeft } } } y += vsp; x += hsp; if (jumpDuration > 0) { jumpDuration -= 1; } if (downDuration > 0) { downDuration -= 1; } //parallax code //x pos if hsp < 0 || hsp > 0 { Asset1posx = x * -0.05 + 46 layer_x("Assets_1", Asset1posx) Asset2posx = x * -0.03 + 28 layer_x("Assets_2", Asset2posx) Asset3posx = x * -0.01 + 9 layer_x("Assets_3", Asset3posx) Asset4posx = x * -0.015 + 14 layer_x("Assets_4", Asset4posx) } //y pos if vsp < 0 || vsp > 0 { Asset1posy = y * -0.025 + 55 layer_y("Assets_1", Asset1posy) Asset2posy = y * -0.0175 + 39 layer_y("Assets_2", Asset2posy) Asset3posy = y * -0.01 + 22 layer_y("Assets_3", Asset3posy) Asset4posy = y * -0.015 + 15 layer_y("Assets_4", Asset4posy) } //backup parallax //Asset1posx = x * -0.1 + 278 //layer_x("Assets_1", Asset1posx) //Asset2posx = x * -0.05 + 185 //layer_x("Assets_2", Asset2posx) //Asset3posx = x * -0.01 + 93 //layer_x("Assets_3", Asset3posx) //teleport for easier dev movement if keyboard_check(ord("1")) { x = 500 y = 820 } if keyboard_check(ord("2")) { x = 3570 y = 2666 } if keyboard_check(ord("3")) { x = 4166 y = 1111 }
Leave a Comment