Music tool WIP
This commit is contained in:
94
breakout.lua
94
breakout.lua
@@ -1,94 +0,0 @@
|
||||
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
|
||||
91
mapedit.lua
91
mapedit.lua
@@ -1,91 +0,0 @@
|
||||
ind = 22
|
||||
function init()
|
||||
setmode(2)
|
||||
map = {}
|
||||
col = {}
|
||||
for i=0,299 do
|
||||
map[i] = 32
|
||||
col[i] = 0x0f
|
||||
end
|
||||
map[ind] = 65
|
||||
sel_col = 0x0f
|
||||
sel_chr = 65
|
||||
end
|
||||
|
||||
blink=30
|
||||
|
||||
function update()
|
||||
if btn(KEY_TAB) then
|
||||
draw_picker()
|
||||
update_picker()
|
||||
else
|
||||
draw_map()
|
||||
--update_map()
|
||||
end
|
||||
end
|
||||
|
||||
function draw_picker()
|
||||
for i=0,255 do
|
||||
poke(i, i)
|
||||
poke(300+i, sel_col)
|
||||
end
|
||||
for i=0,15 do
|
||||
poke(580+i, i<<4)
|
||||
poke(560+i, i<<4)
|
||||
poke(280+i, 32)
|
||||
poke(260+i, 32)
|
||||
end
|
||||
poke(580, 15) poke(560, 15)
|
||||
poke(260+(sel_col&0xf), 203)
|
||||
poke(280+(sel_col>>4), 203)
|
||||
local mx, my = mousex(), mousey()
|
||||
|
||||
if my<13 then
|
||||
poke(300+(mx+my*20), 0x4e)
|
||||
print(mx+my*20, 16, 13)
|
||||
elseif my>=13 then
|
||||
poke(mx+my*20, 144)
|
||||
end
|
||||
end
|
||||
|
||||
function update_picker()
|
||||
local mx, my = mousex(), mousey()
|
||||
if mousebutton(1) then
|
||||
if my<13 then
|
||||
sel_chr = mx+my*20
|
||||
else
|
||||
if mx < 16 then
|
||||
if my == 13 then
|
||||
sel_col = (sel_col & 0xf0) + mx
|
||||
else
|
||||
sel_col = (sel_col & 0x0f) + (mx << 4)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function draw_map()
|
||||
for i=0,299 do
|
||||
poke(i, map[i])
|
||||
poke(300+i, col[i])
|
||||
end
|
||||
|
||||
local mx, my = mousex(), mousey()
|
||||
if mousebutton(1) then
|
||||
map[mx+my*20] = sel_chr
|
||||
col[mx+my*20] = sel_col
|
||||
end
|
||||
if btn(KEY_SPACE) then
|
||||
sel_chr = peek(mx+my*20)
|
||||
sel_col = peek(300+mx+my*20)
|
||||
end
|
||||
|
||||
blink = blink - 1
|
||||
if blink < 30 then
|
||||
if blink==0 then blink = 60 end
|
||||
local mx, my = mousex(), mousey()
|
||||
local c = peek(300+(mx+my*20))
|
||||
poke(300+(mx+my*20), c~0xff)
|
||||
end
|
||||
end
|
||||
115
pong.lua
115
pong.lua
@@ -1,115 +0,0 @@
|
||||
function init()
|
||||
-- mode 1: 40x30 characters
|
||||
setmode(1)
|
||||
-- prepare everything for the match
|
||||
reset_match()
|
||||
p1,p2=0,0 -- reset scores
|
||||
end
|
||||
|
||||
function update()
|
||||
cls()
|
||||
|
||||
-- ball movement
|
||||
-- 'wait' is a counter to skip some cycles before moving the ball, so it starts slower
|
||||
-- 'speed' defines how many cycles to skip. Every 5 hits to the paddles 'speed' goes down by 1, effectively increasing the ball's speed
|
||||
-- 'speed' is reset every point
|
||||
wait=wait-1
|
||||
if wait==0 then
|
||||
wait=speed
|
||||
-- move ball
|
||||
bx=bx+dx
|
||||
by=by+dy
|
||||
-- if ball hits top or down walls, bounce
|
||||
if by==0 or by==29 then
|
||||
dy=-dy
|
||||
if playing then play("a") end -- if we are not playing, be quiet
|
||||
end
|
||||
|
||||
-- during a match, paddles bounce the ball and left and right walls award points
|
||||
-- but before or after a match the ball just bounces around
|
||||
if playing then
|
||||
-- if ball hits left or right ball, reset the ball and award a point to the opposing paddle
|
||||
if bx==0 then p2=p2+1 reset_ball() end
|
||||
if bx==39 then p1=p1+1 reset_ball() end
|
||||
-- if ball hits paddle, bounce
|
||||
if (bx==1 and by>=y1 and by<=y1+4) or (bx==38 and by>=y2 and by<=y2+4) then
|
||||
play("c")
|
||||
dx=-dx
|
||||
-- also, increase hits. Every 5 hits the ball will speed up (only if it's not already as fast as possible)
|
||||
hits=hits+1
|
||||
if (hits%5 == 0) and (speed>0) then speed=speed-1 end
|
||||
end
|
||||
else
|
||||
-- when not playing, just bounce freely
|
||||
if bx==0 or bx==39 then dx=-dx end
|
||||
end
|
||||
end
|
||||
|
||||
-- player 1 controls
|
||||
if btn(KEY_Q) and y1>0 then y1=y1-1 end
|
||||
if btn(KEY_A) and y1<25 then y1=y1+1 end
|
||||
|
||||
-- player 2 controls
|
||||
if btn(KEY_UP) and y2>0 then y2=y2-1 end
|
||||
if btn(KEY_DOWN) and y2<25 then y2=y2+1 end
|
||||
|
||||
-- draw net
|
||||
if playing then for i=0,29 do print("\145",20,i) end end
|
||||
|
||||
-- draw score
|
||||
print(p1,18,3)
|
||||
print(p2,22,3)
|
||||
|
||||
-- draw ball
|
||||
print("\143",flr(bx),flr(by))
|
||||
|
||||
-- draw paddles
|
||||
for i=0,4 do
|
||||
print("\143",1,y1+i)
|
||||
print("\143",38,y2+i)
|
||||
end
|
||||
|
||||
if not playing then
|
||||
-- while not playing show the messages
|
||||
if p1==10 then print("PLAYER 1 WINS!", 14, 8)
|
||||
elseif p2==10 then print("PLAYER 2 WINS!", 14, 8)
|
||||
else print("PONG!", 18, 10) end
|
||||
|
||||
print("Press SPACE to play", 11, 20)
|
||||
if btn(KEY_SPACE) then
|
||||
start_match()
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function start_match()
|
||||
playing=true
|
||||
p1,p2=0,0 -- reset scores
|
||||
end
|
||||
|
||||
function reset_match()
|
||||
play("l2drl2d#l4e>l2crr<e>crr<l4e>crrrl2r cl4dl2d#l4el2cl4del2r<b>l4dl2rl4crrrl2r< drl2d#l4e>l2crr<e>crr<l4e>crrrl2r< l2argl4f#l2a>l4cl2errdl4cl2<al4>drrrl2r< l2drl2d#l4e>l2crr<e>crr<l4e>crrrl2r cl4dl2d#l4el2cl4del2r<b>l4dl2rl4crrrl2r<")
|
||||
|
||||
playing=false
|
||||
bx,by=20,15 -- init ball's position
|
||||
dx,dy=1,1 -- init ball's direction
|
||||
y1,y2=14,14 -- init paddle's y coordinate
|
||||
wait=1 -- reset wait counter
|
||||
speed=4 -- reset speed
|
||||
hits=0 -- reset hits counter
|
||||
end
|
||||
|
||||
function reset_ball()
|
||||
play("l0o3bagfedc") -- play sad tune
|
||||
bx,by=20,15 -- reset ball's position
|
||||
speed=4 -- reset speed
|
||||
hits=0 -- reset hits counter
|
||||
dx=-dx -- invert x direction
|
||||
|
||||
-- si algu arriba a 10, la partida acaba
|
||||
if p1==10 or p2==10 then
|
||||
playing=false
|
||||
play("o5l1crl0ergrl4o6c")
|
||||
end
|
||||
end
|
||||
106
scredit.lua
106
scredit.lua
@@ -1,106 +0,0 @@
|
||||
ind = 22
|
||||
function init()
|
||||
setmode(1)
|
||||
map = {}
|
||||
col = {}
|
||||
for i=0,1199 do
|
||||
map[i] = 32
|
||||
col[i] = 0x0f
|
||||
end
|
||||
map[ind] = 65
|
||||
sel_col = 0x0f
|
||||
sel_chr = 65
|
||||
end
|
||||
|
||||
blink=30
|
||||
|
||||
function update()
|
||||
if btn(KEY_TAB) then
|
||||
draw_picker()
|
||||
update_picker()
|
||||
else
|
||||
draw_map()
|
||||
--update_map()
|
||||
end
|
||||
end
|
||||
|
||||
function draw_picker()
|
||||
for y=0,15 do
|
||||
for x=0,15 do
|
||||
poke(x+y*40, x+y*16)
|
||||
poke(1200+x+y*40, sel_col)
|
||||
end
|
||||
end
|
||||
for i=0,15 do
|
||||
poke(1840+i, i<<4)
|
||||
poke(1880+i, i<<4)
|
||||
poke(640+i, 32)
|
||||
poke(680+i, 32)
|
||||
end
|
||||
poke(1840, 15) poke(1880, 15)
|
||||
poke(640+(sel_col&0xf), 203)
|
||||
poke(680+(sel_col>>4), 203)
|
||||
local mx, my = mousex(), mousey()
|
||||
|
||||
if mx<16 then
|
||||
if my<16 then
|
||||
poke(1200+(mx+my*40), 0x4e)
|
||||
print(mx+my*40, 16, 13)
|
||||
elseif my>=16 then
|
||||
poke(mx+my*40, 144)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function update_picker()
|
||||
local mx, my = mousex(), mousey()
|
||||
if mousebutton(1) then
|
||||
if mx<16 then
|
||||
if my<16 then
|
||||
sel_chr = mx+my*16
|
||||
else
|
||||
if my == 16 then
|
||||
sel_col = (sel_col & 0xf0) + mx
|
||||
elseif my == 17 then
|
||||
sel_col = (sel_col & 0x0f) + (mx << 4)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function draw_map()
|
||||
for i=0,1199 do
|
||||
poke(i, map[i])
|
||||
poke(1200+i, col[i])
|
||||
end
|
||||
|
||||
local mx, my = mousex(), mousey()
|
||||
if mousebutton(1) then
|
||||
map[mx+my*40] = sel_chr
|
||||
col[mx+my*40] = sel_col
|
||||
end
|
||||
if btn(KEY_SPACE) then
|
||||
sel_chr = peek(mx+my*40)
|
||||
sel_col = peek(1200+mx+my*40)
|
||||
end
|
||||
|
||||
blink = blink - 1
|
||||
if blink < 30 then
|
||||
if blink==0 then blink = 60 end
|
||||
local mx, my = mousex(), mousey()
|
||||
local c = peek(1200+(mx+my*40))
|
||||
poke(1200+(mx+my*40), c~0xff)
|
||||
end
|
||||
|
||||
if btn(KEY_S) then
|
||||
fileout("scr.bin", 0, 2400);
|
||||
elseif btn(KEY_L) then
|
||||
filein("scr.bin", 0, 2400);
|
||||
for i=0,1199 do
|
||||
map[i] = peek(i)
|
||||
col[i] = peek(1200+i)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -10,7 +10,7 @@ function init()
|
||||
mousewait=0
|
||||
compas = 0
|
||||
compasos = {}
|
||||
for i=0,31 do compasos[i] = 108 end
|
||||
for i=0,1279 do compasos[i] = 108 end
|
||||
compasos[0] = 49
|
||||
compasos[1] = 49
|
||||
compasos[2] = 49
|
||||
@@ -25,6 +25,16 @@ end
|
||||
function update()
|
||||
color(COLOR_WHITE, COLOR_BLACK)
|
||||
cls()
|
||||
ink(COLOR_BLACK)
|
||||
for i=0,39 do
|
||||
if (i==compas) then paper(COLOR_LIGHT_RED) else paper(COLOR_LIGHT_GRAY) end
|
||||
print("___\003",(i%10)*4,flr(i/10)+5)
|
||||
end
|
||||
|
||||
if mousebutton(1) and mousey()<=8 and mousey()>=5 then
|
||||
compas = flr(mousex()/4)+(mousey()-5)*10
|
||||
end
|
||||
|
||||
for i=0,11 do
|
||||
local k = 11-i
|
||||
local pos = ((piano_pos+i)%12)+1
|
||||
@@ -55,15 +65,15 @@ function update()
|
||||
end
|
||||
|
||||
for i=0,31 do
|
||||
local n = compasos[i]
|
||||
local n = compasos[(compas*32)+i]
|
||||
if n>=piano_pos and n<=piano_pos+11 then
|
||||
if i>0 and n~=compasos[i-1] then
|
||||
if i>0 and n~=compasos[(compas*32)+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
|
||||
if i==31 or compasos[(compas*32)+i+1]~=n then
|
||||
print("\003",8+i,10+11-(n-piano_pos))
|
||||
else
|
||||
print("_",8+i,10+11-(n-piano_pos))
|
||||
@@ -73,7 +83,7 @@ function update()
|
||||
|
||||
if mousex()>=8 and mousey()>=10 and mousey()<=21 then
|
||||
if mousebutton(1) then
|
||||
compasos[mousex()-8] = piano_pos+11-(mousey()-10)
|
||||
compasos[(compas*32)+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])
|
||||
@@ -82,12 +92,18 @@ function update()
|
||||
else
|
||||
old_mouse_x,old_mouse_y = 0,0
|
||||
if mousebutton(3) then
|
||||
compasos[mousex()-8] = 108
|
||||
compasos[(compas*32)+mousex()-8] = 108
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if btnp(KEY_RETURN) then play_song() end
|
||||
if btnp(KEY_RETURN) then
|
||||
if btn(KEY_LSHIFT) then
|
||||
play_song(true)
|
||||
else
|
||||
play_song()
|
||||
end
|
||||
end
|
||||
|
||||
color(15,0)print("\143",0,0)
|
||||
color(14,0)print("\143",1,0)
|
||||
@@ -101,18 +117,33 @@ function update()
|
||||
|
||||
end
|
||||
|
||||
function play_song()
|
||||
function search_song_end()
|
||||
local i = 1279
|
||||
while i>0 and compasos[i] == 108 do i=i-1 end
|
||||
return i+1
|
||||
end
|
||||
|
||||
function play_song(entire_song)
|
||||
entire_song = entire_song or false
|
||||
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
|
||||
|
||||
local p=compas*32
|
||||
local ends=32+compas*32
|
||||
|
||||
if entire_song then
|
||||
p=0
|
||||
ends=search_song_end()
|
||||
end
|
||||
|
||||
while p<ends do
|
||||
current_note = compasos[p]
|
||||
local d=0
|
||||
while current_note == compasos[p] do d=d+1 p=p+1 end
|
||||
while d<32 and 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
|
||||
@@ -136,5 +167,6 @@ function play_song()
|
||||
end
|
||||
end
|
||||
end
|
||||
log(song)
|
||||
play(song)
|
||||
end
|
||||
Reference in New Issue
Block a user