File tree 2 files changed +60
-0
lines changed
resources/scripts/game/screens/play
2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change
1
+ Game . Screens . Play . Ready = class Ready extends Engine . Layer {
2
+ get events ( ) {
3
+ return {
4
+ "keydown" : "onKeyDown"
5
+ } ;
6
+ }
7
+
8
+ constructor ( screen , snakes ) {
9
+ super ( screen ) ;
10
+
11
+ this . snakes = snakes ;
12
+
13
+ // Create "ready" sprite and set its properties
14
+ let readyTexture = this . assets . minecraftiaFont . createTexture ( "Ready" ) ;
15
+ let readySprite = new Engine . Sprite ( readyTexture ) ;
16
+ readySprite . align = "center" ;
17
+ readySprite . setPercentage ( "width" , this . width , 15 , "height" ) ;
18
+
19
+ // Create fade out animation for "ready" sprite
20
+ this . readyAnim = new Engine . Animations . Keyframe ( readySprite , [
21
+ {
22
+ x : this . width / 2 ,
23
+ y : this . height / 2 ,
24
+ opacity : 1 ,
25
+ frame : 0
26
+ } ,
27
+ {
28
+ y : this . height / 3 ,
29
+ opacity : 0 ,
30
+ frame : 700
31
+ }
32
+ ] ) ;
33
+ }
34
+
35
+ draw ( context ) {
36
+ this . readyAnim . draw ( context ) ;
37
+ }
38
+
39
+ update ( span ) {
40
+ if ( ! this . ready ) return ;
41
+
42
+ if ( this . readyAnim . playing ) {
43
+ this . readyAnim . update ( span ) ;
44
+ }
45
+ // Once animation is finished, dispose layer
46
+ else {
47
+ this . screen . removeLayer ( this ) ;
48
+ }
49
+ }
50
+
51
+ onKeyDown ( ) {
52
+ // One time event
53
+ this . disposeEventListeners ( )
54
+
55
+ // This will start playing the animation
56
+ this . ready = true ;
57
+ this . readyAnim . play ( ) ;
58
+ }
59
+ } ;
Original file line number Diff line number Diff line change 24
24
< script type ="text/javascript " src ="/scripts/engine/game.js "> </ script >
25
25
< script type ="text/javascript " src ="/scripts/game/entities/snake.js "> </ script >
26
26
< script type ="text/javascript " src ="/scripts/game/screens/play/index.js "> </ script >
27
+ < script type ="text/javascript " src ="/scripts/game/screens/play/ready.js "> </ script >
27
28
< script type ="text/javascript " src ="/scripts/game/screens/menu/index.js "> </ script >
28
29
< script type ="text/javascript " src ="/scripts/game/screens/splash/index.js "> </ script >
29
30
< script type ="text/javascript " src ="/scripts/main.js "> </ script >
You can’t perform that action at this time.
0 commit comments