Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
oetzit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
commul
oetzit
Commits
1ea0d269
Commit
1ea0d269
authored
2 years ago
by
Paolo Brasolin
Browse files
Options
Downloads
Patches
Plain Diff
feat: #fe track personal best on game over
parent
3b614f56
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/src/js/game_over_scene.ts
+73
-15
73 additions, 15 deletions
frontend/src/js/game_over_scene.ts
with
73 additions
and
15 deletions
frontend/src/js/game_over_scene.ts
+
73
−
15
View file @
1ea0d269
import
"
phaser
"
;
import
{
FONTS
}
from
"
./assets
"
;
import
BackgroundScene
from
"
./background_scene
"
;
import
{
formatTime
,
ICONS
,
THIN_SPACE
}
from
"
./hud
"
;
import
{
formatTime
,
ICONS
}
from
"
./hud
"
;
const
BUTTON_HIGHLIGHT_COLOR
=
"
darkorange
"
;
const
SS_KEYS
=
{
BEST_WORDS
:
"
OETZIT/BEST_WORDS
"
,
BEST_SCORE
:
"
OETZIT/BEST_SCORE
"
,
BEST_TIMER
:
"
OETZIT/BEST_TIMER
"
,
};
const
TEXT_STYLE
:
{
[
key
:
string
]:
Phaser
.
Types
.
GameObjects
.
Text
.
TextStyle
;
}
=
{
...
...
@@ -22,6 +28,10 @@ export default class GameOverScene extends Phaser.Scene {
music
!
:
Phaser
.
Sound
.
BaseSound
;
continueButton
!
:
Phaser
.
GameObjects
.
Text
;
beatScore
!
:
boolean
;
beatTimer
!
:
boolean
;
beatWords
!
:
boolean
;
constructor
()
{
super
(
"
game_over
"
);
}
...
...
@@ -53,13 +63,27 @@ export default class GameOverScene extends Phaser.Scene {
data
.
music
,
);
this
.
processRecords
(
data
.
score
,
data
.
time
,
data
.
words
);
this
.
drawTitle
();
this
.
drawSubtitle
(
data
.
words
);
this
.
drawResult
(
data
.
score
,
data
.
time
);
this
.
drawSubtitle
();
this
.
drawResult
(
data
.
words
,
data
.
score
,
data
.
time
);
this
.
drawCTA
();
this
.
bindEvents
();
}
processRecords
(
score
:
number
,
timer
:
number
,
words
:
number
)
{
const
bestScore
=
sessionStorage
.
getItem
(
SS_KEYS
.
BEST_SCORE
);
const
bestTimer
=
sessionStorage
.
getItem
(
SS_KEYS
.
BEST_TIMER
);
const
bestWords
=
sessionStorage
.
getItem
(
SS_KEYS
.
BEST_WORDS
);
this
.
beatScore
=
bestScore
===
null
||
parseInt
(
bestScore
)
<
score
;
this
.
beatTimer
=
bestTimer
===
null
||
parseInt
(
bestTimer
)
<
timer
;
this
.
beatWords
=
bestWords
===
null
||
parseInt
(
bestWords
)
<
words
;
sessionStorage
.
setItem
(
SS_KEYS
.
BEST_SCORE
,
score
.
toString
());
sessionStorage
.
setItem
(
SS_KEYS
.
BEST_TIMER
,
timer
.
toString
());
sessionStorage
.
setItem
(
SS_KEYS
.
BEST_WORDS
,
words
.
toString
());
}
drawTitle
()
{
const
text
=
"
GAME OVER
"
;
const
title
=
this
.
add
.
text
(
0
,
0
,
text
,
{
...
...
@@ -68,15 +92,15 @@ export default class GameOverScene extends Phaser.Scene {
fontStyle
:
"
bold
"
,
color
:
"
#ff0000
"
,
});
title
.
setOrigin
(
0.5
,
1
);
title
.
setOrigin
(
0.5
,
0
);
title
.
setPosition
(
this
.
cameras
.
main
.
width
*
0.5
,
this
.
cameras
.
main
.
height
*
0.
2
,
this
.
cameras
.
main
.
height
*
0.
1
,
);
}
drawSubtitle
(
wordCount
=
1234
)
{
const
text
=
`You
d
on
ated to our research\n
${
wordCount
}
WORDS\n
${
ICONS
.
HEALTH
}${
THIN_SPACE
}
Thank you!
${
THIN_SPACE
}${
ICONS
.
HEALTH
}
`
;
//
drawSubtitle
()
{
const
text
=
`You
c
on
tributed\n
${
ICONS
.
HEALTH
}
to our research!
${
ICONS
.
HEALTH
}
\nThank you!
`
;
//
const
subtitle
=
this
.
add
.
text
(
0
,
0
,
text
,
{
fontSize
:
"
28px
"
,
fontFamily
:
FONTS
.
MONO
,
...
...
@@ -92,33 +116,67 @@ export default class GameOverScene extends Phaser.Scene {
);
}
drawResult
(
score
=
12345678
,
time
=
12
*
60
*
1000
+
34
*
1000
+
56
*
10
)
{
const
timer
=
formatTime
(
time
);
const
text
=
`
${
score
}
\u2009
${
ICONS
.
SCORE
}
\n
${
timer
}
\u2009
${
ICONS
.
CLOCK
}
`
;
formatResult
(
words
:
number
,
score
:
number
,
time
:
number
)
{
let
wordsLabel
=
words
.
toString
();
let
scoreLabel
=
score
.
toString
();
let
timerLabel
=
formatTime
(
time
);
const
labelWidth
=
Math
.
max
(
wordsLabel
.
length
,
scoreLabel
.
length
,
timerLabel
.
length
,
);
wordsLabel
=
wordsLabel
.
padStart
(
labelWidth
,
"
"
)
+
"
🔤
"
;
scoreLabel
=
scoreLabel
.
padStart
(
labelWidth
,
"
"
)
+
"
"
+
ICONS
.
SCORE
;
timerLabel
=
timerLabel
.
padStart
(
labelWidth
,
"
"
)
+
"
"
+
ICONS
.
CLOCK
;
if
(
this
.
beatScore
)
scoreLabel
+=
"
🏅
"
;
if
(
this
.
beatTimer
)
timerLabel
+=
"
🏅
"
;
if
(
this
.
beatWords
)
wordsLabel
+=
"
🏅
"
;
return
[
wordsLabel
,
scoreLabel
,
timerLabel
].
join
(
"
\n
"
);
}
drawResult
(
words
=
1234
,
score
=
12345678
,
time
=
12
*
60
*
1000
+
34
*
1000
+
56
*
10
,
)
{
const
text
=
this
.
formatResult
(
words
,
score
,
time
);
const
title
=
this
.
add
.
text
(
0
,
0
,
text
,
{
fontSize
:
"
28px
"
,
fontFamily
:
FONTS
.
MONO
,
fontStyle
:
"
bold
"
,
color
:
"
#ffffff
"
,
align
:
"
right
"
,
testString
:
text
,
});
title
.
setOrigin
(
0.5
,
1
);
title
.
setOrigin
(
0.5
,
0
);
title
.
setPosition
(
this
.
cameras
.
main
.
width
*
0.5
,
this
.
cameras
.
main
.
height
*
0.
8
-
16
,
this
.
cameras
.
main
.
height
*
0.
5
,
);
if
(
this
.
beatScore
||
this
.
beatTimer
||
this
.
beatWords
)
{
const
newPB
=
this
.
add
.
text
(
0
,
0
,
"
You set new records!
"
,
{
fontSize
:
"
28px
"
,
fontFamily
:
FONTS
.
MONO
,
fontStyle
:
"
bold
"
,
color
:
"
#ffffff
"
,
testString
:
text
,
});
newPB
.
setOrigin
(
0.5
,
0
);
newPB
.
setPosition
(
this
.
cameras
.
main
.
width
*
0.5
,
title
.
getBounds
().
bottom
+
16
,
);
}
}
drawCTA
()
{
const
verb
=
this
.
game
.
device
.
os
.
desktop
?
"
Click
"
:
"
Tap
"
;
const
text
=
`
${
verb
}
to continue`
;
this
.
continueButton
=
this
.
add
.
text
(
this
.
cameras
.
main
.
centerX
,
this
.
cameras
.
main
.
height
*
0.
8
,
text
,
{
.
text
(
this
.
cameras
.
main
.
centerX
,
this
.
cameras
.
main
.
height
*
0.
9
,
text
,
{
...
TEXT_STYLE
.
BUTTON
,
fontSize
:
"
32px
"
,
})
.
setOrigin
(
0.5
,
0
)
.
setOrigin
(
0.5
,
1
)
.
setPadding
(
4
)
.
setInteractive
({
useHandCursor
:
true
})
.
on
(
"
pointerover
"
,
()
=>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment