This commit is contained in:
assada 2024-06-01 22:46:36 +03:00
parent 29a5ed2f62
commit f19610e458
Signed by: assada
GPG Key ID: D4860A938E541F06
12 changed files with 543 additions and 451 deletions

View File

@ -1,265 +1,265 @@
--metrics={"baseline":0,"xHeight":0,"capHeight":0,"pairs":{"Ta":[-4,1],"Tc":[-4,1],"Te":[-4,1],"To":[-4,1],"Tm":[-4,1],"Tn":[-4,1],"Tr":[-4,1],"Tu":[-4,1],"Tv":[-4,1],"Tw":[-4,1],"fB":[2,1],"fD":[2,1],"fE":[2,1],"fF":[2,1],"fH":[2,1],"fI":[2,1],"fK":[2,1],"fL":[2,1],"fM":[2,1],"fN":[2,1],"fP":[2,1],"fR":[2,1],"fW":[2,1],"fb":[2,1],"fh":[2,1],"fk":[2,1],"fC":[2,1],"fG":[2,1],"fO":[2,1],"fQ":[2,1],"fU":[2,1],"fl":[2,1],"lB":[1,1],"lD":[1,1],"lE":[1,1],"lF":[1,1],"lH":[1,1],"lI":[1,1],"lK":[1,1],"lL":[1,1],"lM":[1,1],"lN":[1,1],"lP":[1,1],"lR":[1,1],"lW":[1,1],"lb":[1,1],"lh":[1,1],"lk":[1,1],"lC":[1,1],"lG":[1,1],"lO":[1,1],"lQ":[1,1],"lU":[0,1,1,1],"ll":[0,1,1,1],"la":[0,1,1,1],"lc":[0,1,1,1],"le":[0,1,1,1],"lo":[0,1,1,1],"lm":[1,1],"ln":[1,1],"lr":[1,1],"lu":[0,1,1,1],"lv":[0,1,1,1],"lw":[0,1,1,1],"Fa":[-2,1],"Fc":[-2,1],"Fe":[-2,1],"Fo":[-2,1],"Fm":[-2,1],"Fn":[-2,1],"Fr":[-2,1],"Fu":[-2,1],"Fv":[-2,1],"Fw":[-2,1],"aT":[-4,2],"uT":[-4,2],"gT":[-4,2],"yT":[-4,2],"mT":[-4,2],"nT":[-4,2],"vT":[-4,2],"wT":[-4,2],"Td":[-4,0],"Tf":[-2,0],"Tg":[-4,0],"Tp":[-4,0],"Tq":[-4,0],"Ts":[-4,0],"Tt":[-2,0],"Tx":[-4,0],"Ty":[-4,0],"Tz":[-4,0],"TJ":[-4,0],"T<>":[-4,0],"bT":[-4,0],"cT":[-4,0],"eT":[-4,0],"fA":[1,0,2,0],"fT":[2,0],"fi":[2,0],"fj":[2,0],"fY":[2,0],"fJ":[-2,0],"fS":[2,0],"fV":[2,0],"fX":[2,0],"fZ":[2,0],"hT":[-4,0],"kT":[-4,0],"lA":[1,0],"lT":[-1,0],"ld":[0,0,1,0],"lf":[-1,0],"lg":[0,0,1,0],"li":[1,0],"lj":[1,0],"lp":[1,0],"lq":[0,0,1,0],"ls":[1,0],"lt":[-1,0],"lx":[1,0],"ly":[0,0,1,0],"lz":[1,0],"lY":[-1,0],"lJ":[1,0],"lS":[1,0],"lV":[-1,0],"lX":[1,0],"lZ":[1,0],"l<>":[-1,0],"oT":[-4,0],"pT":[-4,0],"qT":[-4,0],"rT":[-4,0],"rX":[-2,0],"rZ":[-2,0],"sT":[-4,0],"tT":[-2,0],"xT":[-4,0],"zT":[-4,0],"C<>":[-2,0],"Ef":[-2,0],"Et":[-2,0],"E<>":[-2,0],"Fd":[-2,0],"Ff":[-2,0],"Fg":[-2,0],"Fp":[-2,0],"Fq":[-2,0],"Fs":[-2,0],"Ft":[-2,0],"Fx":[-2,0],"Fy":[-2,0],"Fz":[-2,0],"FJ":[-2,0],"F<>":[-2,0],"YJ":[-2,0],"Kf":[-2,0],"Kt":[-2,0],"K<>":[-4,0],"LT":[-4,0],"Lf":[-2,0],"Lt":[-2,0],"LY":[-4,0],"LV":[-4,0],"L<>":[-4,0],"PJ":[-2,0],"X<>":[-2,0],"Z<>":[-2,0],"<22>T":[-4,0],"<22>X":[-2,0],"<22>Z":[-2,0]},"left":["BDEFHIKLMNPRWbhk","CGOQ","Ul","aceo","mnr","uvw"],"right":["AQ","DO","HIMNWd","JU","au","gy","mn","vw"]}
tracking=2
0 12
1 12
2 12
3 12
4 12
5 12
6 12
7 12
8 12
9 12
space 8
. 4
A 12
B 12
T 12
a 12
b 12
c 12
d 12
e 12
f 8
g 12
h 12
i 4
j 4
k 12
l 5
m 16
n 12
o 12
p 12
q 12
r 12
s 12
t 8
u 12
v 12
w 16
x 12
y 12
z 12
, 4
C 12
D 12
E 12
F 12
G 12
O 12
H 12
I 4
! 4
" 10
' 4
Y 12
{ 8
| 4
} 8
J 12
K 14
L 12
M 14
N 14
P 12
Q 12
R 12
S 12
U 12
V 14
W 14
X 12
Z 12
/ 12
\ 12
[ 6
] 6
: 4
; 4
^ 12
_ 10
` 8
~ 16
¥ 12
… 16
™ 14
‼ 10
© 18
® 18
<EFBFBD> 16
@ 18
# 18
$ 12
% 14
& 12
( 6
) 6
* 12
+ 12
- 10
= 10
? 12
< 10
> 10
Ta -4
Tc -4
Te -4
To -4
Tm -4
Tn -4
Tr -4
Tu -4
Tv -4
Tw -4
fB 2
fD 2
fE 2
fF 2
fH 2
fI 2
fK 2
fL 2
fM 2
fN 2
fP 2
fR 2
fW 2
fb 2
fh 2
fk 2
fC 2
fG 2
fO 2
fQ 2
fU 2
fl 2
lB 1
lD 1
lE 1
lF 1
lH 1
lI 1
lK 1
lL 1
lM 1
lN 1
lP 1
lR 1
lW 1
lb 1
lh 1
lk 1
lC 1
lG 1
lO 1
lQ 1
lm 1
ln 1
lr 1
Fa -2
Fc -2
Fe -2
Fo -2
Fm -2
Fn -2
Fr -2
Fu -2
Fv -2
Fw -2
aT -4
uT -4
gT -4
yT -4
mT -4
nT -4
vT -4
wT -4
Td -4
Tf -2
Tg -4
Tp -4
Tq -4
Ts -4
Tt -2
Tx -4
Ty -4
Tz -4
TJ -4
T<EFBFBD> -4
bT -4
cT -4
eT -4
fA 1
fT 2
fi 2
fj 2
fY 2
fJ -2
fS 2
fV 2
fX 2
fZ 2
hT -4
kT -4
lA 1
lT -1
lf -1
li 1
lj 1
lp 1
ls 1
lt -1
lx 1
lz 1
lY -1
lJ 1
lS 1
lV -1
lX 1
lZ 1
l<EFBFBD> -1
oT -4
pT -4
qT -4
rT -4
rX -2
rZ -2
sT -4
tT -2
xT -4
zT -4
C<EFBFBD> -2
Ef -2
Et -2
E<EFBFBD> -2
Fd -2
Ff -2
Fg -2
Fp -2
Fq -2
Fs -2
Ft -2
Fx -2
Fy -2
Fz -2
FJ -2
F<EFBFBD> -2
YJ -2
Kf -2
Kt -2
K<EFBFBD> -4
LT -4
Lf -2
Lt -2
LY -4
LV -4
L<EFBFBD> -4
PJ -2
X<EFBFBD> -2
Z<EFBFBD> -2
<EFBFBD>T -4
<EFBFBD>X -2
<EFBFBD>Z -2
--metrics={"baseline":0,"xHeight":0,"capHeight":0,"pairs":{"Ta":[-4,1],"Tc":[-4,1],"Te":[-4,1],"To":[-4,1],"Tm":[-4,1],"Tn":[-4,1],"Tr":[-4,1],"Tu":[-4,1],"Tv":[-4,1],"Tw":[-4,1],"fB":[2,1],"fD":[2,1],"fE":[2,1],"fF":[2,1],"fH":[2,1],"fI":[2,1],"fK":[2,1],"fL":[2,1],"fM":[2,1],"fN":[2,1],"fP":[2,1],"fR":[2,1],"fW":[2,1],"fb":[2,1],"fh":[2,1],"fk":[2,1],"fC":[2,1],"fG":[2,1],"fO":[2,1],"fQ":[2,1],"fU":[2,1],"fl":[2,1],"lB":[1,1],"lD":[1,1],"lE":[1,1],"lF":[1,1],"lH":[1,1],"lI":[1,1],"lK":[1,1],"lL":[1,1],"lM":[1,1],"lN":[1,1],"lP":[1,1],"lR":[1,1],"lW":[1,1],"lb":[1,1],"lh":[1,1],"lk":[1,1],"lC":[1,1],"lG":[1,1],"lO":[1,1],"lQ":[1,1],"lU":[0,1,1,1],"ll":[0,1,1,1],"la":[0,1,1,1],"lc":[0,1,1,1],"le":[0,1,1,1],"lo":[0,1,1,1],"lm":[1,1],"ln":[1,1],"lr":[1,1],"lu":[0,1,1,1],"lv":[0,1,1,1],"lw":[0,1,1,1],"Fa":[-2,1],"Fc":[-2,1],"Fe":[-2,1],"Fo":[-2,1],"Fm":[-2,1],"Fn":[-2,1],"Fr":[-2,1],"Fu":[-2,1],"Fv":[-2,1],"Fw":[-2,1],"aT":[-4,2],"uT":[-4,2],"gT":[-4,2],"yT":[-4,2],"mT":[-4,2],"nT":[-4,2],"vT":[-4,2],"wT":[-4,2],"Td":[-4,0],"Tf":[-2,0],"Tg":[-4,0],"Tp":[-4,0],"Tq":[-4,0],"Ts":[-4,0],"Tt":[-2,0],"Tx":[-4,0],"Ty":[-4,0],"Tz":[-4,0],"TJ":[-4,0],"T<>":[-4,0],"bT":[-4,0],"cT":[-4,0],"eT":[-4,0],"fA":[1,0,2,0],"fT":[2,0],"fi":[2,0],"fj":[2,0],"fY":[2,0],"fJ":[-2,0],"fS":[2,0],"fV":[2,0],"fX":[2,0],"fZ":[2,0],"hT":[-4,0],"kT":[-4,0],"lA":[1,0],"lT":[-1,0],"ld":[0,0,1,0],"lf":[-1,0],"lg":[0,0,1,0],"li":[1,0],"lj":[1,0],"lp":[1,0],"lq":[0,0,1,0],"ls":[1,0],"lt":[-1,0],"lx":[1,0],"ly":[0,0,1,0],"lz":[1,0],"lY":[-1,0],"lJ":[1,0],"lS":[1,0],"lV":[-1,0],"lX":[1,0],"lZ":[1,0],"l<>":[-1,0],"oT":[-4,0],"pT":[-4,0],"qT":[-4,0],"rT":[-4,0],"rX":[-2,0],"rZ":[-2,0],"sT":[-4,0],"tT":[-2,0],"xT":[-4,0],"zT":[-4,0],"C<>":[-2,0],"Ef":[-2,0],"Et":[-2,0],"E<>":[-2,0],"Fd":[-2,0],"Ff":[-2,0],"Fg":[-2,0],"Fp":[-2,0],"Fq":[-2,0],"Fs":[-2,0],"Ft":[-2,0],"Fx":[-2,0],"Fy":[-2,0],"Fz":[-2,0],"FJ":[-2,0],"F<>":[-2,0],"YJ":[-2,0],"Kf":[-2,0],"Kt":[-2,0],"K<>":[-4,0],"LT":[-4,0],"Lf":[-2,0],"Lt":[-2,0],"LY":[-4,0],"LV":[-4,0],"L<>":[-4,0],"PJ":[-2,0],"X<>":[-2,0],"Z<>":[-2,0],"<22>T":[-4,0],"<22>X":[-2,0],"<22>Z":[-2,0]},"left":["BDEFHIKLMNPRWbhk","CGOQ","Ul","aceo","mnr","uvw"],"right":["AQ","DO","HIMNWd","JU","au","gy","mn","vw"]}
tracking=2
0 12
1 12
2 12
3 12
4 12
5 12
6 12
7 12
8 12
9 12
space 8
. 4
A 12
B 12
T 12
a 12
b 12
c 12
d 12
e 12
f 8
g 12
h 12
i 4
j 4
k 12
l 5
m 16
n 12
o 12
p 12
q 12
r 12
s 12
t 8
u 12
v 12
w 16
x 12
y 12
z 12
, 4
C 12
D 12
E 12
F 12
G 12
O 12
H 12
I 4
! 4
" 10
' 4
Y 12
{ 8
| 4
} 8
J 12
K 14
L 12
M 14
N 14
P 12
Q 12
R 12
S 12
U 12
V 14
W 14
X 12
Z 12
/ 12
\ 12
[ 6
] 6
: 4
; 4
^ 12
_ 10
` 8
~ 16
¥ 12
… 16
™ 14
‼ 10
© 18
® 18
<EFBFBD> 16
@ 18
# 18
$ 12
% 14
& 12
( 6
) 6
* 12
+ 12
- 10
= 10
? 12
< 10
> 10
Ta -4
Tc -4
Te -4
To -4
Tm -4
Tn -4
Tr -4
Tu -4
Tv -4
Tw -4
fB 2
fD 2
fE 2
fF 2
fH 2
fI 2
fK 2
fL 2
fM 2
fN 2
fP 2
fR 2
fW 2
fb 2
fh 2
fk 2
fC 2
fG 2
fO 2
fQ 2
fU 2
fl 2
lB 1
lD 1
lE 1
lF 1
lH 1
lI 1
lK 1
lL 1
lM 1
lN 1
lP 1
lR 1
lW 1
lb 1
lh 1
lk 1
lC 1
lG 1
lO 1
lQ 1
lm 1
ln 1
lr 1
Fa -2
Fc -2
Fe -2
Fo -2
Fm -2
Fn -2
Fr -2
Fu -2
Fv -2
Fw -2
aT -4
uT -4
gT -4
yT -4
mT -4
nT -4
vT -4
wT -4
Td -4
Tf -2
Tg -4
Tp -4
Tq -4
Ts -4
Tt -2
Tx -4
Ty -4
Tz -4
TJ -4
T<EFBFBD> -4
bT -4
cT -4
eT -4
fA 1
fT 2
fi 2
fj 2
fY 2
fJ -2
fS 2
fV 2
fX 2
fZ 2
hT -4
kT -4
lA 1
lT -1
lf -1
li 1
lj 1
lp 1
ls 1
lt -1
lx 1
lz 1
lY -1
lJ 1
lS 1
lV -1
lX 1
lZ 1
l<EFBFBD> -1
oT -4
pT -4
qT -4
rT -4
rX -2
rZ -2
sT -4
tT -2
xT -4
zT -4
C<EFBFBD> -2
Ef -2
Et -2
E<EFBFBD> -2
Fd -2
Ff -2
Fg -2
Fp -2
Fq -2
Fs -2
Ft -2
Fx -2
Fy -2
Fz -2
FJ -2
F<EFBFBD> -2
YJ -2
Kf -2
Kt -2
K<EFBFBD> -4
LT -4
Lf -2
Lt -2
LY -4
LV -4
L<EFBFBD> -4
PJ -2
X<EFBFBD> -2
Z<EFBFBD> -2
<EFBFBD>T -4
<EFBFBD>X -2
<EFBFBD>Z -2

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -17,6 +17,7 @@ import "scripts/player"
import "scripts/groundSprite"
import "scripts/balebaSprite"
import "scripts/dangerSprite"
import "scripts/tankSprite"
import "scenes/BaseScene"
import 'scenes/Menu'
@ -35,4 +36,4 @@ playdate.display.setRefreshRate(50)
Noble.showFPS = true
Noble.new(Menu)
Noble.new(Game)

