Merge branch 'levels' of https://github.com/Ewpratten/ludum-dare-49 into levels

This commit is contained in:
Marcelo Geldres 2021-10-04 01:11:50 -04:00
commit 9735e6c260
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
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)
- 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/)
- Character art
- Animations
- Tilesets
- [**Kori**](https://www.instagram.com/korigama/)
- Concept art
- 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.

View File

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

View File

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

View File

@ -13,6 +13,7 @@ pub const GRAVITY_PPS: f32 = 2.0;
pub fn modify_player_based_on_forces(
player: &mut MainCharacter,
colliders: &Vec<Rectangle>,
killers: &Vec<Rectangle>,
level_height_offset: f32,
) -> Result<(), ()> {
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;
// 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.y - (player.size.x / 2.0),
player.size.x,
@ -48,6 +49,15 @@ pub fn modify_player_based_on_forces(
|| 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 = || {
colliders.iter().any(|rect| {
let mut translated_rect = rect.clone();
@ -76,10 +86,11 @@ pub fn modify_player_based_on_forces(
return player.update_player(
Some(CharacterState::Running),
colliders,
killers,
level_height_offset,
);
}
}else if player.current_state == CharacterState::Running {
} else if player.current_state == CharacterState::Running {
player.override_state(CharacterState::Jumping);
}
@ -87,22 +98,27 @@ pub fn modify_player_based_on_forces(
player.position += player.velocity;
// Re-calculate the player rect
player_rect = Rectangle::new(
let player_rect = Rectangle::new(
player.position.x - (player.size.x / 2.0),
player.position.y - (player.size.x / 2.0),
player.size.x,
player.size.y,
);
if player.position.y > 50.0 || colliders.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)
}) {
if player.position.y > 50.0
|| colliders.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)
})
{
return Err(());
}
if check_player_colliding_with_killers() {
return Err(());
}
Ok(())
}

View File

@ -66,6 +66,7 @@ impl MainCharacter {
&mut self,
state: Option<CharacterState>,
colliders: &Vec<Rectangle>,
killers: &Vec<Rectangle>,
level_height_offset: f32,
) -> Result<(), ()> {
if let Some(state) = state {
@ -81,7 +82,7 @@ impl MainCharacter {
}
// 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) {

View File

@ -4,16 +4,21 @@ use chrono::{DateTime, Duration, Utc};
use discord_sdk::activity::ActivityBuilder;
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)]
pub enum ControlFlag {
Quit,
SwitchLevel(usize),
UpdateLevelStart(DateTime<Utc>),
SaveProgress,
MaybeUpdateHighScore(usize, Duration),
SoundTrigger(String)
BeginLevel(usize),
EndLevel,
// UpdateLevelStart(DateTime<Utc>),
// SaveProgress,
// MaybeUpdateHighScore(usize, Duration),
SoundTrigger(String),
}
#[derive(Debug)]
@ -24,6 +29,7 @@ pub struct GameContext {
pub config: GameConfig,
pub player_progress: ProgressData,
pub current_level: usize,
pub total_levels: usize,
pub level_start_time: DateTime<Utc>,
pub discord_rpc_send: Sender<Option<ActivityBuilder>>,
pub flag_send: Sender<Option<ControlFlag>>,

View File

@ -82,7 +82,7 @@ use crate::{
context::GameContext,
discord_rpc::{maybe_set_discord_presence, try_connect_to_local_discord},
progress::ProgressData,
scenes::{build_screen_state_machine, Scenes},
scenes::{build_screen_state_machine, ingame_scene::level::loader::load_all_levels, Scenes},
utilities::{
audio_player::AudioPlayer,
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(),
audio: audio_system,
sounds,
total_levels: 0,
current_level: 0,
player_progress: save_file,
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
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
info!("Setting up the scene management 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
.force_change_state(Scenes::MainMenuScreen)
.unwrap();
@ -356,27 +362,24 @@ pub async fn game_begin(game_config: &mut GameConfig) -> Result<(), Box<dyn std:
if let Some(flag) = flag {
match flag {
context::ControlFlag::Quit => break,
context::ControlFlag::SwitchLevel(level) => {
context::ControlFlag::BeginLevel(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.as_mut().level_start_time = time;
context.as_mut().player_progress.save();
}
context::ControlFlag::SaveProgress => {
context.as_mut().player_progress.save();
}
context::ControlFlag::MaybeUpdateHighScore(level, time) => {
context
.as_mut()
.player_progress
.maybe_write_new_time(level, &time);
context::ControlFlag::EndLevel => {
let now = Utc::now();
let elapsed = now - context.as_mut().level_start_time;
if elapsed.num_seconds().abs() > 1 {
let current_level = context.as_mut().current_level;
context
.as_mut()
.player_progress
.maybe_write_new_time(current_level, &elapsed);
context.as_mut().player_progress.save();
}
}
context::ControlFlag::SoundTrigger(name) => {
context.audio.play_sound(
context.sounds.get(&name).unwrap(),
);
context.audio.play_sound(context.sounds.get(&name).unwrap());
}
}
}

View File

@ -20,6 +20,7 @@ use tracing::{debug, error, info, trace};
#[derive(Debug)]
pub struct HowToPlayScreen {
is_btm_pressed: bool, //Is back to menu button pressed
counter: i32,
}
impl HowToPlayScreen {
@ -27,6 +28,7 @@ impl HowToPlayScreen {
pub fn new() -> Self {
Self {
is_btm_pressed: false,
counter: 0,
}
}
}
@ -61,6 +63,8 @@ impl Action<Scenes, ScreenError, GameContext> for HowToPlayScreen {
trace!("execute() called on HowToPlayScreen");
self.render_screen_space(&mut context.renderer.borrow_mut(), &context.config);
self.counter += 1;
if self.is_btm_pressed {
context
.flag_send
@ -75,6 +79,7 @@ impl Action<Scenes, ScreenError, GameContext> for HowToPlayScreen {
fn on_finish(&mut self, _interrupted: bool) -> Result<(), ScreenError> {
debug!("Finished HowToPlayScreen");
self.is_btm_pressed = false;
self.counter = 0;
Ok(())
}
}
@ -105,13 +110,28 @@ impl ScreenSpaceRender for HowToPlayScreen {
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),
"How to Play",
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),
"[How to Play]",
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
raylib.draw_rgb_split_text(

View File

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

View File

@ -75,6 +75,7 @@ impl Action<Scenes, ScreenError, GameContext> for InGameScreen {
let _ = self.player.update_player(
Some(CharacterState::Running),
&cur_level.colliders,
&cur_level.zones.kill,
-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 {
self.current_level_idx = context.current_level;
self.level_switch_timestamp = Utc::now();
context
.flag_send
.send(Some(ControlFlag::UpdateLevelStart(
self.level_switch_timestamp,
)))
.unwrap();
// self.level_switch_timestamp = Utc::now();
// context
// .flag_send
// .send(Some(ControlFlag::UpdateLevelStart(
// self.level_switch_timestamp,
// )))
// .unwrap();
}
// Grab exclusive access to the renderer
@ -133,35 +134,33 @@ impl Action<Scenes, ScreenError, GameContext> for InGameScreen {
// Render the HUD
self.render_screen_space(&mut renderer, &context.config);
// Check if the player won
let cur_level = self.levels.get(context.current_level).unwrap();
if self.player.position.x > cur_level.zones.win.x {
// Save the current time
let elapsed = Utc::now() - self.level_switch_timestamp;
context
.flag_send
.send(Some(ControlFlag::MaybeUpdateHighScore(
self.current_level_idx,
elapsed,
)))
.unwrap();
// let elapsed = Utc::now() - self.level_switch_timestamp;
// context
// .flag_send
// .send(Some(ControlFlag::MaybeUpdateHighScore(
// self.current_level_idx,
// elapsed,
// )))
// .unwrap();
// Save the progress
context
.flag_send
.send(Some(ControlFlag::SaveProgress))
.unwrap();
// End the level
context.flag_send.send(Some(ControlFlag::EndLevel)).unwrap();
// If this is the last level, win the game
if self.current_level_idx >= self.levels.len() - 1 {
return Ok(ActionFlag::SwitchState(Scenes::WinScreen));
} else {
// Otherwise, increment the level counter and switch to the next level
context
.flag_send
.send(Some(ControlFlag::SwitchLevel(self.current_level_idx + 1)))
.unwrap();
// context
// .flag_send
// .send(Some(ControlFlag::SwitchLevel(self.current_level_idx + 1)))
// .unwrap();
return Ok(ActionFlag::SwitchState(Scenes::NextLevelScreen));
}

View File

@ -35,12 +35,14 @@ impl FrameUpdate for InGameScreen {
self.player.update_player(
Some(CharacterState::Jumping),
&cur_level.colliders,
&cur_level.zones.kill,
-cur_level.platform_tex.height as f32,
)
} else if is_dash {
self.player.update_player(
Some(CharacterState::Dashing),
&cur_level.colliders,
&cur_level.zones.kill,
-cur_level.platform_tex.height as f32,
)
} else {
@ -50,12 +52,14 @@ impl FrameUpdate for InGameScreen {
self.player.update_player(
Some(CharacterState::Running),
&cur_level.colliders,
&cur_level.zones.kill,
-cur_level.platform_tex.height as f32,
)
} else {
self.player.update_player(
None,
&cur_level.colliders,
&cur_level.zones.kill,
-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
.send(Some(ControlFlag::SoundTrigger("button-press".to_string())))
.unwrap();
Ok(ActionFlag::SwitchState(Scenes::InGameScene))
Ok(ActionFlag::SwitchState(Scenes::LevelSelectScreen))
} else if self.is_htp_pressed {
context
.flag_send
@ -271,6 +271,8 @@ impl ScreenSpaceRender for MainMenuScreen {
};
self.is_options_pressed = mouse_pressed && hovering_options;
// CREDITS
let hovering_credits =
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() {
let time = Duration::seconds(*time);
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,
100 + (25 * (*i as i32)),
20,
@ -331,6 +333,5 @@ impl ScreenSpaceRender for MainMenuScreen {
}
self.is_quit_pressed = mouse_pressed && hovering_quit;
// for
}
}

View File

@ -1,11 +1,4 @@
use self::{
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 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};
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 raylib::{texture::Texture2D, RaylibThread};
@ -19,6 +12,7 @@ pub mod pause_screen;
pub mod death_screen;
pub mod win_screen;
pub mod next_level_screen;
pub mod level_select_screen;
/// Defines all scenes
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)]
@ -33,6 +27,7 @@ pub enum Scenes {
DeathScreen,
WinScreen,
NextLevelScreen,
LevelSelectScreen,
}
/// Contains any possible errors thrown while rendering
@ -46,6 +41,7 @@ pub enum ScreenError {
pub fn build_screen_state_machine(
raylib_handle: &mut HackedRaylibHandle,
thread: &RaylibThread,
levels: Vec<Level>
) -> Result<
// StateMachine<Scenes, ScreenError, RefCell<(NonRefDrawHandle, Rc<RefCell<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();
let world_background =
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
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::WinScreen, WinScreen::new())?;
machine.add_action(Scenes::NextLevelScreen, NextLevelScreen::new())?;
machine.add_action(Scenes::LevelSelectScreen, LevelSelectScreen::new())?;
Ok(machine)
}

View File

@ -6,13 +6,17 @@ use discord_sdk::activity::{ActivityBuilder, Assets};
use pkg_version::pkg_version_major;
use raylib::prelude::*;
use crate::{GameConfig, context::{ControlFlag, GameContext}, utilities::{
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};
@ -20,6 +24,7 @@ use tracing::{debug, error, info, trace};
#[derive(Debug)]
pub struct NextLevelScreen {
is_next_pressed: bool,
is_level_select_pressed: bool,
screen_load_time: DateTime<Utc>,
attempt_time: String,
best_time: String,
@ -30,6 +35,7 @@ impl NextLevelScreen {
pub fn new() -> Self {
Self {
is_next_pressed: false,
is_level_select_pressed: false,
screen_load_time: Utc::now(),
attempt_time: String::new(),
best_time: String::new(),
@ -87,8 +93,19 @@ impl Action<Scenes, ScreenError, GameContext> for NextLevelScreen {
.flag_send
.send(Some(ControlFlag::SoundTrigger("button-press".to_string())))
.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))
} else {
}
else if self.is_level_select_pressed {
Ok(ActionFlag::SwitchState(Scenes::LevelSelectScreen))
}else {
Ok(ActionFlag::Continue)
}
}
@ -96,6 +113,7 @@ impl Action<Scenes, ScreenError, GameContext> for NextLevelScreen {
fn on_finish(&mut self, _interrupted: bool) -> Result<(), ScreenError> {
debug!("Finished NextLevelScreen");
self.is_next_pressed = false;
self.is_level_select_pressed = false;
Ok(())
}
}
@ -156,11 +174,42 @@ impl ScreenSpaceRender for NextLevelScreen {
.check_collision_point_rec(mouse_position);
raylib.draw_rgb_split_text(
Vector2::new(80.0, screen_size.y / 2.0 + 50.0),
">> Next Level",
"Next Level",
25,
hovering_next_button,
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;
//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)]
pub struct OptionsScreen {
is_btm_pressed: bool, //Is back to menu button pressed
counter: i32,
}
impl OptionsScreen {
@ -27,6 +28,7 @@ impl OptionsScreen {
pub fn new() -> Self {
Self {
is_btm_pressed: false,
counter: 0,
}
}
}
@ -64,6 +66,8 @@ impl Action<Scenes, ScreenError, GameContext> for OptionsScreen {
trace!("execute() called on OptionsScreen");
self.render_screen_space(&mut context.renderer.borrow_mut(), &context.config);
self.counter += 1;
if self.is_btm_pressed {
context
.flag_send
@ -108,7 +112,17 @@ impl ScreenSpaceRender for OptionsScreen {
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), "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
raylib.draw_rgb_split_text(

View File

@ -69,7 +69,7 @@ impl Action<Scenes, ScreenError, GameContext> for WinScreen {
.flag_send
.send(Some(ControlFlag::SoundTrigger("button-press".to_string())))
.unwrap();
context.flag_send.send(Some(ControlFlag::SwitchLevel(0))).unwrap();
context.flag_send.send(Some(ControlFlag::EndLevel)).unwrap();
Ok(ActionFlag::SwitchState(Scenes::MainMenuScreen))
} else {
Ok(ActionFlag::Continue)

View File

@ -9,3 +9,4 @@ pub mod render_layer;
pub mod shaders;
pub mod world_paint_texture;
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 {
// }
// }
// }