Skip to content

Commit 22f88db

Browse files
Organise the screens a bit more
1 parent 3fcd4fd commit 22f88db

File tree

15 files changed

+198
-229
lines changed

15 files changed

+198
-229
lines changed

resources/maps/01.map

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.comment Define all of our variables
22

33
.end We **rustaceans** love all animals and we do not want to disappoint them like the gophers. \nWe also have animals in our language too like Cow<>. \nWe just love the correct animals ⌐■_■
4-
.using Turbofish Gun
4+
.using_weapon Turbofish Gun
55

66
.comment The map
77
[-4------]_[--8---8---*-]_[--------------8]

src/dead.rs

Lines changed: 0 additions & 154 deletions
This file was deleted.

src/main.rs

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,35 @@ use ggez::{
1414
};
1515
use utils::AssetManager;
1616

17-
mod dead;
18-
mod game;
19-
mod map;
20-
mod menu;
21-
mod physics;
2217
mod utils;
2318

24-
mod components {
25-
pub mod barrel;
26-
pub mod bullet;
27-
pub mod cloud;
28-
pub mod enemy;
29-
pub mod player;
30-
pub mod tile;
19+
mod screens {
20+
pub mod menu {
21+
pub mod menu;
22+
}
23+
24+
pub mod game {
25+
pub mod components {
26+
pub mod barrel;
27+
pub mod bullet;
28+
pub mod cloud;
29+
pub mod enemy;
30+
pub mod player;
31+
pub mod tile;
32+
}
33+
34+
pub mod game;
35+
pub mod map;
36+
pub mod physics;
37+
}
38+
39+
pub mod dead {
40+
pub mod dead;
41+
}
3142
}
3243

44+
pub use screens::*;
45+
3346
const WIDTH: f32 = 1000.0;
3447
const HEIGHT: f32 = 600.0;
3548

@@ -91,9 +104,9 @@ pub enum Screen {
91104

92105
pub struct Game {
93106
screen: Screen,
94-
menu_screen: menu::Menu,
95-
game_screen: Mutex<game::Game>,
96-
death_screen: dead::Death,
107+
menu_screen: menu::menu::Menu,
108+
game_screen: Mutex<game::game::Game>,
109+
death_screen: dead::dead::Death,
97110

98111
asset_manager: Rc<AssetManager>,
99112
}
@@ -107,9 +120,9 @@ impl Game {
107120
Self {
108121
screen: Screen::Menu,
109122

110-
menu_screen: menu::Menu::create(ctx, asset_manager.clone()),
111-
game_screen: game::Game::create(ctx, asset_manager.clone()),
112-
death_screen: dead::Death::spawn(ctx),
123+
menu_screen: menu::menu::Menu::create(ctx, asset_manager.clone()),
124+
game_screen: game::game::Game::create(ctx, asset_manager.clone()),
125+
death_screen: dead::dead::Death::spawn(ctx, asset_manager.clone()),
113126

114127
asset_manager,
115128
}
@@ -179,7 +192,8 @@ impl EventHandler for Game {
179192
if let Some(s) = change {
180193
match s {
181194
Screen::Menu => {
182-
self.game_screen = game::Game::create(ctx, self.asset_manager.clone());
195+
self.game_screen =
196+
game::game::Game::create(ctx, self.asset_manager.clone());
183197
}
184198

185199
_ => (),

src/screens/dead/dead.rs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
use std::rc::Rc;
2+
3+
use ggez::{
4+
graphics::Color,
5+
graphics::{self, Scale, Text, TextFragment},
6+
nalgebra::Point2,
7+
Context, GameResult,
8+
};
9+
use graphics::DrawParam;
10+
11+
use crate::{utils::AssetManager, WIDTH};
12+
13+
pub struct Death {
14+
asset_manager: Rc<AssetManager>,
15+
}
16+
17+
impl Death {
18+
pub fn spawn(_ctx: &mut Context, asset_manager: Rc<AssetManager>) -> Self {
19+
Self { asset_manager }
20+
}
21+
22+
pub fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
23+
graphics::clear(ctx, graphics::BLACK);
24+
25+
let consolas = self.asset_manager.get_font("Consolas.ttf");
26+
let ferris_planet = self.asset_manager.get_image("ferris_planet.png");
27+
28+
let dead = Text::new(
29+
TextFragment::new("YOU DEAD")
30+
.scale(Scale::uniform(35.0))
31+
.font(consolas)
32+
.color(Color::from_rgb(255, 80, 76)),
33+
);
34+
35+
let unsafe_dead = Text::new(
36+
TextFragment::new("unsafe")
37+
.scale(Scale::uniform(30.0))
38+
.font(consolas)
39+
.color(Color::from_rgb(74, 129, 191)),
40+
);
41+
42+
let unsafe_dead_block_start = Text::new(
43+
TextFragment::new("{")
44+
.scale(Scale::uniform(30.0))
45+
.font(consolas)
46+
.color(Color::from_rgb(255, 255, 255)),
47+
);
48+
49+
let unsafe_dead_block_func = Text::new(
50+
TextFragment::new("dead()")
51+
.scale(Scale::uniform(30.0))
52+
.font(consolas)
53+
.color(Color::from_rgb(214, 208, 132)),
54+
);
55+
56+
let unsafe_dead_block_end = Text::new(
57+
TextFragment::new("}")
58+
.scale(Scale::uniform(30.0))
59+
.font(consolas)
60+
.color(Color::from_rgb(255, 255, 255)),
61+
);
62+
63+
graphics::draw(
64+
ctx,
65+
&dead,
66+
DrawParam::default().dest(Point2::new((WIDTH / 2.0) - 60.0, 40.0)),
67+
)?;
68+
69+
graphics::draw(
70+
ctx,
71+
&unsafe_dead,
72+
DrawParam::default().dest(Point2::new((WIDTH / 2.0) - 200.0, 200.0)),
73+
)?;
74+
75+
graphics::draw(
76+
ctx,
77+
&unsafe_dead_block_start,
78+
DrawParam::default().dest(Point2::new((WIDTH / 2.0) - 90.0, 200.0)),
79+
)?;
80+
81+
graphics::draw(
82+
ctx,
83+
&unsafe_dead_block_func,
84+
DrawParam::default().dest(Point2::new((WIDTH / 2.0) - 125.0, 260.0)),
85+
)?;
86+
87+
graphics::draw(
88+
ctx,
89+
&unsafe_dead_block_end,
90+
DrawParam::default().dest(Point2::new((WIDTH / 2.0) - 200.0, 300.0)),
91+
)?;
92+
93+
graphics::draw(
94+
ctx,
95+
&ferris_planet,
96+
DrawParam::default().dest(Point2::new((WIDTH / 2.0) - 10.0, 240.0)),
97+
)?;
98+
99+
graphics::present(ctx)
100+
}
101+
102+
pub fn update(&self, _ctx: &mut Context) -> GameResult {
103+
Ok(())
104+
}
105+
}

src/components/barrel.rs renamed to src/screens/game/components/barrel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use ggez_goodies::{camera::Camera, nalgebra_glm::Vec2};
33
use graphics::DrawParam;
44

55
use crate::{
6-
physics::{isometry_to_point, Physics},
6+
game::physics::{isometry_to_point, Physics},
77
utils::AssetManager,
88
HEIGHT,
99
};

src/components/bullet.rs renamed to src/screens/game/components/bullet.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ use ggez::{
66
use ggez_goodies::{camera::Camera, nalgebra_glm::Vec2};
77

88
use nphysics2d::{algebra::Velocity2, math::Velocity, nalgebra as na, object::DefaultBodyHandle};
9-
use physics::ObjectData;
109

1110
use crate::{
12-
physics::{self, isometry_to_point, Physics},
11+
game::physics::{isometry_to_point, ObjectData, Physics},
1312
utils::AssetManager,
1413
};
1514

@@ -18,6 +17,11 @@ pub enum PlayerWeapon {
1817
Grappling(Grappling),
1918
}
2019

20+
pub enum WeaponType {
21+
Turbofish,
22+
Grappling,
23+
}
24+
2125
pub struct Turbofish {
2226
body: DefaultBodyHandle,
2327
}
@@ -141,8 +145,6 @@ impl Grappling {
141145
camera: &Camera,
142146
physics: &mut Physics,
143147
) -> GameResult<()> {
144-
// FIXME
145-
146148
let player = isometry_to_point(physics.get_rigid_body(self.player_body).position());
147149

148150
let rect = graphics::Mesh::new_rectangle(
File renamed without changes.

0 commit comments

Comments
 (0)