Added demos and tools (WIP)
This commit is contained in:
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