DEV-415 looking for enemy in both side
This commit is contained in:
parent
c17da1cfd8
commit
7d3c3ec092
|
|
@ -1,8 +1,10 @@
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
|
use crate::msg::Message;
|
||||||
|
use crate::Enemy;
|
||||||
use fyrox::{
|
use fyrox::{
|
||||||
core::{
|
core::{
|
||||||
algebra::{Vector2, Vector3, Point2},
|
algebra::{Point2, Vector2, Vector3},
|
||||||
color::Color,
|
color::Color,
|
||||||
impl_component_provider,
|
impl_component_provider,
|
||||||
log::Log,
|
log::Log,
|
||||||
|
|
@ -14,9 +16,9 @@ use fyrox::{
|
||||||
event::{ElementState, Event, TouchPhase, WindowEvent},
|
event::{ElementState, Event, TouchPhase, WindowEvent},
|
||||||
keyboard::{KeyCode, PhysicalKey},
|
keyboard::{KeyCode, PhysicalKey},
|
||||||
scene::{
|
scene::{
|
||||||
collider::InteractionGroups,
|
|
||||||
animation::spritesheet::SpriteSheetAnimation,
|
animation::spritesheet::SpriteSheetAnimation,
|
||||||
base::BaseBuilder,
|
base::BaseBuilder,
|
||||||
|
collider::InteractionGroups,
|
||||||
dim2::{
|
dim2::{
|
||||||
physics::{Intersection, RayCastOptions},
|
physics::{Intersection, RayCastOptions},
|
||||||
rectangle::{Rectangle, RectangleBuilder},
|
rectangle::{Rectangle, RectangleBuilder},
|
||||||
|
|
@ -25,10 +27,8 @@ use fyrox::{
|
||||||
node::Node,
|
node::Node,
|
||||||
transform::TransformBuilder,
|
transform::TransformBuilder,
|
||||||
},
|
},
|
||||||
script::{ScriptContext, ScriptTrait, ScriptMessageContext, ScriptMessagePayload},
|
script::{ScriptContext, ScriptMessageContext, ScriptMessagePayload, ScriptTrait},
|
||||||
};
|
};
|
||||||
use crate::msg::Message;
|
|
||||||
use crate::Enemy;
|
|
||||||
|
|
||||||
#[derive(Visit, Reflect, Debug, Clone, Default)]
|
#[derive(Visit, Reflect, Debug, Clone, Default)]
|
||||||
pub struct Player {
|
pub struct Player {
|
||||||
|
|
@ -326,11 +326,12 @@ impl Player {
|
||||||
let self_position = self_node.global_position();
|
let self_position = self_node.global_position();
|
||||||
// Cast a ray from *this* node in the direction of the player node
|
// Cast a ray from *this* node in the direction of the player node
|
||||||
let mut buffer = Vec::<Intersection>::new();
|
let mut buffer = Vec::<Intersection>::new();
|
||||||
|
let x_coord: [f32; 2] = [-1.0, 1.0];
|
||||||
|
for x in x_coord.iter() {
|
||||||
context.scene.graph.physics2d.cast_ray(
|
context.scene.graph.physics2d.cast_ray(
|
||||||
RayCastOptions {
|
RayCastOptions {
|
||||||
ray_origin: Point2::new(self_position.x, self_position.y),
|
ray_origin: Point2::new(self_position.x, self_position.y),
|
||||||
ray_direction: Vector2::new(-1.0, 0.0),
|
ray_direction: Vector2::new(x.clone(), 0.0),
|
||||||
max_len: 1.0,
|
max_len: 1.0,
|
||||||
groups: InteractionGroups::default(),
|
groups: InteractionGroups::default(),
|
||||||
// groups: InteractionGroups::default(),
|
// groups: InteractionGroups::default(),
|
||||||
|
|
@ -340,22 +341,27 @@ impl Player {
|
||||||
// Store the collisions in the vector
|
// Store the collisions in the vector
|
||||||
&mut buffer,
|
&mut buffer,
|
||||||
);
|
);
|
||||||
if buffer.len() == 0 {
|
if buffer.len() == 1 {
|
||||||
return ;
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
for i in 0..buffer.len() {
|
for i in 0..buffer.len() {
|
||||||
if buffer[i].toi == 0.0 {
|
if buffer[i].toi == 0.0 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let Some(d) = context.scene.graph.try_get(buffer[i].collider) {
|
if let Some(d) = context.scene.graph.try_get(buffer[i].collider) {
|
||||||
match context.scene.graph.try_get_script_of_mut::<Enemy>(d.parent()) {
|
match context
|
||||||
|
.scene
|
||||||
|
.graph
|
||||||
|
.try_get_script_of_mut::<Enemy>(d.parent())
|
||||||
|
{
|
||||||
Some(script) => {
|
Some(script) => {
|
||||||
script.take_damage(&self.damage);
|
script.take_damage(&self.damage);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -470,7 +476,9 @@ impl ScriptTrait for Player {
|
||||||
|
|
||||||
// Put start logic - it is called when every other script is already initialized.
|
// Put start logic - it is called when every other script is already initialized.
|
||||||
fn on_start(&mut self, context: &mut ScriptContext) {
|
fn on_start(&mut self, context: &mut ScriptContext) {
|
||||||
context.message_dispatcher.subscribe_to::<Message>(context.handle);
|
context
|
||||||
|
.message_dispatcher
|
||||||
|
.subscribe_to::<Message>(context.handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_message(
|
fn on_message(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue