Merge branch 'master' into levels

This commit is contained in:
Evan Pratten 2021-10-03 21:23:59 -07:00 committed by GitHub
commit bb7b267896
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 416 additions and 86 deletions

View File

@ -13,7 +13,7 @@ All development documentation has been moved to [`DEVELOPERS.md`](./DEVELOPERS.m
## The Team ## The Team
This game is developed by a team of 6 students from *Sheridan College* and *Trent University*. This game is developed by a team of 8 students from *Sheridan College* and *Trent University*.
- [**Evan Pratten**](https://github.com/ewpratten) - [**Evan Pratten**](https://github.com/ewpratten)
- Team lead - Team lead
@ -31,9 +31,13 @@ This game is developed by a team of 6 students from *Sheridan College* and *Tren
- [**Emilia Frias**](https://www.instagram.com/demilurii/) - [**Emilia Frias**](https://www.instagram.com/demilurii/)
- Character art - Character art
- Animations - Animations
- Tilesets
- [**Kori**](https://www.instagram.com/korigama/) - [**Kori**](https://www.instagram.com/korigama/)
- Concept art - Concept art
- Tilesets - Tilesets
- **J.J.**
- *"Composer? I hardly know her!"*
- Playtesting
- [**James Feener**](https://twitter.com/jamesmakesgame)
- Playtesting
A special thanks goes out to: [James Nickoli](https://github.com/rsninja722/) for insight on 2D collision detection, as well as [Ray](https://github.com/raysan5) and the members of the [raylib community](https://discord.gg/raylib) on discord for their support with the past two game jam projects. A special thanks goes out to: [James Nickoli](https://github.com/rsninja722/) for insight on 2D collision detection, as well as [Ray](https://github.com/raysan5) and the members of the [raylib community](https://discord.gg/raylib) on discord for their support with the past two game jam projects.

View File

@ -26,6 +26,9 @@
"width": 56, "width": 56,
"height": 313 "height": 313
} }
],
"kill":[
], ],
"win": { "win": {
"x": 12000, "x": 12000,

View File

@ -44,6 +44,9 @@
"width": 704, "width": 704,
"height": 64 "height": 64
} }
],
"kill":[
], ],
"win": { "win": {
"x": 12000, "x": 12000,

View File

@ -13,6 +13,7 @@ pub const GRAVITY_PPS: f32 = 2.0;
pub fn modify_player_based_on_forces( pub fn modify_player_based_on_forces(
player: &mut MainCharacter, player: &mut MainCharacter,
colliders: &Vec<Rectangle>, colliders: &Vec<Rectangle>,
killers: &Vec<Rectangle>,
level_height_offset: f32, level_height_offset: f32,
) -> Result<(), ()> { ) -> Result<(), ()> {
trace!("Player state: {:?}", player.current_state); trace!("Player state: {:?}", player.current_state);
@ -25,7 +26,7 @@ pub fn modify_player_based_on_forces(
let predicted_player_position = player.position + player.velocity; let predicted_player_position = player.position + player.velocity;
// Calculate a bounding rect around the player both now, and one frame in the future // Calculate a bounding rect around the player both now, and one frame in the future
let mut player_rect = Rectangle::new( let player_rect = Rectangle::new(
predicted_player_position.x - (player.size.x / 2.0), predicted_player_position.x - (player.size.x / 2.0),
predicted_player_position.y - (player.size.x / 2.0), predicted_player_position.y - (player.size.x / 2.0),
player.size.x, player.size.x,
@ -48,6 +49,15 @@ pub fn modify_player_based_on_forces(
|| translated_rect.check_collision_recs(&predicted_player_rect) || translated_rect.check_collision_recs(&predicted_player_rect)
}) })
}; };
let check_player_colliding_with_killers = || {
killers.iter().any(|rect| {
let mut translated_rect = rect.clone();
translated_rect.y += level_height_offset;
translated_rect.x += WORLD_LEVEL_X_OFFSET;
translated_rect.check_collision_recs(&player_rect.clone())
|| translated_rect.check_collision_recs(&predicted_player_rect)
})
};
let check_player_colliding_with_colliders_forwards = || { let check_player_colliding_with_colliders_forwards = || {
colliders.iter().any(|rect| { colliders.iter().any(|rect| {
let mut translated_rect = rect.clone(); let mut translated_rect = rect.clone();
@ -76,10 +86,11 @@ pub fn modify_player_based_on_forces(
return player.update_player( return player.update_player(
Some(CharacterState::Running), Some(CharacterState::Running),
colliders, colliders,
killers,
level_height_offset, level_height_offset,
); );
} }
}else if player.current_state == CharacterState::Running { } else if player.current_state == CharacterState::Running {
player.override_state(CharacterState::Jumping); player.override_state(CharacterState::Jumping);
} }
@ -87,22 +98,27 @@ pub fn modify_player_based_on_forces(
player.position += player.velocity; player.position += player.velocity;
// Re-calculate the player rect // Re-calculate the player rect
player_rect = Rectangle::new( let player_rect = Rectangle::new(
player.position.x - (player.size.x / 2.0), player.position.x - (player.size.x / 2.0),
player.position.y - (player.size.x / 2.0), player.position.y - (player.size.x / 2.0),
player.size.x, player.size.x,
player.size.y, player.size.y,
); );
if player.position.y > 50.0 || colliders.iter().any(|rect| { if player.position.y > 50.0
let mut translated_rect = rect.clone(); || colliders.iter().any(|rect| {
translated_rect.y += level_height_offset; let mut translated_rect = rect.clone();
translated_rect.x += WORLD_LEVEL_X_OFFSET; translated_rect.y += level_height_offset;
translated_rect.check_collision_recs(&player_rect) translated_rect.x += WORLD_LEVEL_X_OFFSET;
}) { translated_rect.check_collision_recs(&player_rect)
})
{
return Err(()); return Err(());
} }
if check_player_colliding_with_killers() {
return Err(());
}
Ok(()) Ok(())
} }

View File

@ -66,6 +66,7 @@ impl MainCharacter {
&mut self, &mut self,
state: Option<CharacterState>, state: Option<CharacterState>,
colliders: &Vec<Rectangle>, colliders: &Vec<Rectangle>,
killers: &Vec<Rectangle>,
level_height_offset: f32, level_height_offset: f32,
) -> Result<(), ()> { ) -> Result<(), ()> {
if let Some(state) = state { if let Some(state) = state {
@ -81,7 +82,7 @@ impl MainCharacter {
} }
// Update the player based on the new velocity // Update the player based on the new velocity
modify_player_based_on_forces(self, colliders, level_height_offset) modify_player_based_on_forces(self, colliders, killers, level_height_offset)
} }
pub fn reset(&mut self) { pub fn reset(&mut self) {

View File

@ -4,16 +4,21 @@ use chrono::{DateTime, Duration, Utc};
use discord_sdk::activity::ActivityBuilder; use discord_sdk::activity::ActivityBuilder;
use raylib::audio::Sound; use raylib::audio::Sound;
use crate::{GameConfig, progress::ProgressData, utilities::{audio_player::AudioPlayer, non_ref_raylib::HackedRaylibHandle}}; use crate::{
progress::ProgressData,
utilities::{audio_player::AudioPlayer, non_ref_raylib::HackedRaylibHandle},
GameConfig,
};
#[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,
SoundTrigger(String) // MaybeUpdateHighScore(usize, Duration),
SoundTrigger(String),
} }
#[derive(Debug)] #[derive(Debug)]
@ -24,6 +29,7 @@ pub struct GameContext {
pub config: GameConfig, pub config: GameConfig,
pub player_progress: ProgressData, pub player_progress: ProgressData,
pub current_level: usize, pub current_level: usize,
pub total_levels: usize,
pub level_start_time: DateTime<Utc>, pub level_start_time: DateTime<Utc>,
pub discord_rpc_send: Sender<Option<ActivityBuilder>>, pub discord_rpc_send: Sender<Option<ActivityBuilder>>,
pub flag_send: Sender<Option<ControlFlag>>, pub flag_send: Sender<Option<ControlFlag>>,

View File

@ -82,7 +82,7 @@ use crate::{
context::GameContext, context::GameContext,
discord_rpc::{maybe_set_discord_presence, try_connect_to_local_discord}, discord_rpc::{maybe_set_discord_presence, try_connect_to_local_discord},
progress::ProgressData, progress::ProgressData,
scenes::{build_screen_state_machine, Scenes}, scenes::{build_screen_state_machine, ingame_scene::level::loader::load_all_levels, Scenes},
utilities::{ utilities::{
audio_player::AudioPlayer, audio_player::AudioPlayer,
datastore::{load_music_from_internal_data, load_sound_from_internal_data}, datastore::{load_music_from_internal_data, load_sound_from_internal_data},
@ -191,6 +191,7 @@ pub async fn game_begin(game_config: &mut GameConfig) -> Result<(), Box<dyn std:
config: game_config.clone(), config: game_config.clone(),
audio: audio_system, audio: audio_system,
sounds, sounds,
total_levels: 0,
current_level: 0, current_level: 0,
player_progress: save_file, player_progress: save_file,
level_start_time: Utc::now(), level_start_time: Utc::now(),
@ -210,10 +211,15 @@ pub async fn game_begin(game_config: &mut GameConfig) -> Result<(), Box<dyn std:
// Start the song // Start the song
context.audio.play_music_stream(&mut main_song); context.audio.play_music_stream(&mut main_song);
// Load all levels
let levels = load_all_levels(&mut context.renderer.borrow_mut(), &raylib_thread).unwrap();
context.total_levels = levels.len();
// 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).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();
@ -356,27 +362,24 @@ 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.audio.play_sound(context.sounds.get(&name).unwrap());
context.sounds.get(&name).unwrap(),
);
} }
} }
} }

View File

@ -20,6 +20,7 @@ use tracing::{debug, error, info, trace};
#[derive(Debug)] #[derive(Debug)]
pub struct HowToPlayScreen { pub struct HowToPlayScreen {
is_btm_pressed: bool, //Is back to menu button pressed is_btm_pressed: bool, //Is back to menu button pressed
counter: i32,
} }
impl HowToPlayScreen { impl HowToPlayScreen {
@ -27,6 +28,7 @@ impl HowToPlayScreen {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
is_btm_pressed: false, is_btm_pressed: false,
counter: 0,
} }
} }
} }
@ -61,6 +63,8 @@ impl Action<Scenes, ScreenError, GameContext> for HowToPlayScreen {
trace!("execute() called on HowToPlayScreen"); trace!("execute() called on HowToPlayScreen");
self.render_screen_space(&mut context.renderer.borrow_mut(), &context.config); self.render_screen_space(&mut context.renderer.borrow_mut(), &context.config);
self.counter += 1;
if self.is_btm_pressed { if self.is_btm_pressed {
context context
.flag_send .flag_send
@ -75,6 +79,7 @@ impl Action<Scenes, ScreenError, GameContext> for HowToPlayScreen {
fn on_finish(&mut self, _interrupted: bool) -> Result<(), ScreenError> { fn on_finish(&mut self, _interrupted: bool) -> Result<(), ScreenError> {
debug!("Finished HowToPlayScreen"); debug!("Finished HowToPlayScreen");
self.is_btm_pressed = false; self.is_btm_pressed = false;
self.counter = 0;
Ok(()) Ok(())
} }
} }
@ -105,13 +110,28 @@ impl ScreenSpaceRender for HowToPlayScreen {
let mouse_pressed: bool = raylib.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON); let mouse_pressed: bool = raylib.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON);
//Render the title //Render the title
raylib.draw_rgb_split_text( let timer: i32 = get_random_value(50, 400);
Vector2::new(40.0, 80.0), if self.counter > timer {
"How to Play", raylib.draw_rgb_split_text(
70, Vector2::new(40.0, 80.0),
true, "[How to Play]",
Color::WHITE, 70,
); true,
Color::WHITE,
);
if self.counter > timer + 20 {
self.counter = 0;
}
}
else{
raylib.draw_rgb_split_text(
Vector2::new(40.0, 80.0),
"[How to Play]",
70,
false,
Color::WHITE,
);
}
// Render the instructions // Render the instructions
raylib.draw_rgb_split_text( raylib.draw_rgb_split_text(

View File

@ -8,6 +8,7 @@ pub mod loader;
pub struct LevelZones { pub struct LevelZones {
pub appear: Vec<Rectangle>, pub appear: Vec<Rectangle>,
pub disappear: Vec<Rectangle>, pub disappear: Vec<Rectangle>,
pub kill: Vec<Rectangle>,
pub win: Rectangle, pub win: Rectangle,
} }

View File

@ -75,6 +75,7 @@ impl Action<Scenes, ScreenError, GameContext> for InGameScreen {
let _ = self.player.update_player( let _ = self.player.update_player(
Some(CharacterState::Running), Some(CharacterState::Running),
&cur_level.colliders, &cur_level.colliders,
&cur_level.zones.kill,
-cur_level.platform_tex.height as f32, -cur_level.platform_tex.height as f32,
); );
@ -103,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
@ -133,35 +134,33 @@ impl Action<Scenes, ScreenError, GameContext> for InGameScreen {
// Render the HUD // Render the HUD
self.render_screen_space(&mut renderer, &context.config); self.render_screen_space(&mut renderer, &context.config);
// Check if the player won // Check if the player won
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));
} }

View File

@ -35,12 +35,14 @@ impl FrameUpdate for InGameScreen {
self.player.update_player( self.player.update_player(
Some(CharacterState::Jumping), Some(CharacterState::Jumping),
&cur_level.colliders, &cur_level.colliders,
&cur_level.zones.kill,
-cur_level.platform_tex.height as f32, -cur_level.platform_tex.height as f32,
) )
} else if is_dash { } else if is_dash {
self.player.update_player( self.player.update_player(
Some(CharacterState::Dashing), Some(CharacterState::Dashing),
&cur_level.colliders, &cur_level.colliders,
&cur_level.zones.kill,
-cur_level.platform_tex.height as f32, -cur_level.platform_tex.height as f32,
) )
} else { } else {
@ -50,12 +52,14 @@ impl FrameUpdate for InGameScreen {
self.player.update_player( self.player.update_player(
Some(CharacterState::Running), Some(CharacterState::Running),
&cur_level.colliders, &cur_level.colliders,
&cur_level.zones.kill,
-cur_level.platform_tex.height as f32, -cur_level.platform_tex.height as f32,
) )
} else { } else {
self.player.update_player( self.player.update_player(
None, None,
&cur_level.colliders, &cur_level.colliders,
&cur_level.zones.kill,
-cur_level.platform_tex.height as f32, -cur_level.platform_tex.height as f32,
) )
} }

View File

@ -0,0 +1,189 @@
use std::ops::{Div, Sub};
use chrono::{DateTime, Utc};
use dirty_fsm::{Action, ActionFlag};
use discord_sdk::activity::{ActivityBuilder, Assets};
use pkg_version::pkg_version_major;
use raylib::prelude::*;
use crate::{
context::{ControlFlag, GameContext},
utilities::{
datastore::{load_texture_from_internal_data, ResourceLoadError},
game_version::get_version_string,
math::interpolate_exp,
non_ref_raylib::HackedRaylibHandle,
render_layer::ScreenSpaceRender,
},
GameConfig,
};
use super::{Scenes, ScreenError};
use tracing::{debug, error, info, trace};
#[derive(Debug)]
pub struct LevelSelectScreen {
is_btm_pressed: bool,
selected_level: Option<usize>,
visible_levels: usize,
}
impl LevelSelectScreen {
/// Construct a new `LevelSelectScreen`
pub fn new() -> Self {
Self {
is_btm_pressed: false,
selected_level: None,
visible_levels: 0,
}
}
}
impl Action<Scenes, ScreenError, GameContext> for LevelSelectScreen {
fn on_register(&mut self) -> Result<(), ScreenError> {
debug!("Registered");
Ok(())
}
fn on_first_run(&mut self, context: &GameContext) -> Result<(), ScreenError> {
debug!("Running LevelSelectScreen for the first time");
if let Err(e) = context.discord_rpc_send.send(Some(
ActivityBuilder::default()
.details("learning how to play")
.assets(
Assets::default().large("game-logo-small", Some(context.config.name.clone())),
),
)) {
error!("Failed to update discord: {}", e);
}
// Calculate the number of levels to render
self.visible_levels =
(context.player_progress.level_best_times.len() + 1).min(context.total_levels);
Ok(())
}
fn execute(
&mut self,
_delta: &chrono::Duration,
context: &GameContext,
) -> Result<dirty_fsm::ActionFlag<Scenes>, ScreenError> {
trace!("execute() called on LevelSelectScreen");
self.render_screen_space(&mut context.renderer.borrow_mut(), &context.config);
if let Some(level) = self.selected_level {
// Play the sound
context
.flag_send
.send(Some(ControlFlag::SoundTrigger("button-press".to_string())))
.unwrap();
// Switch the level
context
.flag_send
.send(Some(ControlFlag::BeginLevel(level)))
.unwrap();
// context
// .flag_send
// .send(Some(ControlFlag::UpdateLevelStart(
// Utc::now(),
// )))
// .unwrap();
// Enter the game
Ok(ActionFlag::SwitchState(Scenes::InGameScene))
} else if self.is_btm_pressed {
context
.flag_send
.send(Some(ControlFlag::SoundTrigger("button-press".to_string())))
.unwrap();
Ok(ActionFlag::SwitchState(Scenes::MainMenuScreen))
} else {
Ok(ActionFlag::Continue)
}
}
fn on_finish(&mut self, _interrupted: bool) -> Result<(), ScreenError> {
debug!("Finished LevelSelectScreen");
self.selected_level = None;
self.is_btm_pressed = false;
Ok(())
}
}
impl ScreenSpaceRender for LevelSelectScreen {
fn render_screen_space(
&mut self,
raylib: &mut crate::utilities::non_ref_raylib::HackedRaylibHandle,
config: &GameConfig,
) {
let screen_size = raylib.get_screen_size();
// Render the background
raylib.clear_background(Color::BLACK);
raylib.draw_rectangle_lines(
0,
0,
screen_size.x as i32,
screen_size.y as i32,
config.colors.white,
);
let screen_size = raylib.get_screen_size();
//Mouse Position
let mouse_position: Vector2 = raylib.get_mouse_position();
let mouse_pressed: bool = raylib.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON);
//Render the title
raylib.draw_rgb_split_text(
Vector2::new(40.0, 80.0),
"Level Select",
70,
true,
Color::WHITE,
);
// Render the levels
for level in 0..self.visible_levels {
let hovering_button =
Rectangle::new(100.0, 300.0 + (25.0 * level as f32), 180.0, 25.0 ).check_collision_point_rec(mouse_position);
raylib.draw_rgb_split_text(
Vector2::new(100.0, 300.0+ (25.0 * level as f32)),
&format!("LEVEL {}", level),
25,
hovering_button,
Color::WHITE,
);
if hovering_button {
raylib.draw_rgb_split_text(
Vector2::new(70.0, 300.0+ (25.0 * level as f32)),
">>",
25,
hovering_button,
Color::WHITE,
);
};
if mouse_pressed && hovering_button {
self.selected_level = Some(level);
break;
}
}
//Back to Menu
let hovering_back_button = Rectangle::new(35.0, screen_size.y as f32 - 80.0, 200.0, 40.0)
.check_collision_point_rec(mouse_position);
raylib.draw_rgb_split_text(
Vector2::new(25.0, screen_size.y - 50.0),
"BACK TO MENU",
25,
hovering_back_button,
Color::WHITE,
);
self.is_btm_pressed = hovering_back_button && mouse_pressed;
}
}

View File

@ -83,7 +83,7 @@ impl Action<Scenes, ScreenError, GameContext> for MainMenuScreen {
.flag_send .flag_send
.send(Some(ControlFlag::SoundTrigger("button-press".to_string()))) .send(Some(ControlFlag::SoundTrigger("button-press".to_string())))
.unwrap(); .unwrap();
Ok(ActionFlag::SwitchState(Scenes::InGameScene)) Ok(ActionFlag::SwitchState(Scenes::LevelSelectScreen))
} else if self.is_htp_pressed { } else if self.is_htp_pressed {
context context
.flag_send .flag_send
@ -271,6 +271,8 @@ impl ScreenSpaceRender for MainMenuScreen {
}; };
self.is_options_pressed = mouse_pressed && hovering_options; self.is_options_pressed = mouse_pressed && hovering_options;
// CREDITS // CREDITS
let hovering_credits = let hovering_credits =
Rectangle::new(80.0, 445.0, 135.0, 20.0).check_collision_point_rec(mouse_position); Rectangle::new(80.0, 445.0, 135.0, 20.0).check_collision_point_rec(mouse_position);
@ -321,7 +323,7 @@ impl ScreenSpaceRender for MainMenuScreen {
for (i, (level, time)) in times.iter() { for (i, (level, time)) in times.iter() {
let time = Duration::seconds(*time); let time = Duration::seconds(*time);
raylib.draw_text( raylib.draw_text(
&format!("Lvl {} {}:{}", level + 1, time.num_minutes(), time.num_seconds() % 60), &format!("Lvl {} {}:{}", level, time.num_minutes(), time.num_seconds() % 60),
screen_size.x as i32 - 200, screen_size.x as i32 - 200,
100 + (25 * (*i as i32)), 100 + (25 * (*i as i32)),
20, 20,
@ -331,6 +333,5 @@ impl ScreenSpaceRender for MainMenuScreen {
} }
self.is_quit_pressed = mouse_pressed && hovering_quit; self.is_quit_pressed = mouse_pressed && hovering_quit;
// for
} }
} }

