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
5 changed files with 10 additions and 12 deletions
Showing only changes of commit cacb52ebf4 - Show all commits

Binary file not shown.

After

Width:  |  Height:  |  Size: 806 KiB

View file

@ -2,15 +2,14 @@
use bevy::prelude::*;
use border_wars::camera::CameraPlugin;
use border_wars::map::generation::{EndMapGeneration, MapGenerationPlugin, StartMapGeneration};
use border_wars::map::generation::{MapGenerationPlugin, StartMapGeneration};
use border_wars::map::renderer::RendererPlugin;
use border_wars::map::Tile;
use border_wars::scenes::ScenesPlugin;
fn setup(mut writer: EventWriter<StartMapGeneration>) {
writer.send(StartMapGeneration {
seed: 7128,
radius: 30,
radius: 5,
});
}

View file

@ -4,9 +4,6 @@ use bevy::prelude::*;
use crate::map::{Tile, TilePosition};
const IMAGE_WIDTH: f32 = 92.;
const OFFSET: f32 = 4.;
const IMAGE_HEIGHT: f32 = 40.;
/// A plugin to render the map.
pub struct RendererPlugin;
@ -25,8 +22,8 @@ impl Tile {
pub fn get_texture(&self, asset_server: &AssetServer) -> Handle<Image> {
match self {
Tile::Grass => asset_server.load("tiles/grass.png"),
Tile::Forest => asset_server.load("tiles/forest.png"),
Tile::Hill => asset_server.load("tiles/hill.png"),
Tile::Forest => asset_server.load("tiles/grass.png"),
Tile::Hill => asset_server.load("tiles/grass.png"),
}
}
}
@ -39,15 +36,17 @@ fn render_map(
) {
for (entity, position, tile) in query.iter() {
let pixel_position_ratio = position.to_pixel_coordinates();
let position_x = (IMAGE_WIDTH / 2. + OFFSET) * pixel_position_ratio.x;
let position_y = pixel_position_ratio.y * (IMAGE_WIDTH / 3. + OFFSET);
let position_x = 70. * pixel_position_ratio.x;
let position_y = pixel_position_ratio.y * 40.;
commands.entity(entity).insert(SpriteBundle {
transform: Transform::from_translation(Vec3 {
transform: Transform { translation: Vec3 {
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.
x: position_x,
y: position_y,
z: -1.0 / (1.0 + (-position_y * 10_f64.powf(-5.0) as f32).exp()),
}),
},
scale: Vec3 {x: 1./10., y: 1./10., z: 1.0}, ..Default::default()},
texture: tile.get_texture(&*asset_server),
..default()
});