-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
26 lines (23 loc) · 987 Bytes
/
Copy pathmain.lua
File metadata and controls
26 lines (23 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
-- hello neslua: a greeting + a little ship you fly around with the d-pad.
--
-- Build it with the sprite sheet:
-- neslua build examples/hello/main.lua --sheet examples/hello/ship.chr
--
-- The ship is a real hardware sprite: spr(0, x, y, 2, 2) is a 16x16 sprite (a
-- 2x2 block of 8x8 tiles) from the imported sheet, DMA'd to the PPU every frame,
-- so it moves for free. nes.spal(1) draws it in the cyan sub-palette. Visible
-- screen is 256x224.
local x = 120
local y = 120
function _update60() -- 60fps: read the d-pad, move the ship
if (btn(1)) then x += 2 end -- right
if (btn(0)) then x -= 2 end -- left
if (btn(3)) then y += 2 end -- down
if (btn(2)) then y -= 2 end -- up
end
function _draw() -- runs every frame
cls(0) -- black backdrop (space)
print("hello neslua", 72, 88, 7)
nes.spal(1) -- cyan sprite sub-palette
spr(0, x, y, 2, 2) -- the ship (16x16)
end