Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- key_left = keyboard_check(vk_left);
- key_right = keyboard_check(vk_right);
- key_jump = keyboard_check_pressed(vk_space);
- key_jump_held = keyboard_check(vk_space);
- key_down_held = keyboard_check(vk_down);
- key_interact = keyboard_check_pressed(ord("E"));
- //check if moving left or right
- var horizontal_input = key_right - key_left;
- //grounded check
- if ((place_meeting(x,y+1,oSolidTile) || place_meeting(x,y+1,oPlatform)) && !grounded){
- grounded = true;
- coyote_time = max_coyote_time;
- land_time = max_land_time;
- }
- if (land_time){
- land_time--;
- }
- if (!place_meeting(x,y+1,oSolidTile) && !place_meeting(x,y+1,oPlatform)){
- if (coyote_time){
- coyote_time--;
- }
- else{
- }
- grounded = false;
- }
- //applying jump if grounded
- if ((grounded || coyote_time) && key_jump){
- if (key_down_held && place_meeting(x,y+1,oPlatform)){
- vsp = -jump_speed;
- }
- else{
- vsp = jump_speed;
- jump_time = max_jump_time;
- }
- coyote_time = 0;
- hsp += jump_boost * horizontal_input;
- }
- if (!grounded){
- if (key_jump_held){
- if (abs(vsp) <= half_gravity_threshold){
- grav_mult = 0.5;
- }
- else{
- grav_mult = 1;
- }
- if (jump_time){
- vsp = jump_speed;
- }
- }
- jump_time--;
- if (coyote_time < 2){
- vsp = clamp((vsp + (gravity_speed * grav_mult)), -infinity, max_fall);
- }
- }
- //horizontal movement
- if (horizontal_input != 0){
- if (grounded){
- hsp = clamp((hsp + horizontal_input * walk_accel), -walk_speed, walk_speed);
- }
- else{
- hsp = clamp((hsp + horizontal_input * air_accel), -air_max_speed, air_max_speed);
- }
- }
- else{ //friction
- if (grounded){
- hsp *= 1 - ground_friction;
- }
- else{
- hsp *= 1 - air_friction;
- }
- }
- if (cam.new_room != noone){
- can_move = false;
- }
- else{
- can_move = true;
- }
- //horizontal collision
- if (place_meeting(x+hsp,y,oSolidTile)){
- while(!place_meeting(x+sign(hsp),y,oSolidTile)){
- x += sign(hsp);
- }
- hsp = 0;
- }
- if (can_move){
- x += hsp;
- }
- //vertical collision
- if (place_meeting(x,y+vsp,oSolidTile)){
- while(!place_meeting(x,y+sign(vsp),oSolidTile)){
- y += sign(vsp);
- }
- vsp = 0;
- }
- with (oPlatform){
- if (place_meeting(x,y+other.vsp,other) && other.bbox_bottom < bbox_top){
- with (other){
- while(!place_meeting(x,y+sign(vsp),other)){
- y += sign(vsp);
- }
- vsp = 0;
- }
- }
- }
- if (can_move){
- y += vsp;
- }
- //squash and stretch
- if (vsp < 0){
- draw_xscale = 1 + 0.05 * vsp;
- draw_yscale = 1 - 0.1 * vsp;
- }
- else if (land_time){
- draw_xscale = 1 + 0.075 * land_time;
- draw_yscale = 1 - 0.025 * land_time;
- }
- else{
- draw_xscale = 1;
- draw_yscale = 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement