Added demos and tools (WIP)
This commit is contained in:
94
demos/breakout.lua
Normal file
94
demos/breakout.lua
Normal file
@@ -0,0 +1,94 @@
|
||||
function init()
|
||||
setmode(1)
|
||||
reset()
|
||||
end
|
||||
|
||||
function reset()
|
||||
bx,by=20,28
|
||||
dx,dy=-1+rnd(1)*2,-1
|
||||
px=18
|
||||
wait=1
|
||||
speed=6
|
||||
bricks = {}
|
||||
for i=0,35 do bricks[i]=COLOR_RED end
|
||||
for i=36,71 do bricks[i]=COLOR_BROWN end
|
||||
for i=72,107 do bricks[i]=COLOR_GREEN end
|
||||
for i=108,143 do bricks[i]=COLOR_YELLOW end
|
||||
end
|
||||
|
||||
function update()
|
||||
-- move ball
|
||||
wait=wait-1
|
||||
if wait==0 then
|
||||
wait=speed
|
||||
bx=bx+dx
|
||||
by=by+dy
|
||||
if speed<6 then
|
||||
if bx==2 or bx==37 then dx=-dx play("o3l0c") end
|
||||
if by<9 then
|
||||
local index=flr(bx/2)-1+(by-1)*18
|
||||
if bricks[index]~=COLOR_BLACK then
|
||||
play("o5l0c")
|
||||
bricks[index]=COLOR_BLACK
|
||||
dy=-dy
|
||||
else
|
||||
if by==1 then dy=-dy play("o3l0c") end
|
||||
end
|
||||
end
|
||||
if by==28 and bx>=px and bx<=px+4 then
|
||||
play("o4l0c")
|
||||
dy=-dy
|
||||
end
|
||||
if by==29 then
|
||||
play("l0o3bagfedc")
|
||||
reset()
|
||||
end
|
||||
else
|
||||
if bx==2 or bx==37 then dx=-dx end
|
||||
if by==9 or by==29 then dy=-dy end
|
||||
end
|
||||
end
|
||||
|
||||
-- move paddle
|
||||
if btn(KEY_LEFT) and px>2 then px=px-1 end
|
||||
if btn(KEY_RIGHT) and px<34 then px=px+1 end
|
||||
|
||||
-- clear screen
|
||||
paper(COLOR_BLACK)
|
||||
cls()
|
||||
|
||||
-- draw white border
|
||||
ink(COLOR_WHITE)
|
||||
print("\150\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\156",1,0)
|
||||
for i=1,29 do
|
||||
print("\149",1,i)
|
||||
print("\149",38,i)
|
||||
end
|
||||
|
||||
-- draw bricks
|
||||
for i=0,143 do
|
||||
color(0,bricks[i])
|
||||
print("\095\003",2+2*(i%18),1+flr(i/18))
|
||||
end
|
||||
|
||||
--draw ball
|
||||
color(COLOR_WHITE,COLOR_BLACK)
|
||||
print("\233",bx,by)
|
||||
|
||||
-- draw paddle
|
||||
ink(COLOR_LIGHT_BLUE)
|
||||
for i=0,3 do print("\131",px+i,29) end
|
||||
|
||||
if speed==6 then
|
||||
ink(rnd(16))
|
||||
print("BREAKOUT",16,13)
|
||||
ink(COLOR_WHITE)
|
||||
print("Press '1' to play EASY",9,18)
|
||||
print("Press '2' to play NORMAL",8,20)
|
||||
print("Press '3' to play HARD",9,22)
|
||||
|
||||
if btn(KEY_1) then reset() speed=4 end
|
||||
if btn(KEY_2) then reset() speed=3 end
|
||||
if btn(KEY_3) then reset() speed=2 end
|
||||
end
|
||||
end
|
||||
140
demos/pong.lua
Normal file
140
demos/pong.lua
Normal file
@@ -0,0 +1,140 @@
|
||||
function init()
|
||||
setmode(1)
|
||||
setchar(94, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
|
||||
piano = { "_____", "\143\143\143\154\154", " ", "\143\143\143\154\154", "^^^^^", "_____",
|
||||
"\143\143\143\154\154", " ", "\143\143\143\154\154", " ", "\143\143\143\154\154", "^^^^^" }
|
||||
notes = {"C ", "C#", "D ", "D#", "E ", "F ", "F#", "G ", "G#", "A ", "A#", "B "}
|
||||
pnotes = {"c", "c#", "d", "d#", "e", "f", "f#", "g", "g#", "a", "a#", "b"}
|
||||
|
||||
piano_pos=18
|
||||
mousewait=0
|
||||
compas = 0
|
||||
compasos = {}
|
||||
for i=0,31 do compasos[i] = 108 end
|
||||
compasos[0] = 49
|
||||
compasos[1] = 49
|
||||
compasos[2] = 49
|
||||
compasos[7] = 50
|
||||
compasos[8] = 50
|
||||
compasos[9] = 50
|
||||
compasos[10] = 50
|
||||
|
||||
old_mouse_x,old_mouse_y = 0,0
|
||||
end
|
||||
|
||||
function update()
|
||||
color(COLOR_WHITE, COLOR_BLACK)
|
||||
cls()
|
||||
for i=0,11 do
|
||||
local k = 11-i
|
||||
local pos = ((piano_pos+i)%12)+1
|
||||
local oct = flr((piano_pos+i)/12)+1
|
||||
color(COLOR_WHITE, COLOR_BLACK)
|
||||
print(notes[pos], 1, 10+k)
|
||||
color(COLOR_BLACK, COLOR_WHITE)
|
||||
print(piano[pos], 3, 10+k)
|
||||
color(COLOR_BLACK, COLOR_LIGHT_GRAY+flr(oct%2))
|
||||
print("_______\003_______\003_______\003_______\003", 8, 10+k)
|
||||
color(COLOR_BLACK, oct)
|
||||
if pos==6 then
|
||||
print(tostr(oct), 0, 10+k)
|
||||
else
|
||||
print(" ", 0, 10+k)
|
||||
end
|
||||
end
|
||||
|
||||
piano_pos = mid(0, piano_pos+mousewheel(), 96)
|
||||
|
||||
if mousewait>0 then mousewait=mousewait-1 end
|
||||
if mousebutton(1) and mousewait==0 then
|
||||
if mousex()<8 and mousey()>=10 and mousey()<=21 then
|
||||
local note = piano_pos+(11-(mousey()-10))
|
||||
play("l4o"..tostr(note/12)..pnotes[(note%12)+1])
|
||||
mousewait=10
|
||||
end
|
||||
end
|
||||
|
||||
for i=0,31 do
|
||||
local n = compasos[i]
|
||||
if n>=piano_pos and n<=piano_pos+11 then
|
||||
if i>0 and n~=compasos[i-1] then
|
||||
local oct = flr(n/12)+1
|
||||
color(COLOR_BLACK, COLOR_LIGHT_GRAY+flr(oct%2))
|
||||
print("\003",7+i,10+11-(n-piano_pos))
|
||||
end
|
||||
color(COLOR_BLACK,COLOR_LIGHT_RED)
|
||||
if i==31 or compasos[i+1]~=n then
|
||||
print("\003",8+i,10+11-(n-piano_pos))
|
||||
else
|
||||
print("_",8+i,10+11-(n-piano_pos))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if mousex()>=8 and mousey()>=10 and mousey()<=21 then
|
||||
if mousebutton(1) then
|
||||
compasos[mousex()-8] = piano_pos+11-(mousey()-10)
|
||||
if old_mouse_x ~= mousex() or old_mouse_y ~= mousey() then
|
||||
local note = piano_pos+11-(mousey()-10)
|
||||
play("l4o"..tostr(note/12)..pnotes[(note%12)+1])
|
||||
end
|
||||
old_mouse_x,old_mouse_y = mousex(),mousey()
|
||||
else
|
||||
old_mouse_x,old_mouse_y = 0,0
|
||||
if mousebutton(3) then
|
||||
compasos[mousex()-8] = 108
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if btnp(KEY_RETURN) then play_song() end
|
||||
|
||||
color(15,0)print("\143",0,0)
|
||||
color(14,0)print("\143",1,0)
|
||||
color(12,0)print("\143",2,0)
|
||||
color(6,0)print("\143",3,0)
|
||||
color(4,0)print("\143",4,0)
|
||||
color(5,4)print("\143",5,0)
|
||||
color(9,0)print("\143",6,0)
|
||||
color(1,0)print("\143",7,0)
|
||||
color(0,0)print("\143",8,0)
|
||||
|
||||
end
|
||||
|
||||
function play_song()
|
||||
local note_size = {1,2,3,4,6,8,12,16,24,32}
|
||||
local note_names = {"c","c#","d", "d#","e","f","f#","g","g#","a","a#","b"}
|
||||
local song = ""
|
||||
|
||||
local current_note = 255
|
||||
local current_octave = 4
|
||||
local p=0
|
||||
while p<32 do
|
||||
current_note = compasos[p]
|
||||
local d=0
|
||||
while current_note == compasos[p] do d=d+1 p=p+1 end
|
||||
local o = flr(current_note/12)
|
||||
if o<9 and current_octave~=o then
|
||||
current_octave=o
|
||||
song=song.."o"..tostr(o)
|
||||
end
|
||||
local n = current_note%12
|
||||
local note = note_names[n+1]
|
||||
while d>0 do
|
||||
local i=1
|
||||
while d>note_size[i] do i=i+1 end
|
||||
if note_size[i]>d then i=i-1 end
|
||||
d=d-note_size[i]
|
||||
if current_length~=i-1 then
|
||||
current_length = i-1
|
||||
song=song.."l"..tostr(i-1)
|
||||
end
|
||||
if o<9 then
|
||||
song=song..note
|
||||
else
|
||||
song=song.."r"
|
||||
end
|
||||
end
|
||||
end
|
||||
play(song)
|
||||
end
|
||||
Reference in New Issue
Block a user