1
- use ggez:: {
2
- event:: KeyCode ,
3
- graphics:: { self , Scale , Text , TextFragment } ,
4
- Context , GameResult ,
5
- } ;
1
+ use ggez:: { Context , GameResult , event:: KeyCode , graphics:: { self , Scale , Text , TextFragment } , nalgebra:: { Point2 , Vector2 } } ;
2
+ use graphics:: DrawParam ;
6
3
use std:: process:: exit;
7
4
8
5
use crate :: HEIGHT ;
@@ -11,68 +8,47 @@ use crate::WIDTH;
11
8
pub struct Menu {
12
9
pub consolas : graphics:: Font ,
13
10
pub ferris_ninja : graphics:: Image ,
11
+ pub logo : graphics:: Image ,
12
+ pub bg : graphics:: Image
14
13
}
15
14
16
15
impl Menu {
17
16
pub fn create ( ctx : & mut Context ) -> Self {
18
17
Self {
19
18
consolas : graphics:: Font :: new ( ctx, "/fonts/Consolas.ttf" ) . unwrap ( ) ,
20
19
ferris_ninja : graphics:: Image :: new ( ctx, "/images/ferris_ninja.png" ) . unwrap ( ) ,
20
+ logo : graphics:: Image :: new ( ctx, "/images/logo.png" ) . unwrap ( ) ,
21
+ bg : graphics:: Image :: new ( ctx, "/images/menu_bg.png" ) . unwrap ( ) ,
21
22
}
22
23
}
23
24
24
25
pub fn draw ( & self , ctx : & mut Context ) -> GameResult < ( ) > {
25
26
// Clear the screen
26
27
graphics:: clear ( ctx, graphics:: BLACK ) ;
27
28
28
- let title_call = TextFragment {
29
- text : "CALL" . to_owned ( ) ,
30
- font : Some ( self . consolas ) ,
31
- scale : Some ( Scale :: uniform ( 30.0 ) ) ,
32
-
33
- ..Default :: default ( )
34
- } ;
35
-
36
- let title_of = TextFragment {
37
- text : "OF" . to_owned ( ) ,
38
- font : Some ( self . consolas ) ,
39
- scale : Some ( Scale :: uniform ( 15.0 ) ) ,
40
-
41
- ..Default :: default ( )
42
- } ;
43
-
44
- let title_ferris = TextFragment {
45
- text : "FERRIS" . to_owned ( ) ,
46
- font : Some ( self . consolas ) ,
47
- scale : Some ( Scale :: uniform ( 30.0 ) ) ,
48
-
49
- ..Default :: default ( )
50
- } ;
51
-
52
- graphics:: draw (
53
- ctx,
54
- & Text :: new ( title_call) ,
55
- ( ggez:: nalgebra:: Point2 :: new ( WIDTH - 220.0 , 10.0 ) , ) ,
56
- ) ?;
57
-
58
29
graphics:: draw (
59
30
ctx,
60
- & Text :: new ( title_of) ,
61
- ( ggez:: nalgebra:: Point2 :: new ( WIDTH - 150.0 , 20.0 ) , ) ,
31
+ & self . bg ,
32
+ DrawParam :: default ( )
33
+ . dest ( Point2 :: new ( 0.0 , 0.0 ) )
34
+ . scale ( Vector2 :: new ( 0.6 , 0.5 ) )
62
35
) ?;
63
36
64
37
graphics:: draw (
65
38
ctx,
66
- & Text :: new ( title_ferris) ,
67
- ( ggez:: nalgebra:: Point2 :: new ( WIDTH - 130.0 , 10.0 ) , ) ,
39
+ & self . logo ,
40
+ ( ggez:: nalgebra:: Point2 :: new (
41
+ WIDTH - ( self . logo . width ( ) as f32 + 20.0 ) ,
42
+ 10.0
43
+ ) , ) ,
68
44
) ?;
69
45
70
46
graphics:: draw (
71
47
ctx,
72
48
& self . ferris_ninja ,
73
49
( ggez:: nalgebra:: Point2 :: new (
74
- WIDTH - ( WIDTH - 100 .0) ,
75
- HEIGHT - ( & self . ferris_ninja . height ( ) + 30 ) as f32 ,
50
+ WIDTH - ( WIDTH - 400 .0) ,
51
+ HEIGHT - ( & self . ferris_ninja . height ( ) + 140 ) as f32 ,
76
52
) , ) ,
77
53
) ?;
78
54
@@ -97,32 +73,32 @@ impl Menu {
97
73
& Text :: new ( press_and_to) ,
98
74
( ggez:: nalgebra:: Point2 :: new (
99
75
WIDTH - 200.0 ,
100
- HEIGHT - ( & self . ferris_ninja . height ( ) + 60 ) as f32 ,
76
+ HEIGHT - ( & self . ferris_ninja . height ( ) + 30 ) as f32 ,
101
77
) , ) ,
102
78
) ?;
103
79
104
80
let play_rect = graphics:: Mesh :: new_rectangle (
105
81
ctx,
106
82
graphics:: DrawMode :: fill ( ) ,
107
83
graphics:: Rect :: new (
108
- WIDTH - 260 .0,
109
- HEIGHT - ( & self . ferris_ninja . height ( ) + 40 ) as f32 ,
84
+ WIDTH - 200 .0,
85
+ HEIGHT - ( & self . ferris_ninja . height ( ) + 10 ) as f32 ,
110
86
220.0 ,
111
87
40.0 ,
112
88
) ,
113
- [ 36.0 / 255.0 , 36.0 / 255.0 , 36.0 / 255.0 , 1.0 ] . into ( ) ,
89
+ [ 36.0 / 255.0 , 36.0 / 255.0 , 36.0 / 255.0 , 0.5 ] . into ( ) ,
114
90
) ?;
115
91
116
92
let quit_rect = graphics:: Mesh :: new_rectangle (
117
93
ctx,
118
94
graphics:: DrawMode :: fill ( ) ,
119
95
graphics:: Rect :: new (
120
- WIDTH - 260 .0,
96
+ WIDTH - 200 .0,
121
97
HEIGHT - ( & self . ferris_ninja . height ( ) - 70 ) as f32 ,
122
98
220.0 ,
123
99
40.0 ,
124
100
) ,
125
- [ 36.0 / 255.0 , 36.0 / 255.0 , 36.0 / 255.0 , 1.0 ] . into ( ) ,
101
+ [ 36.0 / 255.0 , 36.0 / 255.0 , 36.0 / 255.0 , 0.5 ] . into ( ) ,
126
102
) ?;
127
103
128
104
let play_text = TextFragment {
@@ -149,7 +125,7 @@ impl Menu {
149
125
& Text :: new ( play_text) ,
150
126
( ggez:: nalgebra:: Point2 :: new (
151
127
WIDTH - 170.0 ,
152
- HEIGHT - ( & self . ferris_ninja . height ( ) + 28 ) as f32 ,
128
+ HEIGHT - self . ferris_ninja . height ( ) as f32 ,
153
129
) , ) ,
154
130
) ?;
155
131
0 commit comments