View File

@ -1,11 +1,4 @@
use self::{ use self::{death_screen::DeathScreen, fsm_error_screen::FsmErrorScreen, how_to_play_screen::HowToPlayScreen, ingame_scene::{InGameScreen, level::{Level, loader::load_all_levels}}, level_select_screen::LevelSelectScreen, main_menu_screen::MainMenuScreen, next_level_screen::NextLevelScreen, options_screen::OptionsScreen, pause_screen::PauseScreen, win_screen::WinScreen};
pause_screen::PauseScreen,
fsm_error_screen::FsmErrorScreen,
ingame_scene::{level::loader::load_all_levels, InGameScreen},
main_menu_screen::MainMenuScreen, options_screen::OptionsScreen, how_to_play_screen::HowToPlayScreen,
death_screen::DeathScreen, win_screen::WinScreen,
next_level_screen::NextLevelScreen
};
use crate::{context::GameContext, utilities::{datastore::{ResourceLoadError, load_music_from_internal_data, load_sound_from_internal_data, load_texture_from_internal_data}, non_ref_raylib::HackedRaylibHandle}}; use crate::{context::GameContext, utilities::{datastore::{ResourceLoadError, load_music_from_internal_data, load_sound_from_internal_data, load_texture_from_internal_data}, non_ref_raylib::HackedRaylibHandle}};
use dirty_fsm::StateMachine; use dirty_fsm::StateMachine;
use raylib::{texture::Texture2D, RaylibThread}; use raylib::{texture::Texture2D, RaylibThread};
@ -19,6 +12,7 @@ pub mod pause_screen;
pub mod death_screen; pub mod death_screen;
pub mod win_screen; pub mod win_screen;
pub mod next_level_screen; pub mod next_level_screen;
pub mod level_select_screen;
/// Defines all scenes /// Defines all scenes
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)]
@ -33,6 +27,7 @@ pub enum Scenes {
DeathScreen, DeathScreen,
WinScreen, WinScreen,
NextLevelScreen, NextLevelScreen,
LevelSelectScreen,
} }
/// Contains any possible errors thrown while rendering /// Contains any possible errors thrown while rendering
@ -46,6 +41,7 @@ pub enum ScreenError {
pub fn build_screen_state_machine( pub fn build_screen_state_machine(
raylib_handle: &mut HackedRaylibHandle, raylib_handle: &mut HackedRaylibHandle,
thread: &RaylibThread, thread: &RaylibThread,
levels: Vec<Level>
) -> Result< ) -> Result<
// StateMachine<Scenes, ScreenError, RefCell<(NonRefDrawHandle, Rc<RefCell<GameContext>>)>>, // StateMachine<Scenes, ScreenError, RefCell<(NonRefDrawHandle, Rc<RefCell<GameContext>>)>>,
StateMachine<Scenes, ScreenError, GameContext>, StateMachine<Scenes, ScreenError, GameContext>,
@ -56,7 +52,6 @@ pub fn build_screen_state_machine(
load_texture_from_internal_data(raylib_handle, thread, "character/player_run.png").unwrap(); load_texture_from_internal_data(raylib_handle, thread, "character/player_run.png").unwrap();
let world_background = let world_background =
load_texture_from_internal_data(raylib_handle, thread, "default-texture.png").unwrap(); load_texture_from_internal_data(raylib_handle, thread, "default-texture.png").unwrap();
let levels = load_all_levels(raylib_handle, thread).unwrap();
// Set up the state machine // Set up the state machine
let mut machine = StateMachine::new(); let mut machine = StateMachine::new();
@ -72,6 +67,7 @@ pub fn build_screen_state_machine(
machine.add_action(Scenes::DeathScreen, DeathScreen::new())?; machine.add_action(Scenes::DeathScreen, DeathScreen::new())?;
machine.add_action(Scenes::WinScreen, WinScreen::new())?; machine.add_action(Scenes::WinScreen, WinScreen::new())?;
machine.add_action(Scenes::NextLevelScreen, NextLevelScreen::new())?; machine.add_action(Scenes::NextLevelScreen, NextLevelScreen::new())?;
machine.add_action(Scenes::LevelSelectScreen, LevelSelectScreen::new())?;
Ok(machine) Ok(machine)
} }

View File

@ -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};
@ -20,6 +24,7 @@ use tracing::{debug, error, info, trace};
#[derive(Debug)] #[derive(Debug)]
pub struct NextLevelScreen { pub struct NextLevelScreen {
is_next_pressed: bool, is_next_pressed: bool,
is_level_select_pressed: bool,
screen_load_time: DateTime<Utc>, screen_load_time: DateTime<Utc>,
attempt_time: String, attempt_time: String,
best_time: String, best_time: String,
@ -30,6 +35,7 @@ impl NextLevelScreen {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
is_next_pressed: false, is_next_pressed: false,
is_level_select_pressed: false,
screen_load_time: Utc::now(), screen_load_time: Utc::now(),
attempt_time: String::new(), attempt_time: String::new(),
best_time: String::new(), best_time: String::new(),
@ -87,8 +93,19 @@ 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 if self.is_level_select_pressed {
Ok(ActionFlag::SwitchState(Scenes::LevelSelectScreen))
}else {
Ok(ActionFlag::Continue) Ok(ActionFlag::Continue)
} }
} }
@ -96,6 +113,7 @@ impl Action<Scenes, ScreenError, GameContext> for NextLevelScreen {
fn on_finish(&mut self, _interrupted: bool) -> Result<(), ScreenError> { fn on_finish(&mut self, _interrupted: bool) -> Result<(), ScreenError> {
debug!("Finished NextLevelScreen"); debug!("Finished NextLevelScreen");
self.is_next_pressed = false; self.is_next_pressed = false;
self.is_level_select_pressed = false;
Ok(()) Ok(())
} }
} }
@ -156,11 +174,42 @@ impl ScreenSpaceRender for NextLevelScreen {
.check_collision_point_rec(mouse_position); .check_collision_point_rec(mouse_position);
raylib.draw_rgb_split_text( raylib.draw_rgb_split_text(
Vector2::new(80.0, screen_size.y / 2.0 + 50.0), Vector2::new(80.0, screen_size.y / 2.0 + 50.0),
">> Next Level", "Next Level",
25, 25,
hovering_next_button, hovering_next_button,
Color::WHITE, Color::WHITE,
); );
if hovering_next_button {
raylib.draw_rgb_split_text(
Vector2::new(50.0, screen_size.y as f32 / 2.0 + 50.0),
">>",
25,
hovering_next_button,
Color::WHITE,
);
};
self.is_next_pressed = hovering_next_button && mouse_pressed; self.is_next_pressed = hovering_next_button && mouse_pressed;
//Next Level
let hovering_level_select_button =
Rectangle::new(80.0, screen_size.y as f32 / 2.0 + 90.0, 300.0, 20.0)
.check_collision_point_rec(mouse_position);
raylib.draw_rgb_split_text(
Vector2::new(80.0, screen_size.y / 2.0 + 100.0),
"Back To Level Select",
25,
hovering_level_select_button,
Color::WHITE,
);
if hovering_level_select_button {
raylib.draw_rgb_split_text(
Vector2::new(50.0, screen_size.y as f32 / 2.0 + 100.0),
">>",
25,
hovering_level_select_button,
Color::WHITE,
);
};
self.is_level_select_pressed = hovering_level_select_button && mouse_pressed;
} }
} }

View File

@ -20,6 +20,7 @@ use tracing::{debug, error, info, trace};
#[derive(Debug)] #[derive(Debug)]
pub struct OptionsScreen { pub struct OptionsScreen {
is_btm_pressed: bool, //Is back to menu button pressed is_btm_pressed: bool, //Is back to menu button pressed
counter: i32,
} }
impl OptionsScreen { impl OptionsScreen {
@ -27,6 +28,7 @@ impl OptionsScreen {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
is_btm_pressed: false, is_btm_pressed: false,
counter: 0,
} }
} }
} }
@ -64,6 +66,8 @@ impl Action<Scenes, ScreenError, GameContext> for OptionsScreen {
trace!("execute() called on OptionsScreen"); trace!("execute() called on OptionsScreen");
self.render_screen_space(&mut context.renderer.borrow_mut(), &context.config); self.render_screen_space(&mut context.renderer.borrow_mut(), &context.config);
self.counter += 1;
if self.is_btm_pressed { if self.is_btm_pressed {
context context
.flag_send .flag_send
@ -108,7 +112,17 @@ impl ScreenSpaceRender for OptionsScreen {
let mouse_pressed: bool = raylib.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON); let mouse_pressed: bool = raylib.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON);
// Render the title // Render the title
raylib.draw_rgb_split_text(Vector2::new(40.0, 80.0), "Options", 70, true, Color::WHITE); let timer: i32 = get_random_value(50, 400);
if self.counter > timer {
raylib.draw_rgb_split_text(Vector2::new(40.0, 80.0), "[Options]", 70, true, Color::WHITE);
if self.counter > timer + 20 {
self.counter = 0;
}
}
else{
raylib.draw_rgb_split_text(Vector2::new(40.0, 80.0), "[Options]", 70, false, Color::WHITE);
}
// Render the text // Render the text
raylib.draw_rgb_split_text( raylib.draw_rgb_split_text(

View File

@ -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)

View File

@ -9,3 +9,4 @@ pub mod render_layer;
pub mod shaders; pub mod shaders;
pub mod world_paint_texture; pub mod world_paint_texture;
pub mod audio_player; pub mod audio_player;
pub mod reusable_button;

View File

@ -0,0 +1,20 @@
// use raylib::prelude::*;
// #[derive(Debug)]
// pub struct ReusableButton {
// text: String,
// position: Vector2,
// font_size: f32,
// font_color: Color,
// arrow_on_hover: bool
// }
// impl ReusableButton {
// /// Construct a new reusable button.
// pub fn new() -> Self {
// Self {
// }
// }
// }