View File

@ -28,6 +28,8 @@ function scene:setValues()
scene.t = playdate.timer.new(10000)
scene.t.repeats = true
scene.tankTimer = playdate.timer.new(1000)
scene.fp = playdate.sound.fileplayer.new( "assets/audio/war" )
scene.fp:setVolume(0.7)
scene.hello = playdate.sound.fileplayer.new( "assets/audio/hello" )
@ -68,7 +70,7 @@ function scene:enter()
end
local k = #scene.balebas+1
scene.balebas[k] = scene:spawnBaleba()
--scene.balebas[k] = scene:spawnBaleba()
end
for i=1, 3 do
@ -80,6 +82,11 @@ function scene:enter()
if musicEnabled then
scene.fp:play(0)
end
scene.tankTimer.timerEndedCallback = function()
scene.tank = Tank(550, 190, scene.player, scene.ground)
scene.tank:add()
end
end
function scene:update()
@ -90,15 +97,13 @@ function scene:update()
return
end
if scene.player.isDead() then
if not scene.telemLostSoundPlayed then
scene.telemLostSound:play(1)
scene.telemLostSoundPlayed = true
screenShake(500, 5)
end
scene:destroyPlayer()
local et = playdate.timer.new(2000)
if scene.player.isDead() and not scene.telemLostSoundPlayed then
scene.telemLostSound:play(1)
scene.telemLostSoundPlayed = true
screenShake(500, 5)
local et = playdate.timer.new(6000)
et.timerEndedCallback = function()
Noble.transition(Menu)
end
@ -126,6 +131,9 @@ function scene:exit()
scene.ground:remove()
scene.ground = nil
scene.tank:remove()
scene.ground = nil
for i=1, #scene.balebas do
scene.balebas[i]:destroy()
scene.balebas[i] = nil
@ -139,6 +147,9 @@ function scene:exit()
scene.t:remove()
scene.t = nil
scene.tankTimer:remove()
scene.tankTimer = nil
Noble.showFPS = false
end

