新增piano小程序(目前只支持键盘操作)

This commit is contained in:
MrZ626
2021-11-14 22:19:45 +08:00
parent abd15d6307
commit 00bc24bd50
2 changed files with 55 additions and 0 deletions

View File

@@ -611,6 +611,11 @@ local commands={}do
scene='app_arithmetic', scene='app_arithmetic',
description="Arithmetic" description="Arithmetic"
}, },
{
code="piano",
scene='app_piano',
description="A simple keyboard piano"
},
} }
commands.app={ commands.app={
code=function(name) code=function(name)

View File

@@ -0,0 +1,50 @@
local gc=love.graphics
local kb=love.keyboard
local instList={'lead','bell','bass'}
local keys={
['1']='C6',['2']='D6',['3']='E6',['4']='F6',['5']='G6',['6']='A6',['7']='B6',['8']='C7',['9']='D7',['0']='E7',['-']='F7',['=']='G7',
['q']='C5',['w']='D5',['e']='E5',['r']='F5',['t']='G5',['y']='A5',['u']='B5',['i']='C6',['o']='D6',['p']='E6',['[']='F6',[']']='G6',['\\']='A6',
['a']='C4',['s']='D4',['d']='E4',['f']='F4',['g']='G4',['h']='A4',['j']='B4',['k']='C5',['l']='D5',[';']='E5',["'"]='F5',
['z']='C3',['x']='D3',['c']='E3',['v']='F3',['b']='G3',['n']='A3',['m']='B3',[',']='C4',['.']='D4',['/']='E4',
}
local inst
local scene={}
function scene.sceneInit()
inst='lead'
end
function scene.touchDown(x,y,k)
end
scene.mouseDown=scene.touchDown
function scene.keyDown(key,isRep)
if isRep then return end
if key=='tab'then
inst=TABLE.next(instList,inst)
else
local note=keys[key]
if note then
if kb.isDown('lshift','rshift')then note=note:sub(1,1)..'#'..note:sub(2,2)end
SFX.playSample(inst,note)
TEXT.show(note,math.random(150,1130),math.random(140,500),60,'score',.8)
end
end
end
function scene.update(dt)
end
function scene.draw()
setFont(30)
gc.print(inst,40,60)
end
scene.widgetList={
WIDGET.newButton{name="back", x=1140,y=640,w=170,h=80,fText=CHAR.icon.back,code=backScene},
}
return scene