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