Sort ECS stuff into modules
This commit is contained in:
parent
5ba82fd26c
commit
8bdc8e31d6
9 changed files with 75 additions and 46 deletions
5
src/components/left_mover.rs
Normal file
5
src/components/left_mover.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
use specs::prelude::*;
|
||||||
|
use specs_derive::Component;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct LeftMover {}
|
9
src/components/mod.rs
Normal file
9
src/components/mod.rs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
pub use left_mover::LeftMover;
|
||||||
|
pub use player::Player;
|
||||||
|
pub use position::Position;
|
||||||
|
pub use renderable::Renderable;
|
||||||
|
|
||||||
|
pub mod left_mover;
|
||||||
|
pub mod player;
|
||||||
|
pub mod position;
|
||||||
|
pub mod renderable;
|
14
src/components/player.rs
Normal file
14
src/components/player.rs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
|
use specs::prelude::*;
|
||||||
|
use specs_derive::Component;
|
||||||
|
|
||||||
|
#[derive(Component, Debug)]
|
||||||
|
pub struct Player {
|
||||||
|
pub last_moved: Instant,
|
||||||
|
pub score: u32,
|
||||||
|
pub gems: u32,
|
||||||
|
pub whips: u32,
|
||||||
|
pub teleports: u32,
|
||||||
|
pub keys: u32,
|
||||||
|
}
|
8
src/components/position.rs
Normal file
8
src/components/position.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
use specs::prelude::*;
|
||||||
|
use specs_derive::Component;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct Position {
|
||||||
|
pub x: i32,
|
||||||
|
pub y: i32,
|
||||||
|
}
|
10
src/components/renderable.rs
Normal file
10
src/components/renderable.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
use bracket_lib::prelude::*;
|
||||||
|
use specs::prelude::*;
|
||||||
|
use specs_derive::Component;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct Renderable {
|
||||||
|
pub glyph: FontCharType,
|
||||||
|
pub fg: RGB,
|
||||||
|
pub bg: RGB,
|
||||||
|
}
|
53
src/main.rs
53
src/main.rs
|
@ -1,51 +1,27 @@
|
||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
use bracket_lib::prelude::*;
|
use bracket_lib::prelude::*;
|
||||||
|
use components::{LeftMover, Player, Position, Renderable};
|
||||||
use constants::{MAP_HEIGHT, MAP_WIDTH, MAP_X, MAP_Y};
|
use constants::{MAP_HEIGHT, MAP_WIDTH, MAP_X, MAP_Y};
|
||||||
use map::{Map, TileType};
|
use map::{Map, TileType};
|
||||||
|
use resources::LevelNumber;
|
||||||
use sound::SoundSystem;
|
use sound::SoundSystem;
|
||||||
use sound_effects::SoundEffects;
|
use sound_effects::SoundEffects;
|
||||||
use specs::prelude::*;
|
use specs::prelude::*;
|
||||||
use specs_derive::Component;
|
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
use systems::LeftWalker;
|
||||||
use vga_color as vga;
|
use vga_color as vga;
|
||||||
|
|
||||||
|
pub mod components;
|
||||||
pub mod constants;
|
pub mod constants;
|
||||||
mod map;
|
mod map;
|
||||||
|
pub mod resources;
|
||||||
mod sidebar;
|
mod sidebar;
|
||||||
mod sound;
|
mod sound;
|
||||||
mod sound_effects;
|
mod sound_effects;
|
||||||
|
pub mod systems;
|
||||||
pub mod vga_color;
|
pub mod vga_color;
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
struct LevelNumber(u32);
|
|
||||||
|
|
||||||
#[derive(Component)]
|
|
||||||
struct Position {
|
|
||||||
x: i32,
|
|
||||||
y: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Component)]
|
|
||||||
struct Renderable {
|
|
||||||
glyph: FontCharType,
|
|
||||||
fg: RGB,
|
|
||||||
bg: RGB,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Component)]
|
|
||||||
struct LeftMover {}
|
|
||||||
|
|
||||||
#[derive(Component, Debug)]
|
|
||||||
struct Player {
|
|
||||||
last_moved: Instant,
|
|
||||||
score: u32,
|
|
||||||
gems: u32,
|
|
||||||
whips: u32,
|
|
||||||
teleports: u32,
|
|
||||||
keys: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
ecs: World,
|
ecs: World,
|
||||||
sound_system: SoundSystem,
|
sound_system: SoundSystem,
|
||||||
|
@ -164,21 +140,6 @@ impl GameState for State {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LeftWalker {}
|
|
||||||
|
|
||||||
impl<'a> System<'a> for LeftWalker {
|
|
||||||
type SystemData = (ReadStorage<'a, LeftMover>, WriteStorage<'a, Position>);
|
|
||||||
|
|
||||||
fn run(&mut self, (lefty, mut pos): Self::SystemData) {
|
|
||||||
for (_lefty, pos) in (&lefty, &mut pos).join() {
|
|
||||||
pos.x -= 1;
|
|
||||||
if pos.x < 0 {
|
|
||||||
pos.x = 65;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
fn run_systems(&mut self) {
|
fn run_systems(&mut self) {
|
||||||
let mut lw = LeftWalker {};
|
let mut lw = LeftWalker {};
|
||||||
|
@ -193,8 +154,8 @@ fn main() -> BError {
|
||||||
.with_title("Kroz")
|
.with_title("Kroz")
|
||||||
.with_tile_dimensions(8, 16)
|
.with_tile_dimensions(8, 16)
|
||||||
.build()?;
|
.build()?;
|
||||||
let mut ss = SoundSystem::new();
|
|
||||||
|
|
||||||
|
let mut ss = SoundSystem::new();
|
||||||
let sound_effects = SoundEffects::new(&ss);
|
let sound_effects = SoundEffects::new(&ss);
|
||||||
ss.play_sound(sound_effects.startup.clone());
|
ss.play_sound(sound_effects.startup.clone());
|
||||||
|
|
||||||
|
|
2
src/resources/mod.rs
Normal file
2
src/resources/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct LevelNumber(pub u32);
|
17
src/systems/left_walker.rs
Normal file
17
src/systems/left_walker.rs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
use crate::components::{left_mover::LeftMover, position::Position};
|
||||||
|
use specs::prelude::*;
|
||||||
|
|
||||||
|
pub struct LeftWalker {}
|
||||||
|
|
||||||
|
impl<'a> System<'a> for LeftWalker {
|
||||||
|
type SystemData = (ReadStorage<'a, LeftMover>, WriteStorage<'a, Position>);
|
||||||
|
|
||||||
|
fn run(&mut self, (lefty, mut pos): Self::SystemData) {
|
||||||
|
for (_lefty, pos) in (&lefty, &mut pos).join() {
|
||||||
|
pos.x -= 1;
|
||||||
|
if pos.x < 0 {
|
||||||
|
pos.x = 65;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3
src/systems/mod.rs
Normal file
3
src/systems/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
pub use left_walker::LeftWalker;
|
||||||
|
|
||||||
|
pub mod left_walker;
|
Loading…
Add table
Reference in a new issue