0% found this document useful (0 votes)
15 views2 pages

Move GMK

This document contains GameMaker code for controlling player movement and orientation based on keyboard input. It checks keyboard input to control horizontal and vertical speed, prevents movement through blocks, orients the player sprite based on movement direction, and sets the appropriate idle or running sprite.

Uploaded by

Rafael Magno
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Move GMK

This document contains GameMaker code for controlling player movement and orientation based on keyboard input. It checks keyboard input to control horizontal and vertical speed, prevents movement through blocks, orients the player sprite based on movement direction, and sets the appropriate idle or running sprite.

Uploaded by

Rafael Magno
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

RGT=-1

LFT=-1
UP=-1
DWN=-1

hsp=0
vsp=0

spd=3

dir=0

-----------------------------------------------------------------------------------
----------------------

RGT=keyboard_check(ord("D"))
LFT=keyboard_check(ord("A"))
UP=keyboard_check(ord("W"))
DWN=keyboard_check(ord("S"))

//Walk
hsp=(RGT-LFT)*spd

if place_meeting(x+hsp,y,obj_Block) {
while !place_meeting(x+sign(hsp),y,obj_Block) {
x+=sign(hsp)
}
hsp=0
}

x+=hsp

vsp=(DWN-UP)*spd

if place_meeting(x,y+vsp,obj_Block) {
while !place_meeting(x,y+sign(vsp),obj_Block) {
y+=sign(vsp)
}
vsp=0
}
y+=vsp

//Mouse Orientation + Sprite Change


dir=floor((point_direction(x,y,mouse_x,mouse_y)+45)/90)

if hsp==0 and vsp==0 {


switch dir {
default:
sprite_index=spr_player_idle_right
break
case 1:
sprite_index=spr_player_idle_up
break
case 2:
sprite_index=spr_player_idle_left
break
case 3:
sprite_index=spr_player_idle_down
break
}
} else {
switch dir {
default:
sprite_index=spr_player_run_right
break
case 1:
sprite_index=spr_player_run_up
break
case 2:
sprite_index=spr_player_run_left
break
case 3:
sprite_index=spr_player_run_down
break
}
}

You might also like