View File

@ -1,7 +1,7 @@
Ground = {}
class("Ground").extends(Graphics.sprite)
local groundImage = playdate.graphics.image.new("assets/sprites/groundFin")
local groundImage = Graphics.image.new("assets/sprites/groundFin")
function Ground:init(x, y, player)
Ground.super.init(self, groundImage)
@ -24,6 +24,12 @@ function Ground:setMoveSpeed(speed)
end
function Ground:update()
-- Stop ground
if Ground.moveSpeed == 0 then
return
end
-- Speedup when player is moving right
if Ground.player.isMovingRight() == false then
Ground.moveSpeed = 0.2

View File

@ -99,6 +99,24 @@ function Player:changeToRunState(direction)
end
end
function Player:boom(collisionObject)
Player.dead = true
self:changeState("boom")
local particleB = ParticlePoly(self.x, self.y)
particleB:setThickness(2)
particleB:setAngular(-15, 15)
particleB:setSize(1, 2)
particleB:setSpeed(1, 3)
particleB:setMode(Particles.modes.STAY)
particleB:setBounds(0, 0, 400, 240)
particleB:setColour(Graphics.kColorXOR)
particleB:add(20)
if collisionObject then
collisionObject:remove()
end
end
function Player:handleMovementAndCollisions()
if Player.dead then
return
@ -134,23 +152,24 @@ function Player:handleMovementAndCollisions()
end
if collisionTag == 3 then -- Ground
Player.dead = true
self:changeState("boom")
self:boom()
return
elseif collisionTag == 154 then -- Baleba
Player.dead = true
self:changeState("boom")
-- self:boom(collisionObject)
return
elseif collisionTag == 2 then -- Tank
self:boom()
local particleB = ParticlePoly(self.x, self.y)
particleB:setThickness(2)
particleB:setAngular(-15, 15)
particleB:setSize(1, 2)
particleB:setSpeed(1, 3)
particleB:setMode(Particles.modes.STAY)
particleB:setBounds(0, 0, 400, 240)
particleB:setColour(Graphics.kColorXOR)
particleB:add(20)
collisionObject:remove()
local particleC = ParticlePoly(collisionObject.x, collisionObject.y)
particleC:setThickness(5)
particleC:setAngular(-15, 15)
particleC:setSize(1, 5)
particleC:setSpeed(1, 3)
particleC:setMode(Particles.modes.STAY)
particleC:setBounds(0, 0, 400, 240)
particleC:setColour(Graphics.kColorXOR)
particleC:add(50)
collisionObject:fadeout()
return
end
end

