add archer
This commit is contained in:
parent
f0142c3ed2
commit
f258ec0761
|
|
@ -44,10 +44,10 @@ impl ArcherSpawn {
|
||||||
|
|
||||||
fn block_anmation(&self, resource_manager: &ResourceManager) -> SpriteSheetAnimation<fyrox::asset::Resource<Texture>> {
|
fn block_anmation(&self, resource_manager: &ResourceManager) -> SpriteSheetAnimation<fyrox::asset::Resource<Texture>> {
|
||||||
let idle = resource_manager.request::<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 {
|
let mut idle_animation = SpriteSheetAnimation::new_from_image_parameters(ImageParameters {
|
||||||
width: 128,
|
width: 768,
|
||||||
height: 128,
|
height: 128,
|
||||||
frame_width: 128,
|
frame_width: 128,
|
||||||
frame_height: 128,
|
frame_height: 128,
|
||||||
|
|
@ -64,7 +64,7 @@ impl ArcherSpawn {
|
||||||
|
|
||||||
fn attack_anmation(&self, resource_manager: &ResourceManager) -> SpriteSheetAnimation<fyrox::asset::Resource<Texture>> {
|
fn attack_anmation(&self, resource_manager: &ResourceManager) -> SpriteSheetAnimation<fyrox::asset::Resource<Texture>> {
|
||||||
let idle = resource_manager.request::<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 {
|
let mut idle_animation = SpriteSheetAnimation::new_from_image_parameters(ImageParameters {
|
||||||
width: 512,
|
width: 512,
|
||||||
|
|
@ -84,7 +84,7 @@ impl ArcherSpawn {
|
||||||
|
|
||||||
fn run_anmation(&self, resource_manager: &ResourceManager) -> SpriteSheetAnimation<fyrox::asset::Resource<Texture>> {
|
fn run_anmation(&self, resource_manager: &ResourceManager) -> SpriteSheetAnimation<fyrox::asset::Resource<Texture>> {
|
||||||
let idle = resource_manager.request::<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 {
|
let mut idle_animation = SpriteSheetAnimation::new_from_image_parameters(ImageParameters {
|
||||||
width: 1024,
|
width: 1024,
|
||||||
|
|
@ -104,15 +104,15 @@ impl ArcherSpawn {
|
||||||
|
|
||||||
fn die_anmation(&self, resource_manager: &ResourceManager) -> SpriteSheetAnimation<fyrox::asset::Resource<Texture>> {
|
fn die_anmation(&self, resource_manager: &ResourceManager) -> SpriteSheetAnimation<fyrox::asset::Resource<Texture>> {
|
||||||
let idle = resource_manager.request::<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 {
|
let mut idle_animation = SpriteSheetAnimation::new_from_image_parameters(ImageParameters {
|
||||||
width: 512,
|
width: 640,
|
||||||
height: 128,
|
height: 128,
|
||||||
frame_width: 128,
|
frame_width: 128,
|
||||||
frame_height: 128,
|
frame_height: 128,
|
||||||
first_frame: 0,
|
first_frame: 0,
|
||||||
last_frame: 4,
|
last_frame: 5,
|
||||||
column_major: false,
|
column_major: false,
|
||||||
});
|
});
|
||||||
idle_animation.set_texture(Some(idle));
|
idle_animation.set_texture(Some(idle));
|
||||||
|
|
@ -124,7 +124,7 @@ impl ArcherSpawn {
|
||||||
|
|
||||||
fn idle_anmation(&self, resource_manager: &ResourceManager) -> SpriteSheetAnimation<fyrox::asset::Resource<Texture>> {
|
fn idle_anmation(&self, resource_manager: &ResourceManager) -> SpriteSheetAnimation<fyrox::asset::Resource<Texture>> {
|
||||||
let idle = resource_manager.request::<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 {
|
let mut idle_animation = SpriteSheetAnimation::new_from_image_parameters(ImageParameters {
|
||||||
width: 896,
|
width: 896,
|
||||||
|
|
@ -192,7 +192,7 @@ impl ArcherSpawn {
|
||||||
.build(graph),
|
.build(graph),
|
||||||
])
|
])
|
||||||
// Optional, set name of tile
|
// Optional, set name of tile
|
||||||
.with_name(format!("Sceleton ({x}, {y})",))
|
.with_name(format!("Archer ({x}, {y})",))
|
||||||
// Set position of tile
|
// Set position of tile
|
||||||
.with_local_transform(rb_transform)
|
.with_local_transform(rb_transform)
|
||||||
.with_script(enemy),
|
.with_script(enemy),
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,10 @@ use fyrox::{
|
||||||
},
|
},
|
||||||
script::{ScriptContext, ScriptTrait},
|
script::{ScriptContext, ScriptTrait},
|
||||||
};
|
};
|
||||||
|
use crate::Game;
|
||||||
|
|
||||||
impl_component_provider!(Enemy,);
|
impl_component_provider!(Swordman,);
|
||||||
uuid_provider!(Enemy = "a5671d19-9f1a-4286-8486-add4ebaadaec");
|
uuid_provider!(Swordman = "a5671d19-9f1a-4286-8486-add4ebaadaec");
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Copy)]
|
#[derive(Debug, Clone, Default, Copy)]
|
||||||
enum Animations {
|
enum Animations {
|
||||||
|
|
@ -43,7 +44,7 @@ const END_MAP_RIGHT: f32 = 30.0;
|
||||||
const SPEED: f32 = 3.1;
|
const SPEED: f32 = 3.1;
|
||||||
|
|
||||||
#[derive(Visit, Reflect, Debug, Clone, Default)]
|
#[derive(Visit, Reflect, Debug, Clone, Default)]
|
||||||
pub struct Enemy {
|
pub struct Swordman {
|
||||||
// pub sprite: Handle<Node>,
|
// pub sprite: Handle<Node>,
|
||||||
move_left: bool,
|
move_left: bool,
|
||||||
move_right: bool,
|
move_right: bool,
|
||||||
|
|
@ -68,7 +69,7 @@ pub struct Enemy {
|
||||||
pub x: f32,
|
pub x: f32,
|
||||||
pub y: f32,
|
pub y: f32,
|
||||||
}
|
}
|
||||||
impl Enemy {
|
impl Swordman {
|
||||||
fn init(&mut self) {
|
fn init(&mut self) {
|
||||||
self.attack_damage = 100.0;
|
self.attack_damage = 100.0;
|
||||||
self.attack_speed = 0.1;
|
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) {
|
fn on_init(&mut self, context: &mut ScriptContext) {
|
||||||
self.init();
|
self.init();
|
||||||
// Store reference to *this* instance of the enemy node
|
// 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) {
|
fn on_update(&mut self, context: &mut ScriptContext) {
|
||||||
if self.intersections_box(&mut context.scene.graph) {
|
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.set_fight(context);
|
||||||
self.change_orientation(context);
|
self.change_orientation(context);
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@ mod map;
|
||||||
mod msg;
|
mod msg;
|
||||||
mod player;
|
mod player;
|
||||||
|
|
||||||
use enemies::swordsman::{enemy::Swordman, spawn::SwordmanSpawn};
|
|
||||||
use enemies::archer::{enemy::Archer, spawn::ArcherSpawn};
|
use enemies::archer::{enemy::Archer, spawn::ArcherSpawn};
|
||||||
|
use enemies::swordsman::{enemy::Swordman, spawn::SwordmanSpawn};
|
||||||
use map::build_map;
|
use map::build_map;
|
||||||
use msg::Message;
|
use msg::Message;
|
||||||
use player::Player;
|
use player::Player;
|
||||||
|
|
@ -47,6 +47,8 @@ pub struct Game {
|
||||||
new_game: Handle<UiNode>,
|
new_game: Handle<UiNode>,
|
||||||
exit: Handle<UiNode>,
|
exit: Handle<UiNode>,
|
||||||
level: u32,
|
level: u32,
|
||||||
|
need_change_level: bool,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Game {
|
impl Game {
|
||||||
|
|
@ -71,9 +73,14 @@ impl Game {
|
||||||
scene: Handle::NONE,
|
scene: Handle::NONE,
|
||||||
new_game: Handle::NONE,
|
new_game: Handle::NONE,
|
||||||
exit: 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 {
|
impl Plugin for Game {
|
||||||
|
|
@ -81,8 +88,12 @@ impl Plugin for Game {
|
||||||
// Do a cleanup here.
|
// Do a cleanup here.
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, _context: &mut PluginContext) {
|
fn update(&mut self, context: &mut PluginContext) {
|
||||||
// Add your global update code here.
|
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) {
|
fn on_os_event(&mut self, event: &Event<()>, context: PluginContext) {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
use std::{thread, time::Duration};
|
||||||
|
|
||||||
use crate::msg::Message;
|
use crate::msg::Message;
|
||||||
use crate::Swordman;
|
use crate::Swordman;
|
||||||
|
|
@ -52,7 +53,6 @@ pub struct Player {
|
||||||
start_fight_last: f32,
|
start_fight_last: f32,
|
||||||
prev_y_velosity: f32,
|
prev_y_velosity: f32,
|
||||||
damage: f32,
|
damage: f32,
|
||||||
damage: f32,
|
|
||||||
|
|
||||||
pub window_height: u32, // TODO: need change place
|
pub window_height: u32, // TODO: need change place
|
||||||
pub window_width: u32,
|
pub window_width: u32,
|
||||||
|
|
@ -140,7 +140,7 @@ impl Player {
|
||||||
1.,
|
1.,
|
||||||
))
|
))
|
||||||
// Position the healthbar just above the player, and just in front of the background
|
// 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(),
|
.build(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue