attack-human #21
3 changed files with 58 additions and 22 deletions
|
@ -37,9 +37,9 @@ impl HouseState {
|
||||||
let room_count = random_i32(2, MAX_ROOMS) as usize;
|
let room_count = random_i32(2, MAX_ROOMS) as usize;
|
||||||
let human_count = random_i32(1, room_count as i32) as usize;
|
let human_count = random_i32(1, room_count as i32) as usize;
|
||||||
|
|
||||||
let mut possible_rooms : IndexSet::<usize> = (0..room_count).collect();
|
let mut possible_rooms: IndexSet<usize> = (0 .. room_count).collect();
|
||||||
let mut human_rooms = Vec::new();
|
let mut human_rooms = Vec::new();
|
||||||
for _ in 0..human_count {
|
for _ in 0 .. human_count {
|
||||||
if !possible_rooms.is_empty() {
|
if !possible_rooms.is_empty() {
|
||||||
let random_idx = usize::gen_range(0, possible_rooms.len());
|
let random_idx = usize::gen_range(0, possible_rooms.len());
|
||||||
|
|
||||||
|
@ -132,6 +132,4 @@ pub fn update(state: &mut crate::State, ctx: &mut comfy::EngineContext<'_>) {
|
||||||
state.ghost.overworld_pos -= vec2(0.0, 1.0);
|
state.ghost.overworld_pos -= vec2(0.0, 1.0);
|
||||||
state.activity = Activity::Overworld;
|
state.activity = Activity::Overworld;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,10 @@ use super::{
|
||||||
room::{Room, SCALE},
|
room::{Room, SCALE},
|
||||||
Grid
|
Grid
|
||||||
};
|
};
|
||||||
use comfy::{delta, draw_circle, draw_sprite, is_key_down, is_key_pressed, main_camera_mut, texture_id, vec2, KeyCode, Vec2, RED, WHITE};
|
use comfy::{
|
||||||
|
delta, draw_circle, draw_sprite, is_key_down, is_key_pressed, main_camera_mut,
|
||||||
|
texture_id, vec2, KeyCode, Vec2, RED, WHITE
|
||||||
|
};
|
||||||
use log::error;
|
use log::error;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
@ -37,7 +40,13 @@ impl Player {
|
||||||
|
|
||||||
pub fn draw(&self) {
|
pub fn draw(&self) {
|
||||||
//draw_circle(self.position, 0.5, RED, 0);
|
//draw_circle(self.position, 0.5, RED, 0);
|
||||||
draw_sprite(texture_id("ghost_house"), self.position, WHITE, 5, vec2(1.25, 1.25));
|
draw_sprite(
|
||||||
|
texture_id("ghost_house"),
|
||||||
|
self.position,
|
||||||
|
WHITE,
|
||||||
|
5,
|
||||||
|
vec2(1.25, 1.25)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self, room: &Room) {
|
pub fn update(&mut self, room: &Room) {
|
||||||
|
@ -381,7 +390,11 @@ fn attack_human_routine(player: &mut Player, room: &Room) {
|
||||||
|
|
||||||
if human_pos.is_some() {
|
if human_pos.is_some() {
|
||||||
for node_index in human_nodes {
|
for node_index in human_nodes {
|
||||||
if in_node_range(&player.position, room.grid.nodes.get(*node_index).unwrap(), range) {
|
if in_node_range(
|
||||||
|
&player.position,
|
||||||
|
room.grid.nodes.get(*node_index).unwrap(),
|
||||||
|
range
|
||||||
|
) {
|
||||||
human_attacked = true;
|
human_attacked = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
use super::{furniture::Furniture, grid::Grid};
|
use super::{furniture::Furniture, grid::Grid};
|
||||||
use crate::game::{self, ZLayer};
|
use crate::game::{self, ZLayer};
|
||||||
use comfy::{
|
use comfy::{
|
||||||
draw_circle, draw_rect, draw_rect_outline, draw_sprite, error, random_i32, texture_id, vec2, EngineContext, HashSet, RandomRange as _, Vec2, GOLD, GREEN, PURPLE, RED, WHITE
|
draw_circle, draw_rect, draw_rect_outline, draw_sprite, error, random_i32,
|
||||||
|
texture_id, vec2, EngineContext, HashSet, RandomRange as _, Vec2, GOLD, GREEN,
|
||||||
|
PURPLE, RED, WHITE
|
||||||
};
|
};
|
||||||
use indexmap::IndexSet;
|
use indexmap::IndexSet;
|
||||||
|
|
||||||
|
@ -61,10 +63,29 @@ impl Room {
|
||||||
human_pos -= vec2(size.0 as f32 / 2.0, size.1 as f32 / 2.0);
|
human_pos -= vec2(size.0 as f32 / 2.0, size.1 as f32 / 2.0);
|
||||||
human_pos *= SCALE;
|
human_pos *= SCALE;
|
||||||
|
|
||||||
let node_index_left = grid.nodes.iter().enumerate().filter(|(_i, &node)| node.y <= size.1 as f32 / 6.0).filter(|(_i, &node)| node.x <= (human_pos.x - 0.5*SCALE)).max_by_key(|(_i, &node)| node.x as i32).map(|(i, _)| i).unwrap();
|
let node_index_left = grid
|
||||||
let node_index_right = grid.nodes.iter().enumerate().filter(|(_i, &node)| node.y <= size.1 as f32 / 6.0).filter(|(_i, &node)| node.x >= (human_pos.x + 0.5*SCALE)).min_by_key(|(_i, &node)| node.x as i32).map(|(i, _)| i).unwrap();
|
.nodes
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter(|(_i, &node)| node.y <= size.1 as f32 / 6.0)
|
||||||
|
.filter(|(_i, &node)| node.x <= (human_pos.x - 0.5 * SCALE))
|
||||||
|
.max_by_key(|(_i, &node)| node.x as i32)
|
||||||
|
.map(|(i, _)| i)
|
||||||
|
.unwrap();
|
||||||
|
let node_index_right = grid
|
||||||
|
.nodes
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter(|(_i, &node)| node.y <= size.1 as f32 / 6.0)
|
||||||
|
.filter(|(_i, &node)| node.x >= (human_pos.x + 0.5 * SCALE))
|
||||||
|
.min_by_key(|(_i, &node)| node.x as i32)
|
||||||
|
.map(|(i, _)| i)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
(Some(human_pos), (node_index_left..=node_index_right).collect())
|
(
|
||||||
|
Some(human_pos),
|
||||||
|
(node_index_left ..= node_index_right).collect()
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
(None, Vec::new())
|
(None, Vec::new())
|
||||||
};
|
};
|
||||||
|
@ -468,17 +489,21 @@ impl Room {
|
||||||
if human_layer {
|
if human_layer {
|
||||||
if let Some(human_pos) = self.human_pos {
|
if let Some(human_pos) = self.human_pos {
|
||||||
//draw_circle(human_pos, 0.5, RED, 20);
|
//draw_circle(human_pos, 0.5, RED, 20);
|
||||||
draw_sprite(texture_id("human_house"), human_pos, WHITE, ZLayer::Human.into(), vec2(1.0, 2.0) * SCALE);
|
draw_sprite(
|
||||||
|
texture_id("human_house"),
|
||||||
|
human_pos,
|
||||||
|
WHITE,
|
||||||
|
ZLayer::Human.into(),
|
||||||
|
vec2(1.0, 2.0) * SCALE
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Debug draw
|
/* Debug draw
|
||||||
for node_index in &self.human_nodes {
|
for node_index in &self.human_nodes {
|
||||||
draw_circle(*self.grid.nodes.get(*node_index).unwrap(), 0.5, GREEN, ZLayer::Human.into());
|
draw_circle(*self.grid.nodes.get(*node_index).unwrap(), 0.5, GREEN, ZLayer::Human.into());
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
|
||||||
self.grid.draw();
|
self.grid.draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue