update
Some checks failed
Rust Checks / checks (push) Failing after 6s
Rust Checks / checks (pull_request) Failing after 5s

This commit is contained in:
CoCo_Sol 2024-03-03 00:37:39 +01:00
parent cacb52ebf4
commit 7bc4fc1d50
2 changed files with 18 additions and 3 deletions

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.,
})
}
/// 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 {