bkcarter77
Member
So I'm trying to do tileset collision and I got it partly working. it works from the left and bottom of the tileset and from the right and top I go through the tileset and stop while standing on it. I'm using a virtual joystick and not getting my head wrapped around it. here is the code for the joystick. It works all the way with the keyboard arrow keys but I really need it working with the joystick as it's going to be a mobile game.
and here is the code for the collision detection
How would I go about doing this?
Code:
if(device_mouse_x_to_gui(0) < get_stop_view/2) {
guiposX = event_data[? "guiposX"];
guiposY = event_data[? "guiposY"];
// jDis = joystick distance
// jDir = joystick direction
var jDis = min(30, point_distance(guistartposX, guistartposY, guiposX, guiposY));
var jDir = point_direction(guistartposX, guistartposY, guiposX, guiposY);
guiposX = guistartposX + lengthdir_x(jDis, jDir);
guiposY = guistartposY + lengthdir_y(jDis, jDir);
for(var i=0; i<2; i++) {
if (jDis >=2) && (device_mouse_check_button(i, mb_left)) {
obj_blob.direction = jDir;
obj_blob.speed = jDis/10;
show_debug_message(obj_blob.direction);
}
if (jDis = 0) { obj_blob.speed = 0 }
}
jVisible = true;
}
Code:
var bbox_side;
key_right = keyboard_check(vk_right);
key_left = keyboard_check(vk_left);
key_up = keyboard_check(vk_up);
key_down = keyboard_check(vk_down);
hsp = (key_right - key_left) * 2;
vsp = (key_down - key_up) * 2;
//Keep player inside the map
if (x <= 64) x = 64;
if (x >= room_width - 64) x = room_width - 64;
if (y <= 64) y = 64;
if (y >= room_height - 64) y = room_height - 64;
for(var i=0; i<2; i++) {
}
x += hsp;
if(speed = 0) {
image_speed = 0;
} else {
image_speed = .2;
}
// Horizontal collison
if (hsp > 0) bbox_side = bbox_right; else bbox_side = bbox_left;
if (tilemap_get_at_pixel(tilemap,bbox_side+hsp,bbox_top) != 0) || (tilemap_get_at_pixel(tilemap,bbox_side+hsp,bbox_bottom) != 0)
{
if (hsp > 0) x = x - (x mod 32) + 31 - (bbox_right - x);
else x = x - (x mod 32) - (bbox_left - x);
hsp = 0;
}
x += hsp;
// Vertical collison
if (vsp > 0) bbox_side = bbox_bottom; else bbox_side = bbox_top;
if (tilemap_get_at_pixel(tilemap,bbox_left,bbox_side+vsp) != 0) || (tilemap_get_at_pixel(tilemap,bbox_right,bbox_side+vsp) != 0)
{
if (vsp > 0) y = y - (y mod 32) + 31 - (bbox_bottom - y);
else y = y - (y mod 32) - (bbox_top - y);
vsp = 0;
}
y += vsp;
Last edited: