generated from tipragot/rust
Add a rendering system using temporary images #61
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 806 KiB |
Binary file not shown.
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
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()
|
||||
});
|
||||
|
|
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.