diff --git a/data/scene.rgs b/data/scene.rgs index 762341b..09a145b 100644 Binary files a/data/scene.rgs and b/data/scene.rgs differ diff --git a/executor-wasm/pkg/executor_wasm.js b/executor-wasm/pkg/executor_wasm.js index 1d6ecaa..509e40a 100644 --- a/executor-wasm/pkg/executor_wasm.js +++ b/executor-wasm/pkg/executor_wasm.js @@ -1593,68 +1593,68 @@ function __wbg_get_imports() { const ret = wasm.memory; return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper11061 = function(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 9367, __wbg_adapter_32); + imports.wbg.__wbindgen_closure_wrapper11134 = function(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 9432, __wbg_adapter_32); return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper11062 = function(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 9367, __wbg_adapter_32); + imports.wbg.__wbindgen_closure_wrapper11135 = function(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 9432, __wbg_adapter_32); return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper11063 = function(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 9367, __wbg_adapter_32); + imports.wbg.__wbindgen_closure_wrapper11136 = function(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 9432, __wbg_adapter_32); return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper11064 = function(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 9367, __wbg_adapter_39); + imports.wbg.__wbindgen_closure_wrapper11137 = function(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 9432, __wbg_adapter_39); return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper11065 = function(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 9367, __wbg_adapter_32); + imports.wbg.__wbindgen_closure_wrapper11138 = function(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 9432, __wbg_adapter_32); return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper11066 = function(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 9367, __wbg_adapter_44); + imports.wbg.__wbindgen_closure_wrapper11139 = function(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 9432, __wbg_adapter_44); return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper11070 = function(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 9367, __wbg_adapter_32); + imports.wbg.__wbindgen_closure_wrapper11143 = function(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 9432, __wbg_adapter_32); return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper30719 = function(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 25936, __wbg_adapter_49); + imports.wbg.__wbindgen_closure_wrapper30792 = function(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 26001, __wbg_adapter_49); return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper32137 = function(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 26655, __wbg_adapter_52); + imports.wbg.__wbindgen_closure_wrapper32210 = function(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 26720, __wbg_adapter_52); return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper32138 = function(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 26655, __wbg_adapter_55); + imports.wbg.__wbindgen_closure_wrapper32211 = function(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 26720, __wbg_adapter_55); return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper32139 = function(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 26655, __wbg_adapter_55); + imports.wbg.__wbindgen_closure_wrapper32212 = function(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 26720, __wbg_adapter_55); return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper32140 = function(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 26655, __wbg_adapter_55); + imports.wbg.__wbindgen_closure_wrapper32213 = function(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 26720, __wbg_adapter_55); return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper32141 = function(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 26655, __wbg_adapter_55); + imports.wbg.__wbindgen_closure_wrapper32214 = function(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 26720, __wbg_adapter_55); return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper32142 = function(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 26655, __wbg_adapter_55); + imports.wbg.__wbindgen_closure_wrapper32215 = function(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 26720, __wbg_adapter_55); return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper32143 = function(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 26655, __wbg_adapter_55); + imports.wbg.__wbindgen_closure_wrapper32216 = function(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 26720, __wbg_adapter_55); return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper37689 = function(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 30051, __wbg_adapter_68); + imports.wbg.__wbindgen_closure_wrapper37762 = function(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 30116, __wbg_adapter_68); return addHeapObject(ret); }; diff --git a/executor-wasm/pkg/executor_wasm_bg.wasm b/executor-wasm/pkg/executor_wasm_bg.wasm index 7bcb04c..21718f3 100644 Binary files a/executor-wasm/pkg/executor_wasm_bg.wasm and b/executor-wasm/pkg/executor_wasm_bg.wasm differ diff --git a/game/src/enemy.rs b/game/src/enemy.rs index 8660b53..101240d 100644 --- a/game/src/enemy.rs +++ b/game/src/enemy.rs @@ -1,10 +1,14 @@ use fyrox::{ core::{ - impl_component_provider, pool::Handle, reflect::prelude::*, uuid_provider, + algebra::{Vector2}, + impl_component_provider, + pool::Handle, + reflect::prelude::*, + uuid_provider, visitor::prelude::*, }, scene::animation::spritesheet::SpriteSheetAnimation, - scene::dim2::collider::Collider, + scene::dim2::{collider::Collider, rectangle::Rectangle, rigidbody::RigidBody}, scene::node::Node, script::{ScriptContext, ScriptTrait}, }; @@ -12,6 +16,13 @@ use fyrox::{ impl_component_provider!(Enemy,); uuid_provider!(Enemy = "a5671d19-9f1a-4286-8486-add4ebaadaec"); +#[derive(Debug, Clone, Default)] +enum Animations { + #[default] + Idle = 0, + Run = 1, +} + #[derive(Visit, Reflect, Debug, Clone, Default)] pub struct Enemy { sprite: Handle, @@ -20,13 +31,70 @@ pub struct Enemy { jump: bool, animations: Vec, fight: bool, - current_animation: u32, + + #[reflect(hidden)] + #[visit(skip)] + current_animation: Animations, handle: Handle, player_handle: Handle, player_collider: Handle, } +impl Enemy { + pub fn build(&self) { + // let mut material = Material::standard_2d(); + // material + // .set_property( + // &ImmutableString::new("diffuseTexture"), + // PropertyValue::Sampler { + // value: Some(resource_manager.request::(path)), + // fallback: SamplerFallback::Normal, + // }, + // ) + // .unwrap(); + // material_resource = MaterialResource::new_ok(Default::default(), material); + } + fn get_speed(&self) -> f32 { + return -2.0; + } + + fn move_do(&mut self, context: &mut ScriptContext) { + let rigid_body = context.scene.graph[context.handle].cast_mut::(); + match rigid_body { + Some(rigid_data) => { + let x_speed = self.get_speed(); + rigid_data.set_lin_vel(Vector2::new(x_speed, rigid_data.lin_vel().y)); + } + None => {} + } + } + + pub fn animation_do(&mut self, context: &mut ScriptContext) { + let mut current_animation = Animations::Run; + let current_animation = self.animations.get_mut(current_animation as usize); + match current_animation { + Some(animation_data) => { + animation_data.update(context.dt); + + if let Some(sprite) = context + .scene + .graph + .try_get_mut(self.sprite) + .and_then(|n| n.cast_mut::()) + { + sprite + .material() + .data_ref() + .set_texture(&"diffuseTexture".into(), animation_data.texture()) + .unwrap(); + sprite.set_uv_rect(animation_data.current_frame_uv_rect().unwrap_or_default()); + } + } + None => {} + } + } +} impl ScriptTrait for Enemy { fn on_init(&mut self, context: &mut ScriptContext) { // Store reference to *this* instance of the enemy node @@ -49,4 +117,9 @@ impl ScriptTrait for Enemy { None => {} } } + + fn on_update(&mut self, context: &mut ScriptContext) { + self.animation_do(context); + self.move_do(context); + } } diff --git a/game/src/lib.rs b/game/src/lib.rs index b3f0667..d6cd8dc 100644 --- a/game/src/lib.rs +++ b/game/src/lib.rs @@ -17,6 +17,8 @@ mod enemy; use map::build_map; use player::Player; +use enemy::Enemy; + pub struct GameConstructor; @@ -25,6 +27,7 @@ impl PluginConstructor for GameConstructor { // Register your scripts here. let script_constructors = &context.serialization_context.script_constructors; script_constructors.add::("Player"); + script_constructors.add::("Enemy"); } fn create_instance(&self, scene_path: Option<&str>, context: PluginContext) -> Box { diff --git a/settings.ron b/settings.ron index cb90912..f353489 100644 --- a/settings.ron +++ b/settings.ron @@ -316,367 +316,13 @@ scene_settings: { "data/scene.rgs": ( camera_settings: ( - position: (6.305661, 0.0, -3.0), - yaw: -6.4613833, - pitch: 0.14342158, + position: (6.8261476, -3.0730605, -3.0), + yaw: 0.0, + pitch: 0.0, ), node_infos: { ( - index: 71, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 26, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 54, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 52, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 72, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 62, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 16, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 81, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 11, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 46, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 7, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 42, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 8, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 6, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 38, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 50, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 48, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 2, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 69, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 66, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 3, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 35, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 5, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 27, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 28, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 34, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 47, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 91, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 49, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 59, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 57, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 20, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 1, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 13, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 45, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 87, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 29, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 60, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 17, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 33, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 36, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 44, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 24, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 86, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 74, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 32, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 55, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 77, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 30, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 80, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 14, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 82, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 15, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 22, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 21, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 12, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 93, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 0, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 65, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 83, + index: 40, generation: 1, ): ( is_expanded: true, @@ -688,11 +334,41 @@ is_expanded: true, ), ( - index: 39, + index: 58, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 12, generation: 1, ): ( is_expanded: false, ), + ( + index: 29, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 57, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 86, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 47, + generation: 1, + ): ( + is_expanded: true, + ), ( index: 10, generation: 1, @@ -700,29 +376,17 @@ is_expanded: true, ), ( - index: 25, + index: 91, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 69, generation: 1, ): ( is_expanded: false, ), - ( - index: 23, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 4, - generation: 1, - ): ( - is_expanded: true, - ), - ( - index: 18, - generation: 1, - ): ( - is_expanded: true, - ), ( index: 56, generation: 1, @@ -730,7 +394,7 @@ is_expanded: true, ), ( - index: 90, + index: 39, generation: 1, ): ( is_expanded: false, @@ -742,19 +406,49 @@ is_expanded: true, ), ( - index: 9, + index: 45, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 44, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 17, generation: 1, ): ( is_expanded: false, ), ( - index: 37, + index: 35, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 33, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 72, generation: 1, ): ( is_expanded: false, ), ( - index: 58, + index: 52, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 13, generation: 1, ): ( is_expanded: true, @@ -766,31 +460,19 @@ is_expanded: true, ), ( - index: 63, + index: 32, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 25, generation: 1, ): ( is_expanded: false, ), ( - index: 19, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 75, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 78, - generation: 1, - ): ( - is_expanded: false, - ), - ( - index: 43, + index: 22, generation: 1, ): ( is_expanded: false, @@ -801,6 +483,126 @@ ): ( is_expanded: true, ), + ( + index: 14, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 36, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 48, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 7, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 60, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 75, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 42, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 4, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 87, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 18, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 0, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 19, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 50, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 5, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 54, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 37, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 28, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 65, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 20, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 3, + generation: 1, + ): ( + is_expanded: true, + ), ( index: 89, generation: 1, @@ -808,17 +610,179 @@ is_expanded: true, ), ( - index: 40, + index: 46, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 24, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 82, generation: 1, ): ( is_expanded: true, ), + ( + index: 27, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 93, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 1, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 6, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 81, + generation: 1, + ): ( + is_expanded: false, + ), ( index: 84, generation: 1, ): ( is_expanded: false, ), + ( + index: 51, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 80, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 43, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 8, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 21, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 63, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 11, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 16, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 66, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 83, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 55, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 26, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 49, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 78, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 74, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 30, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 90, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 71, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 77, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 2, + generation: 1, + ): ( + is_expanded: true, + ), ( index: 31, generation: 1, @@ -826,13 +790,49 @@ is_expanded: true, ), ( - index: 41, + index: 23, generation: 1, ): ( is_expanded: true, ), ( - index: 51, + index: 38, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 59, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 15, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 34, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 9, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 62, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 41, generation: 1, ): ( is_expanded: true,