This commit is contained in:
artem 2024-03-08 22:12:06 +03:00
parent c9b33d3557
commit 82831eaa20
7 changed files with 107 additions and 86 deletions

View File

@ -1607,68 +1607,68 @@ function __wbg_get_imports() {
const ret = wasm.memory;
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper5074 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 5134, __wbg_adapter_32);
imports.wbg.__wbindgen_closure_wrapper5083 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 5140, __wbg_adapter_32);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper5075 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 5134, __wbg_adapter_32);
imports.wbg.__wbindgen_closure_wrapper5084 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 5140, __wbg_adapter_32);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper5076 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 5134, __wbg_adapter_32);
imports.wbg.__wbindgen_closure_wrapper5085 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 5140, __wbg_adapter_32);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper5077 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 5134, __wbg_adapter_32);
imports.wbg.__wbindgen_closure_wrapper5086 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 5140, __wbg_adapter_32);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper5078 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 5134, __wbg_adapter_41);
imports.wbg.__wbindgen_closure_wrapper5087 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 5140, __wbg_adapter_41);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper5079 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 5134, __wbg_adapter_44);
imports.wbg.__wbindgen_closure_wrapper5088 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 5140, __wbg_adapter_44);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper5080 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 5134, __wbg_adapter_32);
imports.wbg.__wbindgen_closure_wrapper5089 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 5140, __wbg_adapter_32);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper41460 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36198, __wbg_adapter_49);
imports.wbg.__wbindgen_closure_wrapper41469 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36204, __wbg_adapter_49);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper42715 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36817, __wbg_adapter_52);
imports.wbg.__wbindgen_closure_wrapper42724 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36823, __wbg_adapter_52);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper42716 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36817, __wbg_adapter_55);
imports.wbg.__wbindgen_closure_wrapper42725 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36823, __wbg_adapter_55);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper42717 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36817, __wbg_adapter_55);
imports.wbg.__wbindgen_closure_wrapper42726 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36823, __wbg_adapter_55);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper42718 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36817, __wbg_adapter_55);
imports.wbg.__wbindgen_closure_wrapper42727 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36823, __wbg_adapter_55);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper42719 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36817, __wbg_adapter_55);
imports.wbg.__wbindgen_closure_wrapper42728 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36823, __wbg_adapter_55);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper42720 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36817, __wbg_adapter_55);
imports.wbg.__wbindgen_closure_wrapper42729 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36823, __wbg_adapter_55);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper42721 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36817, __wbg_adapter_55);
imports.wbg.__wbindgen_closure_wrapper42730 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 36823, __wbg_adapter_55);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper45016 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 37310, __wbg_adapter_68);
imports.wbg.__wbindgen_closure_wrapper45025 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 37316, __wbg_adapter_68);
return addHeapObject(ret);
};

View File

