Skip to content

Commit

Permalink
Cleanup (#197)
Browse files Browse the repository at this point in the history
* remove unwrap from sprite_animation_system

* remove * import and exports from assets module

* add comment to change_bg_music_system

* remove unused star explode system

* rename screen shake systems add comments

* remove star imports and collision module, limit visibility of collision systems

* remove * imports from run module

* remove * imports and some warnings from spawnable module

* remove * export of mob module from spawnable

* remove * imports from arena module, limit visibility of exports

* comment assets module

* limit visibility of exports from modules
  • Loading branch information
cdsupina authored Oct 5, 2024
1 parent 850c4dc commit 931bc21
Show file tree
Hide file tree
Showing 40 changed files with 324 additions and 191 deletions.
70 changes: 38 additions & 32 deletions src/animation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use bevy::{
schedule::IntoSystemConfigs,
system::{Query, Res},
},
prelude::error,
sprite::{TextureAtlas, TextureAtlasLayout},
state::condition::in_state,
time::{Time, Timer},
Expand Down Expand Up @@ -84,43 +85,48 @@ fn animate_sprite_system(
// check if frame has completed
if animation.timer.finished() {
// get the texture atlas
let texture_atlas_layout = texture_atlas_layouts
.get(texture_atlas.layout.id())
.unwrap();

// update animation based on the animation direction
match &animation.direction {
AnimationDirection::None => {}
AnimationDirection::Forward => {
let new_idx = (texture_atlas.index + 1) % texture_atlas_layout.textures.len();
if new_idx == 0 {
animation_complete_event_writer.send(AnimationCompletedEvent(entity));
}
texture_atlas.index = new_idx;
}
AnimationDirection::PingPong(direction) => match direction {
PingPongDirection::Forward => {
if texture_atlas.index < (texture_atlas_layout.textures.len() - 1) {
texture_atlas.index += 1;
}

if texture_atlas.index == (texture_atlas_layout.textures.len() - 1) {
animation.direction =
AnimationDirection::PingPong(PingPongDirection::Backward)
if let Some(texture_atlas_layout) = texture_atlas_layouts.get(texture_atlas.layout.id())
{
// update animation based on the animation direction
match &animation.direction {
AnimationDirection::None => {}
AnimationDirection::Forward => {
let new_idx =
(texture_atlas.index + 1) % texture_atlas_layout.textures.len();
if new_idx == 0 {
animation_complete_event_writer.send(AnimationCompletedEvent(entity));
}
texture_atlas.index = new_idx;
}
PingPongDirection::Backward => {
if texture_atlas.index > 0 {
texture_atlas.index -= 1;
AnimationDirection::PingPong(direction) => match direction {
PingPongDirection::Forward => {
if texture_atlas.index < (texture_atlas_layout.textures.len() - 1) {
texture_atlas.index += 1;
}

if texture_atlas.index == (texture_atlas_layout.textures.len() - 1) {
animation.direction =
AnimationDirection::PingPong(PingPongDirection::Backward)
}
}
PingPongDirection::Backward => {
if texture_atlas.index > 0 {
texture_atlas.index -= 1;
}

if texture_atlas.index == 0 {
animation.direction =
AnimationDirection::PingPong(PingPongDirection::Forward)
if texture_atlas.index == 0 {
animation.direction =
AnimationDirection::PingPong(PingPongDirection::Forward)
}
}
}
},
};
},
};
} else {
error!(
"Could not get texture atlas layout for id: {}.",
texture_atlas.layout.id()
);
}
}
}
}
4 changes: 3 additions & 1 deletion src/arena/barrier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use crate::{game::GameParametersResource, spawnable::SpawnEffectEvent};
use bevy::prelude::{
Commands, Component, EventWriter, Name, Quat, Res, Transform, TransformBundle, Vec2, Vec3,
};
use bevy_rapier2d::prelude::*;
use bevy_rapier2d::prelude::{
ActiveEvents, Collider, CollisionGroups, Friction, Group, Restitution, RigidBody,
};
use std::f32::consts::FRAC_PI_2;
use thetawave_interface::{spawnable::EffectType, states::GameCleanup};

Expand Down
14 changes: 12 additions & 2 deletions src/arena/gate.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
use crate::spawnable::{MobComponent, MobSegmentComponent, SpawnableComponent};
use bevy::prelude::*;
use bevy_rapier2d::{prelude::*, rapier::prelude::CollisionEventFlags};
use bevy::{
core::Name,
math::Vec2,
prelude::{
Commands, Component, DespawnRecursiveExt, Entity, EventReader, EventWriter, Query,
Transform, TransformBundle, With,
},
};
use bevy_rapier2d::{
prelude::{Collider, CollisionEvent, Sensor},
rapier::prelude::CollisionEventFlags,
};
use thetawave_interface::{objective::MobReachedBottomGateEvent, states::GameCleanup};

/// Tag for the gate that triggers mobs to respawn (and cause something bad to happen to the
Expand Down
9 changes: 7 additions & 2 deletions src/arena/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
//! Exposes a plugin that renders a rectangular boundary that the player cannot cross, but mobs
//! can. Also handles sending events when mobs reach the botton of the screen.

use bevy::prelude::*;
use barrier::spawn_barriers_system;
use bevy::{
app::{App, Plugin, Update},
prelude::{in_state, IntoSystemConfigs, OnEnter},
};
use thetawave_interface::{objective::MobReachedBottomGateEvent, states};
mod barrier;
mod gate;

use crate::GameEnterSet;

pub use self::barrier::*;
use self::gate::{despawn_gates_system, spawn_despawn_gates_system};

pub(crate) use self::barrier::ArenaBarrierComponent;

/// Plugin that spawns a rectangular boundary for the main game play area and fires off
/// `MobReachedBottomGateEvent` at the right times
pub(super) struct ArenaPlugin;
Expand Down
17 changes: 12 additions & 5 deletions src/assets/audio.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use bevy::prelude::*;
use bevy_asset_loader::prelude::*;
use bevy::{
asset::Handle,
prelude::{Res, Resource},
};
use bevy_asset_loader::asset_collection::AssetCollection;
use bevy_kira_audio::AudioSource;
use rand::Rng;
use thetawave_interface::audio::{BGMusicType, CollisionSoundType, SoundEffectType};

/// Collection of all audio assets in the game including sound effects and background music
#[derive(AssetCollection, Resource)]
pub struct GameAudioAssets {
pub(crate) struct GameAudioAssets {
#[asset(key = "sounds.main_music")]
pub main_music: Handle<AudioSource>,
#[asset(key = "sounds.game_music")]
Expand Down Expand Up @@ -69,7 +73,8 @@ pub struct GameAudioAssets {
}

impl GameAudioAssets {
pub fn get_bg_music_asset(&self, bg_music_type: &BGMusicType) -> Handle<AudioSource> {
/// Use a BGMusicType enum to access a handle for a track of music
pub(crate) fn get_bg_music_asset(&self, bg_music_type: &BGMusicType) -> Handle<AudioSource> {
match bg_music_type {
BGMusicType::Game => self.game_music.clone(),
BGMusicType::Boss => self.boss_music.clone(),
Expand All @@ -78,7 +83,9 @@ impl GameAudioAssets {
}
}

pub fn get_sound_effect(&self, sound_type: &SoundEffectType) -> Handle<AudioSource> {
/// Use a SoundEffectType enum to access a handle for a sound effect
/// Sound effects that produced a randomized sound will we return a random effect from a subset
pub(crate) fn get_sound_effect(&self, sound_type: &SoundEffectType) -> Handle<AudioSource> {
match sound_type {
SoundEffectType::Collision(collsion_type) => match collsion_type {
CollisionSoundType::Squishy => self.squishy_collision.clone(),
Expand Down
9 changes: 6 additions & 3 deletions src/assets/consumable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use bevy_asset_loader::prelude::AssetCollection;

use thetawave_interface::spawnable::ConsumableType;

/// Collection of texture atlases and images for consumable sprites
#[derive(AssetCollection, Resource)]
pub struct ConsumableAssets {
pub(crate) struct ConsumableAssets {
#[asset(key = "health_wrench.layout")]
pub health_wrench_layout: Handle<TextureAtlasLayout>,
#[asset(key = "health_wrench.image")]
Expand All @@ -31,7 +32,8 @@ pub struct ConsumableAssets {
}

impl ConsumableAssets {
pub fn get_texture_atlas_layout(
/// Use a ConsumableType enum to access a texture atlas layout
pub(crate) fn get_texture_atlas_layout(
&self,
consumable_type: &ConsumableType,
) -> Handle<TextureAtlasLayout> {
Expand All @@ -44,7 +46,8 @@ impl ConsumableAssets {
}
}

pub fn get_image(&self, consumable_type: &ConsumableType) -> Handle<Image> {
/// Use a ConsumableType enum to access an image handle
pub(crate) fn get_image(&self, consumable_type: &ConsumableType) -> Handle<Image> {
match consumable_type {
ConsumableType::Money1 => self.money1_image.clone(),
ConsumableType::Money3 => self.money3_image.clone(),
Expand Down
11 changes: 8 additions & 3 deletions src/assets/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use bevy_asset_loader::prelude::AssetCollection;

use thetawave_interface::spawnable::EffectType;

/// Collection of texture atlases and images for effect sprites
#[derive(AssetCollection, Resource)]
pub struct EffectAssets {
pub(crate) struct EffectAssets {
#[asset(key = "ally_blast_explosion.layout")]
pub ally_blast_explosion_layout: Handle<TextureAtlasLayout>,
#[asset(key = "ally_blast_explosion.image")]
Expand Down Expand Up @@ -52,7 +53,9 @@ pub struct EffectAssets {
}

impl EffectAssets {
pub fn get_texture_atlas_layout(
/// Use a EffectType enum to access a texture atlas layout
/// Option because a Text effect doesn't have a texture atlas
pub(crate) fn get_texture_atlas_layout(
&self,
effect_type: &EffectType,
) -> Option<Handle<TextureAtlasLayout>> {
Expand All @@ -72,7 +75,9 @@ impl EffectAssets {
}
}

pub fn get_image(&self, effect_type: &EffectType) -> Option<Handle<Image>> {
/// Use a EffectType enum to access an image handle
/// Option because a Text effect doesn't have an image
pub(crate) fn get_image(&self, effect_type: &EffectType) -> Option<Handle<Image>> {
match effect_type {
EffectType::AllyBlastExplosion => Some(self.ally_blast_explosion_image.clone()),
EffectType::AllyBlastDespawn => Some(self.ally_blast_despawn_image.clone()),
Expand Down
12 changes: 9 additions & 3 deletions src/assets/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ use bevy_asset_loader::prelude::AssetCollection;

use thetawave_interface::spawnable::ItemType;

/// Collection of texture atlases and images for item sprites
#[derive(AssetCollection, Resource)]
pub struct ItemAssets {
pub(crate) struct ItemAssets {
#[asset(key = "item_placeholder.layout")]
pub item_placeholder_layout: Handle<TextureAtlasLayout>,
#[asset(key = "item_placeholder.image")]
pub item_placeholder_image: Handle<Image>,
}

impl ItemAssets {
pub fn get_texture_atlas_layout(&self, item_type: &ItemType) -> Handle<TextureAtlasLayout> {
/// Use a ItemType enum to access a texture atlas layout
pub(crate) fn get_texture_atlas_layout(
&self,
item_type: &ItemType,
) -> Handle<TextureAtlasLayout> {
match item_type {
ItemType::EnhancedPlating => self.item_placeholder_layout.clone(),
/*
Expand All @@ -37,7 +42,8 @@ impl ItemAssets {
}
}

pub fn get_image(&self, item_type: &ItemType) -> Handle<Image> {
/// Use a ItemType enum to access an item image handle
pub(crate) fn get_image(&self, item_type: &ItemType) -> Handle<Image> {
match item_type {
ItemType::EnhancedPlating => self.item_placeholder_image.clone(),
}
Expand Down
26 changes: 19 additions & 7 deletions src/assets/mob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use thetawave_interface::spawnable::{
NeutralMobType,
};

/// Collection of texture atlases and images for mob and mob segment sprites
#[derive(AssetCollection, Resource)]
pub struct MobAssets {
pub(crate) struct MobAssets {
#[asset(key = "tutorial_drone.layout")]
pub tutorial_drone_layout: Handle<TextureAtlasLayout>,
#[asset(key = "tutorial_drone.image")]
Expand Down Expand Up @@ -193,7 +194,11 @@ pub struct MobAssets {
}

impl MobAssets {
pub fn get_mob_texture_atlas_layout(&self, mob_type: &MobType) -> Handle<TextureAtlasLayout> {
/// Use a MobType enum to access a texture atlas layout
pub(crate) fn get_mob_texture_atlas_layout(
&self,
mob_type: &MobType,
) -> Handle<TextureAtlasLayout> {
match mob_type {
MobType::Enemy(enemy_type) => match enemy_type {
EnemyMobType::Pawn => self.pawn_layout.clone(),
Expand Down Expand Up @@ -223,7 +228,8 @@ impl MobAssets {
}
}

pub fn get_mob_image(&self, mob_type: &MobType) -> Handle<Image> {
/// Use a MobType enum to access an image handle
pub(crate) fn get_mob_image(&self, mob_type: &MobType) -> Handle<Image> {
match mob_type {
MobType::Enemy(enemy_type) => match enemy_type {
EnemyMobType::Pawn => self.pawn_image.clone(),
Expand Down Expand Up @@ -253,7 +259,8 @@ impl MobAssets {
}
}

pub fn get_mob_segment_texture_atlas_layout(
/// Use a MobSegmentType enum to access a texture atlas layout
pub(crate) fn get_mob_segment_texture_atlas_layout(
&self,
mob_segment_type: &MobSegmentType,
) -> Handle<TextureAtlasLayout> {
Expand Down Expand Up @@ -324,7 +331,8 @@ impl MobAssets {
}
}

pub fn get_mob_segment_image(&self, mob_segment_type: &MobSegmentType) -> Handle<Image> {
/// Use a MobSegmentType enum to access an image handle
pub(crate) fn get_mob_segment_image(&self, mob_segment_type: &MobSegmentType) -> Handle<Image> {
match mob_segment_type {
MobSegmentType::Neutral(neutral_type) => match neutral_type {
NeutralMobSegmentType::HaulerBack => self.hauler_back_image.clone(),
Expand Down Expand Up @@ -390,7 +398,9 @@ impl MobAssets {
}
}

pub fn get_thruster_texture_atlas_layout(
/// Use a MobType enum to access its associated thruster's texture atlas layout
/// Returns an option due to some mobs not having an thruster
pub(crate) fn get_thruster_texture_atlas_layout(
&self,
mob_type: &MobType,
) -> Option<Handle<TextureAtlasLayout>> {
Expand Down Expand Up @@ -423,7 +433,9 @@ impl MobAssets {
}
}

pub fn get_thruster_image(&self, mob_type: &MobType) -> Option<Handle<Image>> {
/// Use a MobType enum to access its associated thruster's image
/// Returns an option due to some mobs not having an thruster
pub(crate) fn get_thruster_image(&self, mob_type: &MobType) -> Option<Handle<Image>> {
match mob_type {
MobType::Enemy(enemy_type) => match enemy_type {
EnemyMobType::Pawn => Some(self.pawn_thruster_image.clone()),
Expand Down
5 changes: 3 additions & 2 deletions src/assets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod player;
mod projectile;
mod ui;

pub use self::{
audio::*, consumable::*, effect::*, item::*, mob::*, player::*, projectile::*, ui::*,
pub(crate) use self::{
audio::GameAudioAssets, consumable::ConsumableAssets, effect::EffectAssets, item::ItemAssets,
mob::MobAssets, player::PlayerAssets, projectile::ProjectileAssets, ui::UiAssets,
};
9 changes: 6 additions & 3 deletions src/assets/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use bevy::prelude::{Handle, Image, Res, Resource};
use bevy_asset_loader::prelude::AssetCollection;
use thetawave_interface::character::CharacterType;

/// Collection of images for player characters
#[derive(AssetCollection, Resource)]
pub struct PlayerAssets {
pub(crate) struct PlayerAssets {
#[asset(key = "captain")]
pub captain: Handle<Image>,
#[asset(key = "juggernaut")]
Expand All @@ -15,14 +16,16 @@ pub struct PlayerAssets {
}

impl PlayerAssets {
pub fn get_asset(&self, character_type: &CharacterType) -> Handle<Image> {
/// Use a CharacterType enum to access an image handle
pub(crate) fn get_asset(&self, character_type: &CharacterType) -> Handle<Image> {
match character_type {
CharacterType::Captain => self.captain.clone(),
CharacterType::Juggernaut => self.juggernaut.clone(),
}
}

pub fn get_outline_asset(&self, character_type: &CharacterType) -> Handle<Image> {
/// Use a CharacterType enum to access a character's associated outline image handle
pub(crate) fn get_outline_asset(&self, character_type: &CharacterType) -> Handle<Image> {
match character_type {
CharacterType::Captain => self.captain_outline.clone(),
CharacterType::Juggernaut => self.juggernaut_outline.clone(),
Expand Down
Loading

0 comments on commit 931bc21

Please sign in to comment.