From fdb93c03fd1ef697fdd91d4d90f0dcb7bf1779f5 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sun, 25 Apr 2021 19:07:10 -0400 Subject: [PATCH 01/15] clean unused code for fish --- src/entities/fish.rs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/entities/fish.rs b/src/entities/fish.rs index 6cae1ab..ed1d153 100644 --- a/src/entities/fish.rs +++ b/src/entities/fish.rs @@ -2,18 +2,10 @@ 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; - const FISH_VISION: f32 = 25.0; const FISH_MAX_SPEED: f32 = 2.0; const FISH_MAX_FORCE: f32 = 0.05; @@ -63,7 +55,7 @@ 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,10 +132,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 { From 602f600379cf6035948c7319e534fce2e7234636 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sun, 25 Apr 2021 19:07:48 -0400 Subject: [PATCH 02/15] clean octopus --- src/entities/enemy/octopus.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/entities/enemy/octopus.rs b/src/entities/enemy/octopus.rs index e3d4869..c92a090 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 { @@ -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; } From 8c8d0ab595e9a270c56b5a919686c0f1a3880bf1 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sun, 25 Apr 2021 19:08:16 -0400 Subject: [PATCH 03/15] Clean jellyfish --- src/entities/enemy/jellyfish.rs | 6 +++--- src/entities/enemy/octopus.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) 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 c92a090..73d8cee 100644 --- a/src/entities/enemy/octopus.rs +++ b/src/entities/enemy/octopus.rs @@ -123,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 From 068c8be089abd773b8fe97191954d7a969febc38 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sun, 25 Apr 2021 19:08:42 -0400 Subject: [PATCH 04/15] rm complexanimation --- src/lib/wrappers/complexanimation.rs | 32 ---------------------------- src/lib/wrappers/mod.rs | 3 +-- 2 files changed, 1 insertion(+), 34 deletions(-) delete mode 100644 src/lib/wrappers/complexanimation.rs 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 From 7edfe6f1322443d9511f74326325e7e11da0a65d Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sun, 25 Apr 2021 19:09:28 -0400 Subject: [PATCH 05/15] clean root ingame --- src/logic/ingame/mod.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/logic/ingame/mod.rs b/src/logic/ingame/mod.rs index 99cd752..12681f8 100644 --- a/src/logic/ingame/mod.rs +++ b/src/logic/ingame/mod.rs @@ -7,25 +7,18 @@ use crate::{ entities::enemy::base::EnemyBase, gamecore::{GameCore, GameState}, lib::wrappers::audio::player::AudioPlayer, - pallette::{SKY, WATER, WATER_DARK}, }; use super::screen::Screen; -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(), @@ -188,8 +181,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 @@ -207,7 +200,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); From 5e1ae73b2b9b09e552d90617bd76be32fa45da58 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sun, 25 Apr 2021 19:12:37 -0400 Subject: [PATCH 06/15] more warning removal --- src/entities/fish.rs | 13 +++--- src/logic/gameend.rs | 81 ++++----------------------------- src/logic/ingame/mod.rs | 1 - src/logic/ingame/playerlogic.rs | 20 ++++---- src/logic/loadingscreen.rs | 8 ++-- src/logic/shop/item.rs | 34 +++++++++----- src/logic/shop/mainui.rs | 41 +++++++++++------ src/logic/shop/mod.rs | 14 ++---- 8 files changed, 84 insertions(+), 128 deletions(-) diff --git a/src/entities/fish.rs b/src/entities/fish.rs index ed1d153..ccaeca0 100644 --- a/src/entities/fish.rs +++ b/src/entities/fish.rs @@ -1,10 +1,7 @@ use rand::{prelude::ThreadRng, Rng}; use raylib::prelude::*; -use crate::{ - player::Player, - resources::GlobalResources, -}; +use crate::{player::Player, resources::GlobalResources}; const FISH_VISION: f32 = 25.0; const FISH_MAX_SPEED: f32 = 2.0; @@ -55,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(); @@ -133,7 +135,6 @@ impl FishEntity { } 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/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 12681f8..d989183 100644 --- a/src/logic/ingame/mod.rs +++ b/src/logic/ingame/mod.rs @@ -11,7 +11,6 @@ use crate::{ use super::screen::Screen; - pub struct InGameScreen { shader_time_var_location: i32, } diff --git a/src/logic/ingame/playerlogic.rs b/src/logic/ingame/playerlogic.rs index 91e2cef..3988da3 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; } // Handle movement and collisions @@ -190,8 +194,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/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); From 733839ca10f9294271c61873546d5a95a22edfad Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sun, 25 Apr 2021 19:15:02 -0400 Subject: [PATCH 07/15] 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 +} From d729ae811e042128b6fc10d4cd82d345c87a74ca Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sun, 25 Apr 2021 19:16:10 -0400 Subject: [PATCH 08/15] Reset title --- src/logic/mainmenu.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/logic/mainmenu.rs b/src/logic/mainmenu.rs index 3c99e11..421105c 100644 --- a/src/logic/mainmenu.rs +++ b/src/logic/mainmenu.rs @@ -34,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, From e4ae9b18b3a208ee146d0600cc1351a99282e1de Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sun, 25 Apr 2021 19:22:46 -0400 Subject: [PATCH 09/15] Clean up deps --- Cargo.toml | 5 ----- src/gamecore.rs | 10 ++-------- src/main.rs | 5 ----- 3 files changed, 2 insertions(+), 18 deletions(-) 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/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/main.rs b/src/main.rs index 7e87f62..dc4a0e1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,6 @@ 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, @@ -28,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( @@ -146,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(); } From c8da93bfdb5dcda164478dee3a6319458d0c3df7 Mon Sep 17 00:00:00 2001 From: wm-c Date: Sun, 25 Apr 2021 20:18:11 -0400 Subject: [PATCH 10/15] added whirlpool --- assets/worlds/mainworld.json | 12 +++++- src/entities/enemy/mod.rs | 3 +- src/entities/enemy/whirlpool.rs | 43 ++++++++++++++++++++ src/logic/ingame/mod.rs | 24 ++++++++--- src/logic/ingame/playerlogic.rs | 72 +++++++++++++++++++++++++++++++-- src/player.rs | 5 +++ src/world.rs | 6 ++- 7 files changed, 153 insertions(+), 12 deletions(-) create mode 100644 src/entities/enemy/whirlpool.rs diff --git a/assets/worlds/mainworld.json b/assets/worlds/mainworld.json index add0aa3..146d91d 100644 --- a/assets/worlds/mainworld.json +++ b/assets/worlds/mainworld.json @@ -29,5 +29,15 @@ "y": 100 } } - ] + ], + "whirlpool": [ + { + "position" : { + "x": 250, + "y": 250 + }, + "should_remove": false + } + + ] } \ No newline at end of file diff --git a/src/entities/enemy/mod.rs b/src/entities/enemy/mod.rs index 1189f2b..18acd78 100644 --- a/src/entities/enemy/mod.rs +++ b/src/entities/enemy/mod.rs @@ -1,3 +1,4 @@ pub mod base; pub mod jellyfish; -pub mod octopus; \ No newline at end of file +pub mod octopus; +pub mod whirlpool; \ No newline at end of file diff --git a/src/entities/enemy/whirlpool.rs b/src/entities/enemy/whirlpool.rs new file mode 100644 index 0000000..f0192b3 --- /dev/null +++ b/src/entities/enemy/whirlpool.rs @@ -0,0 +1,43 @@ +use raylib::prelude::*; + +use super::base::EnemyBase; + +use serde::{Deserialize, Serialize}; + + +#[derive(Debug, Serialize, Deserialize, Default, Clone)] +pub struct Whirlpool{ + pub position: Vector2, + pub should_remove: bool, +} + +impl Whirlpool{ + + pub fn should_remove(&self) -> bool{ + return self.should_remove; + } + +} + +impl EnemyBase for Whirlpool{ + fn render( + &mut self, + context_2d: &mut RaylibMode2D, + player: &mut crate::player::Player, + resources: &mut crate::resources::GlobalResources, + dt: f64, + ) { + context_2d.draw_circle(self.position.x as i32, self.position.y as i32, 12.0, Color::RED); + } + + fn handle_logic(&mut self, player: &mut crate::player::Player, dt: f64) { + + } + + fn handle_getting_attacked(&mut self, stun_duration: f64, current_time: f64) { + self.should_remove = true; + } + + + +} \ No newline at end of file diff --git a/src/logic/ingame/mod.rs b/src/logic/ingame/mod.rs index 383bd25..1ebedaf 100644 --- a/src/logic/ingame/mod.rs +++ b/src/logic/ingame/mod.rs @@ -3,14 +3,11 @@ mod playerlogic; use raylib::prelude::*; -use crate::{ - entities::enemy::base::EnemyBase, - 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, pallette::{SKY, WATER, WATER_DARK}}; use super::screen::Screen; +use crate::entities::fish::FishEntity; + pub enum InGameState { BUYING, @@ -210,6 +207,21 @@ impl Screen for InGameScreen { ); } + let mut iter_count = 0; + for whirlpool_mob in game_core.world.whirlpool.iter_mut(){ + whirlpool_mob.handle_logic(&mut game_core.player, dt); + whirlpool_mob.render(&mut context_2d, &mut game_core.player, &mut game_core.resources, dt); + if whirlpool_mob.should_remove(){ + for _ in 0..10{ + game_core.world.fish.push(FishEntity::new(whirlpool_mob.position)); + } + } + + + } + + game_core.world.whirlpool.retain(|x| !x.should_remove()); + // Render transponder game_core.resources.transponder.draw(&mut context_2d, game_core.world.end_position + Vector2::new(0.0, -50.0), 0.0); diff --git a/src/logic/ingame/playerlogic.rs b/src/logic/ingame/playerlogic.rs index 91e2cef..804706b 100644 --- a/src/logic/ingame/playerlogic.rs +++ b/src/logic/ingame/playerlogic.rs @@ -24,7 +24,7 @@ pub fn update_player_movement( // Handle player movement let mouse_pose = draw_handle.get_mouse_position(); let mouse_world_pose = draw_handle.get_screen_to_world2D(mouse_pose, game_core.master_camera); - let raw_movement_direction = mouse_world_pose - game_core.player.position; + let mut raw_movement_direction = mouse_world_pose - game_core.player.position; let mut normalized_movement_direction = raw_movement_direction; normalized_movement_direction.normalize(); @@ -153,6 +153,67 @@ pub fn update_player_movement( player_real_movement *= game_core.player.inventory.flippers.as_ref().unwrap().speed_increase; } + + + + + let mut movement_drift = Vector2::new(0.0, 0.0); + for whirlpool in game_core.world.whirlpool.iter_mut(){ + + + + if game_core.player.position.distance_to(whirlpool.position) <= 100.0 && game_core.player.position.distance_to(whirlpool.position) >= 10.0{ + + let player_pose = game_core.player.position; + let whirlpool_pose = whirlpool.position; + let net_pose = player_pose - whirlpool_pose; + + + + let angle = net_pose.y.atan2(net_pose.x); + + + + // Calculates force + let force = 1.0; + + + let mut force_x = (force as f32 * angle.cos()).clamp(-1.0, 1.0); + let mut force_y = (force as f32 * angle.sin()).clamp(-1.0, 1.0); + + if force_x.is_nan(){ + force_x = 1.0 * net_pose.x; + } + + if force_y.is_nan(){ + force_y = 1.0 * net_pose.y; + } + + movement_drift.x -= force_x; + movement_drift.y -= force_y; + + } + + } + + + game_core.player.position.x += movement_drift.x; + for collider in game_core.world.colliders.iter() { + if game_core.player.collides_with_rec(collider) { + game_core.player.position.x -= movement_drift.x; + break; + } + } + + game_core.player.position.y += movement_drift.y; + for collider in game_core.world.colliders.iter() { + if game_core.player.collides_with_rec(collider) { + game_core.player.position.y -= movement_drift.y; + break; + } + } + + // Handle movement and collisions if raw_movement_direction.distance_to(Vector2::zero()) > game_core.player.size.y / 2.0 && !game_core.player.is_stunned() @@ -187,7 +248,12 @@ pub fn update_player_movement( // Handle updating the stun timer if player_stunned { game_core.player.stun_timer -= dt; - } + } + + + + + // Move the camera to follow the player let direction_from_cam_to_player = @@ -197,7 +263,7 @@ pub fn update_player_movement( // Camera only moves if you get close to the edge of the screen if player_screen_position.distance_to(window_center).abs() > 100.0 { - game_core.master_camera.target += player_real_movement; + game_core.master_camera.target += player_real_movement + movement_drift; } // If the player is not on screen, snap the camera to them diff --git a/src/player.rs b/src/player.rs index 0a78a20..e0e80fa 100644 --- a/src/player.rs +++ b/src/player.rs @@ -126,6 +126,11 @@ impl Player { if octopus.current_position.distance_to(self.position).abs() <= stun_reach { octopus.handle_getting_attacked(self.attacking_timer, current_time); } + } + for whirlpool in world.whirlpool.iter_mut() { + if whirlpool.position.distance_to(self.position).abs() <= stun_reach { + whirlpool.handle_getting_attacked(self.attacking_timer, current_time); + } } } } diff --git a/src/world.rs b/src/world.rs index ed58b00..0f62d1d 100644 --- a/src/world.rs +++ b/src/world.rs @@ -5,7 +5,7 @@ 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, whirlpool::Whirlpool}, fish::FishEntity}, player::Player}; #[derive(Debug, Serialize, Deserialize, Clone)] pub struct World { @@ -21,8 +21,10 @@ pub struct World { #[serde(skip)] pub colliders: Vec, + // Mobs pub jellyfish: Vec, pub octopus: Vec, + pub whirlpool: Vec, } @@ -49,6 +51,8 @@ impl World { }); } + + Ok(result) } From 3007f96ca4c1e2c6eb88fe66a790b01b5c00f33f Mon Sep 17 00:00:00 2001 From: wm-c Date: Sun, 25 Apr 2021 20:49:48 -0400 Subject: [PATCH 11/15] Whirlpools have spirites --- assets/worlds/mainworld.json | 3 ++- src/entities/enemy/whirlpool.rs | 5 ++++- src/logic/ingame/playerlogic.rs | 11 +++++------ src/resources.rs | 10 ++++++++++ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/assets/worlds/mainworld.json b/assets/worlds/mainworld.json index 4f9198f..9c46d40 100644 --- a/assets/worlds/mainworld.json +++ b/assets/worlds/mainworld.json @@ -36,7 +36,8 @@ "x": 250, "y": 250 }, - "should_remove": false + "should_remove": false, + "rotation": 0 } ] diff --git a/src/entities/enemy/whirlpool.rs b/src/entities/enemy/whirlpool.rs index f0192b3..3be4db4 100644 --- a/src/entities/enemy/whirlpool.rs +++ b/src/entities/enemy/whirlpool.rs @@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize}; pub struct Whirlpool{ pub position: Vector2, pub should_remove: bool, + pub rotation: f32, } impl Whirlpool{ @@ -27,7 +28,9 @@ impl EnemyBase for Whirlpool{ resources: &mut crate::resources::GlobalResources, dt: f64, ) { - context_2d.draw_circle(self.position.x as i32, self.position.y as i32, 12.0, Color::RED); + + resources.whirlpool.draw(context_2d, Vector2{x: self.position.x, y: self.position.y}, self.rotation); + self.rotation += 1.0; } fn handle_logic(&mut self, player: &mut crate::player::Player, dt: f64) { diff --git a/src/logic/ingame/playerlogic.rs b/src/logic/ingame/playerlogic.rs index 2c9e509..de0543a 100644 --- a/src/logic/ingame/playerlogic.rs +++ b/src/logic/ingame/playerlogic.rs @@ -177,20 +177,19 @@ pub fn update_player_movement( let angle = net_pose.y.atan2(net_pose.x); - // Calculates force - let force = 1.0; + let force = 15.0 / game_core.player.position.distance_to(whirlpool.position) ; - let mut force_x = (force as f32 * angle.cos()).clamp(-1.0, 1.0); - let mut force_y = (force as f32 * angle.sin()).clamp(-1.0, 1.0); + let mut force_x = (force as f32 * angle.cos()).clamp(-5.0, 5.0); + let mut force_y = (force as f32 * angle.sin()).clamp(-5.0, 5.0); if force_x.is_nan(){ - force_x = 1.0 * net_pose.x; + force_x = 5.0 * net_pose.x; } if force_y.is_nan(){ - force_y = 1.0 * net_pose.y; + force_y = 5.0 * net_pose.y; } movement_drift.x -= force_x; diff --git a/src/resources.rs b/src/resources.rs index cac06cb..35b16ac 100644 --- a/src/resources.rs +++ b/src/resources.rs @@ -32,6 +32,7 @@ pub struct GlobalResources { pub jellyfish_animation_attack: FrameAnimationWrapper, pub octopus_animation_regular: FrameAnimationWrapper, pub octopus_animation_attack: FrameAnimationWrapper, + pub whirlpool: FrameAnimationWrapper, // Darkness layer pub darkness_overlay: Texture2D, @@ -247,6 +248,15 @@ impl GlobalResources { 6, 2, ), + whirlpool: FrameAnimationWrapper::new( + raylib.load_texture_from_image( + &thread, + &Image::load_image("./assets/img/enemies/whirlpool.png")?, + )?, + Vector2 { x: 20.0, y: 20.0 }, + 4, + 4, + ), }) } } From 3c1d56a46b1cb66e312faea1c68ec416c561d0b4 Mon Sep 17 00:00:00 2001 From: wm-c Date: Sun, 25 Apr 2021 20:58:34 -0400 Subject: [PATCH 12/15] Added comments --- src/entities/enemy/whirlpool.rs | 6 ++++++ src/logic/ingame/mod.rs | 5 ++++- src/logic/ingame/playerlogic.rs | 22 +++++++++++++--------- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/entities/enemy/whirlpool.rs b/src/entities/enemy/whirlpool.rs index 3be4db4..a2b7bf0 100644 --- a/src/entities/enemy/whirlpool.rs +++ b/src/entities/enemy/whirlpool.rs @@ -8,12 +8,17 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize, Default, Clone)] pub struct Whirlpool{ pub position: Vector2, + + // Track if it needs removing pub should_remove: bool, + + // variable for tracking rotation pub rotation: f32, } impl Whirlpool{ + // hook to see if item needs removing pub fn should_remove(&self) -> bool{ return self.should_remove; } @@ -37,6 +42,7 @@ impl EnemyBase for Whirlpool{ } + // Whirlpool removed if shoot fn handle_getting_attacked(&mut self, stun_duration: f64, current_time: f64) { self.should_remove = true; } diff --git a/src/logic/ingame/mod.rs b/src/logic/ingame/mod.rs index 104d428..85bebba 100644 --- a/src/logic/ingame/mod.rs +++ b/src/logic/ingame/mod.rs @@ -238,10 +238,12 @@ impl Screen for InGameScreen { ); } - let mut iter_count = 0; + // Iterates over whirlpools and runs render and logic funcs for whirlpool_mob in game_core.world.whirlpool.iter_mut(){ whirlpool_mob.handle_logic(&mut game_core.player, dt); whirlpool_mob.render(&mut context_2d, &mut game_core.player, &mut game_core.resources, dt); + + // Spawns 10 fish on spawn if whirlpool_mob.should_remove(){ for _ in 0..10{ game_core.world.fish.push(FishEntity::new(whirlpool_mob.position)); @@ -251,6 +253,7 @@ impl Screen for InGameScreen { } + // Removes whirlpools set for removal game_core.world.whirlpool.retain(|x| !x.should_remove()); diff --git a/src/logic/ingame/playerlogic.rs b/src/logic/ingame/playerlogic.rs index de0543a..093ece8 100644 --- a/src/logic/ingame/playerlogic.rs +++ b/src/logic/ingame/playerlogic.rs @@ -160,30 +160,33 @@ pub fn update_player_movement( - + // Creates variable to calculate the distant let mut movement_drift = Vector2::new(0.0, 0.0); + + // Check each whirlpool for effects for whirlpool in game_core.world.whirlpool.iter_mut(){ - + // check if its in range and not to close if game_core.player.position.distance_to(whirlpool.position) <= 100.0 && game_core.player.position.distance_to(whirlpool.position) >= 10.0{ - let player_pose = game_core.player.position; - let whirlpool_pose = whirlpool.position; - let net_pose = player_pose - whirlpool_pose; - + // Calculates info for formulas + // Deltas between positions + let net_pose = game_core.player.position - whirlpool.position; + // Angle between: UNITS: RADIANS let angle = net_pose.y.atan2(net_pose.x); // Calculates force - let force = 15.0 / game_core.player.position.distance_to(whirlpool.position) ; - + let force = 15.0 / game_core.player.position.distance_to(whirlpool.position); + // Calculates componets of force let mut force_x = (force as f32 * angle.cos()).clamp(-5.0, 5.0); let mut force_y = (force as f32 * angle.sin()).clamp(-5.0, 5.0); + // Prevents Nan erros if force_x.is_nan(){ force_x = 5.0 * net_pose.x; } @@ -192,6 +195,7 @@ pub fn update_player_movement( force_y = 5.0 * net_pose.y; } + // Adds values to drift tracker movement_drift.x -= force_x; movement_drift.y -= force_y; @@ -199,7 +203,7 @@ pub fn update_player_movement( } - + // Checks collision game_core.player.position.x += movement_drift.x; for collider in game_core.world.colliders.iter() { if game_core.player.collides_with_rec(collider) { From f9091fbce22cac4c96bb29db2801c4c5e6456c24 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Mon, 26 Apr 2021 12:35:12 -0400 Subject: [PATCH 13/15] fix segfault on quit --- src/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index dc4a0e1..9a13100 100644 --- a/src/main.rs +++ b/src/main.rs @@ -140,16 +140,16 @@ fn main() { .create_statistics(&game_core, draw_handle.get_time()); game_core.progress.update(&new_progress); - // For now, just quit - // This also throws a SEGFAULT.. yay for unsafe code.. - unsafe { - raylib::ffi::CloseWindow(); - } + // Break the render loop + break; } game_core.switch_state(new_state, Some(&draw_handle)); } + // Feed the audio engine + // audio_system.update(); + // Feed the profiler // This only runs in the dev profile. #[cfg(debug_assertions)] From 6b77476d09ab9c8ddcc38eae5f30f95af53acd23 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Mon, 26 Apr 2021 12:35:54 -0400 Subject: [PATCH 14/15] remove useless audio update --- src/main.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9a13100..cbf7e65 100644 --- a/src/main.rs +++ b/src/main.rs @@ -147,9 +147,6 @@ fn main() { game_core.switch_state(new_state, Some(&draw_handle)); } - // Feed the audio engine - // audio_system.update(); - // Feed the profiler // This only runs in the dev profile. #[cfg(debug_assertions)] From eb49b08bab00c151d23967061fbc5ab1526cd9e2 Mon Sep 17 00:00:00 2001 From: rsninja722 Date: Mon, 26 Apr 2021 13:26:58 -0400 Subject: [PATCH 15/15] added velocity with friction, translucent shop back --- src/logic/ingame/playerlogic.rs | 60 +++++++++++++++------------------ src/logic/shop/mainui.rs | 2 +- src/player.rs | 2 ++ 3 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/logic/ingame/playerlogic.rs b/src/logic/ingame/playerlogic.rs index 093ece8..cf9a397 100644 --- a/src/logic/ingame/playerlogic.rs +++ b/src/logic/ingame/playerlogic.rs @@ -4,6 +4,8 @@ use crate::gamecore::GameCore; const NORMAL_PLAYER_SPEED: i32 = 1; const BOOST_PLAYER_SPEED: i32 = NORMAL_PLAYER_SPEED * 2; +const PLAYER_FRICTION: f32 = 1.05; +const WHIRLPOOL_PULL: f32 = 3.0; const TURN_SPEED: f32 = 0.15; const BOOST_DECREASE_PER_SECOND: f32 = 0.65; const BOOST_REGEN_PER_SECOND: f32 = 0.25; @@ -157,18 +159,14 @@ pub fn update_player_movement( .speed_increase; } - - - - // Creates variable to calculate the distant - let mut movement_drift = Vector2::new(0.0, 0.0); + let mut should_apply_friction: bool = true; // Check each whirlpool for effects for whirlpool in game_core.world.whirlpool.iter_mut(){ // check if its in range and not to close - if game_core.player.position.distance_to(whirlpool.position) <= 100.0 && game_core.player.position.distance_to(whirlpool.position) >= 10.0{ + if game_core.player.position.distance_to(whirlpool.position) <= 50.0 && game_core.player.position.distance_to(whirlpool.position) >= 10.0{ // Calculates info for formulas @@ -180,7 +178,7 @@ pub fn update_player_movement( // Calculates force - let force = 15.0 / game_core.player.position.distance_to(whirlpool.position); + let force = WHIRLPOOL_PULL / game_core.player.position.distance_to(whirlpool.position); // Calculates componets of force let mut force_x = (force as f32 * angle.cos()).clamp(-5.0, 5.0); @@ -196,56 +194,54 @@ pub fn update_player_movement( } // Adds values to drift tracker - movement_drift.x -= force_x; - movement_drift.y -= force_y; + game_core.player.additional_vel.x -= force_x; + game_core.player.additional_vel.y -= force_y; + should_apply_friction = false; } } - // Checks collision - game_core.player.position.x += movement_drift.x; - for collider in game_core.world.colliders.iter() { - if game_core.player.collides_with_rec(collider) { - game_core.player.position.x -= movement_drift.x; - break; - } + if should_apply_friction { + game_core.player.additional_vel.x /= PLAYER_FRICTION; + game_core.player.additional_vel.y /= PLAYER_FRICTION; + if f32::round(game_core.player.additional_vel.x * 10.0) == 0.0 { + game_core.player.additional_vel.x = 0.0; + } + if f32::round(game_core.player.additional_vel.y * 10.0) == 0.0 { + game_core.player.additional_vel.y = 0.0; + } } - game_core.player.position.y += movement_drift.y; - for collider in game_core.world.colliders.iter() { - if game_core.player.collides_with_rec(collider) { - game_core.player.position.y -= movement_drift.y; - break; - } - } - + if !(raw_movement_direction.distance_to(Vector2::zero()) > game_core.player.size.y / 2.0) { + player_real_movement = Vector2::zero(); + } // Handle movement and collisions - if raw_movement_direction.distance_to(Vector2::zero()) > game_core.player.size.y / 2.0 - && !game_core.player.is_stunned() - { + if !game_core.player.is_stunned() { if game_core.player.is_moving { // move in x - game_core.player.position.x += player_real_movement.x; + game_core.player.position.x += player_real_movement.x + game_core.player.additional_vel.x; // Check for any collisions for collider in game_core.world.colliders.iter() { if game_core.player.collides_with_rec(collider) { - game_core.player.position.x -= player_real_movement.x; + game_core.player.position.x -= player_real_movement.x + game_core.player.additional_vel.x; player_real_movement.x = 0.0; + game_core.player.additional_vel.x = 0.0; break; } } // move in y - game_core.player.position.y += player_real_movement.y; + game_core.player.position.y += player_real_movement.y + game_core.player.additional_vel.y; // Check for any collisions for collider in game_core.world.colliders.iter() { if game_core.player.collides_with_rec(collider) { - game_core.player.position.y -= player_real_movement.y; + game_core.player.position.y -= player_real_movement.y + game_core.player.additional_vel.y; player_real_movement.y = 0.0; + game_core.player.additional_vel.y = 0.0; break; } } @@ -268,7 +264,7 @@ pub fn update_player_movement( // Camera only moves if you get close to the edge of the screen if player_screen_position.distance_to(window_center).abs() > 100.0 { - game_core.master_camera.target += player_real_movement + movement_drift; + game_core.master_camera.target += player_real_movement + game_core.player.additional_vel; } // If the player is not on screen, snap the camera to them diff --git a/src/logic/shop/mainui.rs b/src/logic/shop/mainui.rs index bcba9e5..72c2c57 100644 --- a/src/logic/shop/mainui.rs +++ b/src/logic/shop/mainui.rs @@ -14,7 +14,7 @@ pub fn render_shop( bounds: Rectangle, ) -> Option { // Render background - draw_handle.draw_rectangle_rec(bounds, Color::WHITE); + draw_handle.draw_rectangle_rec(bounds, Color::new(255, 255, 255, 125)); draw_handle.draw_rectangle_lines_ex(bounds, 3, Color::BLACK); // Title diff --git a/src/player.rs b/src/player.rs index 4e4f135..b11b086 100644 --- a/src/player.rs +++ b/src/player.rs @@ -32,6 +32,7 @@ impl PlayerInventory { pub struct Player { pub position: Vector2, pub direction: Vector2, + pub additional_vel: Vector2, pub size: Vector2, pub radius: f32, pub coins: u32, @@ -48,6 +49,7 @@ pub struct Player { impl Player { pub fn new(spawn: &Vector2) -> Self { Self { + additional_vel: Vector2::zero(), boost_percent: 1.0, size: Vector2 { x: 11.0, y: 21.0 }, breath_percent: 1.0,