This commit is contained in:
artem 2024-03-08 14:47:33 +03:00
parent f258ec0761
commit 66493460a2
9 changed files with 637 additions and 612 deletions

Binary file not shown.

Binary file not shown.

View File

@ -22,6 +22,7 @@ use fyrox::{
},
script::{ScriptContext, ScriptTrait},
};
use crate::Game;
impl_component_provider!(Archer,);
uuid_provider!(Archer = "a5671d19-9f1a-4286-8486-add4ebaadaec");
@ -36,11 +37,13 @@ enum Animations {
Block = 4,
}
const DISTANCE_TO_FIGHT: f32 = 0.5;
const DISTANCE_TO_VIEW: f32 = 5.0;
const DISTANCE_TO_FIGHT: f32 = 5.0;
const DISTANCE_TO_VIEW: f32 = 15.0;
const END_MAP_LEFT: f32 = -30.0;
const END_MAP_RIGHT: f32 = 30.0;
const SPEED: f32 = 3.1;
const SPEED: f32 = 2.1;
const DAMAGE: f32 = 20.0;
const ATTACK_SPEED: f32 = 1.0;
#[derive(Visit, Reflect, Debug, Clone, Default)]
pub struct Archer {
@ -70,21 +73,14 @@ pub struct Archer {
}
impl Archer {
fn init(&mut self) {
self.attack_damage = 100.0;
self.attack_speed = 0.1;
self.attack_damage = DAMAGE;
self.attack_speed = ATTACK_SPEED;
}
fn round(&self, a: f32) -> i32 {
return a.round() as i32;
}
pub fn take_damage(&mut self, _damage: &f32) {
if self.dead {
return;
}
self.block = true;
}
fn intersections_box(&self, graph: &mut Graph) -> bool {
if self.dead {
return false;
@ -390,7 +386,7 @@ impl Archer {
self.attack_timer = 0.0;
return;
}
self.fight = false;
// self.fight = false;
}
pub fn animation_do(&mut self, context: &mut ScriptContext) {
@ -469,7 +465,10 @@ impl ScriptTrait for Archer {
fn on_update(&mut self, context: &mut ScriptContext) {
if self.intersections_box(&mut context.scene.graph) {
self.dead = true
self.dead = true;
let game = context.plugins.get_mut::<Game>();
game.next_level();
return;
}
self.set_fight(context);
self.change_orientation(context);

View File

@ -64,20 +64,20 @@ impl ArcherSpawn {
fn attack_anmation(&self, resource_manager: &ResourceManager) -> SpriteSheetAnimation<fyrox::asset::Resource<Texture>> {
let idle = resource_manager.request::<Texture>(
"assets/data/characters/skeleton/Skeleton_Archer/Attack_3.png".to_owned(),
"assets/data/characters/skeleton/Skeleton_Archer/Shot_1.png".to_owned(),
);
let mut idle_animation = SpriteSheetAnimation::new_from_image_parameters(ImageParameters {
width: 512,
width: 1920,
height: 128,
frame_width: 128,
frame_height: 128,
first_frame: 0,
last_frame: 6,
last_frame: 15,
column_major: false,
});
idle_animation.set_texture(Some(idle));
idle_animation.set_looping(true);
idle_animation.set_speed(20.);
idle_animation.set_speed(5.);
idle_animation.play();
return idle_animation;
}
@ -97,7 +97,7 @@ impl ArcherSpawn {
});
idle_animation.set_texture(Some(idle));
idle_animation.set_looping(true);
idle_animation.set_speed(10.);
idle_animation.set_speed(5.);
idle_animation.play();
return idle_animation;
}

View File

@ -42,6 +42,8 @@ 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;
const DAMAGE: f32 = 100.0;
const ATTACK_SPEED: f32 = 0.1;
#[derive(Visit, Reflect, Debug, Clone, Default)]
pub struct Swordman {
@ -71,8 +73,8 @@ pub struct Swordman {
}
impl Swordman {
fn init(&mut self) {
self.attack_damage = 100.0;
self.attack_speed = 0.1;
self.attack_damage = DAMAGE;
self.attack_speed = ATTACK_SPEED;
}
fn round(&self, a: f32) -> i32 {

View File

@ -26,6 +26,8 @@ use map::build_map;
use msg::Message;
use player::Player;
const START_LEVEL: u32 = 2;
pub struct GameConstructor;
impl PluginConstructor for GameConstructor {
@ -73,7 +75,7 @@ impl Game {
scene: Handle::NONE,
new_game: Handle::NONE,
exit: Handle::NONE,
level: 2,
level: START_LEVEL,
need_change_level: false,
}
}
@ -161,12 +163,19 @@ impl Plugin for Game {
let graph: &mut Graph = &mut context.scenes[self.scene].graph;
let resource_manager: &ResourceManager = &context.resource_manager;
build_map(graph, resource_manager);
build_map(graph, resource_manager, self.level);
if self.level == 1 {
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);
}
}
}

View File

@ -228,7 +228,7 @@ fn build_air_island_block(resource_manager: &ResourceManager, graph: &mut Graph,
build_right_block(resource_manager, graph, x - 1.0, y);
}
pub fn build_map(graph: &mut Graph, resource_manager: &ResourceManager) {
pub fn build_map(graph: &mut Graph, resource_manager: &ResourceManager, level: u32) {
let bottom_y: f32 = -5.0;
let left_x: i32 = -43;
let right_x: i32 = 43;
@ -244,7 +244,9 @@ pub fn build_map(graph: &mut Graph, resource_manager: &ResourceManager) {
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);
build_box_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_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);

View File

@ -1,5 +1,4 @@
use std::collections::VecDeque;
use std::{thread, time::Duration};
use crate::msg::Message;
use crate::Swordman;
@ -112,7 +111,7 @@ impl Player {
1.,
))
// Position the healthbar just above the player
.with_local_position(Vector3::new(-0.1, 0.25, 0.01))
.with_local_position(Vector3::new(0.0, 0.25, 0.01))
.build(),
),
)
@ -140,7 +139,7 @@ impl Player {
1.,
))
// Position the healthbar just above the player, and just in front of the background
.with_local_position(Vector3::new(-0.1, 0.25, 0.0))
.with_local_position(Vector3::new(0.0, 0.25, 0.0))
.build(),
),
)
@ -421,15 +420,29 @@ impl Player {
(self.health / self.max_health) * Self::MAX_HEALTH_BAR_WIDTH,
0.0,
);
// If the new scale is different from the current scale, update the scale
if health_bar_scale.x != new_health {
health_bar_transform.set_scale(Vector3::new(
new_health,
new_health ,
// Don't change the y or z scale
health_bar_scale.y,
health_bar_scale.z,
));
let d = health_bar_transform.position();
let mut nex_x = 0.03;
if new_health < 0.7 {
nex_x = 0.05
}
if new_health < 0.5 {
nex_x = 0.07
}
if new_health < 0.3 {
nex_x = 0.08
}
if new_health < 0.2 {
nex_x = 0.1
}
health_bar_transform.set_position(Vector3::new(nex_x, d.y, d.z));
}
if self.health <= 0.0 {
context

File diff suppressed because it is too large Load Diff