34 lines
1.1 KiB
Lua
34 lines
1.1 KiB
Lua
-- scripts/player.lua
|
|
-- Base node: the script handles all drawing.
|
|
|
|
local speed = 200
|
|
local w, h = 40, 50
|
|
|
|
---@param self NodeBase
|
|
function on_init(self)
|
|
log("Player spawned at " .. (self.x) .. ", " .. (self.y))
|
|
end
|
|
|
|
---@param self NodeBase
|
|
---@param dt number
|
|
function on_update(self, 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
|
|
|
|
self.x = math.max(0, math.min(1030, self.x))
|
|
self.y = math.max(0, math.min(665, self.y))
|
|
end
|
|
|
|
---@param self NodeBase
|
|
function on_render(self)
|
|
draw_rect(self.x, self.y, w, h, 80, 160, 255)
|
|
-- eyes
|
|
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)
|
|
draw_text("Player", self.x, self.y - 16, 11, 180, 220, 255)
|
|
end
|