E
Edwin
Guest
Hello, I have a problem.
Well, my game is basic platformer (just for now) with dash system and when player dashes and then collides with corner, he stucks and makes something I can't explain when you press jump button.
CODE:
This code looks like it's very hard to understand, but if you have time, please don't pass by.
Well, my game is basic platformer (just for now) with dash system and when player dashes and then collides with corner, he stucks and makes something I can't explain when you press jump button.
CODE:
Code:
//Variables
grav = 4;
hspd = 0;
vspd = 0;
speed_multiplier = 6;
speed_ground = 18;
speed_air = 12;
speed_air_max = speed_air;
jspd = 24;
dash_speed = 36;
dash_time = 5;
jdashing = false;
jdash_performed = false;
Code:
//Variables
var on_ground = place_meeting(x, y+1, obj_ground);
//Current speed
if (on_ground) {
speed_current = speed_ground;
} else {
if (speed_air_max >= speed_air) {
speed_current = speed_air_max;
} else {
speed_current = speed_air;
}
}
//Gravity
if (!jdashing) {
if (!on_ground) {
vspd += grav;
} else {
vspd = 0;
}
}
//Movement
if (!jdashing) {
if (right_key && !left_key) {
if (hspd < speed_current) {
hspd += speed_multiplier;
} else {
hspd = speed_current;
}
} else
if (left_key && !right_key) {
if (hspd > -speed_current) {
hspd -= speed_multiplier;
} else {
hspd = -speed_current;
}
} else {
if (hspd > 0) {
hspd -= speed_multiplier;
} else
if (hspd < 0) {
hspd += speed_multiplier;
}
}
}
//Jumping
if (on_ground) {
if (jump_key) {
vspd = -jspd;
speed_air_max = abs(hspd);
//Particle
jump_particle = instance_create(x, y, obj_particle_parent);
jump_particle.sprite_index = particle_jumping;
}
}
//Dashing
if (!alarm[0]) {
if (!on_ground) {
if (!jdash_performed) {
if (!place_meeting(x+1, y, obj_ground) && !place_meeting(x-1, y, obj_ground)) {
if (dash_key) {
//Control
if (right_key || left_key) {
if (right_key && !left_key) {
hspd = dash_speed;
} else
if (left_key && !right_key) {
hspd = -dash_speed;
}
} else {
switch (image_flip) {
case 1: hspd = dash_speed; break;
case -1: hspd = -dash_speed; break;
}
}
if (keyboard_check(vk_up) || keyboard_check(vk_down)) {
if (keyboard_check(vk_up) && !keyboard_check(vk_down)) {
vspd = -dash_speed/2;
} else
if (keyboard_check(vk_down) && !keyboard_check(vk_up)) {
vspd = dash_speed/2;
}
} else {
vspd = 0;
}
//Perform dash
alarm[0] = dash_time;
jdashing = true;
}
}
}
} else {
jdash_performed = false;
}
}
//Horizontal collision
if (place_meeting(x+hspd, y, obj_ground)) {
while (!place_meeting(x+sign(hspd), y, obj_ground)) {
x += sign(hspd);
}
hspd = 0;
}
//Initialize horizontal speed
x += hspd;
//Vertical collision
if (place_meeting(x, y+vspd, obj_ground)) {
while (!place_meeting(x, y+sign(vspd), obj_ground)) {
y += sign(vspd);
}
vspd = 0;
}
//Initialize vertical speed
y += vspd;
Code:
draw_sprite_ext(sprite_index, image_index, x, y, image_flip, image_yscale, image_angle, image_blend, image_alpha);
This code looks like it's very hard to understand, but if you have time, please don't pass by.
This is how it looks like: