Skip to content

Commit

Permalink
Merge pull request #262 from red-life-project/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Nereuxofficial authored Dec 10, 2022
2 parents f6a79d4 + 3e2ed74 commit 514d2f0
Show file tree
Hide file tree
Showing 21 changed files with 1,934 additions and 233 deletions.
20 changes: 19 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,23 @@ rustup override set nightly
cargo run --release
```

## Pictures

### Main menu

![Main menu](pictures/start_menu.jpg)

### Gameplay

![Gameplay](pictures/ingame.png)

### Death-screen

![Deathscreen](pictures/death.jpg)

## License
Red Life is licensed under the [GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html) license.

Red Life is licensed under the [GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html) license.



2 changes: 1 addition & 1 deletion game/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "game"
version = "0.7.7"
version = "1.0.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
80 changes: 42 additions & 38 deletions game/src/backend/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::backend::rlcolor::RLColor;
use crate::game_core::player::gen_inventory;
use crate::game_core::resources::Resources;
use crate::languages::german::MACHINE_NAMES;
use crate::machines::machine::State;
use crate::machines::machine::{Machine, State};
use crate::machines::trade::Trade;
use ggez::graphics::{Color, Rect};
use std::string::ToString;
Expand Down Expand Up @@ -37,18 +37,22 @@ pub const MOVEMENT_SPEED: usize = 10;
/// Contains the position of the time.
pub(crate) const TIME_POSITION: (f32, f32) = (1205., 960.);

/// Change rate fot the event Sandsturm
pub(crate) const SANDSTURM_CR: Resources<i16> = Resources {
oxygen: 10,
energy: 0,
life: 0,
};

#[allow(clippy::too_many_lines)]
/// Generates all machines with all their name, position, trades and resources.
/// # Returns
/// `String` - The name of the machine.
/// `Rect` - Returns the collision area of the machine.
/// `Vec<Trade>` - Returns the trades of the machine.
/// `Vec<Resources>` - Returns the resources of the machine.
pub(crate) fn gen_all_machines() -> [(String, Rect, Vec<Trade>, Resources<i16>); 7] {
[
/// A Vector of `Machine`s
pub(crate) fn gen_all_machines() -> Vec<Machine> {
vec![
// Oxygen machine
(
MACHINE_NAMES[1].to_string(),
Machine::new_by_const((
MACHINE_NAMES[0].to_string(),
Rect {
x: 280.0,
y: 230.0,
Expand Down Expand Up @@ -82,14 +86,14 @@ pub(crate) fn gen_all_machines() -> [(String, Rect, Vec<Trade>, Resources<i16>);
),
],
Resources {
oxygen: 25,
oxygen: 30,
energy: -30,
life: 0,
},
),
)),
// Electricity machine
(
MACHINE_NAMES[2].to_string(),
Machine::new_by_const((
MACHINE_NAMES[1].to_string(),
Rect {
x: 282.0,
y: 752.0,
Expand Down Expand Up @@ -127,10 +131,10 @@ pub(crate) fn gen_all_machines() -> [(String, Rect, Vec<Trade>, Resources<i16>);
energy: 200,
life: 0,
},
),
// worker machine
(
MACHINE_NAMES[3].to_string(),
)),
// Worker machine
Machine::new_by_const((
MACHINE_NAMES[2].to_string(),
Rect {
x: 1000.0,
y: 780.0,
Expand Down Expand Up @@ -160,10 +164,10 @@ pub(crate) fn gen_all_machines() -> [(String, Rect, Vec<Trade>, Resources<i16>);
energy: -15,
life: 0,
},
),
// 3d_printer machine
(
MACHINE_NAMES[4].to_string(),
)),
// 3d Printer machine
Machine::new_by_const((
MACHINE_NAMES[3].to_string(),
Rect {
x: 930.0,
y: 230.0,
Expand All @@ -177,7 +181,7 @@ pub(crate) fn gen_all_machines() -> [(String, Rect, Vec<Trade>, Resources<i16>);
State::Broken,
State::Idle,
false,
gen_inventory(2, 1, 0),
gen_inventory(2, 0, 0),
),
Trade::new(
"produce_3d_teil".to_string(),
Expand All @@ -193,10 +197,10 @@ pub(crate) fn gen_all_machines() -> [(String, Rect, Vec<Trade>, Resources<i16>);
energy: -25,
life: 0,
},
),
)),
// Communication module
(
MACHINE_NAMES[5].to_string(),
Machine::new_by_const((
MACHINE_NAMES[4].to_string(),
Rect {
x: 1640.0,
y: 320.0,
Expand All @@ -218,18 +222,18 @@ pub(crate) fn gen_all_machines() -> [(String, Rect, Vec<Trade>, Resources<i16>);
State::Idle,
State::Running,
true,
gen_inventory(0, 0, 0),
gen_inventory(1, 0, 1),
),
],
Resources {
oxygen: 0,
energy: -20,
energy: -30,
life: 0,
},
),
// first hole
(
MACHINE_NAMES[6].to_string(),
)),
// First hole
Machine::new_by_const((
MACHINE_NAMES[5].to_string(),
Rect {
x: 780.0,
y: 230.0,
Expand All @@ -245,14 +249,14 @@ pub(crate) fn gen_all_machines() -> [(String, Rect, Vec<Trade>, Resources<i16>);
gen_inventory(2, 0, 0),
)],
Resources {
oxygen: -20,
oxygen: -15,
energy: -5,
life: 0,
},
),
// second hole
(
MACHINE_NAMES[7].to_string(),
)),
// Second hole
Machine::new_by_const((
MACHINE_NAMES[6].to_string(),
Rect {
x: 680.0,
y: 900.0,
Expand All @@ -268,10 +272,10 @@ pub(crate) fn gen_all_machines() -> [(String, Rect, Vec<Trade>, Resources<i16>);
gen_inventory(2, 0, 0),
)],
Resources {
oxygen: -20,
oxygen: -15,
energy: -5,
life: 0,
},
),
)),
]
}
35 changes: 22 additions & 13 deletions game/src/backend/gamestate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub struct GameState {
/// Needed to send Messages to `machine` to make changes to the game
pub(crate) sender: Option<Sender<GameCommand>>,
/// Defines if the handbook is currently open
pub handbook_visible: bool,
pub handbook_invisible: bool,
}

impl PartialEq for GameState {
Expand Down Expand Up @@ -108,7 +108,7 @@ impl GameState {
/// and checks if the player has died.
/// # Returns
/// * `RLResult`: A `RLResult` to validate the success of the tick function
pub fn tick(&mut self, _ctx: &mut Context) -> RLResult {
pub fn tick(&mut self) -> RLResult {
// Update Resources
self.player.resources = self
.player
Expand All @@ -124,12 +124,12 @@ impl GameState {
if let Some(empty_resource) = Resources::get_death_reason(self.player.resources) {
match empty_resource {
Both => {
self.player.resources_change.life -= 60;
self.player.resources_change.life = -60;
self.machines.iter_mut().for_each(Machine::no_energy);
}
Oxygen => self.player.resources_change.life -= 60,
Oxygen => self.player.resources_change.life = -50,
Energy => {
self.player.resources_change.life -= 10;
self.player.resources_change.life = -10;
self.machines.iter_mut().for_each(Machine::no_energy);
}
};
Expand Down Expand Up @@ -178,7 +178,7 @@ impl GameState {
self.player
.life_regeneration(&self.screen_sender.as_ref().unwrap().clone())?;
for machine in &mut self.machines {
machine.tick(1)?;
machine.tick()?;
}

Ok(())
Expand Down Expand Up @@ -225,24 +225,32 @@ impl GameState {
/// # Arguments
/// * `canvas`: The canvas to draw on
/// * `ctx`: The `Context` of the game
/// # Returns
/// * `RLResult`: A `RLResult` to validate the success of the function
pub fn open_handbook(&self, canvas: &mut Canvas, ctx: &mut Context) -> RLResult {
let scale = get_scale(ctx);
let image = self.assets.get("Handbook.png").unwrap();
draw!(canvas, image, Vec2::new(700.0, 300.0), scale);
match self.player.milestone {
1 => {
self.get_handbook_text(canvas, scale, &FIRST_MILESTONE_HANDBOOK_TEXT);
self.draw_handbook_text(canvas, scale, &FIRST_MILESTONE_HANDBOOK_TEXT);
}

2 => {
self.get_handbook_text(canvas, scale, &SECOND_MILESTONE_HANDBOOK_TEXT);
self.draw_handbook_text(canvas, scale, &SECOND_MILESTONE_HANDBOOK_TEXT);
}
_ => {}
}
Ok(())
}

pub fn get_handbook_text(&self, canvas: &mut Canvas, scale: Vec2, handbook_text: &[&str]) {
/// Draws the text for the current milestone on the handbook on the screen.
/// # Arguments
/// * `canvas`: The canvas to draw on
/// * `scale`: The scale of the canvas
/// * `handbook_text`: The text to draw on the screen
/// # Returns
/// * `RLResult`: A `RLResult` to validate the success of the function
pub fn draw_handbook_text(&self, canvas: &mut Canvas, scale: Vec2, handbook_text: &[&str]) {
handbook_text
.iter()
.enumerate()
Expand All @@ -255,9 +263,10 @@ impl GameState {
&text,
Vec2::new(800.0, 400.0 + (i * 30) as f32),
scale
)
);
});
}

/// Iterates trough the inventory and draws the amount of every item in the inventory.
/// # Arguments
/// * `canvas` - The current canvas to draw on
Expand Down Expand Up @@ -528,7 +537,7 @@ impl Screen for GameState {
/// Updates the game and handles input. Returns `StackCommand::Pop` when Escape is pressed.
fn update(&mut self, ctx: &mut Context) -> RLResult {
if ctx.time.check_update_time(DESIRED_FPS) {
self.tick(ctx)?;
self.tick()?;
self.move_player(ctx)?;
Event::update_events(ctx, self)?;
}
Expand All @@ -554,7 +563,7 @@ impl Screen for GameState {
self.draw_resources(&mut canvas, scale, ctx)?;
self.draw_machines(&mut canvas, scale, ctx)?;
self.draw_items(&mut canvas, ctx)?;
if self.handbook_visible {
if !self.handbook_invisible {
self.open_handbook(&mut canvas, ctx)?;
}
#[cfg(debug_assertions)]
Expand Down
21 changes: 11 additions & 10 deletions game/src/backend/generate_machines.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//!DIESE DATEI IST ZUM TESTEN VON SANDER
use crate::backend::gamestate::GameState;

use crate::machines::machine::Machine;

//! This File handels code surrounding Machine with in `GameState`
use crate::backend::constants::gen_all_machines;
use crate::backend::gamestate::GameState;
use crate::backend::rlcolor::RLColor;
use crate::backend::utils::get_draw_params;
use crate::{draw, RLResult};
Expand All @@ -13,15 +10,19 @@ use ggez::Context;
use tracing::info;

impl GameState {
/// Creates all Machines for initial creation and pushes them into a list
pub fn create_machine(&mut self) {
info!("Generating all Machines");
let all = gen_all_machines();
for m in &all {
let new_ms = Machine::new_by_const(m.clone());
self.machines.push(new_ms);
}
self.machines = gen_all_machines();
}

/// Paints the machine sprites and if applicable it shows the state or time remaining
/// # Arguments
/// * `canvas`: The canvas to draw on
/// * `scale`: The scale of the canvas
/// * `ctx`: The `Context` of the game
/// # Returns
/// * `RLResult`: A `RLResult` to validate the success of the paint function
pub fn draw_machines(&self, canvas: &mut Canvas, scale: Vec2, ctx: &mut Context) -> RLResult {
for machine in &self.machines {
let image = machine.get_graphic();
Expand Down
16 changes: 8 additions & 8 deletions game/src/backend/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ impl GameState {
}
if ctx.keyboard.is_key_just_pressed(VirtualKeyCode::E) {
info!("Interacting with Area: {:?}", self.get_interactable());
let player_ref = &mut self.player.clone();
let player_ref = &self.player.clone();
if let Some(interactable) = self.get_interactable() {
self.player = interactable.interact(player_ref)?;
interactable.interact(player_ref)?;
}
}
if ctx.keyboard.is_key_just_pressed(VirtualKeyCode::H) {
self.handbook_visible = !self.handbook_visible;
self.handbook_invisible = !self.handbook_invisible;
}
// If we are in debug mode, change the milestone by using Z
#[cfg(debug_assertions)]
if ctx.keyboard.is_key_just_pressed(VirtualKeyCode::Z) {
self.player.milestone += 1;
}
let keys = ctx.keyboard.pressed_keys();
for key in keys.iter() {
match key {
// If we are in debug mode, change the milestone by using Z
#[cfg(debug_assertions)]
VirtualKeyCode::Z => {
self.player.milestone += 1;
}
VirtualKeyCode::W => {
if !self.collision_detection((
self.player.position.0,
Expand Down
Loading

0 comments on commit 514d2f0

Please sign in to comment.