1
- use ggez:: { graphics:: Color , Context , GameResult , graphics:: { self , Scale , Text , TextFragment } } ;
1
+ use ggez:: {
2
+ graphics:: Color ,
3
+ graphics:: { self , Scale , Text , TextFragment } ,
4
+ Context , GameResult ,
5
+ } ;
2
6
3
- pub fn draw ( this : & mut crate :: MyGame , ctx : & mut Context ) -> GameResult < ( ) > {
4
- graphics:: clear ( ctx, graphics:: BLACK ) ;
7
+ pub struct Death {
8
+ consolas : graphics:: Font ,
9
+ ferris_planet : graphics:: Image
10
+ }
5
11
6
- let dead = Text :: new ( TextFragment {
7
- // `TextFragment` stores a string, and optional parameters which will override those
8
- // of `Text` itself. This allows inlining differently formatted lines, words,
9
- // or even individual letters, into the same block of text.
10
- text : "YOU DEAD" . to_string ( ) ,
11
- // `Font` is a handle to a loaded TTF, stored inside the `Context`.
12
- // `Font::default()` always exists and maps to DejaVuSerif.
13
- scale : Some ( Scale :: uniform ( 35.0 ) ) ,
14
- font : Some ( this. consolas ) ,
15
- color : Some ( Color :: new ( 1.0 , 80.0 / 255.0 , 76.0 / 255.0 , 1.0 ) ) ,
16
- // This doesn't do anything at this point; can be used to omit fields in declarations.
17
- ..Default :: default ( )
18
- } ) ;
12
+ impl Death {
13
+ pub fn spawn ( ctx : & mut Context ) -> Self {
14
+ Self {
15
+ consolas : graphics:: Font :: new ( ctx, "/Consolas.ttf" ) . unwrap ( ) ,
16
+ ferris_planet : graphics:: Image :: new ( ctx, "/ferris_planet.png" ) . unwrap ( )
17
+ }
18
+ }
19
19
20
- let unsafe_dead = Text :: new ( TextFragment {
21
- // `TextFragment` stores a string, and optional parameters which will override those
22
- // of `Text` itself. This allows inlining differently formatted lines, words,
23
- // or even individual letters, into the same block of text.
24
- text : "unsafe" . to_string ( ) ,
25
- // `Font` is a handle to a loaded TTF, stored inside the `Context`.
26
- // `Font::default()` always exists and maps to DejaVuSerif.
27
- scale : Some ( Scale :: uniform ( 30.0 ) ) ,
28
- font : Some ( this. consolas ) ,
29
- color : Some ( Color :: new ( 74.0 / 255.0 , 129.0 / 255.0 , 191.0 / 255.0 , 1.0 ) ) ,
30
- // This doesn't do anything at this point; can be used to omit fields in declarations.
31
- ..Default :: default ( )
32
- } ) ;
33
-
34
- let unsafe_dead_block_start = Text :: new ( TextFragment {
35
- // `TextFragment` stores a string, and optional parameters which will override those
36
- // of `Text` itself. This allows inlining differently formatted lines, words,
37
- // or even individual letters, into the same block of text.
38
- text : "{" . to_string ( ) ,
39
- // `Font` is a handle to a loaded TTF, stored inside the `Context`.
40
- // `Font::default()` always exists and maps to DejaVuSerif.
41
- scale : Some ( Scale :: uniform ( 30.0 ) ) ,
42
- font : Some ( this. consolas ) ,
43
- color : Some ( Color :: new ( 1.0 , 1.0 , 1.0 , 1.0 ) ) ,
44
- // This doesn't do anything at this point; can be used to omit fields in declarations.
45
- ..Default :: default ( )
46
- } ) ;
47
-
48
- let unsafe_dead_block_func = Text :: new ( TextFragment {
49
- // `TextFragment` stores a string, and optional parameters which will override those
50
- // of `Text` itself. This allows inlining differently formatted lines, words,
51
- // or even individual letters, into the same block of text.
52
- text : "dead()" . to_string ( ) ,
53
- // `Font` is a handle to a loaded TTF, stored inside the `Context`.
54
- // `Font::default()` always exists and maps to DejaVuSerif.
55
- scale : Some ( Scale :: uniform ( 30.0 ) ) ,
56
- font : Some ( this. consolas ) ,
57
- color : Some ( Color :: new ( 214.0 / 255.0 , 208.0 / 255.0 , 132.0 / 255.0 , 1.0 ) ) ,
58
- // This doesn't do anything at this point; can be used to omit fields in declarations.
59
- ..Default :: default ( )
60
- } ) ;
61
-
62
- let unsafe_dead_block_end = Text :: new ( TextFragment {
63
- // `TextFragment` stores a string, and optional parameters which will override those
64
- // of `Text` itself. This allows inlining differently formatted lines, words,
65
- // or even individual letters, into the same block of text.
66
- text : "}" . to_string ( ) ,
67
- // `Font` is a handle to a loaded TTF, stored inside the `Context`.
68
- // `Font::default()` always exists and maps to DejaVuSerif.
69
- scale : Some ( Scale :: uniform ( 30.0 ) ) ,
70
- font : Some ( this. consolas ) ,
71
- color : Some ( Color :: new ( 1.0 , 1.0 , 1.0 , 1.0 ) ) ,
72
- // This doesn't do anything at this point; can be used to omit fields in declarations.
73
- ..Default :: default ( )
74
- } ) ;
75
-
76
- graphics:: draw (
77
- ctx,
78
- & dead,
79
- ( ggez:: mint:: Point2 {
80
- x : ( crate :: WIDTH / 2.0 ) - 60.0 ,
81
- y : 40.0 ,
82
- } , ) ,
83
- ) ?;
84
-
85
- graphics:: draw (
86
- ctx,
87
- & unsafe_dead,
88
- ( ggez:: mint:: Point2 {
89
- x : ( crate :: WIDTH / 2.0 ) - 200.0 ,
90
- y : 200.0 ,
91
- } , ) ,
92
- ) ?;
93
-
94
- graphics:: draw (
95
- ctx,
96
- & unsafe_dead_block_start,
97
- ( ggez:: mint:: Point2 {
98
- x : ( crate :: WIDTH / 2.0 ) - 90.0 ,
99
- y : 200.0 ,
100
- } , ) ,
101
- ) ?;
102
-
103
- graphics:: draw (
104
- ctx,
105
- & unsafe_dead_block_func,
106
- ( ggez:: mint:: Point2 {
107
- x : ( crate :: WIDTH / 2.0 ) - 125.0 ,
108
- y : 260.0 ,
109
- } , ) ,
110
- ) ?;
111
-
112
- graphics:: draw (
113
- ctx,
114
- & unsafe_dead_block_end,
115
- ( ggez:: mint:: Point2 {
116
- x : ( crate :: WIDTH / 2.0 ) - 200.0 ,
117
- y : 300.0 ,
118
- } , ) ,
119
- ) ?;
120
-
121
- graphics:: draw (
122
- ctx,
123
- & this. ferris_planet ,
124
- ( ggez:: nalgebra:: Point2 :: new ( ( crate :: WIDTH / 2.0 ) - 10.0 , 240.0 ) , ) ,
125
- ) . unwrap ( ) ;
126
-
127
- graphics:: present ( ctx)
20
+ pub fn draw ( & mut self , ctx : & mut Context ) -> GameResult < ( ) > {
21
+ graphics:: clear ( ctx, graphics:: BLACK ) ;
22
+
23
+ let dead = Text :: new ( TextFragment {
24
+ // `TextFragment` stores a string, and optional parameters which will override those
25
+ // of `Text` itself. This allows inlining differently formatted lines, words,
26
+ // or even individual letters, into the same block of text.
27
+ text : "YOU DEAD" . to_string ( ) ,
28
+ // `Font` is a handle to a loaded TTF, stored inside the `Context`.
29
+ // `Font::default()` always exists and maps to DejaVuSerif.
30
+ scale : Some ( Scale :: uniform ( 35.0 ) ) ,
31
+ font : Some ( self . consolas ) ,
32
+ color : Some ( Color :: new ( 1.0 , 80.0 / 255.0 , 76.0 / 255.0 , 1.0 ) ) ,
33
+ // This doesn't do anything at this point; can be used to omit fields in declarations.
34
+ ..Default :: default ( )
35
+ } ) ;
36
+
37
+ let unsafe_dead = Text :: new ( TextFragment {
38
+ // `TextFragment` stores a string, and optional parameters which will override those
39
+ // of `Text` itself. This allows inlining differently formatted lines, words,
40
+ // or even individual letters, into the same block of text.
41
+ text : "unsafe" . to_string ( ) ,
42
+ // `Font` is a handle to a loaded TTF, stored inside the `Context`.
43
+ // `Font::default()` always exists and maps to DejaVuSerif.
44
+ scale : Some ( Scale :: uniform ( 30.0 ) ) ,
45
+ font : Some ( self . consolas ) ,
46
+ color : Some ( Color :: new ( 74.0 / 255.0 , 129.0 / 255.0 , 191.0 / 255.0 , 1.0 ) ) ,
47
+ // This doesn't do anything at this point; can be used to omit fields in declarations.
48
+ ..Default :: default ( )
49
+ } ) ;
50
+
51
+ let unsafe_dead_block_start = Text :: new ( TextFragment {
52
+ // `TextFragment` stores a string, and optional parameters which will override those
53
+ // of `Text` itself. This allows inlining differently formatted lines, words,
54
+ // or even individual letters, into the same block of text.
55
+ text : "{" . to_string ( ) ,
56
+ // `Font` is a handle to a loaded TTF, stored inside the `Context`.
57
+ // `Font::default()` always exists and maps to DejaVuSerif.
58
+ scale : Some ( Scale :: uniform ( 30.0 ) ) ,
59
+ font : Some ( self . consolas ) ,
60
+ color : Some ( Color :: new ( 1.0 , 1.0 , 1.0 , 1.0 ) ) ,
61
+ // This doesn't do anything at this point; can be used to omit fields in declarations.
62
+ ..Default :: default ( )
63
+ } ) ;
64
+
65
+ let unsafe_dead_block_func = Text :: new ( TextFragment {
66
+ // `TextFragment` stores a string, and optional parameters which will override those
67
+ // of `Text` itself. This allows inlining differently formatted lines, words,
68
+ // or even individual letters, into the same block of text.
69
+ text : "dead()" . to_string ( ) ,
70
+ // `Font` is a handle to a loaded TTF, stored inside the `Context`.
71
+ // `Font::default()` always exists and maps to DejaVuSerif.
72
+ scale : Some ( Scale :: uniform ( 30.0 ) ) ,
73
+ font : Some ( self . consolas ) ,
74
+ color : Some ( Color :: new ( 214.0 / 255.0 , 208.0 / 255.0 , 132.0 / 255.0 , 1.0 ) ) ,
75
+ // This doesn't do anything at this point; can be used to omit fields in declarations.
76
+ ..Default :: default ( )
77
+ } ) ;
78
+
79
+ let unsafe_dead_block_end = Text :: new ( TextFragment {
80
+ // `TextFragment` stores a string, and optional parameters which will override those
81
+ // of `Text` itself. This allows inlining differently formatted lines, words,
82
+ // or even individual letters, into the same block of text.
83
+ text : "}" . to_string ( ) ,
84
+ // `Font` is a handle to a loaded TTF, stored inside the `Context`.
85
+ // `Font::default()` always exists and maps to DejaVuSerif.
86
+ scale : Some ( Scale :: uniform ( 30.0 ) ) ,
87
+ font : Some ( self . consolas ) ,
88
+ color : Some ( Color :: new ( 1.0 , 1.0 , 1.0 , 1.0 ) ) ,
89
+ // This doesn't do anything at this point; can be used to omit fields in declarations.
90
+ ..Default :: default ( )
91
+ } ) ;
92
+
93
+ graphics:: draw (
94
+ ctx,
95
+ & dead,
96
+ ( ggez:: mint:: Point2 {
97
+ x : ( crate :: WIDTH / 2.0 ) - 60.0 ,
98
+ y : 40.0 ,
99
+ } , ) ,
100
+ ) ?;
101
+
102
+ graphics:: draw (
103
+ ctx,
104
+ & unsafe_dead,
105
+ ( ggez:: mint:: Point2 {
106
+ x : ( crate :: WIDTH / 2.0 ) - 200.0 ,
107
+ y : 200.0 ,
108
+ } , ) ,
109
+ ) ?;
110
+
111
+ graphics:: draw (
112
+ ctx,
113
+ & unsafe_dead_block_start,
114
+ ( ggez:: mint:: Point2 {
115
+ x : ( crate :: WIDTH / 2.0 ) - 90.0 ,
116
+ y : 200.0 ,
117
+ } , ) ,
118
+ ) ?;
119
+
120
+ graphics:: draw (
121
+ ctx,
122
+ & unsafe_dead_block_func,
123
+ ( ggez:: mint:: Point2 {
124
+ x : ( crate :: WIDTH / 2.0 ) - 125.0 ,
125
+ y : 260.0 ,
126
+ } , ) ,
127
+ ) ?;
128
+
129
+ graphics:: draw (
130
+ ctx,
131
+ & unsafe_dead_block_end,
132
+ ( ggez:: mint:: Point2 {
133
+ x : ( crate :: WIDTH / 2.0 ) - 200.0 ,
134
+ y : 300.0 ,
135
+ } , ) ,
136
+ ) ?;
137
+
138
+ graphics:: draw (
139
+ ctx,
140
+ & self . ferris_planet ,
141
+ ( ggez:: nalgebra:: Point2 :: new (
142
+ ( crate :: WIDTH / 2.0 ) - 10.0 ,
143
+ 240.0 ,
144
+ ) , ) ,
145
+ )
146
+ . unwrap ( ) ;
147
+
148
+ graphics:: present ( ctx)
149
+ }
128
150
}
0 commit comments