Merge remote-tracking branch 'origin/master' into outofbreathscreen

This commit is contained in:
Evan Pratten 2021-04-25 13:43:35 -04:00
commit 846b75d6e5
15 changed files with 335 additions and 238 deletions

Binary file not shown.

26
assets/img/map/fish.json Normal file
View File

@ -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": [
]
}
}

BIN
assets/img/map/fish.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

View File

@ -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": [
]
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -2,7 +2,11 @@ use rand::{prelude::ThreadRng, Rng};
use raylib::prelude::*; use raylib::prelude::*;
use crate::{ 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; const FISH_FOLLOW_PLAYER_DISTANCE: f32 = 30.0;
@ -25,9 +29,11 @@ pub struct FishEntity {
direction: Vector2, direction: Vector2,
velocity: Vector2, velocity: Vector2,
pub following_player: bool, pub following_player: bool,
current_frame: u8,
animation_counter: u32,
size: Vector2, size: Vector2,
color: u8,
rng: ThreadRng, rng: ThreadRng,
color: Color,
} }
impl FishEntity { impl FishEntity {
@ -35,16 +41,16 @@ impl FishEntity {
let mut rng = rand::thread_rng(); let mut rng = rand::thread_rng();
Self { Self {
position: position, 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(), velocity: Vector2::zero(),
following_player: false, following_player: false,
animation_counter: 0,
current_frame: 0,
size: Vector2 { x: 5.0, y: 8.0 }, size: Vector2 { x: 5.0, y: 8.0 },
color: Color { color: rng.gen_range(0..6),
r: rng.gen_range(128..225),
g: rng.gen_range(128..225),
b: rng.gen_range(128..225),
a: 140,
},
rng, rng,
} }
} }
@ -138,21 +144,17 @@ impl FishEntity {
// Distance and direction to player // Distance and direction to player
let dist_to_player = player.position - self.position; let dist_to_player = player.position - self.position;
let dist_to_player_lin = self.position.distance_to(player.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 // 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.animation_counter = 0;
// Add currency to the player // Add currency to the player
player.coins += 1; 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<FishEntity>) { pub fn update_position(&mut self, player: &mut Player, dt: f64, other_fish: &Vec<FishEntity>) {
@ -163,40 +165,45 @@ impl FishEntity {
} }
} }
pub fn render(&self, context_2d: &mut RaylibMode2D<RaylibDrawHandle>) { pub fn render(
&mut self,
context_2d: &mut RaylibMode2D<RaylibDrawHandle>,
resources: &mut GlobalResources,
) {
// Direction // Direction
let direction = let direction = (Vector2::zero().angle_to(self.direction.normalized())).to_degrees();
Vector2::zero().angle_to(self.direction.normalized()) + (90.0 as f32).to_radians();
// Get the corners of the fish self.animation_counter += 1;
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,
);
// Draw the fish as a triangle with rotation // swimming
context_2d.draw_triangle( if self.following_player {
self.position + fish_front, if self.animation_counter % 3 == 0 {
self.position + fish_bl, self.current_frame += 1;
self.position + fish_br, if self.current_frame == 8 {
self.color, 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,
);
}
} }
} }

View File

