Skip to content

Instantly share code, notes, and snippets.

@YellowAfterlife
Created September 16, 2015 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YellowAfterlife/4befb658e6bd78718132 to your computer and use it in GitHub Desktop.
Save YellowAfterlife/4befb658e6bd78718132 to your computer and use it in GitHub Desktop.
Movement code for GameMaker using bbox_ variables and collision_line calls.
if (keyboard_check(vk_left)) repeat (3) {
var _x = bbox_left - 1;
if (!collision_line(_x, bbox_top, _x, bbox_bottom, obj_solid, false, true)) x -= 1;
}
if (keyboard_check(vk_right)) repeat (3) {
var _x = bbox_right + 1;
if (!collision_line(_x, bbox_top, _x, bbox_bottom, obj_solid, false, true)) x += 1;
}
if (keyboard_check(vk_up)) repeat (3) {
var _y = bbox_top - 1;
if (!collision_line(bbox_left, _y, bbox_right, _y, obj_solid, false, true)) y -= 1;
}
if (keyboard_check(vk_down)) repeat (3) {
var _y = bbox_bottom + 1;
if (!collision_line(bbox_left, _y, bbox_right, _y, obj_solid, false, true)) y += 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment