несколько багов: чтобы скелет не перекидывал ящик за край, во время бега не бил
This commit is contained in:
parent
b217bf05bf
commit
9845202780
|
|
@ -40,6 +40,7 @@ const DISTANCE_TO_FIGHT: f32 = 0.5;
|
|||
const DISTANCE_TO_VIEW: f32 = 5.0;
|
||||
const END_MAP_LEFT: f32 = -30.0;
|
||||
const END_MAP_RIGHT: f32 = 30.0;
|
||||
const SPEED: f32 = 3.1;
|
||||
|
||||
#[derive(Visit, Reflect, Debug, Clone, Default)]
|
||||
pub struct Enemy {
|
||||
|
|
@ -180,27 +181,21 @@ impl Enemy {
|
|||
if self.win {
|
||||
return;
|
||||
}
|
||||
let collaider = self.intersections_player(graph, 1.);
|
||||
if let Some(collaider_data) = collaider {
|
||||
for i in 0..collaider_data.len() {
|
||||
if collaider_data[i].collider != self.player_collider {
|
||||
continue;
|
||||
if !self.fight {
|
||||
return;
|
||||
}
|
||||
match graph.try_get_script_of_mut::<Player>(self.player_handle) {
|
||||
Some(script) => {
|
||||
if script.get_health() <= 0.0 {
|
||||
self.fight = false;
|
||||
self.block = false;
|
||||
self.win = true;
|
||||
return;
|
||||
}
|
||||
match graph.try_get_script_of_mut::<Player>(self.player_handle) {
|
||||
Some(script) => {
|
||||
if script.get_health() <= 0.0 {
|
||||
self.fight = false;
|
||||
self.block = false;
|
||||
self.win = true;
|
||||
break;
|
||||
}
|
||||
self.block = false;
|
||||
script.take_damage(&self.attack_damage);
|
||||
}
|
||||
None => {}
|
||||
};
|
||||
break;
|
||||
self.block = false;
|
||||
script.take_damage(&self.attack_damage);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -266,10 +261,10 @@ impl Enemy {
|
|||
}
|
||||
|
||||
if distance > DISTANCE_TO_FIGHT {
|
||||
return 3.1;
|
||||
return SPEED;
|
||||
}
|
||||
if distance < DISTANCE_TO_FIGHT * -1.0 {
|
||||
return -3.1;
|
||||
return SPEED * -1.0;
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
|
@ -319,10 +314,6 @@ impl Enemy {
|
|||
self.current_animation = Animations::Block;
|
||||
return;
|
||||
}
|
||||
if self.fight {
|
||||
self.current_animation = Animations::Fight;
|
||||
return;
|
||||
}
|
||||
if self.dead {
|
||||
self.current_animation = Animations::Dead;
|
||||
return;
|
||||
|
|
@ -331,6 +322,10 @@ impl Enemy {
|
|||
self.current_animation = Animations::Run;
|
||||
return;
|
||||
}
|
||||
if self.fight {
|
||||
self.current_animation = Animations::Fight;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fn set_fight(&mut self, context: &mut ScriptContext) {
|
||||
|
|
@ -353,7 +348,9 @@ impl Enemy {
|
|||
if self.attack_timer >= self.attack_speed {
|
||||
self.attack_player(&mut context.scene.graph);
|
||||
self.attack_timer = 0.0;
|
||||
return;
|
||||
}
|
||||
self.fight = false;
|
||||
}
|
||||
|
||||
pub fn animation_do(&mut self, context: &mut ScriptContext) {
|
||||
|
|
@ -432,9 +429,9 @@ impl ScriptTrait for Enemy {
|
|||
if self.intersections_box(&mut context.scene.graph) {
|
||||
self.dead = true
|
||||
}
|
||||
self.set_fight(context);
|
||||
self.change_orientation(context);
|
||||
self.animation_do(context);
|
||||
self.move_do(context);
|
||||
self.set_fight(context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -192,22 +192,22 @@ fn build_stone_block(resource_manager: &ResourceManager, graph: &mut Graph, x: f
|
|||
)
|
||||
}
|
||||
|
||||
fn build_mushroom_block(resource_manager: &ResourceManager, graph: &mut Graph, x: f32, y: f32) {
|
||||
let shape = ColliderShape::Cuboid(CuboidShape {
|
||||
half_extents: Vector2::new(0.25, 0.25),
|
||||
});
|
||||
build_block(
|
||||
graph,
|
||||
x as f32,
|
||||
y + 0.5,
|
||||
0.5,
|
||||
build_material(
|
||||
resource_manager,
|
||||
"assets/data/objects/Mushroom_2.png".to_owned(),
|
||||
),
|
||||
shape,
|
||||
)
|
||||
}
|
||||
// fn build_mushroom_block(resource_manager: &ResourceManager, graph: &mut Graph, x: f32, y: f32) {
|
||||
// let shape = ColliderShape::Cuboid(CuboidShape {
|
||||
// half_extents: Vector2::new(0.25, 0.25),
|
||||
// });
|
||||
// build_block(
|
||||
// graph,
|
||||
// x as f32,
|
||||
// y + 0.5,
|
||||
// 0.5,
|
||||
// build_material(
|
||||
// resource_manager,
|
||||
// "assets/data/objects/Mushroom_2.png".to_owned(),
|
||||
// ),
|
||||
// shape,
|
||||
// )
|
||||
// }
|
||||
|
||||
fn build_box_block(resource_manager: &ResourceManager, graph: &mut Graph, x: f32, y: f32) {
|
||||
let shape = ColliderShape::Cuboid(CuboidShape::default());
|
||||
|
|
@ -235,7 +235,7 @@ pub fn build_map(graph: &mut Graph, resource_manager: &ResourceManager) {
|
|||
for x in left_x..right_x {
|
||||
build_ground_block(resource_manager, graph, x as f32, bottom_y);
|
||||
}
|
||||
build_mushroom_block(resource_manager, graph, 30.0, bottom_y);
|
||||
build_stone_block(resource_manager, graph, 30.0, bottom_y);
|
||||
build_tree_block(resource_manager, graph, 35.0, bottom_y);
|
||||
build_stone_block(resource_manager, graph, -30.0, bottom_y);
|
||||
build_tree_block(resource_manager, graph, -35.0, bottom_y);
|
||||
|
|
|
|||
Loading…
Reference in New Issue