@ -54,7 +54,7 @@ impl ItemBase for StunGun {
} }
fn get_description(&self) -> String { 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 { fn get_texture(&self) -> &Texture2D {
@ -67,7 +67,7 @@ impl ItemBase for StunGun {
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct AirBag { pub struct AirBag {
extra_oxygen: u32, pub extra_oxygen: f32,
pub level: u8, pub level: u8,
cost: u32, cost: u32,
} }
@ -75,21 +75,21 @@ pub struct AirBag {
impl AirBag { impl AirBag {
pub fn lvl1() -> Self { pub fn lvl1() -> Self {
Self { Self {
extra_oxygen: 15, extra_oxygen: 0.15,
level: 1, level: 1,
cost: 30, cost: 30,
} }
} }
pub fn lvl2() -> Self { pub fn lvl2() -> Self {
Self { Self {
extra_oxygen: 30, extra_oxygen: 0.30,
level: 2, level: 2,
cost: 40, cost: 40,
} }
} }
pub fn lvl3() -> Self { pub fn lvl3() -> Self {
Self { Self {
extra_oxygen: 45, extra_oxygen: 0.45,
level: 3, level: 3,
cost: 50, cost: 50,
} }
@ -106,7 +106,7 @@ impl ItemBase for AirBag {
} }
fn get_description(&self) -> String { 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 { fn get_texture(&self) -> &Texture2D {
@ -210,7 +210,7 @@ impl ItemBase for Flippers {
} }
fn get_description(&self) -> String { 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 { fn get_texture(&self) -> &Texture2D {

View File

@ -62,7 +62,7 @@ impl InGameScreen {
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); 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 // Render the world texture

View File

@ -142,11 +142,18 @@ pub fn update_player_movement(
// Update the player's breath // Update the player's breath
game_core.player.breath_percent = 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 // Only do this if the mouse is far enough away
let player_stunned = game_core.player.stun_timer > 0.0; let player_stunned = game_core.player.stun_timer > 0.0;
let mut player_real_movement = game_core.player.direction * speed_multiplier; 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 if raw_movement_direction.distance_to(Vector2::zero()) > game_core.player.size.y / 2.0
&& !game_core.player.is_stunned() && !game_core.player.is_stunned()
{ {

View File

@ -62,6 +62,10 @@ impl<T: ItemBase + Clone> ShopItemWrapper<T> {
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());
}
pub fn render(&mut self, draw_handle: &mut RaylibDrawHandle, player: &Player) { pub fn render(&mut self, draw_handle: &mut RaylibDrawHandle, player: &Player) {
self.ui.render(draw_handle, self.bounds, self.can_player_afford(player)); self.ui.render(draw_handle, self.bounds, self.can_player_afford(player));
} }

View File

@ -1,6 +1,10 @@
use raylib::prelude::*; 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}; use super::{item::ShopItemWrapper, itemui::ShopItemUi};
@ -89,23 +93,83 @@ pub fn render_shop(
flippers_buy_ui.render(draw_handle, &game_core.player); flippers_buy_ui.render(draw_handle, &game_core.player);
// Handle buying items // 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); 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);
} }
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); 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) && 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); let item = flashlight_buy_ui.purchase(&mut game_core.player);
game_core.player.inventory.flashlight = Some(item); 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); let item = flippers_buy_ui.purchase(&mut game_core.player);
game_core.player.inventory.flippers = Some(item); 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 // Handle exit buttons
let bottom_left_button_dimensions = Rectangle { let bottom_left_button_dimensions = Rectangle {
@ -115,7 +179,7 @@ pub fn render_shop(
height: 40.0, height: 40.0,
}; };
let bottom_right_button_dimensions = Rectangle { 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, y: bottom_left_button_dimensions.y,
width: bottom_left_button_dimensions.width, width: bottom_left_button_dimensions.width,
height: bottom_left_button_dimensions.height, height: bottom_left_button_dimensions.height,
@ -146,10 +210,11 @@ pub fn render_shop(
// 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) {
// Handle saving core state // Handle saving core state
if menu_button.is_hovered(draw_handle) || play_button.is_hovered(draw_handle) { 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()); let new_progress = game_core
.player
.create_statistics(game_core, draw_handle.get_time());
game_core.progress.update(&new_progress); game_core.progress.update(&new_progress);
} }

View File

@ -1,6 +1,6 @@
mod mainui;
mod itemui;
mod item; mod item;
mod itemui;
mod mainui;
use raylib::prelude::*; use raylib::prelude::*;
@ -26,42 +26,6 @@ impl ShopScreen {
..Default::default() ..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 { impl Screen for ShopScreen {
@ -74,7 +38,6 @@ impl Screen for ShopScreen {
) -> Option<GameState> { ) -> Option<GameState> {
let mouse_position = draw_handle.get_mouse_position(); 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);
@ -97,8 +60,7 @@ impl Screen for ShopScreen {
}; };
// Render the shop UI // Render the shop UI
let next_state = let next_state = render_shop(draw_handle, thread, audio_system, game_core, shop_ui_bounds);
render_shop(draw_handle, thread, audio_system, game_core, shop_ui_bounds);
// Render the stats UI // Render the stats UI
render_stats(draw_handle, game_core, stats_ui_bounds); render_stats(draw_handle, game_core, stats_ui_bounds);
@ -106,134 +68,3 @@ impl Screen for ShopScreen {
return next_state; 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,
// );
// }
// }

View File

@ -66,6 +66,11 @@ 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;
// 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 { pub fn collides_with_rec(&self, rectangle: &Rectangle) -> bool {

View File

@ -18,6 +18,10 @@ pub struct GlobalResources {
pub player_animation_boost: FrameAnimationWrapper, pub player_animation_boost: FrameAnimationWrapper,
pub player_animation_stunned: FrameAnimationWrapper, pub player_animation_stunned: FrameAnimationWrapper,
// Fish
pub fish_animation_idle: FrameAnimationWrapper,
pub fish_animation_swim: FrameAnimationWrapper,
// Cave // Cave
pub cave_mid_layer: Texture2D, pub cave_mid_layer: Texture2D,
@ -80,6 +84,24 @@ impl GlobalResources {
4, 4,
100 / 8, 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( cave_mid_layer: raylib.load_texture_from_image(
&thread, &thread,
&Image::load_image("./assets/img/map/cave.png")?, &Image::load_image("./assets/img/map/cave.png")?,