From 733839ca10f9294271c61873546d5a95a22edfad Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sun, 25 Apr 2021 19:15:02 -0400 Subject: [PATCH] clean up the rest of the files --- src/items.rs | 1 - src/logic/mainmenu.rs | 9 ++++---- src/logic/winscreen.rs | 9 ++++---- src/main.rs | 11 +++------- src/pallette.rs | 21 ------------------ src/player.rs | 30 -------------------------- src/resources.rs | 48 ++++++++++++++++++++++++------------------ src/world.rs | 17 +++++++++------ 8 files changed, 49 insertions(+), 97 deletions(-) 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/logic/mainmenu.rs b/src/logic/mainmenu.rs index 89f7d87..3c99e11 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 @@ -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/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..7e87f62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,14 +12,9 @@ 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}; 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 0a78a20..127a5fc 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 ed58b00..84629c3 100644 --- a/src/world.rs +++ b/src/world.rs @@ -1,11 +1,16 @@ 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}, fish::FishEntity}, player::Player}; +use crate::{ + entities::{ + enemy::{jellyfish::JellyFish, octopus::Octopus}, + fish::FishEntity, + }, + player::Player, +}; #[derive(Debug, Serialize, Deserialize, Clone)] pub struct World { @@ -23,7 +28,6 @@ pub struct World { pub jellyfish: Vec, pub octopus: Vec, - } impl World { @@ -40,7 +44,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), @@ -67,7 +71,6 @@ impl World { } } - pub fn load_world_colliders(file: String) -> Result, Error> { // Load the file let file = File::open(file)?; @@ -75,4 +78,4 @@ pub fn load_world_colliders(file: String) -> Result, Error> { // Deserialize Ok(serde_json::from_reader(reader)?) -} \ No newline at end of file +}