This commit is contained in:
Edgar 2023-05-08 17:00:23 +02:00
parent d4498482f7
commit 2ea9bc7b80
No known key found for this signature in database
GPG key ID: 70ADAE8F35904387
8 changed files with 90 additions and 26 deletions

36
Cargo.lock generated
View file

@ -544,6 +544,17 @@ dependencies = [
"syn 1.0.109", "syn 1.0.109",
] ]
[[package]]
name = "bevy_ecs_tilemap"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3f6d777dfdc74d24d63ecafaf31628377d2f96bbeeb0012040001a9cb8d442"
dependencies = [
"bevy",
"log",
"regex",
]
[[package]] [[package]]
name = "bevy_egui" name = "bevy_egui"
version = "0.20.3" version = "0.20.3"
@ -1811,9 +1822,9 @@ dependencies = [
[[package]] [[package]]
name = "gpu-alloc" name = "gpu-alloc"
version = "0.5.3" version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fc59e5f710e310e76e6707f86c561dd646f69a8876da9131703b2f717de818d" checksum = "22beaafc29b38204457ea030f6fb7a84c9e4dd1b86e311ba0542533453d87f62"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"gpu-alloc-types", "gpu-alloc-types",
@ -2140,9 +2151,9 @@ dependencies = [
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.142" version = "0.2.143"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317" checksum = "edc207893e85c5d6be840e969b496b53d94cec8be2d501b214f50daa97fa8024"
[[package]] [[package]]
name = "libloading" name = "libloading"
@ -2890,18 +2901,18 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.160" version = "1.0.162"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c" checksum = "71b2f6e1ab5c2b98c05f0f35b236b22e8df7ead6ffbf51d7808da7f8817e7ab6"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.160" version = "1.0.162"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" checksum = "a2a0814352fd64b58489904a44ea8d90cb1a91dcb6b4f5ebabc32c8318e93cb6"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -3048,6 +3059,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"bevy", "bevy",
"bevy-inspector-egui", "bevy-inspector-egui",
"bevy_ecs_tilemap",
] ]
[[package]] [[package]]
@ -3777,9 +3789,9 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
[[package]] [[package]]
name = "winit" name = "winit"
version = "0.28.3" version = "0.28.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f504e8c117b9015f618774f8d58cd4781f5a479bc41079c064f974cbb253874" checksum = "94c9651471cd576737671fbf7081edfea43de3e06846dd9bd4e49ea803c9f55f"
dependencies = [ dependencies = [
"android-activity", "android-activity",
"bitflags", "bitflags",
@ -3855,6 +3867,6 @@ checksum = "a67300977d3dc3f8034dae89778f502b6ba20b269527b3223ba59c0cf393bb8a"
[[package]] [[package]]
name = "xml-rs" name = "xml-rs"
version = "0.8.5" version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "374b609fb36c36ce3501094dc0548f7df5d8d102224b65bc59812e4a5425d571" checksum = "699d0104bcdd7e7af6d093d6c6e2d0c479b8a129ee0d1023b31d2e0c71bfdda2"

View file

@ -8,6 +8,10 @@ edition = "2021"
[profile.dev.package."*"] [profile.dev.package."*"]
opt-level = 3 opt-level = 3
[profile.release]
lto = "thin"
[dependencies] [dependencies]
bevy = { version = "0.10.1", features = ["dynamic_linking"] } bevy = { version = "0.10.1", features = ["dynamic_linking"] }
bevy-inspector-egui = "0.18.3" bevy-inspector-egui = "0.18.3"
bevy_ecs_tilemap = "0.10.0"

View file

@ -1,2 +1,3 @@
[toolchain] [toolchain]
channel = "nightly" # change back to nightly when fix https://github.com/rust-lang/rust/issues/111320
channel = "nightly-2023-05-06"

View file

@ -1,4 +1,5 @@
use bevy::prelude::*; use bevy::prelude::*;
use bevy_ecs_tilemap::prelude::*;
use bevy_inspector_egui::quick::WorldInspectorPlugin; use bevy_inspector_egui::quick::WorldInspectorPlugin;
use misc::AimTarget; use misc::AimTarget;
use physics::Velocity; use physics::Velocity;
@ -12,7 +13,14 @@ fn main() {
App::new() App::new()
.register_type::<Velocity>() .register_type::<Velocity>()
.register_type::<AimTarget>() .register_type::<AimTarget>()
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: String::from("Tee city"),
..Default::default()
}),
..default()
}))
.add_plugin(TilemapPlugin)
.add_plugin(WorldInspectorPlugin::new()) .add_plugin(WorldInspectorPlugin::new())
.add_startup_system(general_setup) .add_startup_system(general_setup)
.add_startup_system(player::add_player) .add_startup_system(player::add_player)
@ -27,4 +35,41 @@ pub struct MainCamera;
fn general_setup(mut commands: Commands, server: Res<AssetServer>) { fn general_setup(mut commands: Commands, server: Res<AssetServer>) {
commands.spawn((Camera2dBundle::default(), MainCamera)); commands.spawn((Camera2dBundle::default(), MainCamera));
let tilemap_handle: Handle<Image> = server.load("generic_clear.png");
let map_size = TilemapSize { x: 2, y: 2 };
let tilemap_entity = commands.spawn_empty().id();
let mut tile_storage = TileStorage::empty(map_size);
for x in 0..map_size.x {
for y in 0..map_size.y {
let tile_pos = TilePos { x, y };
let tile_entity = commands
.spawn(TileBundle {
position: tile_pos,
tilemap_id: TilemapId(tilemap_entity),
texture_index: TileTextureIndex(1),
..Default::default()
})
.id();
tile_storage.set(&tile_pos, tile_entity);
}
}
let tile_size = TilemapTileSize { x: 64.0, y: 64.0 };
let grid_size = tile_size.into();
let map_type = TilemapType::Square;
commands.entity(tilemap_entity).insert(TilemapBundle {
grid_size,
map_type,
size: map_size,
storage: tile_storage,
texture: TilemapTexture::Single(tilemap_handle.clone()),
tile_size,
transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0),
..Default::default()
});
} }

