add archer

This commit is contained in:
artem 2024-03-08 11:02:47 +03:00
parent f0142c3ed2
commit f258ec0761
4 changed files with 36 additions and 21 deletions

View File

@ -44,10 +44,10 @@ impl ArcherSpawn {
fn block_anmation(&self, resource_manager: &ResourceManager) -> SpriteSheetAnimation<fyrox::asset::Resource<Texture>> {
let idle = resource_manager.request::<Texture>(
"assets/data/characters/skeleton/Skeleton_Warrior/Protect.png".to_owned(),
"assets/data/characters/skeleton/Skeleton_Archer/Evasion.png".to_owned(),
);
let mut idle_animation = SpriteSheetAnimation::new_from_image_parameters(ImageParameters {
width: 128,
width: 768,
height: 128,
frame_width: 128,
frame_height: 128,
@ -64,7 +64,7 @@ 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_Warrior/Attack_3.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: 512,
@ -84,7 +84,7 @@ impl ArcherSpawn {
fn run_anmation(&self, resource_manager: &ResourceManager) -> SpriteSheetAnimation<fyrox::asset::Resource<Texture>> {
let idle = resource_manager.request::<Texture>(
"assets/data/characters/skeleton/Skeleton_Warrior/Run.png".to_owned(),
"assets/data/characters/skeleton/Skeleton_Archer/Walk.png".to_owned(),
);
let mut idle_animation = SpriteSheetAnimation::new_from_image_parameters(ImageParameters {
width: 1024,
@ -104,15 +104,15 @@ impl ArcherSpawn {
fn die_anmation(&self, resource_manager: &ResourceManager) -> SpriteSheetAnimation<fyrox::asset::Resource<Texture>> {
let idle = resource_manager.request::<Texture>(
"assets/data/characters/skeleton/Skeleton_Warrior/Dead.png".to_owned(),
"assets/data/characters/skeleton/Skeleton_Archer/Dead.png".to_owned(),
);
let mut idle_animation = SpriteSheetAnimation::new_from_image_parameters(ImageParameters {
width: 512,
width: 640,
height: 128,
frame_width: 128,
frame_height: 128,
first_frame: 0,
last_frame: 4,
last_frame: 5,
column_major: false,
});
idle_animation.set_texture(Some(idle));
@ -124,7 +124,7 @@ impl ArcherSpawn {
fn idle_anmation(&self, resource_manager: &ResourceManager) -> SpriteSheetAnimation<fyrox::asset::Resource<Texture>> {
let idle = resource_manager.request::<Texture>(
"assets/data/characters/skeleton/Skeleton_Warrior/Idle.png".to_owned(),
"assets/data/characters/skeleton/Skeleton_Archer/Idle.png".to_owned(),
);
let mut idle_animation = SpriteSheetAnimation::new_from_image_parameters(ImageParameters {
width: 896,
@ -192,7 +192,7 @@ impl ArcherSpawn {
.build(graph),
])
// Optional, set name of tile
.with_name(format!("Sceleton ({x}, {y})",))
.with_name(format!("Archer ({x}, {y})",))
// Set position of tile
.with_local_transform(rb_transform)
.with_script(enemy),

View File

@ -22,9 +22,10 @@ use fyrox::{
},
script::{ScriptContext, ScriptTrait},
};
use crate::Game;
impl_component_provider!(Enemy,);
uuid_provider!(Enemy = "a5671d19-9f1a-4286-8486-add4ebaadaec");
impl_component_provider!(Swordman,);
uuid_provider!(Swordman = "a5671d19-9f1a-4286-8486-add4ebaadaec");
#[derive(Debug, Clone, Default, Copy)]
enum Animations {
@ -43,7 +44,7 @@ const END_MAP_RIGHT: f32 = 30.0;
const SPEED: f32 = 3.1;
#[derive(Visit, Reflect, Debug, Clone, Default)]
pub struct Enemy {
pub struct Swordman {
// pub sprite: Handle<Node>,
move_left: bool,
move_right: bool,
@ -68,7 +69,7 @@ pub struct Enemy {
pub x: f32,
pub y: f32,
}
impl Enemy {
impl Swordman {
fn init(&mut self) {
self.attack_damage = 100.0;
self.attack_speed = 0.1;
@ -444,7 +445,7 @@ impl Enemy {
}
}
}
impl ScriptTrait for Enemy {
impl ScriptTrait for Swordman {
fn on_init(&mut self, context: &mut ScriptContext) {
self.init();
// Store reference to *this* instance of the enemy node
@ -469,7 +470,10 @@ impl ScriptTrait for Enemy {
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

@ -20,8 +20,8 @@ mod map;
mod msg;
mod player;
use enemies::swordsman::{enemy::Swordman, spawn::SwordmanSpawn};
use enemies::archer::{enemy::Archer, spawn::ArcherSpawn};
use enemies::swordsman::{enemy::Swordman, spawn::SwordmanSpawn};
use map::build_map;
use msg::Message;
use player::Player;
@ -47,6 +47,8 @@ pub struct Game {
new_game: Handle<UiNode>,
exit: Handle<UiNode>,
level: u32,
need_change_level: bool,
}
impl Game {
@ -71,9 +73,14 @@ impl Game {
scene: Handle::NONE,
new_game: Handle::NONE,
exit: Handle::NONE,
level: 1,
level: 2,
need_change_level: false,
}
}
pub fn next_level(&mut self) {
self.need_change_level = true;
}
}
impl Plugin for Game {
@ -81,8 +88,12 @@ impl Plugin for Game {
// Do a cleanup here.
}
fn update(&mut self, _context: &mut PluginContext) {
// Add your global update code here.
fn update(&mut self, context: &mut PluginContext) {
if self.need_change_level {
self.need_change_level = false;
self.level += 1;
context.async_scene_loader.request("data/scene.rgs");
}
}
fn on_os_event(&mut self, event: &Event<()>, context: PluginContext) {

View File

@ -1,4 +1,5 @@
use std::collections::VecDeque;
use std::{thread, time::Duration};
use crate::msg::Message;
use crate::Swordman;
@ -52,7 +53,6 @@ pub struct Player {
start_fight_last: f32,
prev_y_velosity: f32,
damage: f32,
damage: f32,
pub window_height: u32, // TODO: need change place
pub window_width: u32,
@ -140,7 +140,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.35, 0.0))
.with_local_position(Vector3::new(-0.1, 0.25, 0.0))
.build(),
),
)