diff --git a/assets/img/map/fish.aseprite b/assets/img/map/fish.aseprite new file mode 100644 index 0000000..1883247 Binary files /dev/null and b/assets/img/map/fish.aseprite differ diff --git a/assets/img/map/fish.json b/assets/img/map/fish.json new file mode 100644 index 0000000..324ec8a --- /dev/null +++ b/assets/img/map/fish.json @@ -0,0 +1,26 @@ +{ "frames": { + "fish 62.aseprite": { + "frame": { "x": 806, "y": 0, "w": 13, "h": 9 }, + "rotated": false, + "trimmed": false, + "spriteSourceSize": { "x": 0, "y": 0, "w": 13, "h": 9 }, + "sourceSize": { "w": 13, "h": 9 }, + "duration": 50 + } + }, + "meta": { + "app": "http://www.aseprite.org/", + "version": "1.2.27-x64", + "image": "fish.png", + "format": "RGBA8888", + "size": { "w": 819, "h": 9 }, + "scale": "1", + "frameTags": [ + ], + "layers": [ + { "name": "Layer 1", "opacity": 255, "blendMode": "normal" } + ], + "slices": [ + ] + } +} diff --git a/assets/img/map/fish.png b/assets/img/map/fish.png new file mode 100644 index 0000000..29054a8 Binary files /dev/null and b/assets/img/map/fish.png differ diff --git a/assets/img/map/fishIdle.aseprite b/assets/img/map/fishIdle.aseprite new file mode 100644 index 0000000..6514d45 Binary files /dev/null and b/assets/img/map/fishIdle.aseprite differ diff --git a/assets/img/map/fishStill.json b/assets/img/map/fishStill.json new file mode 100644 index 0000000..f8f5e3b --- /dev/null +++ b/assets/img/map/fishStill.json @@ -0,0 +1,130 @@ +{ "frames": { + "fishIdle 0.aseprite": { + "frame": { "x": 0, "y": 0, "w": 13, "h": 9 }, + "rotated": false, + "trimmed": false, + "spriteSourceSize": { "x": 0, "y": 0, "w": 13, "h": 9 }, + "sourceSize": { "w": 13, "h": 9 }, + "duration": 100 + }, + "fishIdle 1.aseprite": { + "frame": { "x": 13, "y": 0, "w": 13, "h": 9 }, + "rotated": false, + "trimmed": false, + "spriteSourceSize": { "x": 0, "y": 0, "w": 13, "h": 9 }, + "sourceSize": { "w": 13, "h": 9 }, + "duration": 100 + }, + "fishIdle 2.aseprite": { + "frame": { "x": 26, "y": 0, "w": 13, "h": 9 }, + "rotated": false, + "trimmed": false, + "spriteSourceSize": { "x": 0, "y": 0, "w": 13, "h": 9 }, + "sourceSize": { "w": 13, "h": 9 }, + "duration": 100 + }, + "fishIdle 3.aseprite": { + "frame": { "x": 39, "y": 0, "w": 13, "h": 9 }, + "rotated": false, + "trimmed": false, + "spriteSourceSize": { "x": 0, "y": 0, "w": 13, "h": 9 }, + "sourceSize": { "w": 13, "h": 9 }, + "duration": 100 + }, + "fishIdle 4.aseprite": { + "frame": { "x": 52, "y": 0, "w": 13, "h": 9 }, + "rotated": false, + "trimmed": false, + "spriteSourceSize": { "x": 0, "y": 0, "w": 13, "h": 9 }, + "sourceSize": { "w": 13, "h": 9 }, + "duration": 100 + }, + "fishIdle 5.aseprite": { + "frame": { "x": 65, "y": 0, "w": 13, "h": 9 }, + "rotated": false, + "trimmed": false, + "spriteSourceSize": { "x": 0, "y": 0, "w": 13, "h": 9 }, + "sourceSize": { "w": 13, "h": 9 }, + "duration": 100 + }, + "fishIdle 6.aseprite": { + "frame": { "x": 78, "y": 0, "w": 13, "h": 9 }, + "rotated": false, + "trimmed": false, + "spriteSourceSize": { "x": 0, "y": 0, "w": 13, "h": 9 }, + "sourceSize": { "w": 13, "h": 9 }, + "duration": 100 + }, + "fishIdle 7.aseprite": { + "frame": { "x": 91, "y": 0, "w": 13, "h": 9 }, + "rotated": false, + "trimmed": false, + "spriteSourceSize": { "x": 0, "y": 0, "w": 13, "h": 9 }, + "sourceSize": { "w": 13, "h": 9 }, + "duration": 100 + }, + "fishIdle 8.aseprite": { + "frame": { "x": 104, "y": 0, "w": 13, "h": 9 }, + "rotated": false, + "trimmed": false, + "spriteSourceSize": { "x": 0, "y": 0, "w": 13, "h": 9 }, + "sourceSize": { "w": 13, "h": 9 }, + "duration": 100 + }, + "fishIdle 9.aseprite": { + "frame": { "x": 117, "y": 0, "w": 13, "h": 9 }, + "rotated": false, + "trimmed": false, + "spriteSourceSize": { "x": 0, "y": 0, "w": 13, "h": 9 }, + "sourceSize": { "w": 13, "h": 9 }, + "duration": 100 + }, + "fishIdle 10.aseprite": { + "frame": { "x": 130, "y": 0, "w": 13, "h": 9 }, + "rotated": false, + "trimmed": false, + "spriteSourceSize": { "x": 0, "y": 0, "w": 13, "h": 9 }, + "sourceSize": { "w": 13, "h": 9 }, + "duration": 100 + }, + "fishIdle 11.aseprite": { + "frame": { "x": 143, "y": 0, "w": 13, "h": 9 }, + "rotated": false, + "trimmed": false, + "spriteSourceSize": { "x": 0, "y": 0, "w": 13, "h": 9 }, + "sourceSize": { "w": 13, "h": 9 }, + "duration": 100 + }, + "fishIdle 12.aseprite": { + "frame": { "x": 156, "y": 0, "w": 13, "h": 9 }, + "rotated": false, + "trimmed": false, + "spriteSourceSize": { "x": 0, "y": 0, "w": 13, "h": 9 }, + "sourceSize": { "w": 13, "h": 9 }, + "duration": 100 + }, + "fishIdle 13.aseprite": { + "frame": { "x": 169, "y": 0, "w": 13, "h": 9 }, + "rotated": false, + "trimmed": false, + "spriteSourceSize": { "x": 0, "y": 0, "w": 13, "h": 9 }, + "sourceSize": { "w": 13, "h": 9 }, + "duration": 100 + } + }, + "meta": { + "app": "http://www.aseprite.org/", + "version": "1.2.27-x64", + "image": "fishIdle.png", + "format": "RGBA8888", + "size": { "w": 182, "h": 9 }, + "scale": "1", + "frameTags": [ + ], + "layers": [ + { "name": "Layer 1", "opacity": 255, "blendMode": "normal" } + ], + "slices": [ + ] + } +} diff --git a/assets/img/map/fishStill.png b/assets/img/map/fishStill.png new file mode 100644 index 0000000..44c6967 Binary files /dev/null and b/assets/img/map/fishStill.png differ diff --git a/src/entities/fish.rs b/src/entities/fish.rs index 8982d0b..6cae1ab 100644 --- a/src/entities/fish.rs +++ b/src/entities/fish.rs @@ -2,7 +2,11 @@ use rand::{prelude::ThreadRng, Rng}; use raylib::prelude::*; use crate::{ - gamecore::GameCore, lib::utils::triangles::rotate_vector, player::Player, world::World, + gamecore::{self, GameCore}, + lib::utils::triangles::rotate_vector, + player::Player, + resources::GlobalResources, + world::World, }; const FISH_FOLLOW_PLAYER_DISTANCE: f32 = 30.0; @@ -25,9 +29,11 @@ pub struct FishEntity { direction: Vector2, velocity: Vector2, pub following_player: bool, + current_frame: u8, + animation_counter: u32, size: Vector2, + color: u8, rng: ThreadRng, - color: Color, } impl FishEntity { @@ -35,16 +41,16 @@ impl FishEntity { let mut rng = rand::thread_rng(); Self { position: position, - direction: Vector2::zero(), + direction: Vector2 { + x: rng.gen_range(0.0..1.0), + y: rng.gen_range(0.0..1.0), + }, velocity: Vector2::zero(), following_player: false, + animation_counter: 0, + current_frame: 0, size: Vector2 { x: 5.0, y: 8.0 }, - color: Color { - r: rng.gen_range(128..225), - g: rng.gen_range(128..225), - b: rng.gen_range(128..225), - a: 140, - }, + color: rng.gen_range(0..6), rng, } } @@ -138,21 +144,17 @@ impl FishEntity { // Distance and direction to player let dist_to_player = player.position - self.position; let dist_to_player_lin = self.position.distance_to(player.position); - let mut direction_to_player = dist_to_player; - direction_to_player.normalize(); // Handle player picking up fish if player.position.distance_to(self.position).abs() <= player.size.y * 2.2 { self.following_player = true; self.velocity = self.direction.normalized(); + self.current_frame = 0; + self.animation_counter = 0; // Add currency to the player player.coins += 1; } - - // Look at the player; - self.position = self.position; - self.direction = direction_to_player; } pub fn update_position(&mut self, player: &mut Player, dt: f64, other_fish: &Vec) { @@ -163,40 +165,45 @@ impl FishEntity { } } - pub fn render(&self, context_2d: &mut RaylibMode2D) { + pub fn render( + &mut self, + context_2d: &mut RaylibMode2D, + resources: &mut GlobalResources, + ) { // Direction - let direction = - Vector2::zero().angle_to(self.direction.normalized()) + (90.0 as f32).to_radians(); + let direction = (Vector2::zero().angle_to(self.direction.normalized())).to_degrees(); - // Get the corners of the fish - let fish_front = rotate_vector( - Vector2 { - x: 0.0, - y: (self.size.y / 2.0) * -1.0, - }, - direction, - ); - let fish_bl = rotate_vector( - Vector2 { - x: (self.size.x / 2.0) * -1.0, - y: (self.size.y / 2.0), - }, - direction, - ); - let fish_br = rotate_vector( - Vector2 { - x: (self.size.x / 2.0), - y: (self.size.y / 2.0), - }, - direction, - ); + self.animation_counter += 1; - // Draw the fish as a triangle with rotation - context_2d.draw_triangle( - self.position + fish_front, - self.position + fish_bl, - self.position + fish_br, - self.color, - ); + // swimming + if self.following_player { + if self.animation_counter % 3 == 0 { + self.current_frame += 1; + if self.current_frame == 8 { + self.current_frame = 0; + } + } + resources.fish_animation_swim.draw_frame( + context_2d, + self.position, + direction, + (self.current_frame + self.color * 9) as u32, + ); + // idle + } else { + if self.animation_counter % 10 == 0 { + if self.current_frame == 0 { + self.current_frame = 1; + } else { + self.current_frame = 0; + } + } + resources.fish_animation_idle.draw_frame( + context_2d, + self.position, + direction, + (self.current_frame + self.color * 2) as u32, + ); + } } } diff --git a/src/items.rs b/src/items.rs index 66638b3..f83afd1 100644 --- a/src/items.rs +++ b/src/items.rs @@ -54,7 +54,7 @@ impl ItemBase for StunGun { } fn get_description(&self) -> String { - return "Stun your enemies! Just don't point it at yourself.".to_string(); + return "Stun your enemies!\nJust don't point it at yourself.".to_string(); } fn get_texture(&self) -> &Texture2D { @@ -67,7 +67,7 @@ impl ItemBase for StunGun { #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] pub struct AirBag { - extra_oxygen: u32, + pub extra_oxygen: f32, pub level: u8, cost: u32, } @@ -75,21 +75,21 @@ pub struct AirBag { impl AirBag { pub fn lvl1() -> Self { Self { - extra_oxygen: 15, + extra_oxygen: 0.15, level: 1, cost: 30, } } pub fn lvl2() -> Self { Self { - extra_oxygen: 30, + extra_oxygen: 0.30, level: 2, cost: 40, } } pub fn lvl3() -> Self { Self { - extra_oxygen: 45, + extra_oxygen: 0.45, level: 3, cost: 50, } @@ -106,7 +106,7 @@ impl ItemBase for AirBag { } fn get_description(&self) -> String { - return "Its.. a bag. Filled with air. Duh".to_string(); + return "Its.. a bag.\nFilled with air. Duh".to_string(); } fn get_texture(&self) -> &Texture2D { @@ -210,7 +210,7 @@ impl ItemBase for Flippers { } fn get_description(&self) -> String { - return "Swim faster, and look stupid at the same time!".to_string(); + return "Swim faster, and look stupid\nat the same time!".to_string(); } fn get_texture(&self) -> &Texture2D { diff --git a/src/logic/ingame/mod.rs b/src/logic/ingame/mod.rs index 0f52cca..cb64580 100644 --- a/src/logic/ingame/mod.rs +++ b/src/logic/ingame/mod.rs @@ -62,7 +62,7 @@ impl InGameScreen { let fish_clone = game_core.world.fish.clone(); for fish in game_core.world.fish.iter_mut() { fish.update_position(&mut game_core.player, dt, &fish_clone); - fish.render(context_2d); + fish.render(context_2d, &mut game_core.resources); } // Render the world texture diff --git a/src/logic/ingame/playerlogic.rs b/src/logic/ingame/playerlogic.rs index a506daa..91e2cef 100644 --- a/src/logic/ingame/playerlogic.rs +++ b/src/logic/ingame/playerlogic.rs @@ -142,11 +142,18 @@ pub fn update_player_movement( // Update the player's breath game_core.player.breath_percent = - (game_core.player.breath_percent - BREATH_DECREASE_PER_SECOND * dt as f32).clamp(0.0, 1.0); + (game_core.player.breath_percent - BREATH_DECREASE_PER_SECOND * dt as f32).max(0.0); // Only do this if the mouse is far enough away let player_stunned = game_core.player.stun_timer > 0.0; let mut player_real_movement = game_core.player.direction * speed_multiplier; + + // 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; + } + + // Handle movement and collisions if raw_movement_direction.distance_to(Vector2::zero()) > game_core.player.size.y / 2.0 && !game_core.player.is_stunned() { diff --git a/src/logic/shop/item.rs b/src/logic/shop/item.rs index 1bddfd2..2c94f3b 100644 --- a/src/logic/shop/item.rs +++ b/src/logic/shop/item.rs @@ -62,6 +62,10 @@ impl ShopItemWrapper { 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()); + } + pub fn render(&mut self, draw_handle: &mut RaylibDrawHandle, player: &Player) { self.ui.render(draw_handle, self.bounds, self.can_player_afford(player)); } diff --git a/src/logic/shop/mainui.rs b/src/logic/shop/mainui.rs index 03d0b46..759da23 100644 --- a/src/logic/shop/mainui.rs +++ b/src/logic/shop/mainui.rs @@ -1,6 +1,10 @@ use raylib::prelude::*; -use crate::{gamecore::{GameCore, GameState}, items::{AirBag, Flashlight, Flippers, ItemBase, StunGun}, lib::{utils::button::OnScreenButton, wrappers::audio::player::AudioPlayer}}; +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}; @@ -89,23 +93,83 @@ pub fn render_shop( flippers_buy_ui.render(draw_handle, &game_core.player); // Handle buying items - if stun_gun_buy_ui.can_player_afford(&game_core.player) && stun_gun_buy_ui.user_clicked_buy(draw_handle) { + if stun_gun_buy_ui.can_player_afford(&game_core.player) + && stun_gun_buy_ui.user_clicked_buy(draw_handle) + { let item = stun_gun_buy_ui.purchase(&mut game_core.player); game_core.player.inventory.stun_gun = Some(item); } - if air_bag_buy_ui.can_player_afford(&game_core.player) && air_bag_buy_ui.user_clicked_buy(draw_handle) { + if air_bag_buy_ui.can_player_afford(&game_core.player) + && air_bag_buy_ui.user_clicked_buy(draw_handle) + { 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) && flashlight_buy_ui.user_clicked_buy(draw_handle) { + if flashlight_buy_ui.can_player_afford(&game_core.player) + && flashlight_buy_ui.user_clicked_buy(draw_handle) + { let item = flashlight_buy_ui.purchase(&mut game_core.player); game_core.player.inventory.flashlight = Some(item); } - if flippers_buy_ui.can_player_afford(&game_core.player) && flippers_buy_ui.user_clicked_buy(draw_handle) { + if flippers_buy_ui.can_player_afford(&game_core.player) + && flippers_buy_ui.user_clicked_buy(draw_handle) + { let item = flippers_buy_ui.purchase(&mut game_core.player); game_core.player.inventory.flippers = Some(item); } + // Render the tooltip box + let hovering_stun_gun = stun_gun_buy_ui.user_hovering_row(draw_handle); + let hovering_air_bag = air_bag_buy_ui.user_hovering_row(draw_handle); + let hovering_flashlight = flashlight_buy_ui.user_hovering_row(draw_handle); + let hovering_flippers = flippers_buy_ui.user_hovering_row(draw_handle); + let should_show_tooltip = + hovering_stun_gun || hovering_air_bag || hovering_flashlight || hovering_flippers; + + if should_show_tooltip { + // Create bounds + let box_bounds = Rectangle { + x: bounds.x + 5.0, + y: bounds.y + 350.0, + width: bounds.width - 10.0, + height: 250.0, + }; + + // Get the hovered item + let hovered_item: &dyn ItemBase; + if hovering_stun_gun { + hovered_item = stun_gun_buy_ui.get_item(); + } else if hovering_air_bag { + hovered_item = air_bag_buy_ui.get_item(); + } else if hovering_flashlight { + hovered_item = flashlight_buy_ui.get_item(); + } else { + hovered_item = flippers_buy_ui.get_item(); + } + + // Draw background box + draw_handle.draw_rectangle_rec(box_bounds, Color::WHITE); + draw_handle.draw_rectangle_lines_ex(box_bounds, 3, Color::BLACK); + + // TODO: draw item sprite + draw_handle.draw_rectangle_v( + Vector2 { + x: box_bounds.x + (box_bounds.width / 2.0) - 40.0, + y: box_bounds.y + 10.0, + }, + Vector2 { x: 80.0, y: 80.0 }, + Color::BLACK, + ); + + // Render item description + draw_handle.draw_text( + &hovered_item.get_description(), + box_bounds.x as i32 + 10, + box_bounds.y as i32 + 100, + 30, + Color::BLACK, + ); + } // Handle exit buttons let bottom_left_button_dimensions = Rectangle { @@ -115,7 +179,7 @@ pub fn render_shop( height: 40.0, }; let bottom_right_button_dimensions = Rectangle { - x: (bounds.x + bottom_left_button_dimensions.width ) + 15.0, + x: (bounds.x + bottom_left_button_dimensions.width) + 15.0, y: bottom_left_button_dimensions.y, width: bottom_left_button_dimensions.width, height: bottom_left_button_dimensions.height, @@ -146,10 +210,11 @@ pub fn render_shop( // Handle click actions on the buttons if draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON) { - // Handle saving core state - if menu_button.is_hovered(draw_handle) || play_button.is_hovered(draw_handle) { - let new_progress = game_core.player.create_statistics(game_core, draw_handle.get_time()); + if menu_button.is_hovered(draw_handle) || play_button.is_hovered(draw_handle) { + let new_progress = game_core + .player + .create_statistics(game_core, draw_handle.get_time()); game_core.progress.update(&new_progress); } diff --git a/src/logic/shop/mod.rs b/src/logic/shop/mod.rs index 0013b5a..9885e04 100644 --- a/src/logic/shop/mod.rs +++ b/src/logic/shop/mod.rs @@ -1,6 +1,6 @@ -mod mainui; -mod itemui; mod item; +mod itemui; +mod mainui; use raylib::prelude::*; @@ -26,42 +26,6 @@ impl ShopScreen { ..Default::default() } } - - // // Creates all the items - // pub fn create_items(&mut self, screen_dimension: Vector2) { - // // gets every item.. hacky - // let items = ShopItems::get_inital_items(); - - // // sets sizes any random number is just a number I think looks good - // let screen_width = screen_dimension.x as f32; - // let screen_height = screen_dimension.y as f32; - - // let box_height = screen_height * 0.15; - // let box_width = screen_width * 0.1; - - // let start_width = screen_width - (box_width * 4.0) - 40.0; - // let draw_height = screen_height - 20.0 - box_height; - - // let mut item_vec = Vec::new(); - - // for box_num in 0..4 { - // let x_pose = start_width + box_width * box_num as f32; - - // // adds an item struct to the item list - // item_vec.push(Item { - // x_pose: ((x_pose + (5 * box_num) as f32) as i32), - // y_pose: (draw_height as i32), - // width: (box_width as i32), - // height: (box_height as i32), - // // Crazy hacky but this gets the data from the enum - // cost: (ShopItems::get_cost(&items.get(box_num).unwrap())), - // level: (ShopItems::get_level(&items.get(box_num).unwrap())), - // name: (ShopItems::get_name(&items.get(box_num).unwrap())), - // }); - // } - - // self.shop_items = item_vec; - // } } impl Screen for ShopScreen { @@ -73,8 +37,7 @@ impl Screen for ShopScreen { 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); @@ -97,8 +60,7 @@ impl Screen for ShopScreen { }; // Render the shop UI - let next_state = - render_shop(draw_handle, thread, audio_system, game_core, shop_ui_bounds); + let next_state = render_shop(draw_handle, thread, audio_system, game_core, shop_ui_bounds); // Render the stats UI render_stats(draw_handle, game_core, stats_ui_bounds); @@ -106,134 +68,3 @@ impl Screen for ShopScreen { return next_state; } } -// pub fn render_shop( -// draw_handle: &mut RaylibDrawHandle, -// game_core: &mut GameCore, -// inGameScreen: &mut InGameScreen, -// ) { -// // Pressing F exits from buying -// if draw_handle.is_key_pressed(KeyboardKey::KEY_F) { -// inGameScreen.current_state = InGameState::SWIMMING; -// } - -// let mouse_position = draw_handle.get_mouse_position(); - -// draw_handle.draw_text( -// &format!("Coins: {}", game_core.player.coins), -// 15, -// 15, -// 30, -// Color::WHITE, -// ); - -// // Draws shop boxes -// for mut item in inGameScreen.shop.shop_items.iter_mut() { -// // If hovering on square draw full -// if mouse_position.x >= item.x_pose as f32 -// && mouse_position.x <= item.x_pose as f32 + item.width as f32 -// && mouse_position.y >= item.y_pose as f32 -// && mouse_position.y <= item.y_pose as f32 + item.width as f32 -// { -// // Draw rect -// draw_handle.draw_rectangle( -// item.x_pose, -// item.y_pose, -// item.width, -// item.height, -// Color::BLACK, -// ); - -// // Preform purchasing functions -// if draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON) -// && game_core.player.coins >= item.cost as u32 -// { -// // Remove currency -// game_core.world.spend_coins(item.cost.into()); -// game_core.player.coins -= item.cost as u32; - -// // Upgrade item in inventory -// match &(item.name)[..] { -// "Stun Gun" => { -// match item.level { -// 0 => game_core.player.inventory.stun_gun = Some(items::StunGun::lvl1()), -// 1 => game_core.player.inventory.stun_gun = Some(items::StunGun::lvl2()), -// 2 => game_core.player.inventory.stun_gun = Some(items::StunGun::lvl3()), -// _ => (return), -// }; -// item.cost += 5; -// item.level += 1; -// } -// "Air Bag" => { -// match item.level { -// 0 => { -// game_core.player.inventory.air_bag = Some(items::AirBag::lvl1()); -// } -// 1 => { -// game_core.player.inventory.air_bag = Some(items::AirBag::lvl2()); -// } -// 2 => { -// game_core.player.inventory.air_bag = Some(items::AirBag::lvl3()); -// } -// _ => (return), -// }; -// item.cost += 5; -// item.level += 1; -// } -// "Flash Light" => { -// match item.level { -// 0 => { -// game_core.player.inventory.flashlight = -// Some(items::Flashlight::lvl1()); -// } -// 1 => { -// game_core.player.inventory.flashlight = -// Some(items::Flashlight::lvl2()); -// } -// 2 => { -// game_core.player.inventory.flashlight = -// Some(items::Flashlight::lvl3()); -// } -// _ => (return), -// }; -// item.cost += 5; -// item.level += 1; -// } -// "Flippers" => { -// match item.level { -// 0 => { -// game_core.player.inventory.flippers = Some(items::Flippers::lvl1()); -// } -// 1 => { -// game_core.player.inventory.flippers = Some(items::Flippers::lvl2()); -// } -// 2 => { -// game_core.player.inventory.flippers = Some(items::Flippers::lvl3()); -// } -// _ => (return), -// }; -// item.cost += 5; -// item.level += 1; -// } -// _ => (return), -// }; -// } -// } else { -// // outlines if not hovered -// draw_handle.draw_rectangle_lines( -// item.x_pose, -// item.y_pose, -// item.width, -// item.height, -// Color::BLACK, -// ); -// } -// // Draw text about object -// draw_handle.draw_text( -// &format!("{}: ${}", item.name, item.cost), -// item.x_pose + 5, -// item.y_pose + 5, -// 12, -// Color::BLACK, -// ); -// } -// } diff --git a/src/player.rs b/src/player.rs index 48fcdbe..0a78a20 100644 --- a/src/player.rs +++ b/src/player.rs @@ -66,6 +66,11 @@ impl Player { self.position = position; self.breath_percent = 1.0; self.boost_percent = 1.0; + + // Handle an air bag being used + if self.inventory.air_bag.is_some() { + self.breath_percent += self.inventory.air_bag.as_ref().unwrap().extra_oxygen; + } } pub fn collides_with_rec(&self, rectangle: &Rectangle) -> bool { diff --git a/src/resources.rs b/src/resources.rs index 4dfe7c7..ee128e5 100644 --- a/src/resources.rs +++ b/src/resources.rs @@ -17,6 +17,10 @@ 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, // Cave pub cave_mid_layer: Texture2D, @@ -80,6 +84,24 @@ impl GlobalResources { 4, 100 / 8, ), + fish_animation_idle: FrameAnimationWrapper::new( + raylib.load_texture_from_image( + &thread, + &Image::load_image("./assets/img/map/fishStill.png")?, + )?, + Vector2 { x: 13.0, y: 9.0 }, + 14, + 30, + ), + fish_animation_swim: FrameAnimationWrapper::new( + raylib.load_texture_from_image( + &thread, + &Image::load_image("./assets/img/map/fish.png")?, + )?, + Vector2 { x: 13.0, y: 9.0 }, + 63, + 30, + ), cave_mid_layer: raylib.load_texture_from_image( &thread, &Image::load_image("./assets/img/map/cave.png")?,