more warning removal

This commit is contained in:
Evan Pratten 2021-04-25 19:12:37 -04:00
parent 7edfe6f132
commit 5e1ae73b2b
8 changed files with 84 additions and 128 deletions

View File

@ -1,10 +1,7 @@
use rand::{prelude::ThreadRng, Rng}; use rand::{prelude::ThreadRng, Rng};
use raylib::prelude::*; use raylib::prelude::*;
use crate::{ use crate::{player::Player, resources::GlobalResources};
player::Player,
resources::GlobalResources,
};
const FISH_VISION: f32 = 25.0; const FISH_VISION: f32 = 25.0;
const FISH_MAX_SPEED: f32 = 2.0; const FISH_MAX_SPEED: f32 = 2.0;
@ -55,7 +52,12 @@ impl FishEntity {
return output; return output;
} }
pub fn handle_follow_player(&mut self, player: &Player, _dt: f64, other_fish: &Vec<FishEntity>) { pub fn handle_follow_player(
&mut self,
player: &Player,
_dt: f64,
other_fish: &Vec<FishEntity>,
) {
let mut acceleration: Vector2 = Vector2::zero(); let mut acceleration: Vector2 = Vector2::zero();
let mut steer: 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) { pub fn handle_free_movement(&mut self, player: &mut Player, _dt: f64) {
// Handle player picking up fish // Handle player picking up fish
if player.position.distance_to(self.position).abs() <= player.size.y * 2.2 { if player.position.distance_to(self.position).abs() <= player.size.y * 2.2 {
self.following_player = true; self.following_player = true;

View File

@ -22,7 +22,7 @@ impl Screen for GameEndScreen {
&mut self, &mut self,
draw_handle: &mut RaylibDrawHandle, draw_handle: &mut RaylibDrawHandle,
_thread: &RaylibThread, _thread: &RaylibThread,
audio_system: &mut AudioPlayer, _audio_system: &mut AudioPlayer,
game_core: &mut GameCore, game_core: &mut GameCore,
) -> Option<GameState> { ) -> Option<GameState> {
draw_handle.clear_background(Color::GRAY); draw_handle.clear_background(Color::GRAY);
@ -91,75 +91,12 @@ impl Screen for GameEndScreen {
go_to_menu_button.render(draw_handle); go_to_menu_button.render(draw_handle);
// If the player clicks on the button send them to shop // 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){ 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)); {
return Some(GameState::InShop);
} }
// 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);
// }
// }
return None; return None;
} }
} }

View File

@ -11,7 +11,6 @@ use crate::{
use super::screen::Screen; use super::screen::Screen;
pub struct InGameScreen { pub struct InGameScreen {
shader_time_var_location: i32, shader_time_var_location: i32,
} }

View File

@ -1,13 +1,9 @@
use raylib::prelude::*; use raylib::prelude::*;
use crate::{ use crate::gamecore::GameCore;
gamecore::GameCore,
pallette::{TRANSLUCENT_WHITE_128, TRANSLUCENT_WHITE_64, TRANSLUCENT_WHITE_96},
};
const NORMAL_PLAYER_SPEED: i32 = 1; const NORMAL_PLAYER_SPEED: i32 = 1;
const BOOST_PLAYER_SPEED: i32 = NORMAL_PLAYER_SPEED * 2; const BOOST_PLAYER_SPEED: i32 = NORMAL_PLAYER_SPEED * 2;
const CAMERA_FOLLOW_SPEED: f32 = 0.7;
const TURN_SPEED: f32 = 0.15; const TURN_SPEED: f32 = 0.15;
const BOOST_DECREASE_PER_SECOND: f32 = 0.65; const BOOST_DECREASE_PER_SECOND: f32 = 0.65;
const BOOST_REGEN_PER_SECOND: f32 = 0.25; 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); let user_request_action = draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_RIGHT_BUTTON);
if user_request_action { 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 // Move the player in their direction
@ -150,7 +148,13 @@ pub fn update_player_movement(
// Handle the player wearing flippers // Handle the player wearing flippers
if game_core.player.inventory.flippers.is_some() { 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 // Handle movement and collisions
@ -190,8 +194,6 @@ pub fn update_player_movement(
} }
// Move the camera to follow the player // 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 = let player_screen_position =
draw_handle.get_world_to_screen2D(game_core.player.position, game_core.master_camera); draw_handle.get_world_to_screen2D(game_core.player.position, game_core.master_camera);

View File

@ -1,11 +1,13 @@
use raylib::prelude::*; 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; use super::screen::Screen;
const SECONDS_PER_LOGO: f64 = 4.0; const SECONDS_PER_LOGO: f64 = 4.0;
const RUST_ORANGE: Color = Color::new(222, 165, 132, 255);
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
enum LoadingScreenState { enum LoadingScreenState {
@ -138,7 +140,7 @@ impl Screen for LoadingScreen {
fn render( fn render(
&mut self, &mut self,
draw_handle: &mut RaylibDrawHandle, draw_handle: &mut RaylibDrawHandle,
thread: &RaylibThread, _thread: &RaylibThread,
_audio_system: &mut AudioPlayer, _audio_system: &mut AudioPlayer,
game_core: &mut GameCore, game_core: &mut GameCore,
) -> Option<GameState> { ) -> Option<GameState> {

View File

@ -1,10 +1,6 @@
use std::marker::PhantomData;
use raylib::prelude::*;
use crate::{items::ItemBase, player::Player, world::World};
use super::itemui::ShopItemUi; use super::itemui::ShopItemUi;
use crate::{items::ItemBase, player::Player};
use raylib::prelude::*;
pub struct ShopItemWrapper<T: ItemBase + Clone> { pub struct ShopItemWrapper<T: ItemBase + Clone> {
bounds: Rectangle, bounds: Rectangle,
@ -17,7 +13,7 @@ impl<T: ItemBase + Clone> ShopItemWrapper<T> {
item: T, item: T,
from_inventory: &Option<T>, from_inventory: &Option<T>,
first_item_bounds: Rectangle, first_item_bounds: Rectangle,
index: u8 index: u8,
) -> Self { ) -> Self {
// Build new bounds for the UI row // Build new bounds for the UI row
let new_bounds = Rectangle { let new_bounds = Rectangle {
@ -47,7 +43,9 @@ impl<T: ItemBase + Clone> ShopItemWrapper<T> {
} }
pub fn can_player_afford(&self, player: &Player, players_item: &Option<T>) -> bool { pub fn can_player_afford(&self, player: &Player, players_item: &Option<T>) -> 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 { pub fn purchase(&self, player: &mut Player) -> T {
@ -59,14 +57,26 @@ impl<T: ItemBase + Clone> ShopItemWrapper<T> {
} }
pub fn user_clicked_buy(&self, draw_handle: &mut RaylibDrawHandle) -> bool { 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 { 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<T>) { pub fn render(
self.ui.render(draw_handle, self.bounds, self.can_player_afford(player, players_item)); &mut self,
draw_handle: &mut RaylibDrawHandle,
player: &Player,
players_item: &Option<T>,
) {
self.ui.render(
draw_handle,
self.bounds,
self.can_player_afford(player, players_item),
);
} }
} }

View File

@ -1,17 +1,15 @@
use raylib::prelude::*; use super::item::ShopItemWrapper;
use crate::{ use crate::{
gamecore::{GameCore, GameState}, gamecore::{GameCore, GameState},
items::{AirBag, Flashlight, Flippers, ItemBase, StunGun}, items::{AirBag, Flashlight, Flippers, ItemBase, StunGun},
lib::{utils::button::OnScreenButton, wrappers::audio::player::AudioPlayer}, lib::{utils::button::OnScreenButton, wrappers::audio::player::AudioPlayer},
}; };
use raylib::prelude::*;
use super::{item::ShopItemWrapper, itemui::ShopItemUi};
pub fn render_shop( pub fn render_shop(
draw_handle: &mut RaylibDrawHandle, draw_handle: &mut RaylibDrawHandle,
_thread: &RaylibThread, _thread: &RaylibThread,
audio_system: &mut AudioPlayer, _audio_system: &mut AudioPlayer,
game_core: &mut GameCore, game_core: &mut GameCore,
bounds: Rectangle, bounds: Rectangle,
) -> Option<GameState> { ) -> Option<GameState> {
@ -87,10 +85,26 @@ pub fn render_shop(
); );
// Render items // Render items
stun_gun_buy_ui.render(draw_handle, &game_core.player, &game_core.player.inventory.stun_gun); stun_gun_buy_ui.render(
air_bag_buy_ui.render(draw_handle, &game_core.player, &game_core.player.inventory.air_bag); draw_handle,
flashlight_buy_ui.render(draw_handle, &game_core.player, &game_core.player.inventory.flashlight); &game_core.player,
flippers_buy_ui.render(draw_handle, &game_core.player, &game_core.player.inventory.flippers); &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 // Handle buying items
if stun_gun_buy_ui.can_player_afford(&game_core.player, &game_core.player.inventory.stun_gun) 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); let item = air_bag_buy_ui.purchase(&mut game_core.player);
game_core.player.inventory.air_bag = Some(item); 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) && flashlight_buy_ui.user_clicked_buy(draw_handle)
{ {
let item = flashlight_buy_ui.purchase(&mut game_core.player); let item = flashlight_buy_ui.purchase(&mut game_core.player);
@ -151,7 +166,6 @@ pub fn render_shop(
draw_handle.draw_rectangle_rec(box_bounds, Color::WHITE); draw_handle.draw_rectangle_rec(box_bounds, Color::WHITE);
draw_handle.draw_rectangle_lines_ex(box_bounds, 3, Color::BLACK); draw_handle.draw_rectangle_lines_ex(box_bounds, 3, Color::BLACK);
hovered_item.get_texture( hovered_item.get_texture(
draw_handle, draw_handle,
&game_core.resources, &game_core.resources,
@ -160,10 +174,9 @@ pub fn render_shop(
y: box_bounds.y + 10.0, y: box_bounds.y + 10.0,
width: (80.0), width: (80.0),
height: (80.0), height: (80.0),
} },
); );
// Render item description // Render item description
draw_handle.draw_text( draw_handle.draw_text(
&hovered_item.get_description(), &hovered_item.get_description(),

View File

@ -2,22 +2,16 @@ mod item;
mod itemui; mod itemui;
mod mainui; mod mainui;
use raylib::prelude::*; use self::mainui::{render_shop, render_stats};
use super::screen::Screen;
use crate::{ use crate::{
gamecore::{GameCore, GameState}, gamecore::{GameCore, GameState},
lib::wrappers::audio::player::AudioPlayer, lib::wrappers::audio::player::AudioPlayer,
}; };
use raylib::prelude::*;
use self::mainui::{render_shop, render_stats};
use super::screen::Screen;
const SCREEN_PANEL_SIZE: Vector2 = Vector2 { x: 300.0, y: 380.0 };
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct ShopScreen { pub struct ShopScreen {
// shop_items: Vec<Item>,
} }
impl ShopScreen { impl ShopScreen {
@ -36,8 +30,6 @@ impl Screen for ShopScreen {
audio_system: &mut AudioPlayer, audio_system: &mut AudioPlayer,
game_core: &mut GameCore, game_core: &mut GameCore,
) -> Option<GameState> { ) -> Option<GameState> {
let mouse_position = draw_handle.get_mouse_position();
// Render the background // Render the background
draw_handle.draw_texture(&game_core.resources.shop_background, 0, 0, Color::WHITE); draw_handle.draw_texture(&game_core.resources.shop_background, 0, 0, Color::WHITE);