View file

@ -1,6 +1,7 @@
use bevy::{math::Vec3Swizzles, prelude::*}; use bevy::{math::Vec3Swizzles, prelude::*};
#[derive(Debug, Component, Reflect, Default)] #[derive(Debug, Component, Reflect, Default)]
#[reflect(Component)]
pub struct AimTarget(pub Option<Vec2>); pub struct AimTarget(pub Option<Vec2>);
pub fn aim_target_system(mut query: Query<(&mut Transform, &AimTarget)>) { pub fn aim_target_system(mut query: Query<(&mut Transform, &AimTarget)>) {

View file

@ -1,6 +1,7 @@
use bevy::prelude::*; use bevy::prelude::*;
#[derive(Debug, Reflect, Component, Default, Clone)] #[derive(Debug, Reflect, Component, Default, Clone)]
#[reflect(Component)]
pub struct Velocity { pub struct Velocity {
pub vel: Vec2, pub vel: Vec2,
pub speed: f32, pub speed: f32,

View file

@ -14,9 +14,9 @@ pub fn add_player(mut commands: Commands, server: Res<AssetServer>) {
let skin_handle: Handle<Image> = server.load("skins/default.png"); let skin_handle: Handle<Image> = server.load("skins/default.png");
let game_handle: Handle<Image> = server.load("game.png"); let game_handle: Handle<Image> = server.load("game.png");
let tee_bundle = TeeBundle::new("Player", Vec3::new(32.0, 32.0, 0.0)); let tee_bundle = TeeBundle::new("Player", Vec3::new(32.0, 32.0, 1.0));
let tee_bundle_children = TeeBundleChildren::new(skin_handle, game_handle); let tee_bundle_children = TeeBundleChildren::new(skin_handle, game_handle, 1.0);
commands commands
.spawn(( .spawn((

View file

@ -1,4 +1,4 @@
use std::{borrow::Cow, default}; use std::borrow::Cow;
use bevy::prelude::*; use bevy::prelude::*;
@ -59,7 +59,7 @@ impl TeeBundle {
} }
impl TeeBundleChildren { impl TeeBundleChildren {
pub fn new(skin_handle: Handle<Image>, game_handle: Handle<Image>) -> Self { pub fn new(skin_handle: Handle<Image>, game_handle: Handle<Image>, base_z: f32) -> Self {
Self { Self {
weapon: TeePartBundle { weapon: TeePartBundle {
sprite: SpriteBundle { sprite: SpriteBundle {
@ -68,7 +68,7 @@ impl TeeBundleChildren {
rect: Some(Weapon::default().get_texture_rect()), rect: Some(Weapon::default().get_texture_rect()),
..Default::default() ..Default::default()
}, },
transform: Weapon::default().get_transform(), transform: Weapon::default().get_transform(base_z),
..default() ..default()
}, },
marker: Weapon::default(), marker: Weapon::default(),
@ -81,7 +81,7 @@ impl TeeBundleChildren {
rect: Some(Rect::from_corners(Vec2::ZERO, Vec2::new(96.0, 96.0))), rect: Some(Rect::from_corners(Vec2::ZERO, Vec2::new(96.0, 96.0))),
..Default::default() ..Default::default()
}, },
transform: Transform::from_xyz(0.0, 0.0, 0.5), transform: Transform::from_xyz(0.0, 0.0, base_z + 0.5),
..default() ..default()
}, },
marker: Body, marker: Body,
@ -94,7 +94,7 @@ impl TeeBundleChildren {
rect: Some(Rect::new(96.0 * 2.0, 32.0, 96.0 * 2.0 + 64.0, 32.0 + 32.0)), rect: Some(Rect::new(96.0 * 2.0, 32.0, 96.0 * 2.0 + 64.0, 32.0 + 32.0)),
..Default::default() ..Default::default()
}, },
transform: Transform::from_xyz(-28.0, -5.0, 0.0) transform: Transform::from_xyz(-28.0, -5.0, base_z + 0.0)
.with_rotation(Quat::from_rotation_z(1.7)), .with_rotation(Quat::from_rotation_z(1.7)),
..default() ..default()
}, },
@ -108,7 +108,7 @@ impl TeeBundleChildren {
rect: Some(Rect::new(96.0 * 2.0, 32.0, 96.0 * 2.0 + 64.0, 32.0 + 32.0)), rect: Some(Rect::new(96.0 * 2.0, 32.0, 96.0 * 2.0 + 64.0, 32.0 + 32.0)),
..Default::default() ..Default::default()
}, },
transform: Transform::from_xyz(28.0, -5.0, 0.0) transform: Transform::from_xyz(28.0, -5.0, base_z + 0.0)
.with_scale(Vec3::new(-1.0, 1.0, 1.0)) .with_scale(Vec3::new(-1.0, 1.0, 1.0))
.with_rotation(Quat::from_rotation_z(-1.7)), .with_rotation(Quat::from_rotation_z(-1.7)),
..default() ..default()
@ -151,13 +151,13 @@ impl Weapon {
} }
} }
pub fn get_transform(&self) -> Transform { pub fn get_transform(&self, base_z: f32) -> Transform {
match self { match self {
Weapon::Katana => Transform::from_xyz(11.5, 50.0, 0.25) Weapon::Katana => Transform::from_xyz(11.5, 50.0, base_z + 0.25)
.with_scale(Vec3::splat(0.5)) .with_scale(Vec3::splat(0.5))
.with_rotation(Quat::from_rotation_z(1.8)), .with_rotation(Quat::from_rotation_z(1.8)),
Weapon::Gun => Transform::from_xyz(2.0, 38.0, 0.25), Weapon::Gun => Transform::from_xyz(2.0, 38.0, base_z + 0.25),
_ => Transform::from_xyz(2.0, 60.0, 0.25) _ => Transform::from_xyz(2.0, 60.0, base_z + 0.25)
.with_scale(Vec3::splat(0.5)) .with_scale(Vec3::splat(0.5))
.with_rotation(Quat::from_rotation_z(std::f32::consts::FRAC_PI_2)), .with_rotation(Quat::from_rotation_z(std::f32::consts::FRAC_PI_2)),
} }