From 31450376770a9b065901b5c4a88c4adb3af93584 Mon Sep 17 00:00:00 2001 From: MrZ_26 <1046101471@qq.com> Date: Wed, 20 Nov 2024 10:45:16 +0800 Subject: [PATCH] =?UTF-8?q?piano=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E9=94=AE=E7=9B=98=E7=8A=B6=E6=80=81=E5=8F=AF=E8=A7=86?= =?UTF-8?q?=E5=8C=96=20=E6=A1=86=E6=9E=B6=E8=B7=9F=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zenitha | 2 +- assets/gamefunc.lua | 1 + assets/scene_app/piano.lua | 81 ++++++++++++++++++++++++++++++++------ 3 files changed, 72 insertions(+), 12 deletions(-) diff --git a/Zenitha b/Zenitha index 9e4ba549..8a7e079d 160000 --- a/Zenitha +++ b/Zenitha @@ -1 +1 @@ -Subproject commit 9e4ba549480a045ff5d5edae632bc28aa23dbde1 +Subproject commit 8a7e079de1ce79e61dd3625d5e5d6eb6d803e979 diff --git a/assets/gamefunc.lua b/assets/gamefunc.lua index 0452cba2..6aaec47b 100644 --- a/assets/gamefunc.lua +++ b/assets/gamefunc.lua @@ -328,6 +328,7 @@ end getTouches=love.touch.getTouches isMouseDown=love.mouse.isDown isKeyDown=love.keyboard.isDown +isSCDown=love.keyboard.isScancodeDown local isKeyDown=isKeyDown function isCtrlPressed() return isKeyDown('lctrl','rctrl') end function isShiftPressed() return isKeyDown('lshift','rshift') end diff --git a/assets/scene_app/piano.lua b/assets/scene_app/piano.lua index 64121a48..84bcc24b 100644 --- a/assets/scene_app/piano.lua +++ b/assets/scene_app/piano.lua @@ -9,6 +9,61 @@ local keys={ ['s']=25,['d']=27, ['g']=30,['h']=32,['j']=34, ['l']=37,[';']=39, ['z']=24,['x']=26,['c']=28,['v']=29,['b']=31,['n']=33,['m']=35,[',']=36,['.']=38,['/']=40, } +local layoutList={ + { + pos={scale=10,x=-65,y=-20}, + {x=-5,y=-5,w=140,h=50}, + + ['2']=37,['3']=39, ['5']=42,['6']=44,['7']=46, ['9']=49,['0']=51, ['=']=54,['backspace']=56, + ['q']=36,['w']=38,['e']=40,['r']=41,['t']=43,['y']=45,['u']=47,['i']=48,['o']=50,['p']=52,['[']=53,[']']=55,['\\']=57, + ['s']=25,['d']=27, ['g']=30,['h']=32,['j']=34, ['l']=37,[';']=39, + ['z']=24,['x']=26,['c']=28,['v']=29,['b']=31,['n']=33,['m']=35,[',']=36,['.']=38,['/']=40, + + {x=005,y=00,w=8,h=8,key='2'}, + {x=015,y=00,w=8,h=8,key='3'}, + {x=035,y=00,w=8,h=8,key='5'}, + {x=045,y=00,w=8,h=8,key='6'}, + {x=055,y=00,w=8,h=8,key='7'}, + {x=075,y=00,w=8,h=8,key='9'}, + {x=085,y=00,w=8,h=8,key='0'}, + {x=105,y=00,w=8,h=8,key='='}, + {x=115,y=00,w=13,h=8,key='backspace'}, + + {x=000,y=10,w=8,h=8,key='q'}, + {x=010,y=10,w=8,h=8,key='w'}, + {x=020,y=10,w=8,h=8,key='e'}, + {x=030,y=10,w=8,h=8,key='r'}, + {x=040,y=10,w=8,h=8,key='t'}, + {x=050,y=10,w=8,h=8,key='y'}, + {x=060,y=10,w=8,h=8,key='u'}, + {x=070,y=10,w=8,h=8,key='i'}, + {x=080,y=10,w=8,h=8,key='o'}, + {x=090,y=10,w=8,h=8,key='p'}, + {x=100,y=10,w=8,h=8,key='['}, + {x=110,y=10,w=8,h=8,key=']'}, + {x=120,y=10,w=8,h=8,key='\\'}, + + {x=015,y=20,w=8,h=8,key='s'}, + {x=025,y=20,w=8,h=8,key='d'}, + {x=045,y=20,w=8,h=8,key='g'}, + {x=055,y=20,w=8,h=8,key='h'}, + {x=065,y=20,w=8,h=8,key='j'}, + {x=085,y=20,w=8,h=8,key='l'}, + {x=095,y=20,w=8,h=8,key=';'}, + + {x=010,y=30,w=8,h=8,key='z'}, + {x=020,y=30,w=8,h=8,key='x'}, + {x=030,y=30,w=8,h=8,key='c'}, + {x=040,y=30,w=8,h=8,key='v'}, + {x=050,y=30,w=8,h=8,key='b'}, + {x=060,y=30,w=8,h=8,key='n'}, + {x=070,y=30,w=8,h=8,key='m'}, + {x=080,y=30,w=8,h=8,key=','}, + {x=090,y=30,w=8,h=8,key='.'}, + {x=100,y=30,w=8,h=8,key='/'}, + } +} +local layout=layoutList[1] local activeEventMap={} local inst local offset @@ -35,22 +90,14 @@ local _param={ param={'release',1}, } function scene.keyDown(key,isRep,keyCode) - if not isRep and keys[keyCode] then - local note=keys[keyCode]+offset + if not isRep and layout[keyCode] then + local note=layout[keyCode]+offset if isShiftPressed() then note=note+1 end if isCtrlPressed() then note=note-1 end _param.tune=note-26 _param.volume=1 _param.param[2]=release*1.0594630943592953^(note-26) activeEventMap[keyCode]=FMOD.effect(inst,_param) - TEXT:add{ - text=SFX.getNoteName(note), - x=800+(keys[keyCode]-40)*26+62*math.random(), - y=math.random(140,500), - fontSize=60, - style='score', - duration=.8, - } elseif key=='tab' then inst=TABLE.next(instList,inst) or instList[1] elseif key=='lalt' then @@ -77,21 +124,33 @@ function scene.keyDown(key,isRep,keyCode) release=math.min(release+100,2600) elseif key=='escape' then if sureCheck('back') then SCN.back() end + elseif key=='`' then + layout=TABLE.next(layoutList,layout) or layoutList[1] end return true end function scene.keyUp(_,keyCode) - if keys[keyCode] and activeEventMap[keyCode] then + if layout[keyCode] and activeEventMap[keyCode] then activeEventMap[keyCode]:stop(FMOD.FMOD_STUDIO_STOP_ALLOWFADEOUT) activeEventMap[keyCode]=false end end +local rect=gc.rectangle +local isSCDown=isSCDown function scene.draw() FONT.set(30) gc.print(inst,40,60) gc.print(offset,40,100) gc.print(release,40,140) + gc.replaceTransform(SCR.xOy_m) + gc.scale(layout.pos.scale) + gc.translate(layout.pos.x,layout.pos.y) + gc.setLineWidth(5/layout.pos.scale) + for i=1,#layout do + local key=layout[i] + rect(key.key and isSCDown(key.key) and 'fill' or 'line',key.x,key.y,key.w,key.h) + end end scene.widgetList={