web biuld

This commit is contained in:
artem 2024-02-25 14:25:21 +03:00
parent 074e5f8b59
commit b173d9e011
4 changed files with 92 additions and 45 deletions

View File

@ -1604,68 +1604,68 @@ function __wbg_get_imports() {
const ret = wasm.memory;
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper13019 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 10966, __wbg_adapter_32);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper13020 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 10966, __wbg_adapter_32);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper13021 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 10968, __wbg_adapter_32);
const ret = makeMutClosure(arg0, arg1, 10966, __wbg_adapter_32);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper13022 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 10968, __wbg_adapter_32);
const ret = makeMutClosure(arg0, arg1, 10966, __wbg_adapter_39);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper13023 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 10968, __wbg_adapter_32);
const ret = makeMutClosure(arg0, arg1, 10966, __wbg_adapter_32);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper13024 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 10968, __wbg_adapter_39);
const ret = makeMutClosure(arg0, arg1, 10966, __wbg_adapter_44);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper13025 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 10968, __wbg_adapter_32);
const ret = makeMutClosure(arg0, arg1, 10966, __wbg_adapter_32);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper13026 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 10968, __wbg_adapter_44);
imports.wbg.__wbindgen_closure_wrapper41736 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36343, __wbg_adapter_49);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper13027 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 10968, __wbg_adapter_32);
imports.wbg.__wbindgen_closure_wrapper43082 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36985, __wbg_adapter_52);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper41738 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36345, __wbg_adapter_49);
imports.wbg.__wbindgen_closure_wrapper43083 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36985, __wbg_adapter_55);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper43084 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36987, __wbg_adapter_52);
const ret = makeMutClosure(arg0, arg1, 36985, __wbg_adapter_52);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper43085 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36987, __wbg_adapter_55);
const ret = makeMutClosure(arg0, arg1, 36985, __wbg_adapter_52);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper43086 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36987, __wbg_adapter_52);
const ret = makeMutClosure(arg0, arg1, 36985, __wbg_adapter_52);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper43087 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36987, __wbg_adapter_52);
const ret = makeMutClosure(arg0, arg1, 36985, __wbg_adapter_52);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper43088 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36987, __wbg_adapter_52);
const ret = makeMutClosure(arg0, arg1, 36985, __wbg_adapter_52);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper43089 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36987, __wbg_adapter_52);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper43090 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36987, __wbg_adapter_52);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper45333 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 37486, __wbg_adapter_68);
imports.wbg.__wbindgen_closure_wrapper45331 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 37484, __wbg_adapter_68);
return addHeapObject(ret);
};

View File

@ -187,10 +187,16 @@ impl Enemy {
if !self.fight {
return;
}
let index = ctx.scene.graph.try_get_script_index_of::<Player>(self.player_handle).unwrap();
let index = ctx
.scene
.graph
.try_get_script_index_of::<Player>(self.player_handle)
.unwrap();
match ctx
.scene
.graph.try_get_mut(self.player_handle).and_then(|node| node.try_get_script_mut::<Player>(index))
.scene
.graph
.try_get_mut(self.player_handle)
.and_then(|node| node.try_get_script_mut::<Player>(index))
{
Some(script) => {
if script.get_health() <= 0.0 {
@ -206,28 +212,40 @@ impl Enemy {
}
}
fn get_player_position(&self, context: &mut ScriptContext) -> Vector3<f32> {
let player_binding = context.scene.graph.try_get_mut(self.player_handle).unwrap();
let player_rigid_body = player_binding.cast::<RigidBody>();
let player_rigid_data = match player_rigid_body {
Some(rigid_body) => rigid_body,
None => panic!("wrong player position"),
};
return Vector3::new(
player_rigid_data.local_transform().position().x,
player_rigid_data.local_transform().position().y,
player_rigid_data.local_transform().position().z,
);
}
fn distance_to_player(&self, context: &mut ScriptContext) -> f32 {
let graph_ctx = context.scene.graph.begin_multi_borrow();
let enemy_binding = graph_ctx.try_get(context.handle).unwrap();
let player_position = self.get_player_position(context);
let enemy_binding = context.scene.graph.try_get_mut(context.handle).unwrap();
let enemy_rigid_body = enemy_binding.cast::<RigidBody>();
let enemy_rigid_data = match enemy_rigid_body {
Some(rigid_data) => rigid_data,
None => return 0.0,
};
let player_binding = graph_ctx.try_get(self.player_handle).unwrap();
let player_rigid_body = player_binding.cast::<RigidBody>();
let player_rigid_data = match player_rigid_body {
Some(rigid_body) => rigid_body,
None => return 0.0,
};
let player_position = player_rigid_data.local_transform().position();
// TODO: if player is places abroad maps - stop activity
if player_position.x <= END_MAP_LEFT || player_position.x >= END_MAP_RIGHT {
return 100.0;
}
// if player_position.x <= END_MAP_LEFT || player_position.x >= END_MAP_RIGHT {
// return 100.0;
// }
let enemy_position = enemy_rigid_data.local_transform().position();
if player_position.y > enemy_position.y {
return DISTANCE_TO_VIEW * 2.0;
}
return player_position.x - enemy_position.x;
}
@ -255,11 +273,40 @@ impl Enemy {
return 0.0;
}
let distance = self.distance_to_player(context);
if distance > DISTANCE_TO_VIEW {
let player_position = self.get_player_position(context);
let enemy_rigid_body = context.scene.graph[context.handle]
.cast_mut::<RigidBody>()
.unwrap();
if enemy_rigid_body.global_position().x <= END_MAP_LEFT {
return 0.0;
}
if distance < DISTANCE_TO_VIEW * -1.0 {
if enemy_rigid_body.global_position().x >= END_MAP_RIGHT {
return 0.0;
}
let mut dif_x = player_position.x - enemy_rigid_body.global_position().x;
if enemy_rigid_body.global_position().x > player_position.x {
dif_x = player_position.x - enemy_rigid_body.global_position().x;
}
if dif_x < 0.0 {
dif_x *= -1.0;
}
if player_position.y > enemy_rigid_body.global_position().y && dif_x < 1.0 {
if player_position.x > enemy_rigid_body.global_position().x {
return SPEED * -1.0;
}
if player_position.x < enemy_rigid_body.global_position().x {
return SPEED;
}
}
if enemy_rigid_body.global_position().x < END_MAP_LEFT + 3.0 {
return SPEED / 2.0;
}
if enemy_rigid_body.global_position().x > END_MAP_RIGHT - 3.0 {
return SPEED / 2.0;
}
let distance = self.distance_to_player(context);
if distance > DISTANCE_TO_VIEW {
return 0.0;
}

View File

@ -214,7 +214,7 @@ fn build_box_block(resource_manager: &ResourceManager, graph: &mut Graph, x: f32
build_dynamic_block(
graph,
x,
y + 1.0,
y + 2.0,
1.0,
build_material(resource_manager, "assets/data/objects/Crate.png".to_owned()),
shape,