1
- use ggez:: {
2
- graphics:: { self , Color , Scale , Text , TextFragment } ,
3
- Context , GameResult ,
4
- } ;
1
+ use ggez:: { Context , GameResult , event:: KeyCode , graphics:: { self , Color , Scale , Text , TextFragment } } ;
2
+ use std:: process:: exit;
5
3
6
- #[ allow( dead_code) ]
7
-
8
- const WIDTH : f32 = crate :: WIDTH ;
9
- #[ allow( dead_code) ]
10
-
11
- const HEIGHT : f32 = crate :: HEIGHT ;
12
-
13
- pub fn draw ( this : & mut crate :: MyGame , ctx : & mut Context ) -> GameResult < ( ) > {
14
- graphics:: clear ( ctx, graphics:: BLACK ) ;
15
-
16
- let call_of_ferris_text = Text :: new ( TextFragment {
17
- // `TextFragment` stores a string, and optional parameters which will override those
18
- // of `Text` itself. This allows inlining differently formatted lines, words,
19
- // or even individual letters, into the same block of text.
20
- text : "Call of Ferris" . to_string ( ) ,
21
- // `Font` is a handle to a loaded TTF, stored inside the `Context`.
22
- // `Font::default()` always exists and maps to DejaVuSerif.
23
- font : Some ( this. consolas ) ,
24
- scale : Some ( Scale :: uniform ( 33.0 ) ) ,
25
- // This doesn't do anything at this point; can be used to omit fields in declarations.
26
- ..Default :: default ( )
27
- } ) ;
28
-
29
- let ownership_war = Text :: new ( TextFragment {
30
- // `TextFragment` stores a string, and optional parameters which will override those
31
- // of `Text` itself. This allows inlining differently formatted lines, words,
32
- // or even individual letters, into the same block of text.
33
- text : "Ownership War" . to_string ( ) ,
34
- // `Font` is a handle to a loaded TTF, stored inside the `Context`.
35
- // `Font::default()` always exists and maps to DejaVuSerif.
36
- font : Some ( this. consolas ) ,
37
- scale : Some ( Scale :: uniform ( 14.0 ) ) ,
38
-
39
- color : Some ( Color :: new ( 1.0 , 80.0 / 255.0 , 76.0 / 255.0 , 1.0 ) ) ,
40
- ..Default :: default ( )
41
- } ) ;
42
-
43
- graphics:: draw (
44
- ctx,
45
- & this. ferris_borrow_fail ,
46
- ( ggez:: nalgebra:: Point2 :: new ( ( WIDTH / 2.0 ) - 85.0 , 100.0 ) , ) ,
47
- )
48
- . unwrap ( ) ;
49
- graphics:: draw (
50
- ctx,
51
- & call_of_ferris_text,
52
- ( ggez:: nalgebra:: Point2 :: new ( ( WIDTH / 2.0 ) - 130.0 , 250.0 ) , ) ,
53
- )
54
- . unwrap ( ) ;
55
- graphics:: draw (
56
- ctx,
57
- & ownership_war,
58
- ( ggez:: nalgebra:: Point2 :: new ( ( WIDTH / 2.0 ) - 50.0 , 300.0 ) , ) ,
59
- )
60
- . unwrap ( ) ;
61
-
62
- let play_rect = graphics:: Mesh :: new_rectangle (
63
- ctx,
64
- graphics:: DrawMode :: fill ( ) ,
65
- graphics:: Rect :: new ( ( WIDTH / 2.0 ) - 320.0 , 410.0 , 160.0 , 60.0 ) ,
66
- [ 1.0 , 0.5 , 0.0 , 1.0 ] . into ( ) ,
67
- ) ?;
68
-
69
- let dirty_pointer = graphics:: Mesh :: new_rectangle (
70
- ctx,
71
- graphics:: DrawMode :: fill ( ) ,
72
- graphics:: Rect :: new ( ( WIDTH / 2.0 ) + 180.0 , 410.0 , 160.0 , 60.0 ) ,
73
- [ 4.0 / 255.0 , 129.0 / 255.0 , 191.0 / 255.0 , 1.0 ] . into ( ) ,
74
- ) ?;
75
-
76
- let play_borrow = Text :: new ( TextFragment {
77
- // `TextFragment` stores a string, and optional parameters which will override those
78
- // of `Text` itself. This allows inlining differently formatted lines, words,
79
- // or even individual letters, into the same block of text.
80
- text : "& to play" . to_string ( ) ,
81
- // `Font` is a handle to a loaded TTF, stored inside the `Context`.
82
- // `Font::default()` always exists and maps to DejaVuSerif.
83
- font : Some ( this. consolas ) ,
84
- scale : Some ( Scale :: uniform ( 25.0 ) ) ,
85
-
86
- color : Some ( Color :: new ( 1.0 , 1.0 , 1.0 , 1.0 ) ) ,
87
- // This doesn't do anything at this point; can be used to omit fields in declarations.
88
- ..Default :: default ( )
89
- } ) ;
90
-
91
- let dirty_pointer_quit = Text :: new ( TextFragment {
92
- // `TextFragment` stores a string, and optional parameters which will override those
93
- // of `Text` itself. This allows inlining differently formatted lines, words,
94
- // or even individual letters, into the same block of text.
95
- text : "* to quit" . to_string ( ) ,
96
- // `Font` is a handle to a loaded TTF, stored inside the `Context`.
97
- // `Font::default()` always exists and maps to DejaVuSerif.
98
- font : Some ( this. consolas ) ,
99
- scale : Some ( Scale :: uniform ( 25.0 ) ) ,
100
-
101
- color : Some ( Color :: new ( 1.0 , 1.0 , 1.0 , 1.0 ) ) ,
102
- // This doesn't do anything at this point; can be used to omit fields in declarations.
103
- ..Default :: default ( )
104
- } ) ;
105
-
106
- graphics:: draw ( ctx, & play_rect, ( ggez:: mint:: Point2 { x : 0.0 , y : 0.0 } , ) ) ?;
107
- graphics:: draw (
108
- ctx,
109
- & dirty_pointer,
110
- ( ggez:: mint:: Point2 { x : 0.0 , y : 0.0 } , ) ,
111
- ) ?;
112
-
113
- graphics:: draw (
114
- ctx,
115
- & play_borrow,
116
- ( ggez:: mint:: Point2 {
117
- x : ( WIDTH / 2.0 ) - 300.0 ,
118
- y : 430.0 ,
119
- } , ) ,
120
- ) ?;
121
- graphics:: draw (
122
- ctx,
123
- & dirty_pointer_quit,
124
- ( ggez:: mint:: Point2 {
125
- x : ( WIDTH / 2.0 ) + 200.0 ,
126
- y : 430.0 ,
127
- } , ) ,
128
- ) ?;
129
-
130
- graphics:: present ( ctx)
4
+ pub struct Menu {
5
+ pub consolas : graphics:: Font ,
6
+ pub ferris_borrow_fail : graphics:: Image
131
7
}
8
+
9
+ impl Menu {
10
+ pub fn draw ( & self , ctx : & mut Context ) -> GameResult < ( ) > {
11
+ graphics:: clear ( ctx, graphics:: BLACK ) ;
12
+
13
+ let call_of_ferris_text = Text :: new ( TextFragment {
14
+ // `TextFragment` stores a string, and optional parameters which will override those
15
+ // of `Text` itself. This allows inlining differently formatted lines, words,
16
+ // or even individual letters, into the same block of text.
17
+ text : "Call of Ferris" . to_string ( ) ,
18
+ // `Font` is a handle to a loaded TTF, stored inside the `Context`.
19
+ // `Font::default()` always exists and maps to DejaVuSerif.
20
+ font : Some ( self . consolas ) ,
21
+ scale : Some ( Scale :: uniform ( 33.0 ) ) ,
22
+ // This doesn't do anything at this point; can be used to omit fields in declarations.
23
+ ..Default :: default ( )
24
+ } ) ;
25
+
26
+ let ownership_war = Text :: new ( TextFragment {
27
+ // `TextFragment` stores a string, and optional parameters which will override those
28
+ // of `Text` itself. This allows inlining differently formatted lines, words,
29
+ // or even individual letters, into the same block of text.
30
+ text : "Ownership War" . to_string ( ) ,
31
+ // `Font` is a handle to a loaded TTF, stored inside the `Context`.
32
+ // `Font::default()` always exists and maps to DejaVuSerif.
33
+ font : Some ( self . consolas ) ,
34
+ scale : Some ( Scale :: uniform ( 14.0 ) ) ,
35
+
36
+ color : Some ( Color :: new ( 1.0 , 80.0 / 255.0 , 76.0 / 255.0 , 1.0 ) ) ,
37
+ ..Default :: default ( )
38
+ } ) ;
39
+
40
+ graphics:: draw (
41
+ ctx,
42
+ & self . ferris_borrow_fail ,
43
+ ( ggez:: nalgebra:: Point2 :: new ( ( crate :: WIDTH / 2.0 ) - 85.0 , 100.0 ) , ) ,
44
+ )
45
+ . unwrap ( ) ;
46
+ graphics:: draw (
47
+ ctx,
48
+ & call_of_ferris_text,
49
+ ( ggez:: nalgebra:: Point2 :: new ( ( crate :: WIDTH / 2.0 ) - 130.0 , 250.0 ) , ) ,
50
+ )
51
+ . unwrap ( ) ;
52
+ graphics:: draw (
53
+ ctx,
54
+ & ownership_war,
55
+ ( ggez:: nalgebra:: Point2 :: new ( ( crate :: WIDTH / 2.0 ) - 50.0 , 300.0 ) , ) ,
56
+ )
57
+ . unwrap ( ) ;
58
+
59
+ let play_rect = graphics:: Mesh :: new_rectangle (
60
+ ctx,
61
+ graphics:: DrawMode :: fill ( ) ,
62
+ graphics:: Rect :: new ( ( crate :: WIDTH / 2.0 ) - 320.0 , 410.0 , 160.0 , 60.0 ) ,
63
+ [ 1.0 , 0.5 , 0.0 , 1.0 ] . into ( ) ,
64
+ ) ?;
65
+
66
+ let dirty_pointer = graphics:: Mesh :: new_rectangle (
67
+ ctx,
68
+ graphics:: DrawMode :: fill ( ) ,
69
+ graphics:: Rect :: new ( ( crate :: WIDTH / 2.0 ) + 180.0 , 410.0 , 160.0 , 60.0 ) ,
70
+ [ 4.0 / 255.0 , 129.0 / 255.0 , 191.0 / 255.0 , 1.0 ] . into ( ) ,
71
+ ) ?;
72
+
73
+ let play_borrow = Text :: new ( TextFragment {
74
+ // `TextFragment` stores a string, and optional parameters which will override those
75
+ // of `Text` itself. This allows inlining differently formatted lines, words,
76
+ // or even individual letters, into the same block of text.
77
+ text : "& to play" . to_string ( ) ,
78
+ // `Font` is a handle to a loaded TTF, stored inside the `Context`.
79
+ // `Font::default()` always exists and maps to DejaVuSerif.
80
+ font : Some ( self . consolas ) ,
81
+ scale : Some ( Scale :: uniform ( 25.0 ) ) ,
82
+
83
+ color : Some ( Color :: new ( 1.0 , 1.0 , 1.0 , 1.0 ) ) ,
84
+ // This doesn't do anything at this point; can be used to omit fields in declarations.
85
+ ..Default :: default ( )
86
+ } ) ;
87
+
88
+ let dirty_pointer_quit = Text :: new ( TextFragment {
89
+ // `TextFragment` stores a string, and optional parameters which will override those
90
+ // of `Text` itself. This allows inlining differently formatted lines, words,
91
+ // or even individual letters, into the same block of text.
92
+ text : "* to quit" . to_string ( ) ,
93
+ // `Font` is a handle to a loaded TTF, stored inside the `Context`.
94
+ // `Font::default()` always exists and maps to DejaVuSerif.
95
+ font : Some ( self . consolas ) ,
96
+ scale : Some ( Scale :: uniform ( 25.0 ) ) ,
97
+
98
+ color : Some ( Color :: new ( 1.0 , 1.0 , 1.0 , 1.0 ) ) ,
99
+ // This doesn't do anything at this point; can be used to omit fields in declarations.
100
+ ..Default :: default ( )
101
+ } ) ;
102
+
103
+ graphics:: draw ( ctx, & play_rect, ( ggez:: mint:: Point2 { x : 0.0 , y : 0.0 } , ) ) ?;
104
+ graphics:: draw (
105
+ ctx,
106
+ & dirty_pointer,
107
+ ( ggez:: mint:: Point2 { x : 0.0 , y : 0.0 } , ) ,
108
+ ) ?;
109
+
110
+ graphics:: draw (
111
+ ctx,
112
+ & play_borrow,
113
+ ( ggez:: mint:: Point2 {
114
+ x : ( crate :: WIDTH / 2.0 ) - 300.0 ,
115
+ y : 430.0 ,
116
+ } , ) ,
117
+ ) ?;
118
+ graphics:: draw (
119
+ ctx,
120
+ & dirty_pointer_quit,
121
+ ( ggez:: mint:: Point2 {
122
+ x : ( crate :: WIDTH / 2.0 ) + 200.0 ,
123
+ y : 430.0 ,
124
+ } , ) ,
125
+ ) ?;
126
+
127
+ graphics:: present ( ctx)
128
+ }
129
+
130
+ pub fn key_press ( & self , keycode : KeyCode ) -> Option < crate :: Screen > {
131
+ if keycode == KeyCode :: Key7 {
132
+ return Some ( crate :: Screen :: Play ) ;
133
+ }
134
+
135
+ else if keycode == KeyCode :: Key8 {
136
+ exit ( 0 ) ;
137
+ }
138
+
139
+ return None ;
140
+ }
141
+ }
0 commit comments