Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
stillonearth committed Jan 1, 2024
1 parent 2893f9c commit 19fc75b
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 987 deletions.
106 changes: 0 additions & 106 deletions src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ use bevy::prelude::*;
use bevy_ecs_ldtk::prelude::*;
use bevy_rapier2d::prelude::*;

use crate::{
enemies::{create_mierda_bundle, Mierda},
items::{create_pizza_bundle, Pizza},
sprites::*,
};

#[derive(Clone, Debug, Default, Bundle, LdtkIntCell)]
pub struct ColliderBundle {
pub collider: Collider,
Expand Down Expand Up @@ -37,103 +31,3 @@ impl From<&EntityInstance> for ColliderBundle {
}
}
}

#[derive(Copy, Clone, Eq, PartialEq, Debug, Default, Component, Reflect)]
pub struct Player {
pub health: u8,
}

#[derive(Default, Bundle)]
pub struct PlayerBundle {
pub sprite_bundle: SpriteSheetBundle,
pub character_animation: CharacterAnimation,
pub animation_timer: AnimationTimer,
pub player: Player,
pub collider_bundle: ColliderBundle,
pub active_events: ActiveEvents,
// pub particle_system_bundle: ParticleSystemBundle,
}

#[derive(Copy, Clone, Eq, PartialEq, Debug, Default, Component)]
pub struct Wall;

#[derive(Clone, Debug, Default, Bundle, LdtkIntCell)]
pub struct WallBundle {
wall: Wall,
sensor: Sensor,
}

impl FromWorld for PlayerSpritesheets {
fn from_world(world: &mut World) -> Self {
let world = world.cell();

let asset_server_world_borrow = world.get_resource::<AssetServer>();
let asset_server = asset_server_world_borrow.as_deref().unwrap();

let mut texture_atlasses_world_borrow = world.get_resource_mut::<Assets<TextureAtlas>>();
let texture_atlasses = texture_atlasses_world_borrow.as_deref_mut().unwrap();

let player_atlas_1 = load_texture_atlas(
PLAYER_ASSET_SHEET_1,
asset_server,
SHEET_1_COLUMNS,
SHEET_1_ROWS,
None,
64.,
texture_atlasses,
);

let player_atlas_2 = load_texture_atlas(
PLAYER_ASSET_SHEET_2,
asset_server,
SHEET_2_COLUMNS,
SHEET_2_ROWS,
None,
64. * 3.,
texture_atlasses,
);

let mierda_atlas = load_texture_atlas(
MIERDA_ASSET_SHEET,
asset_server,
5,
1,
None,
16.0,
texture_atlasses,
);

PlayerSpritesheets {
player_atlas_1,
player_atlas_2,
mierda_atlas,
}
}
}

pub(crate) fn fix_missing_ldtk_entities(
asset_server: Res<AssetServer>,
texture_atlasses: ResMut<Assets<TextureAtlas>>,
mut commands: Commands,
los_mierdas: Query<(Entity, &Mierda), Without<Collider>>,
los_pizzas: Query<(Entity, &Pizza), Without<Collider>>,
) {
let asset_server = asset_server.into_inner();
let texture_atlasses = texture_atlasses.into_inner();

for (e, _) in los_mierdas.iter().filter(|(_, m)| !m.is_dummy) {
let bundle = create_mierda_bundle(asset_server, texture_atlasses, false);
commands.entity(e).insert((
bundle.collider_bundle,
bundle.direction_update_time,
Visibility::Visible,
));
}

for (e, _) in los_pizzas.iter().filter(|(_, m)| !m.is_dummy) {
let bundle = create_pizza_bundle(asset_server, texture_atlasses, false);
commands
.entity(e)
.insert((bundle.collider_bundle, Visibility::Visible));
}
}
5 changes: 4 additions & 1 deletion src/controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use bevy::prelude::*;
use bevy_rapier2d::prelude::*;
use pecs::prelude::*;

use crate::{components::*, events::*, sprites::*};
use crate::{
entities::player::{Player, PlayerAttackEvent},
sprites::*,
};

pub fn controls(
mut commands: Commands,
Expand Down
Loading

0 comments on commit 19fc75b

Please sign in to comment.