-- scripts/player.lua -- Globals provided each frame by the engine: -- self_x, self_y ← read AND write to move the node -- API: draw_rect draw_circle draw_text draw_line -- key_down key_pressed mouse_down mouse_x mouse_y -- log(msg) local speed = 200 local width = 40 local height = 50 local cr, cg, cb = 80, 160, 255 -- ← try changing this color and saving! function on_init() log("Player init at " .. self_x .. ", " .. self_y) -- self_x/self_y already hold the last known position, -- so hot-reload doesn't teleport the player back to origin. end function on_update(dt) if key_down(Key.RIGHT) or key_down(Key.D) then self_x = self_x + speed * dt end if key_down(Key.LEFT) or key_down(Key.A) then self_x = self_x - speed * dt end if key_down(Key.DOWN) or key_down(Key.S) then self_y = self_y + speed * dt end if key_down(Key.UP) or key_down(Key.W) then self_y = self_y - speed * dt end -- Clamp to game area (leave the editor panel free) self_x = math.max(0, math.min(1055, self_x)) self_y = math.max(0, math.min(665, self_y)) end function on_render() -- Body draw_rect(self_x, self_y, width, height, cr, cg, cb) -- Eyes (white + pupil) draw_circle(self_x + 11, self_y + 14, 6, 255, 255, 255) draw_circle(self_x + 29, self_y + 14, 6, 255, 255, 255) draw_circle(self_x + 13, self_y + 14, 3, 0, 0, 0) draw_circle(self_x + 31, self_y + 14, 3, 0, 0, 0) -- Label draw_text("Player", self_x, self_y - 16, 11, 180, 220, 255) end