Skip to content

Commit e2d536e

Browse files
Update menu screen
1 parent cf7d21c commit e2d536e

File tree

4 files changed

+116
-87
lines changed

4 files changed

+116
-87
lines changed

resources/background.png

97.4 KB
Loading

resources/ferris_borrow_angry.png

26.8 KB
Loading

src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ mod menu;
88
mod game;
99
mod dead;
1010

11-
const WIDTH: f32 = 800.0;
11+
const WIDTH: f32 = 1000.0;
1212
const HEIGHT: f32 = 600.0;
1313

1414
fn main() {
15+
// The resources directory contains all of the assets.
16+
// Including sprites and audio files.
1517
let resource_dir = std::path::PathBuf::from("./resources");
1618

1719
// Make a Context and an EventLoop.
@@ -71,7 +73,8 @@ impl MyGame {
7173

7274
menu_screen: menu::Menu {
7375
consolas,
74-
ferris_borrow_fail: ferris_borrow_angry
76+
ferris_ninja: ferris_borrow_angry,
77+
background: graphics::Image::new(ctx, "/background.png").unwrap()
7578
}
7679
}
7780
}

src/menu.rs

Lines changed: 111 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,155 @@
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}};
22
use std::process::exit;
33

4+
use crate::WIDTH;
5+
use crate::HEIGHT;
6+
47
pub struct Menu {
58
pub consolas: graphics::Font,
6-
pub ferris_borrow_fail: graphics::Image
9+
pub ferris_ninja: graphics::Image,
10+
pub background: graphics::Image
711
}
812

913
impl Menu {
1014
pub fn draw(&self, ctx: &mut Context) -> GameResult<()> {
15+
// Clear the screen
1116
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(),
2020
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+
2323
..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(),
3328
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+
3731
..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+
};
3941

4042
graphics::draw(
4143
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+
4650
graphics::draw(
4751
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+
5258
graphics::draw(
5359
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+
5996
let play_rect = graphics::Mesh::new_rectangle(
6097
ctx,
6198
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(),
64101
)?;
65-
66-
let dirty_pointer = graphics::Mesh::new_rectangle(
102+
103+
let quit_rect = graphics::Mesh::new_rectangle(
67104
ctx,
68105
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(),
71108
)?;
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(),
80112
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+
85115
..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(),
95120
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+
100123
..Default::default()
101-
});
102-
124+
};
125+
103126
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+
104129
graphics::draw(
105130
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),),
108135
)?;
109-
136+
110137
graphics::draw(
111138
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),),
117143
)?;
144+
118145
graphics::draw(
119146
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),),
125151
)?;
126-
152+
127153
graphics::present(ctx)
128154
}
129155

0 commit comments

Comments
 (0)