View File

@ -0,0 +1,55 @@
Tank = {}
class("Tank").extends(Graphics.sprite)
function Tank:init(x, y, player, ground)
self.tankImage = Graphics.image.new("assets/sprites/tank")
self.tankImageD = Graphics.image.new("assets/sprites/tankD")
Tank.super.init(self)
local width, height = self.tankImage:getSize()
self.faded_image = Graphics.image.new(width, height, Graphics.kColorClear)
Graphics.pushContext(self.faded_image)
self.tankImageD:drawBlurred(0, 0, 2, 2, Graphics.image.kDitherTypeFloydSteinberg)
Graphics.popContext()
-- Collision properties
self:setZIndex(99)
self:setTag(2)
self:setCollideRect(4, 56, 147, 65)
-- Main properties
Tank.moveSpeed = 2
Tank.player = player
Tank.ground = ground
self:fadein()
self:moveTo(x, y)
end
function Tank:fadein()
self:setImage(self.tankImage)
end
function Tank:fadeout()
self:setImage(self.faded_image)
end
function Tank:update()
if self.x <= 330 then
Tank.ground:setMoveSpeed(0)
return
end
-- Speedup when player is moving right
if Tank.player.isMovingRight() == false then
Tank.moveSpeed = 0.2
else
Tank.moveSpeed = 1
end
self:moveTo(self.x-Tank.moveSpeed, self.y)
end

