Skip to content

Commit

Permalink
Merge pull request #222 from fishfolks/boss-mvp
Browse files Browse the repository at this point in the history
Rebase Boss MVP by @edgarssilva
  • Loading branch information
edgarssilva authored Aug 11, 2022
2 parents 7e2f603 + 17c7c7f commit 4adbe2d
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 17 deletions.
3 changes: 2 additions & 1 deletion assets/beach/beach.level.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ enemies:
- fighter: *brute
location: [450, 20, 0]
trip_point_x: 300
- fighter: *brute
- fighter: /fighters/big_bass/big_bass.fighter.yaml
location: [1000, 20, 0]
trip_point_x: 700
boss: true

stop_points: [500, 1000]

Expand Down
Binary file added assets/fighters/big_bass/BigBass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions assets/fighters/big_bass/big_bass.fighter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Bandit

stats:
max_health: 350
damage: 35
movement_speed: 75

hud:
portrait:
image: portrait.png
image_size: [35, 35]

spritesheet:
image: [BigBass.png]
tile_size: [156, 176]
columns: 15
rows: 3

animation_fps: 0.12
animations:
idle:
frames: [0, 3]
repeat: true
running:
frames: [15, 24]
repeat: true
knocked_right:
frames: [0, 3]
knocked_left:
frames: [0, 3]
dying:
frames: [0, 3]
waiting:
frames: [0, 3]
repeat: false
attacking:
frames: [30, 44]

