Skip to content

Commit

Permalink
Building and Tile enhancements (#94)
Browse files Browse the repository at this point in the history
Issue:
==============
Closes #56

What was done:
==============
* Fixed building spawn issues.
* Added angular damping to arrows so they don't spin too fast.
* Render map using the tileset.
* Added hills and mountains on top of the ground tiles.
* Added sprites for buildings.
  • Loading branch information
mnmaita authored Nov 29, 2023
1 parent e21591b commit f6cde58
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 59 deletions.
40 changes: 32 additions & 8 deletions src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@ use crate::{
game::{GRID_SIZE, HALF_TILE_SIZE, TILE_SIZE},
};

pub const BACKGROUND_LAYER: u8 = 0;
pub const GROUND_LAYER: u8 = 1;
pub const SKY_LAYER: u8 = 2;
pub const UI_LAYER: u8 = 3;
pub enum RenderLayer {
Background = 0,
Topography,
Ground,
Sky,
Ui,
}

impl From<RenderLayer> for u8 {
fn from(value: RenderLayer) -> Self {
value as u8
}
}

pub struct CameraPlugin;

Expand All @@ -25,6 +34,7 @@ impl Plugin for CameraPlugin {
)
.chain(),
y_sorting,
inverse_y_sorting,
),
);
}
Expand Down Expand Up @@ -83,13 +93,19 @@ pub struct MainCamera;
#[derive(Component)]
pub struct YSorted;

#[derive(Component)]
pub struct YSortedInverse;

fn setup_camera(mut commands: Commands) {
commands
.spawn(MainCameraBundle::from_layer(BACKGROUND_LAYER))
.spawn(MainCameraBundle::from_layer(RenderLayer::Background.into()))
.with_children(|builder| {
builder.spawn(SubLayerCameraBundle::from_layer(GROUND_LAYER));
builder.spawn(SubLayerCameraBundle::from_layer(SKY_LAYER));
builder.spawn(SubLayerCameraBundle::from_layer(UI_LAYER));
builder.spawn(SubLayerCameraBundle::from_layer(RenderLayer::Ground.into()));
builder.spawn(SubLayerCameraBundle::from_layer(
RenderLayer::Topography.into(),
));
builder.spawn(SubLayerCameraBundle::from_layer(RenderLayer::Sky.into()));
builder.spawn(SubLayerCameraBundle::from_layer(RenderLayer::Ui.into()));
});
}

Expand Down Expand Up @@ -143,3 +159,11 @@ pub fn y_sorting(mut query: Query<&mut Transform, (Changed<Transform>, With<YSor
transform.translation.z = transform.translation.normalize().y;
}
}

pub fn inverse_y_sorting(
mut query: Query<&mut Transform, (Changed<Transform>, With<YSortedInverse>)>,
) {
for mut transform in &mut query {
transform.translation.z = -transform.translation.normalize().y;
}
}
6 changes: 3 additions & 3 deletions src/game/combat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bevy::{prelude::*, render::view::RenderLayers};
use bevy_rapier2d::prelude::*;

use crate::{
camera::{YSorted, SKY_LAYER},
camera::{RenderLayer, YSorted},
playing,
};

Expand Down Expand Up @@ -127,7 +127,7 @@ fn spawn_projectiles(
damage: ImpactDamage(damage),
emitter: Emitter(emitter),
marker: Projectile,
render_layers: RenderLayers::layer(SKY_LAYER),
render_layers: RenderLayers::layer(RenderLayer::Sky.into()),
rigid_body: RigidBody::Dynamic,
sprite: SpriteBundle {
sprite: Sprite {
Expand All @@ -148,7 +148,7 @@ fn spawn_projectiles(
projectile_entity_commands.insert((
Damping {
linear_damping: 1.0,
..default()
angular_damping: 10.0,
},
InGameEntity,
YSorted,
Expand Down
4 changes: 2 additions & 2 deletions src/game/enemy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use bevy_rapier2d::prelude::*;
use rand::seq::IteratorRandom;

use crate::{
camera::{YSorted, GROUND_LAYER},
camera::{RenderLayer, YSorted},
physics::Speed,
playing,
};
Expand Down Expand Up @@ -91,7 +91,7 @@ fn spawn_enemies(
..default()
},
collider: Collider::cuboid(HALF_TILE_SIZE.x, HALF_TILE_SIZE.y),
render_layers: RenderLayers::layer(GROUND_LAYER),
render_layers: RenderLayers::layer(RenderLayer::Ground.into()),
rigid_body: RigidBody::Dynamic,
collision_groups: CollisionGroups::new(
ENEMY_GROUP,
Expand Down
4 changes: 2 additions & 2 deletions src/game/fire_breath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use bevy_particle_systems::*;
use bevy_rapier2d::prelude::{Collider, CollisionGroups, Sensor};

use crate::{
camera::{YSorted, SKY_LAYER},
camera::{RenderLayer, YSorted},
playing,
};

Expand Down Expand Up @@ -85,7 +85,7 @@ fn spawn_fire_breath(
},
..ParticleSystemBundle::default()
},
render_layers: RenderLayers::layer(SKY_LAYER),
render_layers: RenderLayers::layer(RenderLayer::Sky.into()),
sensor: Sensor,
collider: Collider::ball(25.0),
damage: ImpactDamage(damage),
Expand Down
Loading

0 comments on commit f6cde58

Please sign in to comment.