@ -1,3 +1,4 @@
use crate::Game;
use crate::Player;
use fyrox::graph::SceneGraph;
use fyrox::{
@ -22,7 +23,6 @@ use fyrox::{
},
script::{ScriptContext, ScriptTrait},
};
use crate::Game;
impl_component_provider!(Archer,);
uuid_provider!(Archer = "a5671d19-9f1a-4286-8486-add4ebaadaec");
@ -32,9 +32,9 @@ enum Animations {
#[default]
Idle = 0,
Run = 1,
Fight = 2,
Shot = 2,
Dead = 3,
Block = 4,
Fight = 4,
}
const DISTANCE_TO_FIGHT: f32 = 5.0;
@ -44,6 +44,8 @@ const END_MAP_RIGHT: f32 = 30.0;
const SPEED: f32 = 2.1;
const DAMAGE: f32 = 20.0;
const ATTACK_SPEED: f32 = 1.0;
const SUPER_DAMAGE: f32 = 30.0;
const SUPER_ATTACK_SPEED: f32 = 0.3;
#[derive(Visit, Reflect, Debug, Clone, Default)]
pub struct Archer {
@ -52,10 +54,10 @@ pub struct Archer {
move_right: bool,
jump: bool,
pub animations: Vec<SpriteSheetAnimation>,
fight: bool,
shot: bool,
win: bool,
dead: bool,
block: bool,
fight: bool,
#[reflect(hidden)]
#[visit(skip)]
@ -81,6 +83,13 @@ impl Archer {
return a.round() as i32;
}
pub fn take_damage(&mut self, _damage: &f32) {
if self.dead {
return;
}
self.fight = true;
}
fn intersections_box(&self, graph: &mut Graph) -> bool {
if self.dead {
return false;
@ -176,11 +185,11 @@ impl Archer {
return Some(buffer);
}
fn attack_player(&mut self, ctx: &mut ScriptContext) {
fn attack_player(&mut self, ctx: &mut ScriptContext, damage: f32) {
if self.win {
return;
}
if !self.fight {
if !self.shot {
return;
}
let player_script = ctx
@ -189,13 +198,13 @@ impl Archer {
.try_get_script_of_mut::<Player>(self.player_handle)
.unwrap();
if player_script.get_health() <= 0.0 {
self.shot = false;
self.fight = false;
self.block = false;
self.win = true;
return;
}
self.block = false;
player_script.take_damage(&self.attack_damage);
self.fight = false;
player_script.take_damage(&damage);
}
fn get_player_position(&self, context: &mut ScriptContext) -> Vector3<f32> {
@ -276,12 +285,12 @@ impl Archer {
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.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;
return SPEED * -1.0;
}
if player_position.x < enemy_rigid_body.global_position().x {
return SPEED;
return SPEED;
}
}
if enemy_rigid_body.global_position().x < END_MAP_LEFT + 3.0 {
@ -333,7 +342,7 @@ impl Archer {
fn move_do(&mut self, context: &mut ScriptContext) {
let x_speed = self.get_speed(context);
if x_speed > 0.0 {
self.block = false;
self.fight = false;
}
let enemy_rigid_body = context.scene.graph[context.handle].cast_mut::<RigidBody>();
if let Some(enemy_rigid_data) = enemy_rigid_body {
@ -346,8 +355,8 @@ impl Archer {
if self.win {
return;
}
if self.block {
self.current_animation = Animations::Block;
if self.fight {
self.current_animation = Animations::Fight;
return;
}
if self.dead {
@ -358,8 +367,8 @@ impl Archer {
self.current_animation = Animations::Run;
return;
}
if self.fight {
self.current_animation = Animations::Fight;
if self.shot {
self.current_animation = Animations::Shot;
return;
}
}
@ -371,18 +380,21 @@ impl Archer {
if self.dead {
return;
}
if self.block {
return;
let mut damage = self.attack_damage;
let mut speed = self.attack_speed;
if self.fight {
damage = SUPER_DAMAGE;
speed = SUPER_ATTACK_SPEED;
}
let distance = self.distance_to_player(context);
self.fight = distance < DISTANCE_TO_FIGHT && distance > -1.0 * DISTANCE_TO_FIGHT;
if !self.fight {
self.shot = distance < DISTANCE_TO_FIGHT && distance > -1.0 * DISTANCE_TO_FIGHT;
if !self.shot {
self.attack_timer = 0.0;
return;
}
self.attack_timer += context.dt;
if self.attack_timer >= self.attack_speed {
self.attack_player(context);
if self.attack_timer >= speed {
self.attack_player(context, damage);
self.attack_timer = 0.0;
return;
}

View File

@ -29,7 +29,7 @@ use fyrox::{
};
impl_component_provider!(ArcherSpawn,);
uuid_provider!(ArcherSpawn = "b5671d19-9f1a-4286-8486-add4ebaadaec");
uuid_provider!(ArcherSpawn = "c5671d19-9f1a-4286-8486-add4ebaadaec");
#[derive(Visit, Reflect, Debug, Clone, Default)]
pub struct ArcherSpawn {
x: f32,
@ -42,27 +42,27 @@ impl ArcherSpawn {
}
fn block_anmation(&self, resource_manager: &ResourceManager) -> SpriteSheetAnimation<fyrox::asset::Resource<Texture>> {
fn fight_anmation(&self, resource_manager: &ResourceManager) -> SpriteSheetAnimation<fyrox::asset::Resource<Texture>> {
let idle = resource_manager.request::<Texture>(
"assets/data/characters/skeleton/Skeleton_Archer/Evasion.png".to_owned(),
"assets/data/characters/skeleton/Skeleton_Archer/Attack_3.png".to_owned(),
);
let mut idle_animation = SpriteSheetAnimation::new_from_image_parameters(ImageParameters {
width: 768,
width: 384,
height: 128,
frame_width: 128,
frame_height: 128,
first_frame: 0,
last_frame: 1,
last_frame: 3,
column_major: false,
});
idle_animation.set_texture(Some(idle));
idle_animation.set_looping(false);
idle_animation.set_speed(20.);
idle_animation.set_looping(true);
idle_animation.set_speed(5.);
idle_animation.play();
return idle_animation;
}
fn attack_anmation(&self, resource_manager: &ResourceManager) -> SpriteSheetAnimation<fyrox::asset::Resource<Texture>> {
fn shot_anmation(&self, resource_manager: &ResourceManager) -> SpriteSheetAnimation<fyrox::asset::Resource<Texture>> {
let idle = resource_manager.request::<Texture>(
"assets/data/characters/skeleton/Skeleton_Archer/Shot_1.png".to_owned(),
);
@ -153,9 +153,9 @@ impl ArcherSpawn {
enemy.animations = vec![
self.idle_anmation(resource_manager),
self.run_anmation(resource_manager),
self.attack_anmation(resource_manager),
self.shot_anmation(resource_manager),
self.die_anmation(resource_manager),
self.block_anmation(resource_manager),
self.fight_anmation(resource_manager),
];
material
.set_property(

View File

@ -219,11 +219,7 @@ impl Plugin for Game {
SwordmanSpawn::new().spawn_enemy(graph, resource_manager, -5.0);
}
if self.level == 2 {
ArcherSpawn::new().spawn_enemy(graph, resource_manager, -5.0);
}
if self.level == 3 {
SwordmanSpawn::new().spawn_enemy(graph, resource_manager, -5.0);
ArcherSpawn::new().spawn_enemy(graph, resource_manager, 15.0);
ArcherSpawn::new().spawn_enemy(graph, resource_manager, -25.0);
}
let ui_ctx = &mut context.user_interface.build_ctx();

View File

@ -1,14 +1,23 @@
use fyrox::{
asset::manager::ResourceManager,
core::{algebra::{Vector2, Vector3}, math::Rect, sstorage::ImmutableString},
core::{
algebra::{Vector2, Vector3},
math::Rect,
sstorage::ImmutableString,
},
material::{shader::SamplerFallback, Material, MaterialResource, PropertyValue},
resource::texture::Texture,
scene::{
base::BaseBuilder, collider::InteractionGroups, dim2::{
base::BaseBuilder,
collider::InteractionGroups,
dim2::{
collider::{ColliderBuilder, ColliderShape, CuboidShape},
rectangle::RectangleBuilder,
rigidbody::RigidBodyBuilder,
}, graph::Graph, rigidbody::RigidBodyType, transform::TransformBuilder
},
graph::Graph,
rigidbody::RigidBodyType,
transform::TransformBuilder,
},
};
// /mnt/23154027-2dd3-43ea-93f1-02a8df7a3c5a/projects/fyrox/platformer/assets/data/tiles/
@ -184,10 +193,7 @@ fn build_stone_block(resource_manager: &ResourceManager, graph: &mut Graph, x: f
x as f32,
y + 0.7,
1.0,
build_material(
resource_manager,
"assets/data/objects/Stone.png".to_owned(),
),
build_material(resource_manager, "assets/data/objects/Stone.png".to_owned()),
shape,
)
}
@ -236,22 +242,21 @@ pub fn build_map(graph: &mut Graph, resource_manager: &ResourceManager, level: u
build_ground_block(resource_manager, graph, x as f32, bottom_y);
}
build_stone_block(resource_manager, graph, 30.0, bottom_y);
build_tree_block(resource_manager, graph, 35.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);
if level != 3 {
build_tree_block(resource_manager, graph, -35.0, bottom_y);
}
build_box_block(resource_manager, graph, 10.0, bottom_y);
build_air_island_block(resource_manager, graph, 15.0, bottom_y + 2.5);
build_air_island_block(resource_manager, graph, 18.0, bottom_y + 4.0);
build_air_island_block(resource_manager, graph, 21.0, bottom_y + 5.5);
if level != 2 {
build_box_block(resource_manager, graph, 21.0, bottom_y+ 5.5);
build_box_block(resource_manager, graph, 21.0, bottom_y + 5.5);
}
build_air_island_block(resource_manager, graph, -15.0, bottom_y + 2.5);
build_air_island_block(resource_manager, graph, -18.0, bottom_y + 4.0);
build_air_island_block(resource_manager, graph, -21.0, bottom_y + 5.5);
}

View File

@ -1,7 +1,6 @@
use std::collections::VecDeque;
use crate::msg::Message;
use crate::Swordman;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{
@ -31,6 +30,8 @@ use fyrox::{
script::{ScriptContext, ScriptMessageContext, ScriptMessagePayload, ScriptTrait},
};
use crate::Game;
use crate::Swordman;
use crate::Archer;
const JUMP_HEIGHT: f32 = 6.0;
const SPEED: f32 = 2.9;
@ -340,7 +341,7 @@ impl Player {
RayCastOptions {
ray_origin: Point2::new(self_position.x, self_position.y),
ray_direction: Vector2::new(x.clone(), 0.0),
max_len: 1.0,
max_len: 0.5,
groups: InteractionGroups::default(),
// groups: InteractionGroups::default(),
// Sort the results by distance
@ -370,6 +371,13 @@ impl Player {
if let Some(enemy) = enemy_script {
enemy.take_damage(&self.damage);
}
let enemy_script = context
.scene
.graph
.try_get_script_of_mut::<Archer>(d);
if let Some(enemy) = enemy_script {
enemy.take_damage(&self.damage);
}
}
}
}