audio:
effects:
attacking:
16: hit.ogg
Binary file added assets/fighters/big_bass/hit.ogg
Binary file not shown.
Binary file added assets/fighters/big_bass/portrait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/enemy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ use crate::{
#[derive(Component)]
pub struct Enemy;

/// Temporary marker component used to differentiate bosses from other fighters.
#[derive(Component)]
pub struct Boss;

/// X coordinate of the level that requires to be trespassed in order for the enemies to move.
/// For simplicy, once a given trip point is trespassed for the first time, it's set to f32::MIN.
#[derive(Component)]
Expand Down
143 changes: 130 additions & 13 deletions src/fighter_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
collision::BodyLayers,
consts,
damage::{DamageEvent, Health},
enemy::Enemy,
enemy::{Boss, Enemy},
enemy_ai,
fighter::Inventory,
input::PlayerAction,
Expand Down Expand Up @@ -66,6 +66,7 @@ impl Plugin for FighterStatePlugin {
.run_in_state(GameState::InGame)
.with_system(idling)
.with_system(attacking)
.with_system(boss_attacking)
.with_system(moving)
.with_system(throwing)
.with_system(grabbing)
Expand Down Expand Up @@ -441,18 +442,21 @@ fn idling(mut fighters: Query<(&mut Animation, &mut LinearVelocity), With<Idling
/// > based on the attacks available to that fighter.
fn attacking(
mut commands: Commands,
mut fighters: Query<(
Entity,
&mut Animation,
&mut Transform,
&mut LinearVelocity,
&Facing,
&Stats,
&Handle<FighterMeta>,
&mut Attacking,
Option<&Player>,
Option<&Enemy>,
)>,
mut fighters: Query<
(
Entity,
&mut Animation,
&mut Transform,
&mut LinearVelocity,
&Facing,
&Stats,
&Handle<FighterMeta>,
&mut Attacking,
Option<&Player>,
Option<&Enemy>,
),
Without<Boss>,
>,
fighter_assets: Res<Assets<FighterMeta>>,
) {
for (
Expand Down Expand Up @@ -562,6 +566,119 @@ fn attacking(
}
}

/// The attacking state used for bosses
fn boss_attacking(
mut commands: Commands,
mut fighters: Query<
(
Entity,
&mut Animation,
&mut Transform,
&mut LinearVelocity,
&Facing,
&Stats,
&Handle<FighterMeta>,
&mut Attacking,
),
With<Boss>,
>,
fighter_assets: Res<Assets<FighterMeta>>,
) {
for (
entity,
mut animation,
mut transform,
mut velocity,
facing,
stats,
meta_handle,
mut attacking,
) in &mut fighters
{
// Start the attack
if !attacking.has_started {
attacking.has_started = true;
attacking.start_y = transform.translation.y;

// Start the attack from the beginning
animation.play(Attacking::ANIMATION, false);

// Spawn the attack entity
let attack_entity = commands
.spawn_bundle(TransformBundle::default())
.insert(Sensor)
.insert(ActiveEvents::COLLISION_EVENTS)
.insert(ActiveCollisionTypes::default() | ActiveCollisionTypes::STATIC_STATIC)
.insert(CollisionGroups::new(
BodyLayers::ENEMY_ATTACK,
BodyLayers::PLAYER,
))
.insert(Attack {
damage: stats.damage,
velocity: if facing.is_left() {
Vec2::NEG_X
} else {
Vec2::X
} * Vec2::new(consts::ATTACK_VELOCITY, 0.0),
})
// TODO: Read from figher metadata
.insert(AttackFrames {
startup: 5,
active: 9,
recovery: 14,
})
.id();
commands.entity(entity).push_children(&[attack_entity]);

// Play attack sound effect
if let Some(fighter) = fighter_assets.get(meta_handle) {
if let Some(effects) = fighter.audio.effect_handles.get(Attacking::ANIMATION) {
let fx_playback = AnimationAudioPlayback::new(
Attacking::ANIMATION.to_owned(),
effects.clone(),
);
commands.entity(entity).insert(fx_playback);
}
}
}

// Reset velocity
**velocity = Vec2::ZERO;

if !animation.is_finished() {
// Do a forward jump thing
//TODO: Fix hacky way to get a forward jump

// Control x movement
if animation.current_frame < 3 {
if facing.is_left() {
velocity.x -= 150.0;
} else {
velocity.x += 150.0;
}
}

// Control y movement
if animation.current_frame < 1 {
velocity.y += 270.0;
} else if animation.current_frame < 3 {
velocity.y -= 180.0;
}

// If the animation is finished
} else {
// Stop moving
**velocity = Vec2::ZERO;

// Make sure we "land on the ground" ( i.e. the player y position hasn't changed )
transform.translation.y = attacking.start_y;

// Set flopping to finished
attacking.is_finished = true;
}
}
}

/// Handle fighter moving state
fn moving(
mut commands: Commands,
Expand Down
8 changes: 6 additions & 2 deletions src/loading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rand::seq::SliceRandom;
use crate::{
animation::Animation,
config::ENGINE_CONFIG,
enemy::{Enemy, EnemyBundle},
enemy::{Boss, Enemy, EnemyBundle},
fighter::ActiveFighterBundle,
input::MenuAction,
item::ItemBundle,
Expand Down Expand Up @@ -355,7 +355,11 @@ fn load_level(

// Spawn the enemies
for enemy in &level.enemies {
commands.spawn_bundle(EnemyBundle::new(enemy));
let mut ec = commands.spawn_bundle(EnemyBundle::new(enemy));

if enemy.boss {
ec.insert(Boss);
}
}

// Spawn the items
Expand Down
2 changes: 1 addition & 1 deletion src/loading/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ macro_rules! impl_default_load_progress {
)*
};
}
impl_default_load_progress!(String, f32, usize, u32, Vec2, Vec3, UVec2, egui::TextureId);
impl_default_load_progress!(String, f32, usize, u32, Vec2, Vec3, UVec2, egui::TextureId, bool);

// Implement `HasLoadProgress` for container types
impl<T: HasLoadProgress> HasLoadProgress for Option<T> {
Expand Down
2 changes: 2 additions & 0 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ pub struct FighterSpawnMeta {
// Set only for enemies.
#[serde(default = "default_f32_min")]
pub trip_point_x: f32,
#[serde(default)]
pub boss: bool,
}

fn default_f32_min() -> f32 {
Expand Down

0 comments on commit 4adbe2d

Please sign in to comment.