Added gitignore and WIP Grid and player
This commit is contained in:
parent
c957799a81
commit
3904a7c824
5 changed files with 105 additions and 18 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1 +1,3 @@
|
||||||
/target
|
/target
|
||||||
|
shell.nix
|
||||||
|
.vscode/
|
|
@ -1,7 +1,97 @@
|
||||||
use comfy::*;
|
use comfy::*;
|
||||||
|
|
||||||
pub fn draw(_state: &crate::State, _engine: &comfy::EngineContext) {
|
#[derive(Debug, Default)]
|
||||||
draw_circle(vec2(0.0, 0.0), 0.5, RED, 0);
|
pub struct HouseState {
|
||||||
|
grid: Grid,
|
||||||
|
player: Player
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(_state: &mut crate::State, _engine: &mut comfy::EngineContext) {}
|
#[derive(Debug)]
|
||||||
|
struct Grid {
|
||||||
|
nodes: Vec<Vec2>,
|
||||||
|
connections: Vec<(usize, usize)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
struct Player {
|
||||||
|
position: Vec2
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Grid {
|
||||||
|
fn default() -> Self {
|
||||||
|
Grid::load() //Just for testing purposes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Grid {
|
||||||
|
fn load() -> Self {
|
||||||
|
let mut grid = Self {
|
||||||
|
nodes: vec![
|
||||||
|
vec2(10.0, 0.0),
|
||||||
|
vec2(0.0, 0.0),
|
||||||
|
vec2(0.0, 10.0),
|
||||||
|
vec2(-10.0, 0.0),
|
||||||
|
vec2(10.0, 10.0),
|
||||||
|
],
|
||||||
|
connections: vec![(0, 1), (1, 2), (1, 3), (0, 4), (0, 5), (5, 1), (6, 7)],
|
||||||
|
};
|
||||||
|
|
||||||
|
grid.sanitize();
|
||||||
|
|
||||||
|
grid
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sanitize(&mut self) {
|
||||||
|
let mut len = self.nodes.len();
|
||||||
|
let connections = self.connections.iter().filter(|(conn_i1, conn_i2)| {
|
||||||
|
if conn_i1 >= &mut len || conn_i2 >= &mut len{
|
||||||
|
error!("Connection in grid not possible {:?}", (conn_i1, conn_i2));
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}).map(|(conn_i1, conn_i2)| (*conn_i1, *conn_i2)).collect();
|
||||||
|
|
||||||
|
self.connections = connections;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn draw(state: &crate::State, _engine: &comfy::EngineContext) {
|
||||||
|
//Draw Grid
|
||||||
|
for pos in &state.house.grid.nodes {
|
||||||
|
draw_circle(*pos, 0.25, BLUE, 0);
|
||||||
|
}
|
||||||
|
for (conn_i1, conn_i2) in &state.house.grid.connections {
|
||||||
|
let p1 = state.house.grid.nodes.get(*conn_i1);
|
||||||
|
let p2 = state.house.grid.nodes.get(*conn_i2);
|
||||||
|
|
||||||
|
if p1.is_none() || p2.is_none() {
|
||||||
|
error!("Connection in grid not available {:?}", (conn_i1, conn_i2));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
draw_line(*p1.unwrap(), *p2.unwrap(), 0.1, BLUE, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Draw Player
|
||||||
|
draw_circle(state.house.player.position, 0.5, RED, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update(state: &mut crate::State, _engine: &mut comfy::EngineContext) {
|
||||||
|
if is_key_down(KeyCode::Up) {
|
||||||
|
error!("KEY UPPPPPPPPP");
|
||||||
|
state.house.player.position += vec2(0.0, 1.0) * delta();
|
||||||
|
}
|
||||||
|
|
||||||
|
if is_key_down(KeyCode::Down) {
|
||||||
|
state.house.player.position += vec2(0.0, -1.0) * delta();
|
||||||
|
}
|
||||||
|
|
||||||
|
if is_key_down(KeyCode::Right) {
|
||||||
|
state.house.player.position += vec2(1.0, 0.0) * delta();
|
||||||
|
}
|
||||||
|
|
||||||
|
if is_key_down(KeyCode::Left) {
|
||||||
|
state.house.player.position += vec2(-1.0, 0.0) * delta();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
pub mod house;
|
pub mod house;
|
||||||
pub mod overworld;
|
pub mod overworld;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Default)]
|
||||||
pub enum Activity {
|
pub enum Activity {
|
||||||
|
#[default]
|
||||||
House,
|
House,
|
||||||
Overworld
|
Overworld,
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,19 +2,19 @@ use comfy::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
activities::{house, overworld, Activity},
|
activities::{house, overworld, Activity},
|
||||||
State
|
State,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn update(state: &mut State, engine: &mut EngineContext) {
|
pub fn update(state: &mut State, engine: &mut EngineContext) {
|
||||||
match state.activity {
|
match state.activity {
|
||||||
Activity::House => house::update(state, engine),
|
Activity::House => house::update(state, engine),
|
||||||
Activity::Overworld => overworld::update(state, engine)
|
Activity::Overworld => overworld::update(state, engine),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw(state: &State, engine: &EngineContext) {
|
pub fn draw(state: &State, engine: &EngineContext) {
|
||||||
match state.activity {
|
match state.activity {
|
||||||
Activity::House => house::draw(state, engine),
|
Activity::House => house::draw(state, engine),
|
||||||
Activity::Overworld => overworld::draw(state, engine)
|
Activity::Overworld => overworld::draw(state, engine),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -1,22 +1,16 @@
|
||||||
mod activities;
|
mod activities;
|
||||||
mod game;
|
mod game;
|
||||||
|
|
||||||
|
use activities::house::HouseState;
|
||||||
use activities::Activity;
|
use activities::Activity;
|
||||||
use comfy::*;
|
use comfy::*;
|
||||||
|
|
||||||
const GAME_NAME: &str = "Powercreep";
|
const GAME_NAME: &str = "Powercreep";
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Default)]
|
||||||
struct State {
|
struct State {
|
||||||
activity: Activity
|
activity: Activity,
|
||||||
}
|
house: HouseState,
|
||||||
|
|
||||||
impl Default for State {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
activity: Activity::House
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GameLoop for State {
|
impl GameLoop for State {
|
||||||
|
|
Loading…
Reference in a new issue