refactoring
This commit is contained in:
parent
b173d9e011
commit
b534d5fbde
Binary file not shown.
|
|
@ -1,14 +0,0 @@
|
||||||
{
|
|
||||||
"name": "executor-wasm",
|
|
||||||
"version": "0.1.0",
|
|
||||||
"files": [
|
|
||||||
"executor_wasm_bg.wasm",
|
|
||||||
"executor_wasm.js",
|
|
||||||
"executor_wasm.d.ts"
|
|
||||||
],
|
|
||||||
"module": "executor_wasm.js",
|
|
||||||
"types": "executor_wasm.d.ts",
|
|
||||||
"sideEffects": [
|
|
||||||
"./snippets/*"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
@ -256,7 +256,7 @@ impl Enemy {
|
||||||
if self.win {
|
if self.win {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
let collaider = self.intersections_player(&mut context.scene.graph, 5.);
|
let collaider = self.intersections_player(&mut context.scene.graph, DISTANCE_TO_VIEW);
|
||||||
let mut see_player: bool = false;
|
let mut see_player: bool = false;
|
||||||
if let Some(collaider_data) = collaider {
|
if let Some(collaider_data) = collaider {
|
||||||
for i in 0..collaider_data.len() {
|
for i in 0..collaider_data.len() {
|
||||||
|
|
|
||||||
|
|
@ -148,6 +148,6 @@ impl Plugin for Game {
|
||||||
let graph: &mut Graph = &mut context.scenes[self.scene].graph;
|
let graph: &mut Graph = &mut context.scenes[self.scene].graph;
|
||||||
let resource_manager: &ResourceManager = &context.resource_manager;
|
let resource_manager: &ResourceManager = &context.resource_manager;
|
||||||
build_map(graph, resource_manager);
|
build_map(graph, resource_manager);
|
||||||
EnemySpawn::new().spawn_enemy(graph, resource_manager, 0.0);
|
EnemySpawn::new().spawn_enemy(graph, resource_manager, -5.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,9 @@ use fyrox::{
|
||||||
script::{ScriptContext, ScriptMessageContext, ScriptMessagePayload, ScriptTrait},
|
script::{ScriptContext, ScriptMessageContext, ScriptMessagePayload, ScriptTrait},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const JUMP_HEIGHT: f32 = 6.0;
|
||||||
|
const SPEED: f32 = 2.9;
|
||||||
|
|
||||||
#[derive(Visit, Reflect, Debug, Clone, Default)]
|
#[derive(Visit, Reflect, Debug, Clone, Default)]
|
||||||
pub struct Player {
|
pub struct Player {
|
||||||
sprite: Handle<Node>,
|
sprite: Handle<Node>,
|
||||||
|
|
@ -209,9 +212,9 @@ impl Player {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
return if self.move_left {
|
return if self.move_left {
|
||||||
3.0
|
SPEED
|
||||||
} else if self.move_right {
|
} else if self.move_right {
|
||||||
-3.0
|
SPEED * -1.0
|
||||||
} else {
|
} else {
|
||||||
0.0
|
0.0
|
||||||
};
|
};
|
||||||
|
|
@ -248,13 +251,15 @@ impl Player {
|
||||||
Some(rigid_data) => {
|
Some(rigid_data) => {
|
||||||
if self.jump && !self.is_in_fly(rigid_data) {
|
if self.jump && !self.is_in_fly(rigid_data) {
|
||||||
self.start_y_position = rigid_data.global_position().y;
|
self.start_y_position = rigid_data.global_position().y;
|
||||||
rigid_data.set_lin_vel(Vector2::new(rigid_data.lin_vel().x, 6.0));
|
rigid_data.set_lin_vel(Vector2::new(rigid_data.lin_vel().x, JUMP_HEIGHT));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if rigid_data.lin_vel().y == 0.0 && !self.is_in_fly(rigid_data) {
|
if rigid_data.lin_vel().y == 0.0 && !self.is_in_fly(rigid_data) {
|
||||||
self.start_y_position = rigid_data.global_position().y;
|
self.start_y_position = rigid_data.global_position().y;
|
||||||
}
|
}
|
||||||
|
if rigid_data.global_position().y < -10.0 {
|
||||||
|
self.health = 0.0
|
||||||
|
}
|
||||||
// Log::info(format!(
|
// Log::info(format!(
|
||||||
// "pos {}, dif_height: {}, lin_vel: {}, jump: {}, is_jumping: {}",
|
// "pos {}, dif_height: {}, lin_vel: {}, jump: {}, is_jumping: {}",
|
||||||
// self.prev_y_velosity - rigid_data.lin_vel().y,
|
// self.prev_y_velosity - rigid_data.lin_vel().y,
|
||||||
|
|
@ -358,11 +363,16 @@ impl Player {
|
||||||
parent = Some(d.parent());
|
parent = Some(d.parent());
|
||||||
}
|
}
|
||||||
if let Some(d) = parent {
|
if let Some(d) = parent {
|
||||||
let index = context.scene.graph.try_get_script_index_of::<Enemy>(d).unwrap();
|
let index = context
|
||||||
|
.scene
|
||||||
|
.graph
|
||||||
|
.try_get_script_index_of::<Enemy>(d)
|
||||||
|
.unwrap();
|
||||||
match context
|
match context
|
||||||
.scene
|
.scene
|
||||||
.graph
|
.graph
|
||||||
.try_get_mut(d).and_then(|node| node.try_get_script_mut::<Enemy>(index))
|
.try_get_mut(d)
|
||||||
|
.and_then(|node| node.try_get_script_mut::<Enemy>(index))
|
||||||
{
|
{
|
||||||
Some(script) => {
|
Some(script) => {
|
||||||
script.take_damage(&self.damage);
|
script.take_damage(&self.damage);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue