|
1 |
| -use ggez::{Context, GameResult, event::KeyCode, graphics::{self, Color, Scale, Text, TextFragment}}; |
| 1 | +use ggez::{Context, GameResult, event::KeyCode, graphics::{self, Scale, Text, TextFragment}}; |
2 | 2 | use std::process::exit;
|
3 | 3 |
|
| 4 | +use crate::WIDTH; |
| 5 | +use crate::HEIGHT; |
| 6 | + |
4 | 7 | pub struct Menu {
|
5 | 8 | pub consolas: graphics::Font,
|
6 |
| - pub ferris_borrow_fail: graphics::Image |
| 9 | + pub ferris_ninja: graphics::Image, |
| 10 | + pub background: graphics::Image |
7 | 11 | }
|
8 | 12 |
|
9 | 13 | impl Menu {
|
10 | 14 | pub fn draw(&self, ctx: &mut Context) -> GameResult<()> {
|
| 15 | + // Clear the screen |
11 | 16 | 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. |
| 17 | + |
| 18 | + let title_call = TextFragment { |
| 19 | + text: "CALL".to_owned(), |
20 | 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. |
| 21 | + scale: Some(Scale::uniform(30.0)), |
| 22 | + |
23 | 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. |
| 24 | + }; |
| 25 | + |
| 26 | + let title_of = TextFragment { |
| 27 | + text: "OF".to_owned(), |
33 | 28 | 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)), |
| 29 | + scale: Some(Scale::uniform(15.0)), |
| 30 | + |
37 | 31 | ..Default::default()
|
38 |
| - }); |
| 32 | + }; |
| 33 | + |
| 34 | + let title_ferris = TextFragment { |
| 35 | + text: "FERRIS".to_owned(), |
| 36 | + font: Some(self.consolas), |
| 37 | + scale: Some(Scale::uniform(30.0)), |
| 38 | + |
| 39 | + ..Default::default() |
| 40 | + }; |
39 | 41 |
|
40 | 42 | graphics::draw(
|
41 | 43 | ctx,
|
42 |
| - &self.ferris_borrow_fail, |
43 |
| - (ggez::nalgebra::Point2::new((crate::WIDTH / 2.0) - 85.0, 100.0),), |
44 |
| - ) |
45 |
| - .unwrap(); |
| 44 | + &Text::new( |
| 45 | + title_call, |
| 46 | + ), |
| 47 | + (ggez::nalgebra::Point2::new(WIDTH - 220.0, 10.0),), |
| 48 | + )?; |
| 49 | + |
46 | 50 | graphics::draw(
|
47 | 51 | ctx,
|
48 |
| - &call_of_ferris_text, |
49 |
| - (ggez::nalgebra::Point2::new((crate::WIDTH / 2.0) - 130.0, 250.0),), |
50 |
| - ) |
51 |
| - .unwrap(); |
| 52 | + &Text::new( |
| 53 | + title_of, |
| 54 | + ), |
| 55 | + (ggez::nalgebra::Point2::new(WIDTH - 150.0, 20.0),), |
| 56 | + )?; |
| 57 | + |
52 | 58 | graphics::draw(
|
53 | 59 | ctx,
|
54 |
| - &ownership_war, |
55 |
| - (ggez::nalgebra::Point2::new((crate::WIDTH / 2.0) - 50.0, 300.0),), |
56 |
| - ) |
57 |
| - .unwrap(); |
58 |
| - |
| 60 | + &Text::new( |
| 61 | + title_ferris, |
| 62 | + ), |
| 63 | + (ggez::nalgebra::Point2::new(WIDTH - 130.0, 10.0),), |
| 64 | + )?; |
| 65 | + |
| 66 | + graphics::draw( |
| 67 | + ctx, |
| 68 | + &self.ferris_ninja, |
| 69 | + (ggez::nalgebra::Point2::new(WIDTH - (WIDTH - 100.0), HEIGHT - (&self.ferris_ninja.height() + 30) as f32),), |
| 70 | + )?; |
| 71 | + |
| 72 | + let press_and_to = TextFragment { |
| 73 | + text: "Press & to".to_owned(), |
| 74 | + font: Some(self.consolas), |
| 75 | + scale: Some(Scale::uniform(15.0)), |
| 76 | + |
| 77 | + ..Default::default() |
| 78 | + }; |
| 79 | + |
| 80 | + let press_pointer_to = TextFragment { |
| 81 | + text: "Press * to".to_owned(), |
| 82 | + font: Some(self.consolas), |
| 83 | + scale: Some(Scale::uniform(15.0)), |
| 84 | + |
| 85 | + ..Default::default() |
| 86 | + }; |
| 87 | + |
| 88 | + graphics::draw( |
| 89 | + ctx, |
| 90 | + &Text::new( |
| 91 | + press_and_to, |
| 92 | + ), |
| 93 | + (ggez::nalgebra::Point2::new(WIDTH - 200.0, HEIGHT - (&self.ferris_ninja.height() + 60) as f32),), |
| 94 | + )?; |
| 95 | + |
59 | 96 | let play_rect = graphics::Mesh::new_rectangle(
|
60 | 97 | ctx,
|
61 | 98 | 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(), |
| 99 | + graphics::Rect::new(WIDTH - 260.0, HEIGHT - (&self.ferris_ninja.height() + 40) as f32, 220.0, 40.0), |
| 100 | + [36.0 / 255.0, 36.0 / 255.0, 36.0 / 255.0, 1.0].into(), |
64 | 101 | )?;
|
65 |
| - |
66 |
| - let dirty_pointer = graphics::Mesh::new_rectangle( |
| 102 | + |
| 103 | + let quit_rect = graphics::Mesh::new_rectangle( |
67 | 104 | ctx,
|
68 | 105 | 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(), |
| 106 | + graphics::Rect::new(WIDTH - 260.0, HEIGHT - (&self.ferris_ninja.height() - 70) as f32, 220.0, 40.0), |
| 107 | + [36.0 / 255.0, 36.0 / 255.0, 36.0 / 255.0, 1.0].into(), |
71 | 108 | )?;
|
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. |
| 109 | + |
| 110 | + let play_text = TextFragment { |
| 111 | + text: "PLAY".to_owned(), |
80 | 112 | 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. |
| 113 | + scale: Some(Scale::uniform(20.0)), |
| 114 | + |
85 | 115 | ..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. |
| 116 | + }; |
| 117 | + |
| 118 | + let quit_text = TextFragment { |
| 119 | + text: "QUIT".to_owned(), |
95 | 120 | 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. |
| 121 | + scale: Some(Scale::uniform(20.0)), |
| 122 | + |
100 | 123 | ..Default::default()
|
101 |
| - }); |
102 |
| - |
| 124 | + }; |
| 125 | + |
103 | 126 | graphics::draw(ctx, &play_rect, (ggez::mint::Point2 { x: 0.0, y: 0.0 },))?;
|
| 127 | + graphics::draw(ctx, &quit_rect, (ggez::mint::Point2 { x: 0.0, y: 0.0 },))?; |
| 128 | + |
104 | 129 | graphics::draw(
|
105 | 130 | ctx,
|
106 |
| - &dirty_pointer, |
107 |
| - (ggez::mint::Point2 { x: 0.0, y: 0.0 },), |
| 131 | + &Text::new( |
| 132 | + play_text, |
| 133 | + ), |
| 134 | + (ggez::nalgebra::Point2::new(WIDTH - 170.0, HEIGHT - (&self.ferris_ninja.height() + 28) as f32),), |
108 | 135 | )?;
|
109 |
| - |
| 136 | + |
110 | 137 | graphics::draw(
|
111 | 138 | ctx,
|
112 |
| - &play_borrow, |
113 |
| - (ggez::mint::Point2 { |
114 |
| - x: (crate::WIDTH / 2.0) - 300.0, |
115 |
| - y: 430.0, |
116 |
| - },), |
| 139 | + &Text::new( |
| 140 | + press_pointer_to, |
| 141 | + ), |
| 142 | + (ggez::nalgebra::Point2::new(WIDTH - 200.0, HEIGHT - (&self.ferris_ninja.height() - 50) as f32),), |
117 | 143 | )?;
|
| 144 | + |
118 | 145 | graphics::draw(
|
119 | 146 | ctx,
|
120 |
| - &dirty_pointer_quit, |
121 |
| - (ggez::mint::Point2 { |
122 |
| - x: (crate::WIDTH / 2.0) + 200.0, |
123 |
| - y: 430.0, |
124 |
| - },), |
| 147 | + &Text::new( |
| 148 | + quit_text, |
| 149 | + ), |
| 150 | + (ggez::nalgebra::Point2::new(WIDTH - 170.0, HEIGHT - (&self.ferris_ninja.height() - 80) as f32),), |
125 | 151 | )?;
|
126 |
| - |
| 152 | + |
127 | 153 | graphics::present(ctx)
|
128 | 154 | }
|
129 | 155 |
|
|
0 commit comments