Base commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
-- scripts/box.lua
|
||||
-- Autonomous bouncing box.
|
||||
-- Edit vx, vy, or the color below, save the file, and watch it update live!
|
||||
|
||||
local vx, vy = 2050, 110 -- ← try cranking these up
|
||||
local size = 60
|
||||
local r, g, b = 255, 180, 50 -- ← golden amber box
|
||||
|
||||
function on_init()
|
||||
log("Box ready – bouncing at vx=" .. vx .. " vy=" .. vy)
|
||||
end
|
||||
|
||||
function on_update(dt)
|
||||
self_x = self_x + vx * dt
|
||||
self_y = self_y + vy * dt
|
||||
|
||||
-- Bounce off the four walls (respecting the editor panel)
|
||||
if self_x < 0 or self_x + size > 1055 then
|
||||
vx = -vx
|
||||
self_x = math.max(0, math.min(1055 - size, self_x))
|
||||
end
|
||||
if self_y < 0 or self_y + size > 720 then
|
||||
vy = -vy
|
||||
self_y = math.max(0, math.min(720 - size, self_y))
|
||||
end
|
||||
end
|
||||
|
||||
function on_render()
|
||||
draw_rect(self_x, self_y, size, size, r, g, b)
|
||||
|
||||
-- Velocity debug overlay
|
||||
local speed_label = "v=" .. math.floor(math.sqrt(vx * vx + vy * vy))
|
||||
draw_text(speed_label, self_x + 4, self_y + size / 2 - 6, 12, 0, 0, 0)
|
||||
end
|
||||
@@ -0,0 +1,42 @@
|
||||
-- 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
|
||||
Reference in New Issue
Block a user