Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

balance changes #259

Merged
merged 2 commits into from
Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions game/src/backend/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub(crate) fn gen_all_machines() -> [(String, Rect, Vec<Trade>, Resources<i16>);
[
// Oxygen machine
(
MACHINE_NAMES[1].to_string(),
MACHINE_NAMES[0].to_string(),
Rect {
x: 280.0,
y: 230.0,
Expand Down Expand Up @@ -89,14 +89,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_NAMES[1].to_string(),
Rect {
x: 282.0,
y: 752.0,
Expand Down Expand Up @@ -137,7 +137,7 @@ pub(crate) fn gen_all_machines() -> [(String, Rect, Vec<Trade>, Resources<i16>);
),
// worker machine
(
MACHINE_NAMES[3].to_string(),
MACHINE_NAMES[2].to_string(),
Rect {
x: 1000.0,
y: 780.0,
Expand Down Expand Up @@ -170,7 +170,7 @@ pub(crate) fn gen_all_machines() -> [(String, Rect, Vec<Trade>, Resources<i16>);
),
// 3d_printer machine
(
MACHINE_NAMES[4].to_string(),
MACHINE_NAMES[3].to_string(),
Rect {
x: 930.0,
y: 230.0,
Expand All @@ -184,7 +184,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 @@ -203,7 +203,7 @@ pub(crate) fn gen_all_machines() -> [(String, Rect, Vec<Trade>, Resources<i16>);
),
// Communication module
(
MACHINE_NAMES[5].to_string(),
MACHINE_NAMES[4].to_string(),
Rect {
x: 1640.0,
y: 320.0,
Expand All @@ -225,18 +225,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(),
MACHINE_NAMES[5].to_string(),
Rect {
x: 780.0,
y: 230.0,
Expand All @@ -252,14 +252,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(),
MACHINE_NAMES[6].to_string(),
Rect {
x: 680.0,
y: 900.0,
Expand All @@ -275,7 +275,7 @@ 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,
},
Expand Down
21 changes: 15 additions & 6 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 @@ -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 @@ -258,6 +266,7 @@ impl GameState {
)
});
}

/// 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 @@ -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
2 changes: 1 addition & 1 deletion game/src/backend/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl GameState {
}
}
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)]
Expand Down
8 changes: 4 additions & 4 deletions game/src/game_core/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Event {
/// if no Event is active it either chooses a random event of the Event enum or nothing every 60 seconds
pub fn event_generator() -> Option<Event> {
let rng = fastrand::Rng::new();
let event = rng.usize(..10);
let event = rng.usize(..15);
match event {
8 => Some(Event::new(
SANDSTURM,
Expand Down Expand Up @@ -136,7 +136,7 @@ impl Event {
/// * `gamestate` - The gamestate which is used to access the player and the machines
pub fn action(&self, restore: bool, gamestate: &mut GameState) -> RLResult {
const KOMETENEINSCHLAG_NAME: &str = KOMETENEINSCHLAG[0];
const STROMAUSTFALL_NAME: &str = STROMAUSFALL[0];
const STROMAUSFALL_NAME: &str = STROMAUSFALL[0];
let sender = gamestate.get_screen_sender()?.clone();

// handle event effects
Expand All @@ -153,7 +153,7 @@ impl Event {
one_hole.change_state_to(&State::Running);
}
}
STROMAUSTFALL_NAME => {
STROMAUSFALL_NAME => {
gamestate.machines.iter_mut().for_each(|machine| {
// if machine is running it will b use tracing::{info, Id};e stopped
// event not triggered if machine is broken or idling
Expand Down Expand Up @@ -222,7 +222,7 @@ impl Event {
});
}
// have a maximum of one active event
if ctx.time.ticks() % 200 == 0 {
if ctx.time.ticks() >= 400 && ctx.time.ticks() % 200 == 0 {
// generate new event
// might not return an event
let gen_event = Event::event_generator();
Expand Down
7 changes: 3 additions & 4 deletions game/src/languages/german.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ pub const TIME_NAME: [&str; 1] = ["Zeit"];
/// Constants for the text of the button in the main menu
pub const BUTTON_TEXT: [&str; 3] = ["Fortsetzen", "Neues Spiel", "Beenden"];
/// Contains all machine names as a vec of strings.
pub(crate) const MACHINE_NAMES: [&str; 8] = [
"test",
pub(crate) const MACHINE_NAMES: [&str; 7] = [
"Sauerstoffgenerator",
"Stromgenerator",
"Werkermaschine",
Expand All @@ -115,7 +114,7 @@ pub(crate) const FIRST_MILESTONE_HANDBOOK_TEXT: [&str; 10] = [
"- Denk daran sparsam mit Benzin umzugehen!",
"- Du kannst den Generator kurz anhalten,",
" wenn du genug Energie hast",
"c:",
"\n\n Drücke H zum schließen",
];

pub(crate) const SECOND_MILESTONE_HANDBOOK_TEXT: [&str; 7] = [
Expand All @@ -125,5 +124,5 @@ pub(crate) const SECOND_MILESTONE_HANDBOOK_TEXT: [&str; 7] = [
" während du die Nachricht sendest!",
"- Wenn du die Nachricht abgeschickt hast,",
" gewinnst du automatisch.",
"<*~*>",
"\n\n Drücke H zum schließen",
];