junixbr
Member
I'm having a hard time running a small tile collision system.
The lateral (horizontal) collisions are perfect, the negative vertical collision too, but I cannot make the positive vertical collision work.
I don't know if it has any influence, but the game has infinite scroll (the screen does not depend on elements of the game to scroll).
The lateral (horizontal) collisions are perfect, the negative vertical collision too, but I cannot make the positive vertical collision work.
I don't know if it has any influence, but the game has infinite scroll (the screen does not depend on elements of the game to scroll).
GML:
#region moving
move_right = (keyboard_check(vk_right)) || (keyboard_check(ord("D"))) || (gamepad_button_check(0, gp_padr)) || (gamepad_axis_value(0, gp_axislh) > 0);
move_left = (keyboard_check(vk_left)) || (keyboard_check(ord("A"))) || (gamepad_button_check(0, gp_padl)) || (gamepad_axis_value(0, gp_axislh) < 0);
move_up = (keyboard_check(vk_up)) || (keyboard_check(ord("W"))) || (gamepad_button_check(0, gp_padu)) || (gamepad_axis_value(0, gp_axislv) < 0);
move_down = (keyboard_check(vk_down)) || (keyboard_check(ord("S"))) || (gamepad_button_check(0, gp_padd)) || (gamepad_axis_value(0, gp_axislv) > 0);
// collisions
input_direction = point_direction(0, 0, move_right - move_left, move_down - move_up);
input_magnitude = (move_right - move_left != 0) || (move_down - move_up != 0);
h_speed = lengthdir_x(input_magnitude * max_speed, input_direction);
v_speed = lengthdir_y(input_magnitude * max_speed, input_direction);
// horizontal
if (tilemap_get_at_pixel(tilemap_colisions, x + h_speed, y)) {
x -= x mod tile_size;
if (sign(h_speed) == 1) {
x += tile_size - 1;
h_speed = 0;
}
if (sign(h_speed) == -1) {
h_speed = 0;
}
}
if (move_right) {
image_xscale = 1;
y -= 0.5;
}
if (move_left) {
image_xscale = -1;
y -= 0.5;
}
x += h_speed;
// vertical
if (tilemap_get_at_pixel(tilemap_colisions, x, y + v_speed)) {
y -= y mod tile_size;
if (sign(v_speed) == 1) {
y += tile_size - 1;
v_speed = 0;
}
if (sign(v_speed) == - 1) {
y -= tile_size - 1;
v_speed = 0;
}
if (sign(v_speed) == 0) {
y += tile_size + 1;
v_speed = 0;
}
}
if (move_down) {
if (!move_left && !move_right) {
v_speed -= 1;
}
}
y += v_speed;
if (move_right || move_left || move_down || move_up) {
sprite_index = spr_player_walking_top;
player_botton.sprite_index = spr_player_walking_botton;
}
// idle
if (global.screen_scrolling) {
if (!move_right && !move_left && !move_up && !move_down) {
// scrolling
y -= 0.5;
}
}
#endregion