-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
171: Implement first version of camera stopping r=zicklag a=64kramsystem Define points in the levels, where all the enemies (spawned) until then must be defeated before continuing. The camera logic needs refinements (extra complexity) because for example, as of now, when there is a stop point, the players can't cross it, leaving a small part of the screen unusable by them. Includes a refactoring: created the new bundle ActiveFighterBundle, and extracted fighter activation into a method of this type. Closes #97 (will refine in a separate issue). Depends on #99. Co-authored-by: Saverio Miroddi <[email protected]>
- Loading branch information
Showing
9 changed files
with
197 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use bevy::prelude::*; | ||
use bevy_rapier2d::prelude::CollisionGroups; | ||
use rand::prelude::SliceRandom; | ||
|
||
use crate::{ | ||
animation::Animation, collisions::BodyLayers, enemy::Enemy, metadata::FighterMeta, | ||
player::Player, AnimatedSpriteSheetBundle, CharacterBundle, PhysicsBundle, | ||
}; | ||
|
||
/// Bundle added to a fighter stub, in order to activate it. | ||
#[derive(Bundle)] | ||
pub struct ActiveFighterBundle { | ||
name: Name, | ||
#[bundle] | ||
animated_spritesheet_bundle: AnimatedSpriteSheetBundle, | ||
#[bundle] | ||
character_bundle: CharacterBundle, | ||
#[bundle] | ||
physics_bundle: PhysicsBundle, | ||
} | ||
|
||
/// Turns a fighter stub data (loaded from the metadata) into a fully active fighter. | ||
impl ActiveFighterBundle { | ||
pub fn activate_fighter_stub( | ||
commands: &mut Commands, | ||
fighter: &FighterMeta, | ||
entity: Entity, | ||
transform: &Transform, | ||
player: Option<&Player>, | ||
enemy: Option<&Enemy>, | ||
) { | ||
let body_layers = if player.is_some() { | ||
BodyLayers::PLAYER | ||
} else if enemy.is_some() { | ||
BodyLayers::ENEMY | ||
} else { | ||
unreachable!(); | ||
}; | ||
|
||
let active_fighter_bundle = ActiveFighterBundle { | ||
name: Name::new(fighter.name.clone()), | ||
animated_spritesheet_bundle: AnimatedSpriteSheetBundle { | ||
sprite_sheet: SpriteSheetBundle { | ||
sprite: TextureAtlasSprite::new(0), | ||
texture_atlas: fighter | ||
.spritesheet | ||
.atlas_handle | ||
.choose(&mut rand::thread_rng()) | ||
.unwrap() | ||
.clone(), | ||
transform: *transform, | ||
..Default::default() | ||
}, | ||
animation: Animation::new( | ||
fighter.spritesheet.animation_fps, | ||
fighter.spritesheet.animations.clone(), | ||
), | ||
}, | ||
character_bundle: CharacterBundle { | ||
stats: fighter.stats.clone(), | ||
..default() | ||
}, | ||
physics_bundle: PhysicsBundle { | ||
collision_groups: CollisionGroups::new(body_layers, BodyLayers::ALL), | ||
..default() | ||
}, | ||
}; | ||
|
||
commands.entity(entity).insert_bundle(active_fighter_bundle); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ mod collisions; | |
mod config; | ||
mod consts; | ||
mod enemy; | ||
mod fighter; | ||
mod input; | ||
mod item; | ||
mod loading; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.