B
Brackleforth
Guest
Hello,
I've been following along with HeartBeast's random level generation tutorials, and completed all 7 of them. Afterwards, I adjusted the code to have grid-based movement, so my character moves in a 32 x 32 grid. I want to make a roguelike.
The issue I'm running into is how enemies should collide with each other when they are bunched up trying to reach the player object. The enemies move one unit on the grid, towards the player, every time the player moves. I put that feature in, but the collisions are difficult, since two enemies generally collide with each other in the same moment in the same spot, but they need to have different reactions.
Here is the code I have at my disposal - pretty much directly from HeartBeast's tutorials:
Here is scr_move:
Here is scr_grid_place_meeting:
Here is scr_get_path_to_player:
... in which alarm 0 simply has this...
I appreciate any help. This appears to be a troublesome thing that lots of people have run into with limited success.
I've been following along with HeartBeast's random level generation tutorials, and completed all 7 of them. Afterwards, I adjusted the code to have grid-based movement, so my character moves in a 32 x 32 grid. I want to make a roguelike.
The issue I'm running into is how enemies should collide with each other when they are bunched up trying to reach the player object. The enemies move one unit on the grid, towards the player, every time the player moves. I put that feature in, but the collisions are difficult, since two enemies generally collide with each other in the same moment in the same spot, but they need to have different reactions.
Here is the code I have at my disposal - pretty much directly from HeartBeast's tutorials:
Here is scr_move:
Code:
/// move(hspd, vspd)
var hspd = argument[0];
var vspd = argument[1];
// Horizontal collisions
if (scr_grid_place_meeting(x+hspd, y)) {
while (!scr_grid_place_meeting(x+sign(hspd), y)) {
x+=sign(hspd);
}
hspd = 0;
}
// Move horizontally
x+=hspd;
// Vertival collisions
if (scr_grid_place_meeting(x, y+vspd)) {
while(!scr_grid_place_meeting(x, y+sign(vspd))) {
y+=sign(vspd);
}
vspd = 0;
}
// Move vertically
y+=vspd;
Here is scr_grid_place_meeting:
Code:
///grid_place_meeting(x, y)
var xx = argument[0];
var yy = argument[1];
// Remember out position
var xp = x;
var yp = y;
// Update the position for the bbox calculations
x = xx;
y = yy;
// Check for x meeting
var x_meeting = (obj_level.grid[# bbox_right div CELL_WIDTH, bbox_top div CELL_HEIGHT] != FLOOR) ||
(obj_level.grid[# bbox_left div CELL_WIDTH, bbox_top div CELL_HEIGHT] != FLOOR);
// Check for y meeting
var y_meeting = (obj_level.grid[# bbox_right div CELL_WIDTH, bbox_bottom div CELL_HEIGHT] != FLOOR) ||
(obj_level.grid[# bbox_left div CELL_WIDTH, bbox_bottom div CELL_HEIGHT] != FLOOR);
var center_meeting = obj_level.grid[# xx div CELL_WIDTH, yy div CELL_HEIGHT] != FLOOR;
// Move back
x = xp;
y = yp;
// Return true or false
return x_meeting || y_meeting || center_meeting;
Here is scr_get_path_to_player:
Code:
/// get_path_to_player()
if keyboard_check_pressed(vk_left) or keyboard_check_pressed(vk_right) or keyboard_check_pressed(vk_up) or keyboard_check_pressed(vk_down)
{
if (instance_exists(obj_player)) {
var xx = (obj_player.x div CELL_WIDTH)*CELL_WIDTH+CELL_WIDTH/2;
var yy = (obj_player.y div CELL_HEIGHT)*CELL_HEIGHT+CELL_HEIGHT/2;
if (mp_grid_path(obj_level.grid_path, path, x, y, xx, yy, false)) {
path_start(path, 32, path_action_stop, false);
alarm[0] = 1;
}
}
}
... in which alarm 0 simply has this...
Code:
path_end();
I appreciate any help. This appears to be a troublesome thing that lots of people have run into with limited success.