generated from tipragot/rust
save
This commit is contained in:
parent
34557956e4
commit
9d392e3b08
7
.vscode/settings.json
vendored
Normal file
7
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"cSpell.words": [
|
||||||
|
"despawn",
|
||||||
|
"Despawns",
|
||||||
|
"Perlin"
|
||||||
|
]
|
||||||
|
}
|
BIN
crates/border-wars/assets/tiles/forest.png
Normal file
BIN
crates/border-wars/assets/tiles/forest.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
BIN
crates/border-wars/assets/tiles/grass.png
Normal file
BIN
crates/border-wars/assets/tiles/grass.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
BIN
crates/border-wars/assets/tiles/hill.png
Normal file
BIN
crates/border-wars/assets/tiles/hill.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
BIN
crates/border-wars/src/.main.rs.swp
Normal file
BIN
crates/border-wars/src/.main.rs.swp
Normal file
Binary file not shown.
|
@ -1,11 +1,24 @@
|
||||||
//! The main entry point of the game.
|
//! The main entry point of the game.
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
use border_wars::map::generation::{MapGenerationPlugin, StartMapGeneration};
|
||||||
|
use border_wars::map::renderer::RendererPlugin;
|
||||||
use border_wars::scenes::ScenesPlugin;
|
use border_wars::scenes::ScenesPlugin;
|
||||||
|
use border_wars::CurrentScene;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_plugins(ScenesPlugin)
|
.add_plugins(ScenesPlugin)
|
||||||
|
.add_plugins(MapGenerationPlugin)
|
||||||
|
.add_plugins(RendererPlugin)
|
||||||
|
.add_systems(OnEnter(CurrentScene::Game), gen_map)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn gen_map(mut event: EventWriter<StartMapGeneration>) {
|
||||||
|
event.send(StartMapGeneration {
|
||||||
|
seed: 5667,
|
||||||
|
radius: 5,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
BIN
crates/border-wars/src/map/.renderer.rs.swp
Normal file
BIN
crates/border-wars/src/map/.renderer.rs.swp
Normal file
Binary file not shown.
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
pub mod generation;
|
pub mod generation;
|
||||||
pub mod hex;
|
pub mod hex;
|
||||||
|
pub mod renderer;
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
|
56
crates/border-wars/src/map/renderer.rs
Normal file
56
crates/border-wars/src/map/renderer.rs
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
//! All functions related to the rendering of the map.
|
||||||
|
|
||||||
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
use super::Tile;
|
||||||
|
use crate::map::TilePosition;
|
||||||
|
|
||||||
|
/// A plugin to render the map.
|
||||||
|
pub struct RendererPlugin;
|
||||||
|
|
||||||
|
impl Plugin for RendererPlugin {
|
||||||
|
fn build(&self, app: &mut App) {
|
||||||
|
app.add_systems(Startup, setup_camera).add_systems(
|
||||||
|
Update,
|
||||||
|
render_map.run_if(in_state(crate::CurrentScene::Game)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets up the camera.
|
||||||
|
fn setup_camera(mut commands: Commands) {
|
||||||
|
commands.spawn(Camera2dBundle::default());
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Tile {
|
||||||
|
/// Returns the texture handle of the 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"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Renders the map.
|
||||||
|
fn render_map(
|
||||||
|
query: Query<(Entity, &TilePosition, &Tile), Changed<Tile>>,
|
||||||
|
mut commands: Commands,
|
||||||
|
asset_server: Res<AssetServer>,
|
||||||
|
) {
|
||||||
|
for (entity, position, tile) in query.iter() {
|
||||||
|
let pixel_position_ratio = position.to_pixel_coordinates();
|
||||||
|
let pixel_position = (50. * pixel_position_ratio.x, pixel_position_ratio.y * 30.);
|
||||||
|
|
||||||
|
commands.entity(entity).insert(SpriteBundle {
|
||||||
|
transform: Transform::from_translation(Vec3 {
|
||||||
|
x: pixel_position.0,
|
||||||
|
y: pixel_position.1,
|
||||||
|
z: 0.,
|
||||||
|
}),
|
||||||
|
texture: tile.get_texture(&*asset_server),
|
||||||
|
..default()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue