This lesson shows how to make a ball object move Up, Down, Left, and Right using the arrow keys in GameMaker.
spr_ballobj_ballspr_ballThis sets how fast the ball moves.
speed = 4;
This code checks arrow keys and moves in that direction.
// default: no movement
direction = -1;
// up
if (keyboard_check(vk_up)) {
direction = 90;
}
// down
if (keyboard_check(vk_down)) {
direction = 270;
}
// left
if (keyboard_check(vk_left)) {
direction = 180;
}
// right
if (keyboard_check(vk_right)) {
direction = 0;
}
obj_ball into the room
if (keyboard_check(vk_up)) { direction = 90; speed = 4; }
else if (keyboard_check(vk_down)) { direction = 270; speed = 4; }
else if (keyboard_check(vk_left)) { direction = 180; speed = 4; }
else if (keyboard_check(vk_right)){ direction = 0; speed = 4; }
else { speed = 0; }
Submit 3 files:
Save the files into your google drives under your class period and upload to Google Classroom.