Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //movement code
- if canmove{ //variables used for other stuff
- if hascontrol{
- if (keyboard_check_direct(ord('W'))&&keyboard_check_direct(ord('A'))){
- if place_meeting(x-3, y, obj_newWall)&&!place_meeting(x, y-3, obj_newWall){ //if about to collide with something horizontally BUT not vertically, go up
- motion_set(90, 3);
- }
- else if !place_meeting(x-3, y, obj_newWall)&&place_meeting(x, y-3, obj_newWall){ //if about to collide with something vertically BUT not horizontally, move horizontally NOT WORKING AS INTENDED
- motion_set(180, 3);
- }
- else if place_meeting(x-3, y, obj_newWall)&&place_meeting(x, y-3, obj_newWall) // if about to collide both ways, just stop
- motion_set(direction, 0)
- else
- motion_set(135, 3); // otherwise, move normally
- }
- else if (keyboard_check_direct(ord('W'))&&keyboard_check_direct(ord('D'))){
- if place_meeting(x+3, y, obj_newWall)&&!place_meeting(x, y-3, obj_newWall){
- motion_set(90, 3); //CONTINUE THE PATTERN
- }
- else if !place_meeting(x+3, y, obj_newWall)&&place_meeting(x, y-3, obj_newWall){
- motion_set(0, 3);
- }
- else if place_meeting(x+3, y, obj_newWall)&&place_meeting(x, y-3, obj_newWall)
- motion_set(direction, 0)
- else motion_set(45, 3);
- }
- else if (keyboard_check_direct(ord('S'))&&keyboard_check_direct(ord('D'))){
- if place_meeting(x+3, y, obj_newWall)&&!place_meeting(x, y+3, obj_newWall){
- motion_set(270, 3);
- }
- else if !place_meeting(x+3, y, obj_newWall)&&place_meeting(x, y+3, obj_newWall){
- motion_set(0, 3);
- }
- else if place_meeting(x+3, y, obj_newWall)&&place_meeting(x,y+3, obj_newWall)
- motion_set(direction, 0)
- else motion_set(315, 3);
- }
- else if (keyboard_check_direct(ord('S'))&&keyboard_check_direct(ord('A'))){
- if place_meeting(x-3, y, obj_newWall)&&!place_meeting(x, y+3, obj_newWall){
- motion_set(270, 3);
- }
- else if !place_meeting(x-3, y, obj_newWall)&&place_meeting(x, y+3, obj_newWall){
- motion_set(180, 3);
- }
- else if place_meeting(x-3, y, obj_newWall)&&place_meeting(x, y+3, obj_newWall)
- motion_set(direction, 0)
- else motion_set(225, 3);
- }
- else{
- if keyboard_check_direct(ord('W'))
- {
- motion_set(90, 3);
- if place_meeting(x, y-3, obj_newWall) // set motion first, then check for immediate collision. if collision imminent, keep direction and speed = 0
- motion_set(90, 0); // pattern continues below
- }
- if keyboard_check_direct(ord('S'))
- {
- motion_set(270, 3);
- if place_meeting(x, y+3, obj_newWall)
- motion_set(270, 0);
- }
- if keyboard_check_direct(ord('A'))
- {
- motion_set(180, 3);
- if place_meeting(x-3, y, obj_newWall)
- motion_set(180, 0);
- }
- if keyboard_check_direct(ord('D'))
- {
- motion_set(0, 3);
- if place_meeting(x+3, y, obj_newWall)
- motion_set(0,0);
- }
- }
- if keyboard_check_released(ord('W'))
- or keyboard_check_released(ord('S'))
- or keyboard_check_released(ord('D')) //Stop moving when keys are released, don't change direction.
- or keyboard_check_released(ord('A'))
- {
- speed = 0
- }
- }
- }
- else speed = 0;
Advertisement
Add Comment
Please, Sign In to add comment