Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement first version of camera stopping #171

Merged
merged 5 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions assets/beach/beach.level.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ enemies:
- fighter: *brute
location: [450, 20, 0]
trip_point_x: 300
- fighter: *brute
location: [1000, 20, 0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this brute need a trip point specified?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right! It got lost in a rebase conflict 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been there 😄

I've done a lot of ugly rebases in the past.

trip_point_x: 700

stop_points: [500, 1000]

items:
- item: &bottle /items/bottle/bottle.item.yaml
Expand Down
Binary file added history/history.db
Binary file not shown.
12 changes: 4 additions & 8 deletions src/attack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ use crate::{
},
input::PlayerAction,
item::item_carried_by_player,
metadata::{FighterMeta, GameMeta, ItemMeta},
movement::{
clamp_player_movements, LeftMovementBoundary, MoveInArc, MoveInDirection, Rotate, Target,
},
metadata::{FighterMeta, ItemMeta},
movement::{MoveInArc, MoveInDirection, PlayerMovementClamper, Rotate, Target},
state::State,
ArrivedEvent, Enemy, GameState, Player, Stats,
};
Expand Down Expand Up @@ -297,10 +295,9 @@ fn player_flop(
),
With<Player>,
>,
player_movement_clamper: PlayerMovementClamper,
fighter_assets: Res<Assets<FighterMeta>>,
time: Res<Time>,
left_movement_boundary: Res<LeftMovementBoundary>,
game_meta: Res<GameMeta>,
mut start_y: Local<Option<f32>>,
) {
let players_movement = query
Expand Down Expand Up @@ -387,8 +384,7 @@ fn player_flop(
)
.collect::<Vec<_>>();

let players_movement =
clamp_player_movements(players_movement, &left_movement_boundary, &game_meta);
let players_movement = player_movement_clamper.clamp(players_movement);

for ((_, _, mut transform, _, _, _, _, _), player_dir) in query.iter_mut().zip(players_movement)
{
Expand Down
5 changes: 5 additions & 0 deletions src/enemy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ pub struct Enemy;
#[derive(Component)]
pub struct TripPointX(pub f32);

#[derive(Component)]
pub struct SpawnLocationX(pub f32);

#[derive(Bundle)]
pub struct EnemyBundle {
enemy: Enemy,
facing: Facing,
spawn_location_x: SpawnLocationX,
#[bundle]
transform_bundle: TransformBundle,
fighter_handle: Handle<FighterMeta>,
Expand All @@ -37,6 +41,7 @@ impl EnemyBundle {
EnemyBundle {
enemy: Enemy,
facing: Facing::Left,
spawn_location_x: SpawnLocationX(enemy_pos.x),
transform_bundle,
fighter_handle,
trip_point_x: TripPointX(enemy_meta.trip_point_x),
Expand Down
71 changes: 71 additions & 0 deletions src/fighter.rs
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);
}
}
49 changes: 10 additions & 39 deletions src/loading.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
use bevy::{asset::AssetStage, prelude::*};
use bevy_parallax::ParallaxResource;
use bevy_rapier2d::prelude::CollisionGroups;
use iyes_loopless::{prelude::*, state::NextState};

use rand::seq::SliceRandom;

use crate::{
animation::Animation,
collisions::BodyLayers,
config::ENGINE_CONFIG,
enemy::{Enemy, EnemyBundle},
fighter::ActiveFighterBundle,
input::MenuAction,
item::ItemBundle,
metadata::{BorderImageMeta, FighterMeta, GameMeta, ItemMeta, LevelMeta, Settings},
platform::Storage,
player::{Player, PlayerBundle},
AnimatedSpriteSheetBundle, CharacterBundle, GameStage, GameState, PhysicsBundle, Stats,
GameStage, GameState, Stats,
};

use bevy::{ecs::system::SystemParam, render::camera::ScalingMode};
Expand Down Expand Up @@ -443,42 +442,14 @@ fn load_fighters(
) {
for (entity, transform, fighter_handle, player, enemy) in fighters.iter() {
if let Some(fighter) = fighter_assets.get(fighter_handle) {
let body_layers = if player.is_some() {
BodyLayers::PLAYER
} else if enemy.is_some() {
BodyLayers::ENEMY
} else {
unreachable!();
};

commands
.entity(entity)
.insert(Name::new(fighter.name.clone()))
.insert_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(),
),
})
.insert_bundle(CharacterBundle {
stats: fighter.stats.clone(),
..default()
})
.insert_bundle(PhysicsBundle {
collision_groups: CollisionGroups::new(body_layers, BodyLayers::ALL),
..default()
});
ActiveFighterBundle::activate_fighter_stub(
&mut commands,
fighter,
entity,
transform,
player,
enemy,
);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ mod collisions;
mod config;
mod consts;
mod enemy;
mod fighter;
mod input;
mod item;
mod loading;
Expand Down
1 change: 1 addition & 0 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub struct LevelMeta {
pub music: String,
#[serde(skip)]
pub music_handle: Handle<AudioSource>,
pub stop_points: Vec<f32>,
}

impl LevelMeta {
Expand Down
Loading