Compare commits
No commits in common. "map-builders" and "main" have entirely different histories.
map-builde
...
main
70
Cargo.lock
generated
70
Cargo.lock
generated
@ -35,8 +35,6 @@ name = "adventure-game"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bevy",
|
||||
"getrandom",
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -233,9 +231,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_asset"
|
||||
version = "0.5.1"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bd798cfbed1fcd406c9b3c978a8cb0a278aa03c4c8abd6edf460ee7cad0987e0"
|
||||
checksum = "426b3557161b34230e7ec04bdc48664509985ca7a6b874491f238eadd1e7cab0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bevy_app",
|
||||
@ -797,9 +795,9 @@ checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631"
|
||||
|
||||
[[package]]
|
||||
name = "bytemuck"
|
||||
version = "1.7.2"
|
||||
version = "1.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72957246c41db82b8ef88a5486143830adeb8227ef9837740bdec67724cf2c5b"
|
||||
checksum = "9966d2ab714d0f785dbac0a0396251a35280aeb42413281617d0209ab4898435"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
@ -1257,9 +1255,9 @@ checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59"
|
||||
|
||||
[[package]]
|
||||
name = "fastrand"
|
||||
version = "1.5.0"
|
||||
version = "1.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b394ed3d285a429378d3b384b9eb1285267e7df4b166df24b7a6939a04dc392e"
|
||||
checksum = "77b705829d1e87f762c2df6da140b26af5839e1033aa84aa5f56bb688e4e1bdb"
|
||||
dependencies = [
|
||||
"instant",
|
||||
]
|
||||
@ -1345,15 +1343,15 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
|
||||
|
||||
[[package]]
|
||||
name = "futures-core"
|
||||
version = "0.3.16"
|
||||
version = "0.3.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af51b1b4a7fdff033703db39de8802c673eb91855f2e0d47dcf3bf2c0ef01f99"
|
||||
checksum = "0402f765d8a89a26043b889b26ce3c4679d268fa6bb22cd7c6aad98340e179d1"
|
||||
|
||||
[[package]]
|
||||
name = "futures-io"
|
||||
version = "0.3.16"
|
||||
version = "0.3.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b0e06c393068f3a6ef246c75cdca793d6a46347e75286933e5e75fd2fd11582"
|
||||
checksum = "acc499defb3b348f8d8f3f66415835a9131856ff7714bf10dadfc4ec4bdb29a1"
|
||||
|
||||
[[package]]
|
||||
name = "futures-lite"
|
||||
@ -1642,9 +1640,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "glyph_brush_layout"
|
||||
version = "0.2.3"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc32c2334f00ca5ac3695c5009ae35da21da8c62d255b5b96d56e2597a637a38"
|
||||
checksum = "15cf18cf985bd942f05e14552b63c9d08f7d0ed1ec79a977eb9747c9e065f497"
|
||||
dependencies = [
|
||||
"ab_glyph",
|
||||
"approx",
|
||||
@ -1874,9 +1872,9 @@ checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
|
||||
|
||||
[[package]]
|
||||
name = "jobserver"
|
||||
version = "0.1.23"
|
||||
version = "0.1.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f5ca711fd837261e14ec9e674f092cbb931d3fa1482b017ae59328ddc6f3212b"
|
||||
checksum = "972f5ae5d1cb9c6ae417789196c803205313edde988685da5e3aae0827b9e7fd"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
@ -2180,7 +2178,7 @@ checksum = "8794322172319b972f528bf90c6b467be0079f1fa82780ffb431088e741a73ab"
|
||||
dependencies = [
|
||||
"jni-sys",
|
||||
"ndk-sys",
|
||||
"num_enum 0.5.3",
|
||||
"num_enum 0.5.2",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
@ -2366,12 +2364,12 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "num_enum"
|
||||
version = "0.5.3"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee2c8fd66061a707503d515639b8af10fd3807a5b5ee6959f7ff1bd303634bd5"
|
||||
checksum = "e5adf0198d427ee515335639f275e806ca01acf9f07d7cf14bb36a10532a6169"
|
||||
dependencies = [
|
||||
"derivative",
|
||||
"num_enum_derive 0.5.3",
|
||||
"num_enum_derive 0.5.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2388,9 +2386,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "num_enum_derive"
|
||||
version = "0.5.3"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "474fd1d096da3ad17084694eebed40ba09c4a36c5255cd772bd8b98859cc562e"
|
||||
checksum = "b1def5a3f69d4707d8a040b12785b98029a39e8c610ae685c7f6265669767482"
|
||||
dependencies = [
|
||||
"proc-macro-crate 1.0.0",
|
||||
"proc-macro2",
|
||||
@ -2559,9 +2557,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.28"
|
||||
version = "1.0.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612"
|
||||
checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
@ -2762,18 +2760,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.127"
|
||||
version = "1.0.126"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f03b9878abf6d14e6779d3f24f07b2cfa90352cfec4acc5aab8f1ac7f146fae8"
|
||||
checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.127"
|
||||
version = "1.0.126"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a024926d3432516606328597e0f224a51355a493b49fdd67e9209187cbe55ecc"
|
||||
checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -2782,9 +2780,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.66"
|
||||
version = "1.0.64"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "336b10da19a12ad094b59d870ebde26a45402e5b470add4b5fd03c5048a32127"
|
||||
checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
@ -2819,9 +2817,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sharded-slab"
|
||||
version = "0.1.3"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "740223c51853f3145fe7c90360d2d4232f2b62e3449489c207eccde818979982"
|
||||
checksum = "79c719719ee05df97490f80a45acfc99e5a30ce98a1e4fb67aee422745ae14e3"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
@ -2892,9 +2890,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "spirv-std-macros"
|
||||
version = "0.4.0-alpha.11"
|
||||
version = "0.4.0-alpha.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bac6631356c87e679fa157c613551e368d28e42fac810d2348e16c5c8ecb6878"
|
||||
checksum = "8b9b334f272ad19ae3e071b0d9d3ca275843c77b39f85e29d3908fa2fb6a7cb8"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
@ -2905,9 +2903,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "spirv-types"
|
||||
version = "0.4.0-alpha.11"
|
||||
version = "0.4.0-alpha.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6beac19227d393ff8d8fa47b9ca7086c1fe96af8821cf5e73f24867464c1056b"
|
||||
checksum = "1cfb357212185d2175e5f92c35902f0dc7590cd05121239b22251d360ef01c53"
|
||||
|
||||
[[package]]
|
||||
name = "spirv_cross"
|
||||
|
@ -8,15 +8,9 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
bevy = { version = "0.5", features = ["dynamic"] }
|
||||
rand = "0.8"
|
||||
getrandom = { version = "0.2", features = ["wasm-bindgen"] }
|
||||
|
||||
[profile.dev.package."*"]
|
||||
opt-level = 3
|
||||
|
||||
[profile.dev]
|
||||
opt-level = 1
|
||||
|
||||
[features]
|
||||
default = ["hot-reload"]
|
||||
hot-reload = []
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
21
src/main.rs
21
src/main.rs
@ -1,37 +1,26 @@
|
||||
mod components;
|
||||
mod map;
|
||||
mod plugins;
|
||||
mod resources;
|
||||
mod systems;
|
||||
|
||||
mod prelude {
|
||||
pub use crate::components::*;
|
||||
pub use crate::map::*;
|
||||
pub use crate::plugins::*;
|
||||
pub use crate::resources::*;
|
||||
pub use crate::systems::*;
|
||||
pub use bevy::{
|
||||
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
|
||||
prelude::*,
|
||||
};
|
||||
pub use rand::prelude::*;
|
||||
pub use bevy::prelude::*;
|
||||
|
||||
pub const MAP_WIDTH: i32 = 80;
|
||||
pub const MAP_HEIGHT: i32 = 50;
|
||||
pub const CELL_SIZE: i32 = 64;
|
||||
pub const NUM_TILES: usize = (MAP_WIDTH * MAP_HEIGHT) as usize;
|
||||
pub const SCREEN_WIDTH: f32 = 80.0;
|
||||
pub const SCREEN_HEIGHT: f32 = 50.0;
|
||||
pub const TILE_SIZE: f32 = 64.0;
|
||||
}
|
||||
|
||||
use prelude::*;
|
||||
|
||||
fn main() {
|
||||
App::build()
|
||||
.insert_resource(ClearColor(Color::rgb(0.171875, 0.171875, 0.171875)))
|
||||
.init_resource::<Map>()
|
||||
.insert_resource(ClearColor(Color::rgb(0.0, 0.0, 0.0)))
|
||||
.add_plugins(DefaultPlugins)
|
||||
//.add_plugin(FrameTimeDiagnosticsPlugin)
|
||||
//.add_plugin(LogDiagnosticsPlugin)
|
||||
//.add_plugin(bevy::asset::diagnostic::AssetCountDiagnosticsPlugin::< ColorMaterial>)
|
||||
.add_startup_system(setup.system())
|
||||
.add_startup_system(add_player.system())
|
||||
.add_system(player_movement.system())
|
||||
|
25
src/map.rs
25
src/map.rs
@ -1,25 +0,0 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum Tile {
|
||||
Floor,
|
||||
Wall,
|
||||
}
|
||||
|
||||
pub struct Map {
|
||||
pub tiles: Vec<Tile>,
|
||||
}
|
||||
|
||||
impl Map {
|
||||
pub fn index(&self, x: i32, y: i32) -> usize {
|
||||
((y * MAP_HEIGHT) + x) as usize
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Map {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
tiles: vec![Tile::Floor; NUM_TILES],
|
||||
}
|
||||
}
|
||||
}
|
@ -5,34 +5,27 @@ pub fn setup(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||
map: Res<Map>,
|
||||
) {
|
||||
// Camera
|
||||
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
|
||||
|
||||
// Map
|
||||
let grass_material = materials.add(asset_server.load("grass.png").into());
|
||||
let wall_material = materials.add(asset_server.load("wall.png").into());
|
||||
let half_w = MAP_WIDTH * CELL_SIZE / 2;
|
||||
let half_h = MAP_HEIGHT * CELL_SIZE / 2;
|
||||
let tile_size = Vec2::new(TILE_SIZE, TILE_SIZE);
|
||||
let sprite = Sprite::new(tile_size);
|
||||
let map_size = Vec2::new(SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
let half_x = (map_size.x / 2.0) as i32;
|
||||
let half_y = (map_size.y / 2.0) as i32;
|
||||
|
||||
for j in 0..MAP_HEIGHT {
|
||||
let y = j * CELL_SIZE - half_h;
|
||||
for i in 0..MAP_WIDTH {
|
||||
let x = i * CELL_SIZE - half_w;
|
||||
let index = map.index(i, j);
|
||||
let tile = map.tiles[index];
|
||||
let material = match tile {
|
||||
Tile::Floor => grass_material.clone(),
|
||||
Tile::Wall => wall_material.clone(),
|
||||
};
|
||||
let sprite = Sprite::new(Vec2::new(CELL_SIZE as f32, CELL_SIZE as f32));
|
||||
let transform = Transform::from_xyz(x as f32, y as f32, 0.0);
|
||||
for y in -half_y..half_y {
|
||||
for x in -half_x..half_x {
|
||||
let position = Vec2::new(x as f32, y as f32);
|
||||
let translation = (position * tile_size).extend(0.0);
|
||||
|
||||
commands.spawn_bundle(SpriteBundle {
|
||||
material,
|
||||
sprite,
|
||||
transform,
|
||||
material: grass_material.clone(),
|
||||
sprite: sprite.clone(),
|
||||
transform: Transform::from_translation(translation),
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
@ -52,7 +45,7 @@ pub fn add_player(
|
||||
.insert(Name("Player 1".to_string()))
|
||||
.insert_bundle(SpriteBundle {
|
||||
material: player_material,
|
||||
sprite: Sprite::new(Vec2::new(CELL_SIZE as f32, CELL_SIZE as f32)),
|
||||
sprite: Sprite::new(Vec2::new(TILE_SIZE, TILE_SIZE)),
|
||||
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 1.0)),
|
||||
..Default::default()
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user