x and y (or motion actions).spr_player).obj_player) placed in a room (e.g., rm_level1).moveSpeed).if ( ... ) { ... }.spr_player and obj_player using that sprite.1024 × 768 (or your site standard). Place obj_player near center.moveSpeed = 4sprite_index = spr_playerhInput = 0, vInput = 0hInput = 1hInput = -1vInput = 1vInput = -1hInput and vInput ≠ 0, multiply each by 0.707x = x + hInput * moveSpeedy = y + vInput * moveSpeedx < sprite_width/2 → set to sprite_width/2x > room_width - sprite_width/2 → set to that valuey < sprite_height/2 → set to sprite_height/2y > room_height - sprite_height/2 → set to that valueCreate Event (obj_player)
moveSpeed = 4;
Step Event (obj_player)
// 1) Read input
var h = 0;
var v = 0;
if (keyboard_check(vk_right) || keyboard_check(ord("D"))) h += 1;
if (keyboard_check(vk_left) || keyboard_check(ord("A"))) h -= 1;
if (keyboard_check(vk_down) || keyboard_check(ord("S"))) v += 1;
if (keyboard_check(vk_up) || keyboard_check(ord("W"))) v -= 1;
// 2) Optional: normalize diagonals so diagonals aren't faster
if (h != 0 && v != 0) {
var diag = 1 / sqrt(2); // ≈ 0.707
h *= diag;
v *= diag;
}
// 3) Move
x += h * moveSpeed;
y += v * moveSpeed;
// 4) Clamp to room bounds using sprite size
var halfW = sprite_width * 0.5;
var halfH = sprite_height * 0.5;
x = clamp(x, halfW, room_width - halfW);
y = clamp(y, halfH, room_height - halfH);
x = -10 before clamping.obj_player?moveSpeed.room_width/room_height and sprite_width/sprite_height correctly.var base = 4;
moveSpeed = keyboard_check(vk_shift) ? 6 : base;
// Create
vx = 0; vy = 0; accel = 0.5; maxSpeed = 4; fric = 0.85;
// Step (after computing h and v)
vx = (h != 0) ? clamp(vx + h * accel, -maxSpeed, maxSpeed) : vx * fric;
vy = (v != 0) ? clamp(vy + v * accel, -maxSpeed, maxSpeed) : vy * fric;
x += vx; y += vy;
var halfW = sprite_width * 0.5, halfH = sprite_height * 0.5;
x = clamp(x, halfW, room_width - halfW);
y = clamp(y, halfH, room_height - halfH);
if (x < -sprite_width) x = room_width + sprite_width;
if (x > room_width + sprite_width) x = -sprite_width;
if (y < -sprite_height) y = room_height + sprite_height;
if (y > room_height + sprite_height) y = -sprite_height;
gamepad_axis_value()).| Category | Exceeds | Meets | Approaches |
|---|---|---|---|
| Input handling (3) | Arrow+WASD; continuous; clean structure | Works for both schemes | Only one scheme or inconsistent |
| Movement math (3) | Uses vars; diagonal normalization | Uses vars; correct 4-way move | Hard-coded values; jittery |
| Bounds (3) | Robust clamping with sprite half-size | Clamps reliably to room | Occasional out-of-bounds |
| Clarity (1) | Well-commented & readable | Some comments / labels | Minimal explanation |
SET moveSpeed ← 4
EVERY FRAME:
h ← 0; v ← 0
IF Right OR D pressed: h ← h + 1
IF Left OR A pressed: h ← h - 1
IF Down OR S pressed: v ← v + 1
IF Up OR W pressed: v ← v - 1
IF h ≠ 0 AND v ≠ 0:
h ← h / √2
v ← v / √2
x ← x + h * moveSpeed
y ← y + v * moveSpeed
x ← CLAMP(x, sprite_width/2, room_width - sprite_width/2)
y ← CLAMP(y, sprite_height/2, room_height - sprite_height/2)
Submit the following to Google Classroom and drop it off into google drive: