This commit is contained in:
rsninja722 2021-04-26 20:19:05 -04:00
commit 930696783d
24 changed files with 245 additions and 54 deletions

@ -32,6 +32,10 @@ Core libraries:
- [`serde`](https://serde.rs/) - [`serde`](https://serde.rs/)
- [`serialstudio-rs`](https://github.com/Ewpratten/serialstudio-rs) - [`serialstudio-rs`](https://github.com/Ewpratten/serialstudio-rs)
Sound Samples:
- [JavierZumer](https://freesound.org/people/JavierZumer/sounds/257236/)
- [Noted451](https://freesound.org/people/Noted451/sounds/531015/)
### VSCode Setup ### VSCode Setup
If using VSCode, disable the `Rust` extension, and install everything in the **Workspace Recommendations** (You will see this list by searching `@recommended` in the extensions panel) If using VSCode, disable the `Rust` extension, and install everything in the **Workspace Recommendations** (You will see this list by searching `@recommended` in the extensions panel)

BIN
assets/audio/succ.mp3 Normal file

Binary file not shown.

Binary file not shown.

BIN
assets/audio/zap.mp3 Normal file

Binary file not shown.

Before

(image error) Size: 286 B

After

(image error) Size: 286 B

Before

(image error) Size: 306 B

After

(image error) Size: 306 B

@ -276,6 +276,19 @@
"stun_timer": 0.0, "stun_timer": 0.0,
"puffer_state": "SmallIdle" "puffer_state": "SmallIdle"
},
{
"position" : {
"x":260,
"y":1472
},
"is_knocking_back": false,
"time_knocking_back": 0.0,
"inflate_timer": 0.0,
"is_large": false,
"stun_timer": 0.0,
"puffer_state": "SmallIdle"
} }
] ]

@ -10,6 +10,6 @@ pub trait EnemyBase {
resources: &mut GlobalResources, resources: &mut GlobalResources,
dt: f64, dt: f64,
); );
fn handle_logic(&mut self, player: &mut Player, dt: f64); fn handle_logic(&mut self, player: &mut Player, dt: f64) -> u8;
fn handle_getting_attacked(&mut self, stun_duration: f64, current_time: f64); fn handle_getting_attacked(&mut self, stun_duration: f64, current_time: f64);
} }

@ -77,13 +77,14 @@ impl EnemyBase for JellyFish {
&& !is_jelly_stunned; && !is_jelly_stunned;
} }
fn handle_logic(&mut self, player: &mut Player, _dt: f64) { fn handle_logic(&mut self, player: &mut Player, _dt: f64) -> u8 {
// Handle stunning the player // Handle stunning the player
if self.do_stun_player { if self.do_stun_player {
if self.position.distance_to(player.position).abs() <= JELLYFISH_STUN_REACH { if self.position.distance_to(player.position).abs() <= JELLYFISH_STUN_REACH {
player.set_stun_seconds(JELLYFISH_STUN_DURATION); player.set_stun_seconds(JELLYFISH_STUN_DURATION);
} }
} }
return 0;
} }
fn handle_getting_attacked(&mut self, stun_duration: f64, _current_time: f64) { fn handle_getting_attacked(&mut self, stun_duration: f64, _current_time: f64) {

@ -123,16 +123,19 @@ 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) -> u8 {
if self.suck_air_time_remaining > 0.0 && !self.has_taken_air_from_player { 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 { if player.position.distance_to(self.current_position).abs() <= OCTOPUS_SUCK_AIR_RANGE {
// Take air from the player // Take air from the player
player.breath_percent -= OCTOPUS_SUCK_AIR_AMOUNT; player.breath_percent -= OCTOPUS_SUCK_AIR_AMOUNT;
// Set the flag // Set the flag
self.has_taken_air_from_player = true; self.has_taken_air_from_player = true;
return 1;
} }
} }
return 0;
} }
fn handle_getting_attacked(&mut self, stun_duration: f64, _current_time: f64) { fn handle_getting_attacked(&mut self, stun_duration: f64, _current_time: f64) {

@ -39,7 +39,7 @@ impl EnemyBase for Pufferfish {
// Render the stun ring // Render the stun ring
if is_stunned { if is_stunned {
println!("Stunned"); // println!("Stunned");
let stun_ring_alpha = let stun_ring_alpha =
calculate_linear_slide(self.stun_timer / 1.0); calculate_linear_slide(self.stun_timer / 1.0);
context_2d.draw_circle_v( context_2d.draw_circle_v(
@ -66,7 +66,7 @@ impl EnemyBase for Pufferfish {
angle, angle,
); );
if self.position.distance_to(player.position).abs() <= 100.0 && self.inflate_timer > 1.0{ if self.position.distance_to(player.position).abs() <= 100.0 && self.inflate_timer > 2.0{
self.puffer_state = PufferState::Growing; self.puffer_state = PufferState::Growing;
} }
self.is_large = false; self.is_large = false;
@ -128,7 +128,7 @@ impl EnemyBase for Pufferfish {
} }
} }
fn handle_logic(&mut self, player: &mut crate::player::Player, dt: f64) { fn handle_logic(&mut self, player: &mut crate::player::Player, dt: f64) -> u8 {
@ -144,6 +144,8 @@ impl EnemyBase for Pufferfish {
self.inflate_timer = 0.0; self.inflate_timer = 0.0;
} }
return 0;
} }
fn handle_getting_attacked(&mut self, stun_duration: f64, current_time: f64) { fn handle_getting_attacked(&mut self, stun_duration: f64, current_time: f64) {

@ -38,8 +38,8 @@ impl EnemyBase for Whirlpool{
self.rotation += 1.0; self.rotation += 1.0;
} }
fn handle_logic(&mut self, player: &mut crate::player::Player, dt: f64) { fn handle_logic(&mut self, player: &mut crate::player::Player, dt: f64) -> u8 {
return 0;
} }
// Whirlpool removed if shoot // Whirlpool removed if shoot

@ -1,7 +1,7 @@
use rand::{prelude::ThreadRng, Rng}; use rand::{prelude::ThreadRng, Rng};
use raylib::prelude::*; use raylib::prelude::*;
use crate::{player::Player, resources::GlobalResources}; use crate::{gamecore::{self, GameCore}, lib::wrappers::audio::player::AudioPlayer, 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;
@ -12,6 +12,7 @@ const FISH_FACTOR_COHESION: f32 = 0.1;
const FISH_SEPARATION_DISTANCE: f32 = 15.0; const FISH_SEPARATION_DISTANCE: f32 = 15.0;
const FISH_FACTOR_SEPARATION: f32 = 1.5; const FISH_FACTOR_SEPARATION: f32 = 1.5;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct FishEntity { pub struct FishEntity {
position: Vector2, position: Vector2,
@ -134,25 +135,31 @@ impl FishEntity {
self.position += self.velocity; self.position += self.velocity;
} }
pub fn handle_free_movement(&mut self, player: &mut Player, _dt: f64) { pub fn handle_free_movement(&mut self, player: &mut Player, _dt: f64) -> bool {
// 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;
self.velocity = self.direction.normalized(); self.velocity = self.direction.normalized();
self.current_frame = 0; self.current_frame = 0;
self.animation_counter = 0; self.animation_counter = 0;
// Add currency to the player // Add currency to the player
player.coins += 1; player.coins += 1;
return true;
} }
return false
} }
pub fn update_position(&mut self, player: &mut Player, dt: f64, other_fish: &Vec<FishEntity>) { pub fn update_position(&mut self, player: &mut Player, dt: f64, other_fish: &Vec<FishEntity>) -> bool{
if self.following_player { if self.following_player {
self.handle_follow_player(player, dt, other_fish); self.handle_follow_player(player, dt, other_fish);
} else { } else {
self.handle_free_movement(player, dt); if self.handle_free_movement(player, dt) {
return true;
}
} }
return false;
} }
pub fn render( pub fn render(

@ -61,11 +61,11 @@ impl ItemBase for StunGun {
} }
fn get_name(&self) -> String { fn get_name(&self) -> String {
return "Stun Gun".to_string(); return "Stun Bomb".to_string();
} }
fn get_description(&self) -> String { fn get_description(&self) -> String {
return "Stun your enemies!\nJust don't point it at yourself.".to_string(); return "Right click to stun enemies\n one use per dive".to_string();
} }
fn get_texture( fn get_texture(

@ -18,6 +18,9 @@ pub fn render_hud(
+ slider_bound_height, + slider_bound_height,
}; };
draw_handle.draw_rectangle(10, 10, 20, 700, Color::new(0, 50, 255, 50));
draw_handle.draw_rectangle( 10, 710 - (game_core.player.breath_percent * 450.0) as i32, 20, (game_core.player.breath_percent * 450.0) as i32, Color::new(0, 50, 255, 125));
// Render the base of the slider // Render the base of the slider
draw_handle.draw_rectangle( draw_handle.draw_rectangle(
(progress_slider_position.x - slider_bound_height) as i32, (progress_slider_position.x - slider_bound_height) as i32,

@ -2,15 +2,14 @@ mod hud;
mod playerlogic; mod playerlogic;
use raylib::prelude::*; use raylib::prelude::*;
use crate::{entities::enemy::{base::EnemyBase, whirlpool::Whirlpool}, gamecore::{self, GameCore, GameState}, lib::wrappers::audio::player::AudioPlayer};
use crate::{entities::enemy::{base::EnemyBase, whirlpool::Whirlpool}, gamecore::{GameCore, GameState}, lib::wrappers::audio::player::AudioPlayer};
use super::screen::Screen; use super::screen::Screen;
use crate::entities::fish::FishEntity; use crate::entities::fish::FishEntity;
pub struct InGameScreen { pub struct InGameScreen {
shader_time_var_location: i32, shader_time_var_location: i32,
swim_playing: bool,
} }
impl InGameScreen { impl InGameScreen {
@ -20,6 +19,7 @@ impl InGameScreen {
*game_core.resources.pixel_shader, *game_core.resources.pixel_shader,
rstr!("time").as_ptr(), rstr!("time").as_ptr(),
), ),
swim_playing: false,
} }
} }
@ -28,6 +28,7 @@ impl InGameScreen {
context_2d: &mut RaylibMode2D<RaylibDrawHandle>, context_2d: &mut RaylibMode2D<RaylibDrawHandle>,
game_core: &mut GameCore, game_core: &mut GameCore,
dt: f64, dt: f64,
audio_system: &mut AudioPlayer,
) { ) {
// Build source bounds // Build source bounds
let source_bounds = Rectangle { let source_bounds = Rectangle {
@ -92,9 +93,53 @@ impl InGameScreen {
// Render fish // Render fish
let fish_clone = game_core.world.fish.clone(); let fish_clone = game_core.world.fish.clone();
for fish in game_core.world.fish.iter_mut() { for fish in game_core.world.fish.iter_mut() {
fish.update_position(&mut game_core.player, dt, &fish_clone); if fish.update_position(&mut game_core.player, dt, &fish_clone) {
audio_system.play_sound(&game_core.resources.fish_pickup);
}
fish.render(context_2d, &mut game_core.resources); fish.render(context_2d, &mut game_core.resources);
} }
context_2d.draw_texture_pro(
&game_core.resources.tut1,
Rectangle {
x: 0.0,
y: 0.0,
width: 44.0,
height: 41.0,
},
Rectangle {
x: 110.0,
y: 100.0,
width: 44.0,
height: 41.0,
},
Vector2 {
x: 0.0,
y: 0.0,
},
0.0,
Color::WHITE,
);
context_2d.draw_texture_pro(
&game_core.resources.tut2,
Rectangle {
x: 0.0,
y: 0.0,
width: 44.0,
height: 41.0,
},
Rectangle {
x: 160.0,
y: 110.0,
width: 44.0,
height: 41.0,
},
Vector2 {
x: 0.0,
y: 0.0,
},
0.0,
Color::WHITE,
);
// Render the world texture // Render the world texture
context_2d.draw_texture_rec( context_2d.draw_texture_rec(
@ -190,6 +235,11 @@ impl Screen for InGameScreen {
return Some(GameState::PauseMenu); return Some(GameState::PauseMenu);
} }
// music
if !_audio_system.is_sound_playing(&game_core.resources.song_swim) {
_audio_system.play_sound(&game_core.resources.song_swim);
}
// Window dimensions // Window dimensions
let win_height = draw_handle.get_screen_height(); let win_height = draw_handle.get_screen_height();
let win_width = draw_handle.get_screen_width(); let win_width = draw_handle.get_screen_width();
@ -199,7 +249,12 @@ impl Screen for InGameScreen {
}; };
// Update player movement // Update player movement
playerlogic::update_player_movement(draw_handle, game_core, window_center); playerlogic::update_player_movement(draw_handle, game_core, window_center, _audio_system);
if draw_handle.get_time() % 10.0 <= 0.1 && !_audio_system.is_sound_playing(&game_core.resources.breath){
_audio_system.set_sound_volume(&game_core.resources.breath, 0.5);
_audio_system.play_sound(&game_core.resources.breath);
}
// Open a 2D context // Open a 2D context
{ {
@ -213,7 +268,7 @@ impl Screen for InGameScreen {
context_2d.clear_background(Color::BLACK); context_2d.clear_background(Color::BLACK);
// Render the world // Render the world
self.render_world(&mut context_2d, game_core, dt); self.render_world(&mut context_2d, game_core, dt, _audio_system);
if game_core.show_simple_debug_info { if game_core.show_simple_debug_info {
self.render_colliders(&mut context_2d, game_core); self.render_colliders(&mut context_2d, game_core);
} }
@ -229,7 +284,9 @@ impl Screen for InGameScreen {
); );
} }
for octopus in game_core.world.octopus.iter_mut() { for octopus in game_core.world.octopus.iter_mut() {
octopus.handle_logic(&mut game_core.player, dt); if octopus.handle_logic(&mut game_core.player, dt) == 1 {
_audio_system.play_sound(&game_core.resources.succ);
}
octopus.render( octopus.render(
&mut context_2d, &mut context_2d,
&mut game_core.player, &mut game_core.player,

@ -1,6 +1,6 @@
use raylib::core::audio::RaylibAudio; use raylib::core::audio::RaylibAudio;
use raylib::prelude::*; use raylib::prelude::*;
use rand::{prelude::ThreadRng, Rng};
use crate::{gamecore::GameCore, lib::wrappers::audio::player::AudioPlayer}; use crate::{gamecore::GameCore, lib::wrappers::audio::player::AudioPlayer};
const NORMAL_PLAYER_SPEED: i32 = 1; const NORMAL_PLAYER_SPEED: i32 = 1;
@ -18,10 +18,9 @@ pub fn update_player_movement(
draw_handle: &mut RaylibDrawHandle, draw_handle: &mut RaylibDrawHandle,
game_core: &mut GameCore, game_core: &mut GameCore,
window_center: Vector2, window_center: Vector2,
audio_system: &mut AudioPlayer
) { ) {
// let mut p: AudioPlayer = AudioPlayer::new(RaylibAudio::init_audio_device());
// p.play_sound(&game_core.resources.breath);
// Calculate DT // Calculate DT
let dt = draw_handle.get_time() - game_core.last_frame_time; let dt = draw_handle.get_time() - game_core.last_frame_time;
@ -82,11 +81,26 @@ pub fn update_player_movement(
let user_request_boost = draw_handle.is_mouse_button_down(MouseButton::MOUSE_LEFT_BUTTON); let user_request_boost = draw_handle.is_mouse_button_down(MouseButton::MOUSE_LEFT_BUTTON);
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.has_stunned {
game_core.player.has_stunned = true;
game_core game_core
.player .player
.begin_attack(&mut game_core.world, draw_handle.get_time()); .begin_attack(&mut game_core.world, draw_handle.get_time());
//println!("{{\"x\":{}, \"y\":{}}},",f32::round(game_core.player.position.x),f32::round(game_core.player.position.y)); }
if user_request_action {
// println!("{{\"x\":{}, \"y\":{}}},",f32::round(game_core.player.position.x),f32::round(game_core.player.position.y));
}
// die sound
if game_core.player.breath_percent <= 0.06 {
if !audio_system.is_sound_playing(&game_core.resources.die) {
audio_system.play_sound(&game_core.resources.die);
}
}
if (game_core.player.stun_timer > 0.0 || game_core.player.is_stun_gun_active()) && !audio_system.is_sound_playing(&game_core.resources.zap) {
audio_system.play_sound(&game_core.resources.zap);
} }
// Move the player in their direction // Move the player in their direction
@ -95,6 +109,21 @@ pub fn update_player_movement(
// Set the speed multiplier // Set the speed multiplier
speed_multiplier = BOOST_PLAYER_SPEED as f32; speed_multiplier = BOOST_PLAYER_SPEED as f32;
// swim sound
if !audio_system.is_sound_playing(&game_core.resources.swim1) && !audio_system.is_sound_playing(&game_core.resources.swim2) && !audio_system.is_sound_playing(&game_core.resources.swim3) && !audio_system.is_sound_playing(&game_core.resources.swim4) {
let mut rng = rand::thread_rng();
let num = rng.gen_range(0..3);
if num == 0 {
audio_system.play_sound(&game_core.resources.swim1);
} else if num == 1 {
audio_system.play_sound(&game_core.resources.swim2);
} else if num == 2 {
audio_system.play_sound(&game_core.resources.swim3);
} else {
audio_system.play_sound(&game_core.resources.swim4);
}
}
// Decrease the boost // Decrease the boost
game_core.player.boost_percent -= BOOST_DECREASE_PER_SECOND * dt as f32; game_core.player.boost_percent -= BOOST_DECREASE_PER_SECOND * dt as f32;
game_core.player.is_boosting = true; game_core.player.is_boosting = true;
@ -221,7 +250,7 @@ pub fn update_player_movement(
let angle = net_pose.y.atan2(net_pose.x); let angle = net_pose.y.atan2(net_pose.x);
// Calculates force // Calculates force
let force = 1.0; let force = 0.2;
// Calculates componets of force // Calculates componets of force
let mut force_x = (force as f32 * angle.cos()).clamp(-1.0, 1.0); let mut force_x = (force as f32 * angle.cos()).clamp(-1.0, 1.0);

@ -90,10 +90,11 @@ impl Screen for MainMenuScreen {
if hovering_play_button { if hovering_play_button {
// Reset the world // Reset the world
game_core.world.reset(&mut game_core.player); game_core.world.reset(&mut game_core.player);
_audio_system.play_sound(&game_core.resources.ui_click);
// Start playing // Start playing
return Some(GameState::InGame); return Some(GameState::InGame);
} else if hovering_shop_button { } else if hovering_shop_button {
_audio_system.play_sound(&game_core.resources.ui_click);
return Some(GameState::InShop); return Some(GameState::InShop);
} else if hovering_quit_button { } else if hovering_quit_button {
return Some(GameState::GameQuit); return Some(GameState::GameQuit);

@ -171,8 +171,10 @@ impl Screen for PauseMenuScreen {
// Handle click actions on the buttons // Handle click actions on the buttons
if draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON) { if draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON) {
if menu_button.is_hovered(draw_handle) { if menu_button.is_hovered(draw_handle) {
audio_system.play_sound(&game_core.resources.ui_click);
return Some(GameState::MainMenu); return Some(GameState::MainMenu);
} else if close_button.is_hovered(draw_handle) { } else if close_button.is_hovered(draw_handle) {
audio_system.play_sound(&game_core.resources.ui_click);
return Some(game_core.last_state); return Some(game_core.last_state);
} }
} }

@ -112,12 +112,14 @@ pub fn render_shop(
{ {
let item = stun_gun_buy_ui.purchase(&mut game_core.player); let item = stun_gun_buy_ui.purchase(&mut game_core.player);
game_core.player.inventory.stun_gun = Some(item); game_core.player.inventory.stun_gun = Some(item);
_audio_system.play_sound(&game_core.resources.ui_buy);
} }
if air_bag_buy_ui.can_player_afford(&game_core.player, &game_core.player.inventory.air_bag) if air_bag_buy_ui.can_player_afford(&game_core.player, &game_core.player.inventory.air_bag)
&& air_bag_buy_ui.user_clicked_buy(draw_handle) && air_bag_buy_ui.user_clicked_buy(draw_handle)
{ {
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);
_audio_system.play_sound(&game_core.resources.ui_buy);
} }
if flashlight_buy_ui if flashlight_buy_ui
.can_player_afford(&game_core.player, &game_core.player.inventory.flashlight) .can_player_afford(&game_core.player, &game_core.player.inventory.flashlight)
@ -125,12 +127,14 @@ pub fn render_shop(
{ {
let item = flashlight_buy_ui.purchase(&mut game_core.player); let item = flashlight_buy_ui.purchase(&mut game_core.player);
game_core.player.inventory.flashlight = Some(item); game_core.player.inventory.flashlight = Some(item);
_audio_system.play_sound(&game_core.resources.ui_buy);
} }
if flippers_buy_ui.can_player_afford(&game_core.player, &game_core.player.inventory.flippers) if flippers_buy_ui.can_player_afford(&game_core.player, &game_core.player.inventory.flippers)
&& flippers_buy_ui.user_clicked_buy(draw_handle) && flippers_buy_ui.user_clicked_buy(draw_handle)
{ {
let item = flippers_buy_ui.purchase(&mut game_core.player); let item = flippers_buy_ui.purchase(&mut game_core.player);
game_core.player.inventory.flippers = Some(item); game_core.player.inventory.flippers = Some(item);
_audio_system.play_sound(&game_core.resources.ui_buy);
} }
// Render the tooltip box // Render the tooltip box
@ -232,6 +236,7 @@ pub fn render_shop(
.player .player
.create_statistics(game_core, draw_handle.get_time()); .create_statistics(game_core, draw_handle.get_time());
game_core.progress.update(&new_progress); game_core.progress.update(&new_progress);
_audio_system.play_sound(&game_core.resources.ui_click);
} }
if menu_button.is_hovered(draw_handle) { if menu_button.is_hovered(draw_handle) {

@ -33,6 +33,18 @@ impl Screen for ShopScreen {
// 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);
if !audio_system.is_sound_playing(&game_core.resources.song_shop) {
audio_system.play_sound(&game_core.resources.song_shop);
}
draw_handle.draw_text(
&format!("you really need to get to the bottom huh?\n Well then buy my wares,\n they will help you get to your doo-hicky"),
10,
50,
20,
Color::WHITE,
);
// Window dimensions // Window dimensions
let win_height = draw_handle.get_screen_height(); let win_height = draw_handle.get_screen_height();
let win_width = draw_handle.get_screen_width(); let win_width = draw_handle.get_screen_width();

@ -131,6 +131,16 @@ fn main() {
// If needed, update the global state // If needed, update the global state
if new_state.is_some() { if new_state.is_some() {
let new_state = new_state.unwrap(); let new_state = new_state.unwrap();
// stop music
if (new_state != GameState::PauseMenu && game_core.state != GameState::PauseMenu) || new_state == GameState::MainMenu {
if audio_system.is_sound_playing(&game_core.resources.song_shop) {
audio_system.stop_sound(&game_core.resources.song_shop);
}
if audio_system.is_sound_playing(&game_core.resources.song_swim) {
audio_system.stop_sound(&game_core.resources.song_swim);
}
}
// Handle game quit // Handle game quit
if new_state == GameState::GameQuit { if new_state == GameState::GameQuit {

@ -44,6 +44,7 @@ pub struct Player {
pub inventory: PlayerInventory, pub inventory: PlayerInventory,
pub stun_timer: f64, pub stun_timer: f64,
pub attacking_timer: f64, pub attacking_timer: f64,
pub has_stunned: bool,
} }
impl Player { impl Player {
@ -55,6 +56,7 @@ impl Player {
breath_percent: 1.0, breath_percent: 1.0,
is_moving: true, is_moving: true,
radius: 4.5, radius: 4.5,
has_stunned: false,
position: spawn.clone(), position: spawn.clone(),
inventory: PlayerInventory::new(), inventory: PlayerInventory::new(),
..Default::default() ..Default::default()
@ -65,6 +67,7 @@ impl Player {
self.position = position; self.position = position;
self.breath_percent = 1.0; self.breath_percent = 1.0;
self.boost_percent = 1.0; self.boost_percent = 1.0;
self.has_stunned = false;
// Handle an air bag being used // Handle an air bag being used
if self.inventory.air_bag.is_some() { if self.inventory.air_bag.is_some() {
@ -150,25 +153,28 @@ impl Player {
// Render the player's boost ring // Render the player's boost ring
// This functions both as a breath meter, and as a boost meter // This functions both as a breath meter, and as a boost meter
let boost_ring_max_radius = self.size.x + 5.0; // let boost_ring_max_radius = self.size.x + 5.0;
context_2d.draw_circle( // context_2d.draw_circle(
self.position.x as i32, // self.position.x as i32,
self.position.y as i32, // self.position.y as i32,
boost_ring_max_radius * self.boost_percent, // boost_ring_max_radius * self.boost_percent,
TRANSLUCENT_WHITE_64, // TRANSLUCENT_WHITE_64,
); // );
context_2d.draw_ring(
Vector2 { context_2d.draw_rectangle(self.position.x as i32 - 15,self.position.y as i32 + 15, 30, 4, Color::new(255, 255, 0, 50));
x: self.position.x as i32 as f32, context_2d.draw_rectangle(self.position.x as i32 - 15,self.position.y as i32 + 15, (30.0 * self.boost_percent) as i32, 4, Color::new(255, 255, 0, 125));
y: self.position.y as i32 as f32, // context_2d.draw_ring(
}, // Vector2 {
boost_ring_max_radius, // x: self.position.x as i32 as f32,
boost_ring_max_radius + 1.0, // y: self.position.y as i32 as f32,
0, // },
(360.0 * self.breath_percent) as i32, // boost_ring_max_radius,
0, // boost_ring_max_radius + 1.0,
TRANSLUCENT_WHITE_96, // 0,
); // (360.0 * self.breath_percent) as i32,
// 0,
// TRANSLUCENT_WHITE_96,
// );
// Calculate AOE ring // Calculate AOE ring
if self.is_stun_gun_active() { if self.is_stun_gun_active() {

@ -58,12 +58,28 @@ pub struct GlobalResources {
pub flippers_one: Texture2D, pub flippers_one: Texture2D,
pub flippers_two: Texture2D, pub flippers_two: Texture2D,
pub flippers_three: Texture2D, pub flippers_three: Texture2D,
// tut
pub tut1: Texture2D,
pub tut2: Texture2D,
// Treasure // Treasure
pub transponder: FrameAnimationWrapper, pub transponder: FrameAnimationWrapper,
// Audio // Audio
pub breath: Sound, pub breath: Sound,
pub swim1: Sound,
pub swim2: Sound,
pub swim3: Sound,
pub swim4: Sound,
pub die: Sound,
pub ui_buy: Sound,
pub ui_click: Sound,
pub fish_pickup: Sound,
pub song_shop: Sound,
pub song_swim: Sound,
pub zap: Sound,
pub succ: Sound,
} }
impl GlobalResources { impl GlobalResources {
@ -241,6 +257,14 @@ impl GlobalResources {
&thread, &thread,
&Image::load_image("./assets/img/items/flippers3.png")?, &Image::load_image("./assets/img/items/flippers3.png")?,
)?), )?),
tut1: (raylib.load_texture_from_image(
&thread,
&Image::load_image("./assets/img/map/tut1.png")?,
)?),
tut2: (raylib.load_texture_from_image(
&thread,
&Image::load_image("./assets/img/map/tut2.png")?,
)?),
transponder: FrameAnimationWrapper::new( transponder: FrameAnimationWrapper::new(
raylib.load_texture_from_image( raylib.load_texture_from_image(
&thread, &thread,
@ -266,7 +290,7 @@ impl GlobalResources {
)?, )?,
Vector2 { x: 19.0, y: 19.0 }, Vector2 { x: 19.0, y: 19.0 },
3, 3,
2, 4,
), ),
pufferfish_small: FrameAnimationWrapper::new( pufferfish_small: FrameAnimationWrapper::new(
raylib.load_texture_from_image( raylib.load_texture_from_image(
@ -275,7 +299,7 @@ impl GlobalResources {
)?, )?,
Vector2 { x: 19.0, y: 19.0 }, Vector2 { x: 19.0, y: 19.0 },
6, 6,
2, 4,
), ),
pufferfish_attack: FrameAnimationWrapper::new( pufferfish_attack: FrameAnimationWrapper::new(
raylib.load_texture_from_image( raylib.load_texture_from_image(
@ -284,7 +308,7 @@ impl GlobalResources {
)?, )?,
Vector2 { x: 39.0, y: 25.0 }, Vector2 { x: 39.0, y: 25.0 },
4, 4,
2, 4,
), ),
pufferfish_expand: FrameAnimationWrapper::new( pufferfish_expand: FrameAnimationWrapper::new(
raylib.load_texture_from_image( raylib.load_texture_from_image(
@ -293,9 +317,21 @@ impl GlobalResources {
)?, )?,
Vector2 { x: 19.0, y: 19.0 }, Vector2 { x: 19.0, y: 19.0 },
4, 4,
2, 4,
), ),
breath: Sound::load_sound("./assets/audio/breath.mp3")? breath: Sound::load_sound("./assets/audio/breath.mp3")?,
swim1: Sound::load_sound("./assets/audio/swim1.mp3")?,
swim2: Sound::load_sound("./assets/audio/swim2.mp3")?,
swim3: Sound::load_sound("./assets/audio/swim3.mp3")?,
swim4: Sound::load_sound("./assets/audio/swim4.mp3")?,
die: Sound::load_sound("./assets/audio/die.mp3")?,
ui_buy: Sound::load_sound("./assets/audio/uiBuy.mp3")?,
ui_click: Sound::load_sound("./assets/audio/uiClick.mp3")?,
fish_pickup: Sound::load_sound("./assets/audio/fishPickup.mp3")?,
song_shop: Sound::load_sound("./assets/audio/shopSong.mp3")?,
song_swim: Sound::load_sound("./assets/audio/swimSong.mp3")?,
zap: Sound::load_sound("./assets/audio/zap.mp3")?,
succ: Sound::load_sound("./assets/audio/succ.mp3")?,
}) })
} }
} }