Merge pull request #62 from Ewpratten/i_hardly_know_her
it might work!?
This commit is contained in:
commit
7be250f5b0
@ -13,10 +13,11 @@ use crate::{
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ControlFlag {
|
pub enum ControlFlag {
|
||||||
Quit,
|
Quit,
|
||||||
SwitchLevel(usize),
|
BeginLevel(usize),
|
||||||
UpdateLevelStart(DateTime<Utc>),
|
EndLevel,
|
||||||
SaveProgress,
|
// UpdateLevelStart(DateTime<Utc>),
|
||||||
MaybeUpdateHighScore(usize, Duration),
|
// SaveProgress,
|
||||||
|
// MaybeUpdateHighScore(usize, Duration),
|
||||||
SoundTrigger(String),
|
SoundTrigger(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,7 +218,8 @@ pub async fn game_begin(game_config: &mut GameConfig) -> Result<(), Box<dyn std:
|
|||||||
// Get the main state machine
|
// Get the main state machine
|
||||||
info!("Setting up the scene management state machine");
|
info!("Setting up the scene management state machine");
|
||||||
let mut game_state_machine =
|
let mut game_state_machine =
|
||||||
build_screen_state_machine(&mut context.renderer.borrow_mut(), &raylib_thread, levels).unwrap();
|
build_screen_state_machine(&mut context.renderer.borrow_mut(), &raylib_thread, levels)
|
||||||
|
.unwrap();
|
||||||
game_state_machine
|
game_state_machine
|
||||||
.force_change_state(Scenes::MainMenuScreen)
|
.force_change_state(Scenes::MainMenuScreen)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -361,22 +362,21 @@ pub async fn game_begin(game_config: &mut GameConfig) -> Result<(), Box<dyn std:
|
|||||||
if let Some(flag) = flag {
|
if let Some(flag) = flag {
|
||||||
match flag {
|
match flag {
|
||||||
context::ControlFlag::Quit => break,
|
context::ControlFlag::Quit => break,
|
||||||
context::ControlFlag::SwitchLevel(level) => {
|
context::ControlFlag::BeginLevel(level) => {
|
||||||
context.as_mut().current_level = level;
|
context.as_mut().current_level = level;
|
||||||
context.as_mut().player_progress.save();
|
context.as_mut().level_start_time = Utc::now();
|
||||||
}
|
}
|
||||||
context::ControlFlag::UpdateLevelStart(time) => {
|
context::ControlFlag::EndLevel => {
|
||||||
context.as_mut().level_start_time = time;
|
let now = Utc::now();
|
||||||
context.as_mut().player_progress.save();
|
let elapsed = now - context.as_mut().level_start_time;
|
||||||
}
|
if elapsed.num_seconds().abs() > 1 {
|
||||||
context::ControlFlag::SaveProgress => {
|
let current_level = context.as_mut().current_level;
|
||||||
context.as_mut().player_progress.save();
|
context
|
||||||
}
|
.as_mut()
|
||||||
context::ControlFlag::MaybeUpdateHighScore(level, time) => {
|
.player_progress
|
||||||
context
|
.maybe_write_new_time(current_level, &elapsed);
|
||||||
.as_mut()
|
context.as_mut().player_progress.save();
|
||||||
.player_progress
|
}
|
||||||
.maybe_write_new_time(level, &time);
|
|
||||||
}
|
}
|
||||||
context::ControlFlag::SoundTrigger(name) => {
|
context::ControlFlag::SoundTrigger(name) => {
|
||||||
context.audio.play_sound(context.sounds.get(&name).unwrap());
|
context.audio.play_sound(context.sounds.get(&name).unwrap());
|
||||||
|
@ -104,13 +104,13 @@ impl Action<Scenes, ScreenError, GameContext> for InGameScreen {
|
|||||||
|
|
||||||
if self.current_level_idx != context.current_level {
|
if self.current_level_idx != context.current_level {
|
||||||
self.current_level_idx = context.current_level;
|
self.current_level_idx = context.current_level;
|
||||||
self.level_switch_timestamp = Utc::now();
|
// self.level_switch_timestamp = Utc::now();
|
||||||
context
|
// context
|
||||||
.flag_send
|
// .flag_send
|
||||||
.send(Some(ControlFlag::UpdateLevelStart(
|
// .send(Some(ControlFlag::UpdateLevelStart(
|
||||||
self.level_switch_timestamp,
|
// self.level_switch_timestamp,
|
||||||
)))
|
// )))
|
||||||
.unwrap();
|
// .unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grab exclusive access to the renderer
|
// Grab exclusive access to the renderer
|
||||||
@ -138,30 +138,29 @@ impl Action<Scenes, ScreenError, GameContext> for InGameScreen {
|
|||||||
let cur_level = self.levels.get(context.current_level).unwrap();
|
let cur_level = self.levels.get(context.current_level).unwrap();
|
||||||
if self.player.position.x > cur_level.zones.win.x {
|
if self.player.position.x > cur_level.zones.win.x {
|
||||||
// Save the current time
|
// Save the current time
|
||||||
let elapsed = Utc::now() - self.level_switch_timestamp;
|
// let elapsed = Utc::now() - self.level_switch_timestamp;
|
||||||
context
|
// context
|
||||||
.flag_send
|
// .flag_send
|
||||||
.send(Some(ControlFlag::MaybeUpdateHighScore(
|
// .send(Some(ControlFlag::MaybeUpdateHighScore(
|
||||||
self.current_level_idx,
|
// self.current_level_idx,
|
||||||
elapsed,
|
// elapsed,
|
||||||
)))
|
// )))
|
||||||
.unwrap();
|
// .unwrap();
|
||||||
|
|
||||||
// Save the progress
|
// Save the progress
|
||||||
context
|
|
||||||
.flag_send
|
// End the level
|
||||||
.send(Some(ControlFlag::SaveProgress))
|
context.flag_send.send(Some(ControlFlag::EndLevel)).unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// If this is the last level, win the game
|
// If this is the last level, win the game
|
||||||
if self.current_level_idx >= self.levels.len() - 1 {
|
if self.current_level_idx >= self.levels.len() - 1 {
|
||||||
return Ok(ActionFlag::SwitchState(Scenes::WinScreen));
|
return Ok(ActionFlag::SwitchState(Scenes::WinScreen));
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, increment the level counter and switch to the next level
|
// Otherwise, increment the level counter and switch to the next level
|
||||||
context
|
// context
|
||||||
.flag_send
|
// .flag_send
|
||||||
.send(Some(ControlFlag::SwitchLevel(self.current_level_idx + 1)))
|
// .send(Some(ControlFlag::SwitchLevel(self.current_level_idx + 1)))
|
||||||
.unwrap();
|
// .unwrap();
|
||||||
|
|
||||||
return Ok(ActionFlag::SwitchState(Scenes::NextLevelScreen));
|
return Ok(ActionFlag::SwitchState(Scenes::NextLevelScreen));
|
||||||
}
|
}
|
||||||
|
@ -83,15 +83,15 @@ impl Action<Scenes, ScreenError, GameContext> for LevelSelectScreen {
|
|||||||
// Switch the level
|
// Switch the level
|
||||||
context
|
context
|
||||||
.flag_send
|
.flag_send
|
||||||
.send(Some(ControlFlag::SwitchLevel(level)))
|
.send(Some(ControlFlag::BeginLevel(level)))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
context
|
// context
|
||||||
.flag_send
|
// .flag_send
|
||||||
.send(Some(ControlFlag::UpdateLevelStart(
|
// .send(Some(ControlFlag::UpdateLevelStart(
|
||||||
Utc::now(),
|
// Utc::now(),
|
||||||
)))
|
// )))
|
||||||
.unwrap();
|
// .unwrap();
|
||||||
|
|
||||||
// Enter the game
|
// Enter the game
|
||||||
Ok(ActionFlag::SwitchState(Scenes::InGameScene))
|
Ok(ActionFlag::SwitchState(Scenes::InGameScene))
|
||||||
|
@ -6,13 +6,17 @@ use discord_sdk::activity::{ActivityBuilder, Assets};
|
|||||||
use pkg_version::pkg_version_major;
|
use pkg_version::pkg_version_major;
|
||||||
use raylib::prelude::*;
|
use raylib::prelude::*;
|
||||||
|
|
||||||
use crate::{GameConfig, context::{ControlFlag, GameContext}, utilities::{
|
use crate::{
|
||||||
|
context::{ControlFlag, GameContext},
|
||||||
|
utilities::{
|
||||||
datastore::{load_texture_from_internal_data, ResourceLoadError},
|
datastore::{load_texture_from_internal_data, ResourceLoadError},
|
||||||
game_version::get_version_string,
|
game_version::get_version_string,
|
||||||
math::interpolate_exp,
|
math::interpolate_exp,
|
||||||
non_ref_raylib::HackedRaylibHandle,
|
non_ref_raylib::HackedRaylibHandle,
|
||||||
render_layer::ScreenSpaceRender,
|
render_layer::ScreenSpaceRender,
|
||||||
}};
|
},
|
||||||
|
GameConfig,
|
||||||
|
};
|
||||||
|
|
||||||
use super::{Scenes, ScreenError};
|
use super::{Scenes, ScreenError};
|
||||||
use tracing::{debug, error, info, trace};
|
use tracing::{debug, error, info, trace};
|
||||||
@ -87,6 +91,14 @@ impl Action<Scenes, ScreenError, GameContext> for NextLevelScreen {
|
|||||||
.flag_send
|
.flag_send
|
||||||
.send(Some(ControlFlag::SoundTrigger("button-press".to_string())))
|
.send(Some(ControlFlag::SoundTrigger("button-press".to_string())))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
// Start the next level
|
||||||
|
let current_level = context.current_level;
|
||||||
|
context
|
||||||
|
.flag_send
|
||||||
|
.send(Some(ControlFlag::BeginLevel(current_level + 1)))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
Ok(ActionFlag::SwitchState(Scenes::InGameScene))
|
Ok(ActionFlag::SwitchState(Scenes::InGameScene))
|
||||||
} else {
|
} else {
|
||||||
Ok(ActionFlag::Continue)
|
Ok(ActionFlag::Continue)
|
||||||
|
@ -69,7 +69,7 @@ impl Action<Scenes, ScreenError, GameContext> for WinScreen {
|
|||||||
.flag_send
|
.flag_send
|
||||||
.send(Some(ControlFlag::SoundTrigger("button-press".to_string())))
|
.send(Some(ControlFlag::SoundTrigger("button-press".to_string())))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
context.flag_send.send(Some(ControlFlag::SwitchLevel(0))).unwrap();
|
context.flag_send.send(Some(ControlFlag::EndLevel)).unwrap();
|
||||||
Ok(ActionFlag::SwitchState(Scenes::MainMenuScreen))
|
Ok(ActionFlag::SwitchState(Scenes::MainMenuScreen))
|
||||||
} else {
|
} else {
|
||||||
Ok(ActionFlag::Continue)
|
Ok(ActionFlag::Continue)
|
||||||
|
Reference in New Issue
Block a user