generated from tipragot/rust
Add a rendering system using temporary images #61
|
@ -9,7 +9,7 @@ use border_wars::scenes::ScenesPlugin;
|
|||
fn setup(mut writer: EventWriter<StartMapGeneration>) {
|
||||
writer.send(StartMapGeneration {
|
||||
seed: 7128,
|
||||
radius: 5,
|
||||
radius: 50,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,12 @@ use bevy::prelude::*;
|
|||
|
||||
use crate::map::{Tile, TilePosition};
|
||||
|
||||
#[derive(Resource)]
|
||||
struct TilesOffset {
|
||||
x: f32,
|
||||
y: f32,
|
||||
}
|
||||
|
||||
|
||||
/// A plugin to render the map.
|
||||
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
|
||||
|
||||
/// Renders the map.
|
||||
fn render_map(
|
||||
query: Query<(Entity, &TilePosition, &Tile), Changed<Tile>>,
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
mut tiles_offset: Res<TilesOffset>,
|
||||
) {
|
||||
for (entity, position, tile) in query.iter() {
|
||||
let pixel_position_ratio = position.to_pixel_coordinates();
|
||||
let position_x = 70. * pixel_position_ratio.x;
|
||||
let position_y = pixel_position_ratio.y * 40.;
|
||||
let position_x = tiles_offset.x * pixel_position_ratio.x;
|
||||
let position_y = tiles_offset.y * pixel_position_ratio.y;
|
||||
|
||||
commands.entity(entity).insert(SpriteBundle {
|
||||
transform: Transform { translation: Vec3 {
|
||||
|
|
Loading…
Reference in a new issue
Add a TODO to tell it is temporary. I think we shoud make an image managment system to not hardcode this.