diff --git a/Cargo.toml b/Cargo.toml index cfca01e..c69573f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,9 +13,4 @@ serialstudio = "0.1.0" serde = "1.0.125" serde_json = "1.0.64" failure = "0.1.8" -parry2d = "0.4.0" -log = "0.4.14" -env_logger = "0.8.3" -nalgebra = "0.26.1" rand = "0.8.3" -tiled = "0.9.4" diff --git a/src/entities/enemy/jellyfish.rs b/src/entities/enemy/jellyfish.rs index 7537fdc..1330bdf 100644 --- a/src/entities/enemy/jellyfish.rs +++ b/src/entities/enemy/jellyfish.rs @@ -28,7 +28,7 @@ impl EnemyBase for JellyFish { fn render( &mut self, context_2d: &mut raylib::prelude::RaylibMode2D, - player: &mut Player, + _player: &mut Player, resources: &mut GlobalResources, dt: f64, ) { @@ -77,7 +77,7 @@ impl EnemyBase for JellyFish { && !is_jelly_stunned; } - fn handle_logic(&mut self, player: &mut Player, dt: f64) { + fn handle_logic(&mut self, player: &mut Player, _dt: f64) { // Handle stunning the player if self.do_stun_player { if self.position.distance_to(player.position).abs() <= JELLYFISH_STUN_REACH { @@ -86,7 +86,7 @@ impl EnemyBase for JellyFish { } } - fn handle_getting_attacked(&mut self, stun_duration: f64, current_time: f64) { + fn handle_getting_attacked(&mut self, stun_duration: f64, _current_time: f64) { self.stunned_timer = stun_duration; self.max_stunned_time = stun_duration; } diff --git a/src/entities/enemy/octopus.rs b/src/entities/enemy/octopus.rs index e3d4869..73d8cee 100644 --- a/src/entities/enemy/octopus.rs +++ b/src/entities/enemy/octopus.rs @@ -1,11 +1,11 @@ use crate::{ lib::utils::calculate_linear_slide, - pallette::{TRANSLUCENT_RED_64, TRANSLUCENT_WHITE_128, TRANSLUCENT_WHITE_64}, + pallette::{TRANSLUCENT_RED_64, TRANSLUCENT_WHITE_128}, player::Player, }; use super::base::EnemyBase; -use rand::{prelude::ThreadRng, Rng}; +use rand::Rng; use raylib::prelude::*; use serde::{Deserialize, Serialize}; @@ -13,7 +13,6 @@ const OCTOPUS_SUCK_AIR_DELAY: f64 = 3.5; const OCTOPUS_SUCK_AIR_RANGE: f32 = 70.0; const OCTOPUS_SUCK_AIR_DURATION: f64 = 1.0; const OCTOPUS_SUCK_AIR_AMOUNT: f32 = 0.1; -// const RNG: ThreadRng = rand::thread_rng(); #[derive(Debug, Serialize, Deserialize, Default, Clone)] struct OctopusAirBubble { @@ -124,7 +123,7 @@ impl EnemyBase for Octopus { } } - fn handle_logic(&mut self, player: &mut crate::player::Player, dt: f64) { + fn handle_logic(&mut self, player: &mut crate::player::Player, _dt: f64) { if self.suck_air_time_remaining > 0.0 && !self.has_taken_air_from_player { if player.position.distance_to(self.current_position).abs() <= OCTOPUS_SUCK_AIR_RANGE { // Take air from the player @@ -136,7 +135,7 @@ impl EnemyBase for Octopus { } } - fn handle_getting_attacked(&mut self, stun_duration: f64, current_time: f64) { + fn handle_getting_attacked(&mut self, stun_duration: f64, _current_time: f64) { self.stunned_timer = stun_duration; self.max_stunned_time = stun_duration; } diff --git a/src/entities/fish.rs b/src/entities/fish.rs index 6cae1ab..ccaeca0 100644 --- a/src/entities/fish.rs +++ b/src/entities/fish.rs @@ -1,18 +1,7 @@ use rand::{prelude::ThreadRng, Rng}; use raylib::prelude::*; -use crate::{ - gamecore::{self, GameCore}, - lib::utils::triangles::rotate_vector, - player::Player, - resources::GlobalResources, - world::World, -}; - -const FISH_FOLLOW_PLAYER_DISTANCE: f32 = 30.0; -const FISH_FOLLOW_PLAYER_SPEED: f32 = 1.8; -const FISH_FOLLOW_PLAYER_SPEED_FAST: f32 = FISH_FOLLOW_PLAYER_SPEED * 3.0; -const FISH_ATTACH_RADIUS: f32 = 20.0; +use crate::{player::Player, resources::GlobalResources}; const FISH_VISION: f32 = 25.0; const FISH_MAX_SPEED: f32 = 2.0; @@ -63,7 +52,12 @@ impl FishEntity { return output; } - pub fn handle_follow_player(&mut self, player: &Player, dt: f64, other_fish: &Vec) { + pub fn handle_follow_player( + &mut self, + player: &Player, + _dt: f64, + other_fish: &Vec, + ) { let mut acceleration: Vector2 = Vector2::zero(); let mut steer: Vector2 = Vector2::zero(); @@ -140,11 +134,7 @@ impl FishEntity { self.position += self.velocity; } - pub fn handle_free_movement(&mut self, player: &mut Player, dt: f64) { - // Distance and direction to player - let dist_to_player = player.position - self.position; - let dist_to_player_lin = self.position.distance_to(player.position); - + pub fn handle_free_movement(&mut self, player: &mut Player, _dt: f64) { // Handle player picking up fish if player.position.distance_to(self.position).abs() <= player.size.y * 2.2 { self.following_player = true; diff --git a/src/gamecore.rs b/src/gamecore.rs index 3013213..a5a062c 100644 --- a/src/gamecore.rs +++ b/src/gamecore.rs @@ -5,15 +5,13 @@ use std::{fmt, fs::File, io::BufReader}; use raylib::{ camera::Camera2D, math::Vector2, prelude::RaylibDrawHandle, RaylibHandle, RaylibThread, }; - +use failure::Error; use crate::{ player::{Player, PlayerInventory}, resources::GlobalResources, world::World, }; -use failure::Error; -use log::debug; use serde::{Deserialize, Serialize}; /// Overall states for the game @@ -26,7 +24,7 @@ pub enum GameState { InGame, GameEnd, InShop, - WinGame + WinGame, } impl fmt::Display for GameState { @@ -80,7 +78,6 @@ impl GameProgress { } pub fn update(&mut self, new_progress: &GameProgress) { - // Bring in new data self.coins = new_progress.coins; self.inventory = new_progress.inventory.clone(); @@ -92,7 +89,6 @@ impl GameProgress { if result.is_err() { println!("Could not save game state. Holding in RAM"); } - } } @@ -152,8 +148,6 @@ impl GameCore { } pub fn switch_state(&mut self, new_state: GameState, draw_handle: Option<&RaylibDrawHandle>) { - debug!("Switching global state to: {}", new_state); - self.last_state = self.state; self.state = new_state; diff --git a/src/items.rs b/src/items.rs index f49fc88..f649bd5 100644 --- a/src/items.rs +++ b/src/items.rs @@ -2,7 +2,6 @@ use raylib::{ color::Color, math::{Rectangle, Vector2}, prelude::{RaylibDraw, RaylibDrawHandle}, - texture::Texture2D, }; use serde::{Deserialize, Serialize}; diff --git a/src/lib/wrappers/complexanimation.rs b/src/lib/wrappers/complexanimation.rs deleted file mode 100644 index ad87572..0000000 --- a/src/lib/wrappers/complexanimation.rs +++ /dev/null @@ -1,32 +0,0 @@ -use std::usize; - -use raylib::prelude::*; - -pub struct FrameRange { - pub min: usize, - pub max: usize, -} - -pub struct ComplexAnimationTool { - sprite_sheet: Texture2D, - frames_per_second: f32, - frame_size: Vector2, - sprite_sheet_size_frames: Vector2 -} - -impl ComplexAnimationTool { - pub fn render_loop(&self, context_2d: &mut RaylibMode2D, bounds: Rectangle, rotation: f32, range: &FrameRange) { - - } - - pub fn render_frame(&self, context_2d: &mut RaylibMode2D, bounds: Rectangle, rotation: f32, id: usize) { - - // Convert the ID to an xy - let col_id = id % self.sprite_sheet_size_frames.x as usize; - let row_id = id / self.sprite_sheet_size_frames.y as usize; - - - - - } -} diff --git a/src/lib/wrappers/mod.rs b/src/lib/wrappers/mod.rs index 1a8f43a..9af9ea2 100644 --- a/src/lib/wrappers/mod.rs +++ b/src/lib/wrappers/mod.rs @@ -1,3 +1,2 @@ pub mod audio; -pub mod animation; -pub mod complexanimation; \ No newline at end of file +pub mod animation; \ No newline at end of file diff --git a/src/logic/gameend.rs b/src/logic/gameend.rs index c20064e..845c025 100644 --- a/src/logic/gameend.rs +++ b/src/logic/gameend.rs @@ -22,7 +22,7 @@ impl Screen for GameEndScreen { &mut self, draw_handle: &mut RaylibDrawHandle, _thread: &RaylibThread, - audio_system: &mut AudioPlayer, + _audio_system: &mut AudioPlayer, game_core: &mut GameCore, ) -> Option { draw_handle.clear_background(Color::GRAY); @@ -75,7 +75,7 @@ impl Screen for GameEndScreen { String::from("Return to shop"), Rectangle { x: (((win_width / 2) - ((SCREEN_PANEL_SIZE.x as i32 + 6) / 2) + 5) - + (0.15 * SCREEN_PANEL_SIZE.x) as i32) as f32, + + (0.15 * SCREEN_PANEL_SIZE.x) as i32) as f32, y: (((win_height / 2) - (SCREEN_PANEL_SIZE.y as i32 / 2) + 90) as f32) + 100.0, width: 210.0, height: 50.0, @@ -87,78 +87,15 @@ impl Screen for GameEndScreen { true, ); - // render button + // render button go_to_menu_button.render(draw_handle); - // If the player clicks on the button send them to shop - if go_to_menu_button.is_hovered(draw_handle) && draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON){ - - game_core.switch_state(GameState::InShop, Some(draw_handle)); - - } - - // TODO: Save game progress - - // // Close and quit buttons - // let bottom_left_button_dimensions = Rectangle { - // x: (win_width as f32 / 2.0) - (SCREEN_PANEL_SIZE.x / 2.0) + 5.0, - // y: (win_height as f32 / 2.0) + (SCREEN_PANEL_SIZE.y / 2.0) - 50.0, - // width: (SCREEN_PANEL_SIZE.x / 2.0) - 15.0, - // height: 40.0, - // }; - // let bottom_right_button_dimensions = Rectangle { - // x: (win_width as f32 / 2.0) + 5.0, - // y: bottom_left_button_dimensions.y, - // width: bottom_left_button_dimensions.width, - // height: bottom_left_button_dimensions.height, - // }; - - // // Check if the mouse is over either button - // let mouse_over_bottom_left_button = - // bottom_left_button_dimensions.check_collision_point_rec(mouse_position); - // let mouse_over_bottom_right_button = - // bottom_right_button_dimensions.check_collision_point_rec(mouse_position); - - // // Render buttons - // draw_handle.draw_rectangle_lines_ex( - // bottom_left_button_dimensions, - // 3, - // match mouse_over_bottom_left_button { - // true => Color::GRAY, - // false => Color::BLACK, - // }, - // ); - // draw_handle.draw_text( - // "Quit", - // bottom_left_button_dimensions.x as i32 + 15, - // bottom_left_button_dimensions.y as i32 + 5, - // 30, - // Color::BLACK, - // ); - // draw_handle.draw_rectangle_lines_ex( - // bottom_right_button_dimensions, - // 3, - // match mouse_over_bottom_right_button { - // true => Color::GRAY, - // false => Color::BLACK, - // }, - // ); - // draw_handle.draw_text( - // "Close", - // bottom_right_button_dimensions.x as i32 + 15, - // bottom_right_button_dimensions.y as i32 + 5, - // 30, - // Color::BLACK, - // ); - - // // Handle click actions on the buttons - // if draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON) { - // if mouse_over_bottom_left_button { - // return Some(GameState::GameQuit); - // } else if mouse_over_bottom_right_button { - // return Some(game_core.last_state); - // } - // } + // If the player clicks on the button send them to shop + if go_to_menu_button.is_hovered(draw_handle) + && draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON) + { + return Some(GameState::InShop); + } return None; } diff --git a/src/logic/ingame/mod.rs b/src/logic/ingame/mod.rs index 58f74e1..104d428 100644 --- a/src/logic/ingame/mod.rs +++ b/src/logic/ingame/mod.rs @@ -3,26 +3,19 @@ mod playerlogic; use raylib::prelude::*; -use crate::{entities::enemy::{base::EnemyBase, whirlpool::Whirlpool}, gamecore::{GameCore, GameState}, lib::wrappers::audio::player::AudioPlayer, pallette::{SKY, WATER, WATER_DARK}}; +use crate::{entities::enemy::{base::EnemyBase, whirlpool::Whirlpool}, gamecore::{GameCore, GameState}, lib::wrappers::audio::player::AudioPlayer}; use super::screen::Screen; use crate::entities::fish::FishEntity; -pub enum InGameState { - BUYING, - SWIMMING, -} - pub struct InGameScreen { - current_state: InGameState, shader_time_var_location: i32, } impl InGameScreen { pub unsafe fn new(game_core: &GameCore) -> Self { Self { - current_state: InGameState::SWIMMING, shader_time_var_location: raylib::ffi::GetShaderLocation( *game_core.resources.pixel_shader, rstr!("time").as_ptr(), @@ -185,8 +178,8 @@ impl Screen for InGameScreen { fn render( &mut self, draw_handle: &mut RaylibDrawHandle, - thread: &RaylibThread, - audio_system: &mut AudioPlayer, + _thread: &RaylibThread, + _audio_system: &mut AudioPlayer, game_core: &mut GameCore, ) -> Option { // Calculate DT @@ -204,7 +197,6 @@ impl Screen for InGameScreen { x: (win_width as f32 / 2.0), y: (win_height as f32 / 2.0), }; - let camera_window_center = window_center * (1.0 / game_core.master_camera.zoom); // Update player movement playerlogic::update_player_movement(draw_handle, game_core, window_center); @@ -261,12 +253,6 @@ impl Screen for InGameScreen { game_core.world.whirlpool.retain(|x| !x.should_remove()); - - - - - - diff --git a/src/logic/ingame/playerlogic.rs b/src/logic/ingame/playerlogic.rs index 804706b..2c9e509 100644 --- a/src/logic/ingame/playerlogic.rs +++ b/src/logic/ingame/playerlogic.rs @@ -1,13 +1,9 @@ use raylib::prelude::*; -use crate::{ - gamecore::GameCore, - pallette::{TRANSLUCENT_WHITE_128, TRANSLUCENT_WHITE_64, TRANSLUCENT_WHITE_96}, -}; +use crate::gamecore::GameCore; const NORMAL_PLAYER_SPEED: i32 = 1; const BOOST_PLAYER_SPEED: i32 = NORMAL_PLAYER_SPEED * 2; -const CAMERA_FOLLOW_SPEED: f32 = 0.7; const TURN_SPEED: f32 = 0.15; const BOOST_DECREASE_PER_SECOND: f32 = 0.65; const BOOST_REGEN_PER_SECOND: f32 = 0.25; @@ -79,7 +75,9 @@ pub fn update_player_movement( let user_request_action = draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_RIGHT_BUTTON); if user_request_action { - game_core.player.begin_attack(&mut game_core.world, draw_handle.get_time()); + game_core + .player + .begin_attack(&mut game_core.world, draw_handle.get_time()); } // Move the player in their direction @@ -150,7 +148,13 @@ pub fn update_player_movement( // Handle the player wearing flippers if game_core.player.inventory.flippers.is_some() { - player_real_movement *= game_core.player.inventory.flippers.as_ref().unwrap().speed_increase; + player_real_movement *= game_core + .player + .inventory + .flippers + .as_ref() + .unwrap() + .speed_increase; } @@ -256,8 +260,6 @@ pub fn update_player_movement( // Move the camera to follow the player - let direction_from_cam_to_player = - (game_core.player.position - window_center) - game_core.master_camera.target; let player_screen_position = draw_handle.get_world_to_screen2D(game_core.player.position, game_core.master_camera); diff --git a/src/logic/loadingscreen.rs b/src/logic/loadingscreen.rs index aa13ef2..ba13c53 100644 --- a/src/logic/loadingscreen.rs +++ b/src/logic/loadingscreen.rs @@ -1,11 +1,13 @@ use raylib::prelude::*; -use crate::{gamecore::{GameCore, GameState}, lib::{utils::calculate_linear_slide, wrappers::audio::player::AudioPlayer}}; +use crate::{ + gamecore::{GameCore, GameState}, + lib::{utils::calculate_linear_slide, wrappers::audio::player::AudioPlayer}, +}; use super::screen::Screen; const SECONDS_PER_LOGO: f64 = 4.0; -const RUST_ORANGE: Color = Color::new(222, 165, 132, 255); #[derive(Debug, PartialEq)] enum LoadingScreenState { @@ -138,7 +140,7 @@ impl Screen for LoadingScreen { fn render( &mut self, draw_handle: &mut RaylibDrawHandle, - thread: &RaylibThread, + _thread: &RaylibThread, _audio_system: &mut AudioPlayer, game_core: &mut GameCore, ) -> Option { diff --git a/src/logic/mainmenu.rs b/src/logic/mainmenu.rs index 89f7d87..421105c 100644 --- a/src/logic/mainmenu.rs +++ b/src/logic/mainmenu.rs @@ -3,7 +3,6 @@ use raylib::prelude::*; use crate::{ gamecore::{GameCore, GameState}, lib::wrappers::audio::player::AudioPlayer, - pallette::WATER_DARK, }; use super::screen::Screen; @@ -20,8 +19,8 @@ impl Screen for MainMenuScreen { fn render( &mut self, draw_handle: &mut RaylibDrawHandle, - thread: &RaylibThread, - audio_system: &mut AudioPlayer, + _thread: &RaylibThread, + _audio_system: &mut AudioPlayer, game_core: &mut GameCore, ) -> Option { // Window dimensions @@ -35,8 +34,8 @@ impl Screen for MainMenuScreen { // Render title draw_handle.draw_text( - "PINK MAN SWIM", - (win_height / 2) - 120, + "ONE BREATH", + (win_height / 2) - 80, win_width / 8, 80, Color::BLACK, @@ -55,7 +54,7 @@ impl Screen for MainMenuScreen { draw_handle.draw_text( "Play", (win_height / 2) + 120, - (win_width / 4), + win_width / 4, 60, match hovering_play_button { true => Color::BLUE, @@ -96,7 +95,7 @@ impl Screen for MainMenuScreen { return Some(GameState::InGame); } else if hovering_shop_button { return Some(GameState::InShop); - }else if hovering_quit_button { + } else if hovering_quit_button { return Some(GameState::GameQuit); } } diff --git a/src/logic/shop/item.rs b/src/logic/shop/item.rs index dc7d8bd..2952784 100644 --- a/src/logic/shop/item.rs +++ b/src/logic/shop/item.rs @@ -1,10 +1,6 @@ -use std::marker::PhantomData; - -use raylib::prelude::*; - -use crate::{items::ItemBase, player::Player, world::World}; - use super::itemui::ShopItemUi; +use crate::{items::ItemBase, player::Player}; +use raylib::prelude::*; pub struct ShopItemWrapper { bounds: Rectangle, @@ -17,7 +13,7 @@ impl ShopItemWrapper { item: T, from_inventory: &Option, first_item_bounds: Rectangle, - index: u8 + index: u8, ) -> Self { // Build new bounds for the UI row let new_bounds = Rectangle { @@ -47,7 +43,9 @@ impl ShopItemWrapper { } pub fn can_player_afford(&self, player: &Player, players_item: &Option) -> bool { - return player.coins >= self.item.get_cost() && ((players_item.is_some() && players_item.as_ref().unwrap().get_level() < 3) || players_item.is_none()); + return player.coins >= self.item.get_cost() + && ((players_item.is_some() && players_item.as_ref().unwrap().get_level() < 3) + || players_item.is_none()); } pub fn purchase(&self, player: &mut Player) -> T { @@ -59,14 +57,26 @@ impl ShopItemWrapper { } pub fn user_clicked_buy(&self, draw_handle: &mut RaylibDrawHandle) -> bool { - return self.ui.buy_button_hovered && draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON); + return self.ui.buy_button_hovered + && draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON); } pub fn user_hovering_row(&self, draw_handle: &mut RaylibDrawHandle) -> bool { - return self.bounds.check_collision_point_rec(draw_handle.get_mouse_position()); + return self + .bounds + .check_collision_point_rec(draw_handle.get_mouse_position()); } - pub fn render(&mut self, draw_handle: &mut RaylibDrawHandle, player: &Player, players_item: &Option) { - self.ui.render(draw_handle, self.bounds, self.can_player_afford(player, players_item)); + pub fn render( + &mut self, + draw_handle: &mut RaylibDrawHandle, + player: &Player, + players_item: &Option, + ) { + self.ui.render( + draw_handle, + self.bounds, + self.can_player_afford(player, players_item), + ); } } diff --git a/src/logic/shop/mainui.rs b/src/logic/shop/mainui.rs index d33da9c..bcba9e5 100644 --- a/src/logic/shop/mainui.rs +++ b/src/logic/shop/mainui.rs @@ -1,17 +1,15 @@ -use raylib::prelude::*; - +use super::item::ShopItemWrapper; use crate::{ gamecore::{GameCore, GameState}, items::{AirBag, Flashlight, Flippers, ItemBase, StunGun}, lib::{utils::button::OnScreenButton, wrappers::audio::player::AudioPlayer}, }; - -use super::{item::ShopItemWrapper, itemui::ShopItemUi}; +use raylib::prelude::*; pub fn render_shop( draw_handle: &mut RaylibDrawHandle, _thread: &RaylibThread, - audio_system: &mut AudioPlayer, + _audio_system: &mut AudioPlayer, game_core: &mut GameCore, bounds: Rectangle, ) -> Option { @@ -87,10 +85,26 @@ pub fn render_shop( ); // Render items - stun_gun_buy_ui.render(draw_handle, &game_core.player, &game_core.player.inventory.stun_gun); - air_bag_buy_ui.render(draw_handle, &game_core.player, &game_core.player.inventory.air_bag); - flashlight_buy_ui.render(draw_handle, &game_core.player, &game_core.player.inventory.flashlight); - flippers_buy_ui.render(draw_handle, &game_core.player, &game_core.player.inventory.flippers); + stun_gun_buy_ui.render( + draw_handle, + &game_core.player, + &game_core.player.inventory.stun_gun, + ); + air_bag_buy_ui.render( + draw_handle, + &game_core.player, + &game_core.player.inventory.air_bag, + ); + flashlight_buy_ui.render( + draw_handle, + &game_core.player, + &game_core.player.inventory.flashlight, + ); + flippers_buy_ui.render( + draw_handle, + &game_core.player, + &game_core.player.inventory.flippers, + ); // Handle buying items if stun_gun_buy_ui.can_player_afford(&game_core.player, &game_core.player.inventory.stun_gun) @@ -105,7 +119,8 @@ pub fn render_shop( let item = air_bag_buy_ui.purchase(&mut game_core.player); game_core.player.inventory.air_bag = Some(item); } - if flashlight_buy_ui.can_player_afford(&game_core.player, &game_core.player.inventory.flashlight) + if flashlight_buy_ui + .can_player_afford(&game_core.player, &game_core.player.inventory.flashlight) && flashlight_buy_ui.user_clicked_buy(draw_handle) { let item = flashlight_buy_ui.purchase(&mut game_core.player); @@ -151,8 +166,7 @@ pub fn render_shop( draw_handle.draw_rectangle_rec(box_bounds, Color::WHITE); draw_handle.draw_rectangle_lines_ex(box_bounds, 3, Color::BLACK); - - hovered_item.get_texture( + hovered_item.get_texture( draw_handle, &game_core.resources, Rectangle { @@ -160,9 +174,8 @@ pub fn render_shop( y: box_bounds.y + 10.0, width: (80.0), height: (80.0), - } + }, ); - // Render item description draw_handle.draw_text( diff --git a/src/logic/shop/mod.rs b/src/logic/shop/mod.rs index 9885e04..dcc1aa3 100644 --- a/src/logic/shop/mod.rs +++ b/src/logic/shop/mod.rs @@ -2,22 +2,16 @@ mod item; mod itemui; mod mainui; -use raylib::prelude::*; - +use self::mainui::{render_shop, render_stats}; +use super::screen::Screen; use crate::{ gamecore::{GameCore, GameState}, lib::wrappers::audio::player::AudioPlayer, }; - -use self::mainui::{render_shop, render_stats}; - -use super::screen::Screen; - -const SCREEN_PANEL_SIZE: Vector2 = Vector2 { x: 300.0, y: 380.0 }; +use raylib::prelude::*; #[derive(Debug, Default)] pub struct ShopScreen { - // shop_items: Vec, } impl ShopScreen { @@ -36,8 +30,6 @@ impl Screen for ShopScreen { audio_system: &mut AudioPlayer, game_core: &mut GameCore, ) -> Option { - let mouse_position = draw_handle.get_mouse_position(); - // Render the background draw_handle.draw_texture(&game_core.resources.shop_background, 0, 0, Color::WHITE); diff --git a/src/logic/winscreen.rs b/src/logic/winscreen.rs index 76628bb..c1173b9 100644 --- a/src/logic/winscreen.rs +++ b/src/logic/winscreen.rs @@ -22,8 +22,8 @@ impl Screen for WinScreen { fn render( &mut self, draw_handle: &mut RaylibDrawHandle, - thread: &RaylibThread, - audio_system: &mut AudioPlayer, + _thread: &RaylibThread, + _audio_system: &mut AudioPlayer, game_core: &mut GameCore, ) -> Option { let win_height = draw_handle.get_screen_height(); @@ -57,7 +57,8 @@ impl Screen for WinScreen { // Render message draw_handle.draw_text( "You can use the transponder to \ncontact help!", - ((win_width / 2) - ((SCREEN_PANEL_SIZE.x as i32 + 6) / 2)) + (0.15 * SCREEN_PANEL_SIZE.x)as i32, + ((win_width / 2) - ((SCREEN_PANEL_SIZE.x as i32 + 6) / 2)) + + (0.15 * SCREEN_PANEL_SIZE.x) as i32, (win_height / 2) - (SCREEN_PANEL_SIZE.y as i32 / 2) + 80, 15, Color::BLACK, @@ -87,7 +88,7 @@ impl Screen for WinScreen { { game_core.switch_state(GameState::MainMenu, Some(draw_handle)); } - + return None; } } diff --git a/src/main.rs b/src/main.rs index e4982fe..dc4a0e1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,16 +10,10 @@ mod world; use gamecore::{GameCore, GameProgress, GameState}; use lib::{utils::profiler::GameProfiler, wrappers::audio::player::AudioPlayer}; -use log::info; use logic::{ - gameend::GameEndScreen, - ingame::InGameScreen, - loadingscreen::LoadingScreen, - mainmenu::MainMenuScreen, - pausemenu::PauseMenuScreen, - screen::Screen, - shop::ShopScreen, - winscreen::{self, WinScreen}, + gameend::GameEndScreen, ingame::InGameScreen, loadingscreen::LoadingScreen, + mainmenu::MainMenuScreen, pausemenu::PauseMenuScreen, screen::Screen, shop::ShopScreen, + winscreen::WinScreen, }; use raylib::prelude::*; use world::{load_world_colliders, World}; @@ -33,9 +27,6 @@ const WINDOW_TITLE: &str = r"One Breath"; const MAX_FPS: u32 = 60; fn main() { - // Configure the logger - env_logger::init(); - // Configure a window let (mut raylib, raylib_thread) = raylib::init() .size( @@ -151,7 +142,6 @@ fn main() { // For now, just quit // This also throws a SEGFAULT.. yay for unsafe code.. - info!("User quit game"); unsafe { raylib::ffi::CloseWindow(); } diff --git a/src/pallette.rs b/src/pallette.rs index 65f2243..609fdce 100644 --- a/src/pallette.rs +++ b/src/pallette.rs @@ -21,27 +21,6 @@ pub const TRANSLUCENT_WHITE_64: Color = Color { a: 64, }; -pub const SKY: Color = Color { - r: 15, - g: 193, - b: 217, - a: 255 -}; - -pub const WATER: Color = Color { - r: 24, - g: 66, - b: 143, - a: 255 -}; - -pub const WATER_DARK: Color = Color { - r: 8, - g: 24, - b: 54, - a: 255 -}; - pub const TRANSLUCENT_RED_64: Color = Color { r: 230, g: 41, diff --git a/src/player.rs b/src/player.rs index e0e80fa..4e4f135 100644 --- a/src/player.rs +++ b/src/player.rs @@ -10,9 +10,6 @@ use crate::{ use raylib::prelude::*; use serde::{Deserialize, Serialize}; -const AOE_RING_MAX_RADIUS: f32 = 60.0; -const STUN_ATTACK_TIME: f64 = 0.75; - #[derive(Debug, Serialize, Deserialize, Default, Clone)] pub struct PlayerInventory { pub stun_gun: Option, @@ -74,33 +71,6 @@ impl Player { } pub fn collides_with_rec(&self, rectangle: &Rectangle) -> bool { - // // Build a bounding box of the player by their corners - // let top_left_corner = self.position - (self.size / 2.0); - // let bottom_right_corner = self.position + (self.size / 2.0); - // let top_right_corner = Vector2 { - // x: bottom_right_corner.x, - // y: top_left_corner.y, - // }; - // let bottom_left_corner = Vector2 { - // x: top_left_corner.x, - // y: bottom_right_corner.y, - // }; - - // // Get the rotation - // let rotation = Vector2::zero().angle_to(self.direction); - - // // Rotate the bounds - // let top_left_corner = rotate_vector(top_left_corner, rotation); - // let bottom_right_corner = rotate_vector(bottom_right_corner, rotation); - // let top_right_corner = rotate_vector(top_right_corner, rotation); - // let bottom_left_corner = rotate_vector(bottom_left_corner, rotation); - - // // Check for collisions - // return rectangle.check_collision_point_rec(top_left_corner) - // || rectangle.check_collision_point_rec(bottom_right_corner) - // || rectangle.check_collision_point_rec(top_right_corner) - // || rectangle.check_collision_point_rec(bottom_left_corner); - return rectangle.check_collision_circle_rec(self.position, self.radius); } diff --git a/src/resources.rs b/src/resources.rs index 8175e18..cac06cb 100644 --- a/src/resources.rs +++ b/src/resources.rs @@ -1,5 +1,9 @@ -use failure::Error; -use raylib::{RaylibHandle, RaylibThread, math::Vector2, shaders::Shader, texture::{Image, RenderTexture2D, Texture2D}}; +use raylib::{ + math::Vector2, + shaders::Shader, + texture::{Image, RenderTexture2D, Texture2D}, + RaylibHandle, RaylibThread, +}; use crate::lib::wrappers::animation::FrameAnimationWrapper; @@ -13,7 +17,7 @@ pub struct GlobalResources { pub player_animation_boost_charge: FrameAnimationWrapper, pub player_animation_boost: FrameAnimationWrapper, pub player_animation_stunned: FrameAnimationWrapper, - + // Fish pub fish_animation_idle: FrameAnimationWrapper, pub fish_animation_swim: FrameAnimationWrapper, @@ -31,7 +35,7 @@ pub struct GlobalResources { // Darkness layer pub darkness_overlay: Texture2D, - + // Backgrounds pub background_front: Texture2D, pub background_back: Texture2D, @@ -39,25 +43,24 @@ pub struct GlobalResources { // Shop & items pub shop_background: Texture2D, - pub flashlight_one: Texture2D, - pub flashlight_two: Texture2D, - pub flashlight_three: Texture2D, + pub flashlight_one: Texture2D, + pub flashlight_two: Texture2D, + pub flashlight_three: Texture2D, - pub stun_gun_one: Texture2D, - pub stun_gun_two: Texture2D, - pub stun_gun_three: Texture2D, + pub stun_gun_one: Texture2D, + pub stun_gun_two: Texture2D, + pub stun_gun_three: Texture2D, - pub air_one: Texture2D, - pub air_two: Texture2D, - pub air_three: Texture2D, + pub air_one: Texture2D, + pub air_two: Texture2D, + pub air_three: Texture2D, - pub flippers_one: Texture2D, - pub flippers_two: Texture2D, - pub flippers_three: Texture2D, + pub flippers_one: Texture2D, + pub flippers_two: Texture2D, + pub flippers_three: Texture2D, - // Treasure - pub transponder: FrameAnimationWrapper, - + // Treasure + pub transponder: FrameAnimationWrapper, } impl GlobalResources { @@ -130,7 +133,11 @@ impl GlobalResources { &Image::load_image("./assets/img/map/cave.png")?, )?, pixel_shader: raylib.load_shader(&thread, None, Some("./assets/shaders/pixel.fs"))?, - shader_texture: raylib.load_render_texture(&thread, raylib.get_screen_width() as u32, raylib.get_screen_height() as u32)?, + shader_texture: raylib.load_render_texture( + &thread, + raylib.get_screen_width() as u32, + raylib.get_screen_height() as u32, + )?, jellyfish_animation_regular: FrameAnimationWrapper::new( raylib.load_texture_from_image( &thread, @@ -240,7 +247,6 @@ impl GlobalResources { 6, 2, ), - }) } } diff --git a/src/world.rs b/src/world.rs index 0f62d1d..e1e1e00 100644 --- a/src/world.rs +++ b/src/world.rs @@ -1,11 +1,17 @@ use std::{fs::File, io::BufReader}; +use failure::Error; use raylib::math::{Rectangle, Vector2}; use serde::{Deserialize, Serialize}; -use std::io::Read; -use failure::Error; -use crate::{entities::{enemy::{jellyfish::JellyFish, octopus::Octopus, whirlpool::Whirlpool}, fish::FishEntity}, player::Player}; +use crate::{ + entities::{ + enemy::{jellyfish::JellyFish, octopus::Octopus, whirlpool::Whirlpool,}, + fish::FishEntity, + + }, + player::Player, +}; #[derive(Debug, Serialize, Deserialize, Clone)] pub struct World { @@ -42,7 +48,7 @@ impl World { // Init colliders result.colliders = Vec::new(); - for collider in colliders.iter(){ + for collider in colliders.iter() { result.colliders.push(Rectangle { x: collider.x - (collider.width / 2.0), y: collider.y - (collider.height / 2.0), @@ -71,7 +77,6 @@ impl World { } } - pub fn load_world_colliders(file: String) -> Result, Error> { // Load the file let file = File::open(file)?; @@ -79,4 +84,4 @@ pub fn load_world_colliders(file: String) -> Result, Error> { // Deserialize Ok(serde_json::from_reader(reader)?) -} \ No newline at end of file +}