Skip to content

Commit

Permalink
feat(entity): Entity state, queues (#5)
Browse files Browse the repository at this point in the history
* feat(entity): entity actions queue, state machine

* chore(entity): cago fmt

* remove useless functions

* cargo fmt

* Rename EntityCommand to EntityAction
  • Loading branch information
JakubG-git authored May 10, 2024
1 parent 7388f7b commit 2823fb3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
target
Cargo.lock
.idea
logs/
.idea/
logs/
23 changes: 23 additions & 0 deletions bdi_game/src/simulation/entity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use super::entity_actions_queue::EntityAction;
use super::entity_actions_queue::EntityActionsQueue;
use super::entity_state::EntityState;
use super::grid::GridPoint;

pub struct Entity {
pub position: GridPoint,
pub actions: EntityActionsQueue,
pub state: EntityState,
}

impl Entity {
pub fn new(position: GridPoint) -> Entity {
Entity {
position,
actions: EntityActionsQueue::new(),
state: EntityState::Idle,
}
}
pub fn add_action(&mut self, action: EntityAction) {
self.actions.push_back(action);
}
}
7 changes: 7 additions & 0 deletions bdi_game/src/simulation/entity_actions_queue.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use super::grid::GridPoint;
use std::collections::VecDeque;
pub enum EntityAction {
GoTo { destination: GridPoint },
}

pub type EntityActionsQueue = VecDeque<EntityAction>;
5 changes: 5 additions & 0 deletions bdi_game/src/simulation/entity_state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[derive(PartialEq, Copy, Clone, Debug)]
pub enum EntityState {
Idle,
Moving,
}
3 changes: 3 additions & 0 deletions bdi_game/src/simulation/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
pub mod entity;
pub mod entity_actions_queue;
pub mod entity_state;
pub mod grid;
pub mod simulation;
pub mod world_grid;
Expand Down

0 comments on commit 2823fb3

Please sign in to comment.