It generates a 15 note random song. If you play back all 15 notes, you win. The buttons flash and sound notes. Let me know it you beat it!
- Dav
Code: Select all
'4 Color button music game.
'Follow the computers pattern.
'Replay the 15 note song to win.
'Works in any screen size.
'By Dav, FEB/2015
graphics
option base 1
set buttons custom
'----
start: 'starts a new game
'----
gosub screencheck
song$="" 'make a random song
for t = 1 to 15
song$=song$& str$(rnd(4)+1)
next t
stopnote = 1
delay = .3
pause 1
'-------
mainloop: 'where it all happens
'-------
'play song to stopnote
for t = 1 to stopnote
i = val(mid$(song$,t,1))
playbtn(i)
showbtn(i,1) ! pause delay
showbtn(i,0) ! pause delay
gosub screencheck
next t
a$="" 'user's playback data
do
'get a button press
do
if button_pressed("1") then
a$=a$&"1" ! playbtn(1) !break
end if
if button_pressed("2") then
a$=a$&"2" ! playbtn(2) !break
end if
if button_pressed("3") then
a$=a$&"3" ! playbtn(3) !break
end if
if button_pressed("4") then
a$=a$&"4" ! playbtn(4) !break
end if
gosub screencheck
until 0
pause .3
'see if user matched song pattern
if a$<>mid$(song$,1, len(a$)) then
'play loser sound
notes set "112:s(f4b)b3(f4b)b3(fb)b4(fb)"
notes play
'flash buttons for effect
for r = 1 to 2 !for o = 1 to 4
showbtn(o,1) ! pause .05
showbtn(o,0) ! pause .05
next o ! next r
pause .75
goto start 'restart game
end if
until len(a$)= stopnote
'did you solve it?
if a$=song$ then
pause .5
'play whole song
for t = 1 to len(song$)
i = val(mid$(song$,t,1))
playbtn(i)
showbtn(i,1) ! pause .1
showbtn(i,0) ! pause .1
gosub screencheck
next t
'play winning sound
notes set "h(ceg)q(egc5)i(egc6)(eg)q(cegc7c3)"
notes play
'flash buttons for effect
for r = 1 to 12 ! for o = 1 to 4
showbtn(o,1) ! pause .05
showbtn(o,0) ! pause .05
next o ! next r
end
end if
stopnote=stopnote+1 'go to next note...
delay = delay -.0085 'get faster...
pause 1
goto mainloop
end 'don't need this, but feels good.
'===================
' GOSUBS & FUNCTIONS
'===================
screencheck:
'checks screen orientation.
'if changed, redraw everything.
if screen_width()<>sw then
sw=screen_width()
sh=screen_height()
'draw all buttons
for t = 1 to 4
showbtn(t,0)
next t
end if
return
def showbtn(num,status)
'Shows the 4 color buttons
'num: the number of button to show
'satus: 1 = flashed, 0 = not flashed
'NOTE: uses sw & sh scope variables
if num=1 then
draw color 1,0,0
if status = 0 then
fill color .5,0,0
else
fill color 1,0,0
end if
button "1" text "" at 0,0 size .sw/2,.sh/2
end if
if num=2 then
draw color 0,1,0
if status = 0 then
fill color 0,.5,0
else
fill color 0,1,0
end if
button "2" text "" at .sw/2,0 size .sw/2,.sh/2
end if
if num=3 then
draw color 1,1,0
if status = 0 then
fill color .5,.5,0
else
fill color 1,1,0
end if
button "3" text "" at 0,.sh/2 size .sw/2, .sh/2
end if
if num=4 then
draw color 0,0,1
if status =0 then
fill color 0,0,.5
else
fill color 0,0,1
end if
button "4" text "" at .sw/2,.sh/2 size .sw/2,.sh/2
end if
end def
def playbtn(num)
if num=1 then
notes set "80:c" ! notes play
end if
if num=2 then
notes set "80:d" ! notes play
end if
if num=3 then
notes set "80:g" ! notes play
end if
if num=4 then
notes set "80:a" ! notes play
end if
end def