View File

@ -1,9 +1,9 @@
function enum( t )
local result = {}
for index, name in pairs(t) do
result[name] = index
end
return result
function enum( t )
local result = {}
for index, name in pairs(t) do
result[name] = index
end
return result
end

View File

@ -1,153 +1,153 @@
-- https://gist.github.com/GammaGames/17e0c64e932e6a5b10919af380276fb1
local pd <const> = playdate
local gfx <const> = Graphics
local box = playout.box.new
local text = playout.text.new
local window = {
padding = 8,
border = 2,
borderRadius = 1,
minWidth=160,
maxWidth=210,
backgroundColor = gfx.kColorWhite,
font = Noble.Text.FONT_NEWSLEAK
}
local label = {
padding = 4
}
local labelText = {
alignment = kTextAlignment.left
}
local input = {
padding = 4,
paddingLeft = 8,
borderRadius = 2,
border = 1,
minWidth = 140,
hAlign = playout.kAlignStart
}
local inputText = {
alignment = kTextAlignment.left,
wrap = false
}
local button = {
padding = 4,
paddingLeft = 8
}
local buttonHover = {
padding = 4,
paddingLeft = 8,
borderRadius = 2,
border = 2,
backgroundColor = gfx.kColorWhite,
font = Noble.Text.FONT_NEWSLEAK_BOLD,
}
function notify(_text, callback)
local tree = playout.tree.new(
box({
direction = playout.kDirectionVertical,
spacing = 4,
style = window,
}, {
text(_text, labelText),
box({ style = button, tabIndex = 1 }, { text("Okay") }),
})
)
tree:computeTabIndex()
local nodes = tree.tabIndex
local selectedIndex = 1
nodes[selectedIndex].style = buttonHover
pd.inputHandlers.push({
AButtonDown = function()
pd.inputHandlers.pop()
callback()
end,
BButtonDown = function()
pd.inputHandlers.pop()
callback()
end,
}, true)
return tree:asSprite()
end
function confirm(_text, callback)
local tree = playout.tree.new(
box({
direction = playout.kDirectionVertical,
spacing = 4,
style = window
}, {
box({ style = label}, { text(_text, labelText) }),
box({
direction = playout.kDirectionHorizontal,
spacing = 8
}, {
box({ style = button, tabIndex = 1 }, { text("No") }),
box({ style = button, tabIndex = 2 }, { text("Yes") }),
})
})
)
tree:computeTabIndex()
local nodes = tree.tabIndex
local selectedIndex = 1
nodes[selectedIndex].style = buttonHover
pd.inputHandlers.push({
leftButtonDown = function()
nodes[selectedIndex].style = button
selectedIndex = math.ringInt(selectedIndex - 1, 1, #nodes)
nodes[selectedIndex].style = buttonHover
tree:draw()
end,
rightButtonDown = function()
nodes[selectedIndex].style = button
selectedIndex = math.ringInt(selectedIndex + 1, 1, #nodes)
nodes[selectedIndex].style = buttonHover
tree:draw()
end,
AButtonUp = function()
pd.inputHandlers.pop()
callback(selectedIndex == 2)
end,
BButtonUp = function()
pd.inputHandlers.pop()
callback(false)
end,
}, true)
return tree:asSprite()
end
function prompt(_text, value, callback)
local tree = playout.tree.new(
box({
direction = playout.kDirectionVertical,
style = window,
spacing = 4,
hAlign = playout.kAlignStart
}, {
box({ style = label }, { text(_text, labelText) }),
box({ style = input, tabIndex = 1 }, { text(value, inputText)}),
})
)
tree:computeTabIndex()
local nodes = tree.tabIndex
local input = nodes[1].children[1]
pd.keyboard.show(value)
function pd.keyboard.textChangedCallback()
input.text = pd.keyboard.text
tree:layout()
tree:draw()
end
function pd.keyboard.keyboardWillHideCallback(ok) callback(ok, pd.keyboard.text) end
return tree:asSprite()
-- https://gist.github.com/GammaGames/17e0c64e932e6a5b10919af380276fb1
local pd <const> = playdate
local gfx <const> = Graphics
local box = playout.box.new
local text = playout.text.new
local window = {
padding = 8,
border = 2,
borderRadius = 1,
minWidth=160,
maxWidth=210,
backgroundColor = gfx.kColorWhite,
font = Noble.Text.FONT_NEWSLEAK
}
local label = {
padding = 4
}
local labelText = {
alignment = kTextAlignment.left
}
local input = {
padding = 4,
paddingLeft = 8,
borderRadius = 2,
border = 1,
minWidth = 140,
hAlign = playout.kAlignStart
}
local inputText = {
alignment = kTextAlignment.left,
wrap = false
}
local button = {
padding = 4,
paddingLeft = 8
}
local buttonHover = {
padding = 4,
paddingLeft = 8,
borderRadius = 2,
border = 2,
backgroundColor = gfx.kColorWhite,
font = Noble.Text.FONT_NEWSLEAK_BOLD,
}
function notify(_text, callback)
local tree = playout.tree.new(
box({
direction = playout.kDirectionVertical,
spacing = 4,
style = window,
}, {
text(_text, labelText),
box({ style = button, tabIndex = 1 }, { text("Okay") }),
})
)
tree:computeTabIndex()
local nodes = tree.tabIndex
local selectedIndex = 1
nodes[selectedIndex].style = buttonHover
pd.inputHandlers.push({
AButtonDown = function()
pd.inputHandlers.pop()
callback()
end,
BButtonDown = function()
pd.inputHandlers.pop()
callback()
end,
}, true)
return tree:asSprite()
end
function confirm(_text, callback)
local tree = playout.tree.new(
box({
direction = playout.kDirectionVertical,
spacing = 4,
style = window
}, {
box({ style = label}, { text(_text, labelText) }),
box({
direction = playout.kDirectionHorizontal,
spacing = 8
}, {
box({ style = button, tabIndex = 1 }, { text("No") }),
box({ style = button, tabIndex = 2 }, { text("Yes") }),
})
})
)
tree:computeTabIndex()
local nodes = tree.tabIndex
local selectedIndex = 1
nodes[selectedIndex].style = buttonHover
pd.inputHandlers.push({
leftButtonDown = function()
nodes[selectedIndex].style = button
selectedIndex = math.ringInt(selectedIndex - 1, 1, #nodes)
nodes[selectedIndex].style = buttonHover
tree:draw()
end,
rightButtonDown = function()
nodes[selectedIndex].style = button
selectedIndex = math.ringInt(selectedIndex + 1, 1, #nodes)
nodes[selectedIndex].style = buttonHover
tree:draw()
end,
AButtonUp = function()
pd.inputHandlers.pop()
callback(selectedIndex == 2)
end,
BButtonUp = function()
pd.inputHandlers.pop()
callback(false)
end,
}, true)
return tree:asSprite()
end
function prompt(_text, value, callback)
local tree = playout.tree.new(
box({
direction = playout.kDirectionVertical,
style = window,
spacing = 4,
hAlign = playout.kAlignStart
}, {
box({ style = label }, { text(_text, labelText) }),
box({ style = input, tabIndex = 1 }, { text(value, inputText)}),
})
)
tree:computeTabIndex()
local nodes = tree.tabIndex
local input = nodes[1].children[1]
pd.keyboard.show(value)
function pd.keyboard.textChangedCallback()
input.text = pd.keyboard.text
tree:layout()
tree:draw()
end
function pd.keyboard.keyboardWillHideCallback(ok) callback(ok, pd.keyboard.text) end
return tree:asSprite()
end