Add a rendering system using temporary images #61

Merged
CoCo_Sol merged 26 commits from renderer into main 2024-03-05 18:08:56 +00:00
2 changed files with 18 additions and 3 deletions
Showing only changes of commit 7bc4fc1d50 - Show all commits

View file

@ -9,7 +9,7 @@ use border_wars::scenes::ScenesPlugin;
fn setup(mut writer: EventWriter<StartMapGeneration>) { fn setup(mut writer: EventWriter<StartMapGeneration>) {
writer.send(StartMapGeneration { writer.send(StartMapGeneration {
seed: 7128, seed: 7128,
radius: 5, radius: 50,
}); });
} }

View file

@ -4,6 +4,12 @@ use bevy::prelude::*;
use crate::map::{Tile, TilePosition}; use crate::map::{Tile, TilePosition};
#[derive(Resource)]
struct TilesOffset {
x: f32,
y: f32,
}
/// A plugin to render the map. /// A plugin to render the map.
pub struct RendererPlugin; pub struct RendererPlugin;
@ -28,16 +34,25 @@ impl Tile {
} }
} }
/// Init resources related to the rendering of the map.
fn init_resources_for_rendering(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.insert_resource(TilesOffset {
x: 70.,
y: 40.,
})
}
CoCo_Sol marked this conversation as resolved
Review

Add a TODO to tell it is temporary. I think we shoud make an image managment system to not hardcode this.

Add a TODO to tell it is temporary. I think we shoud make an image managment system to not hardcode this.
/// Renders the map. /// Renders the map.
fn render_map( fn render_map(
query: Query<(Entity, &TilePosition, &Tile), Changed<Tile>>, query: Query<(Entity, &TilePosition, &Tile), Changed<Tile>>,
mut commands: Commands, mut commands: Commands,
asset_server: Res<AssetServer>, asset_server: Res<AssetServer>,
mut tiles_offset: Res<TilesOffset>,
) { ) {
for (entity, position, tile) in query.iter() { for (entity, position, tile) in query.iter() {
let pixel_position_ratio = position.to_pixel_coordinates(); let pixel_position_ratio = position.to_pixel_coordinates();
let position_x = 70. * pixel_position_ratio.x; let position_x = tiles_offset.x * pixel_position_ratio.x;
let position_y = pixel_position_ratio.y * 40.; let position_y = tiles_offset.y * pixel_position_ratio.y;
commands.entity(entity).insert(SpriteBundle { commands.entity(entity).insert(SpriteBundle {
transform: Transform { translation: Vec3 { transform: Transform { translation: Vec3 {