mirror of
https://github.com/doukutsu-rs/doukutsu-rs
synced 2025-04-01 23:34:54 +00:00
Use skin sheet for whimsical star
This commit is contained in:
parent
d3d77b58e3
commit
807cc305b9
|
@ -9,6 +9,7 @@ use crate::weapon::bullet::{Bullet, BulletManager};
|
|||
|
||||
pub struct WhimsicalStar {
|
||||
pub star: [Star; 3],
|
||||
pub tex: String,
|
||||
pub star_count: u8,
|
||||
pub equipped: bool,
|
||||
pub active_star: u8,
|
||||
|
@ -25,25 +26,29 @@ pub struct Star {
|
|||
}
|
||||
|
||||
impl Star {
|
||||
fn new(vel_x: i32, vel_y: i32, rect: Rect<u16>) -> Star {
|
||||
Star { x: 0, y: 0, vel_x, vel_y, prev_x: 0, prev_y: 0, rect }
|
||||
fn new(vel_x: i32, vel_y: i32) -> Star {
|
||||
Star { x: 0, y: 0, vel_x, vel_y, prev_x: 0, prev_y: 0, rect: Rect::new(0, 0, 0, 0) }
|
||||
}
|
||||
}
|
||||
|
||||
impl WhimsicalStar {
|
||||
pub fn new() -> WhimsicalStar {
|
||||
WhimsicalStar {
|
||||
star: [
|
||||
Star::new(0x400, -0x200, Rect { left: 192, top: 0, right: 200, bottom: 8 }),
|
||||
Star::new(-0x200, 0x400, Rect { left: 192, top: 8, right: 200, bottom: 16 }),
|
||||
Star::new(0x200, 0x200, Rect { left: 192, top: 16, right: 200, bottom: 24 }),
|
||||
],
|
||||
star: [Star::new(0x400, -0x200), Star::new(-0x200, 0x400), Star::new(0x200, 0x200)],
|
||||
tex: "MyChar".to_string(),
|
||||
star_count: 0,
|
||||
equipped: false,
|
||||
active_star: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init(&mut self, player: &Player) {
|
||||
self.tex = player.skin.get_skin_texture_name().to_string();
|
||||
for (iter, star) in &mut self.star.iter_mut().enumerate() {
|
||||
star.rect = player.skin.get_whimsical_star_rect(iter);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_prev(&mut self) {
|
||||
for star in &mut self.star {
|
||||
star.prev_x = star.x;
|
||||
|
@ -116,7 +121,7 @@ impl GameEntity<(&Player, &mut BulletManager)> for WhimsicalStar {
|
|||
|
||||
let (frame_x, frame_y) = frame.xy_interpolated(state.frame_time);
|
||||
|
||||
let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, "MyChar")?;
|
||||
let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, &self.tex)?;
|
||||
|
||||
let (active_stars, _) = self.star.split_at(self.star_count as usize);
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use lazy_static::lazy_static;
|
||||
|
||||
|
||||
use crate::common::{Color, Direction, Rect};
|
||||
use crate::framework::context::Context;
|
||||
use crate::framework::filesystem;
|
||||
|
@ -29,6 +28,8 @@ pub struct SkinMeta {
|
|||
pub hit_box: Rect<u16>,
|
||||
#[serde(default = "skinmeta_default_display_box")]
|
||||
pub display_box: Rect<u16>,
|
||||
#[serde(default = "skinmeta_default_whimsical_star")]
|
||||
pub whimsical_star_rect: Rect<u16>,
|
||||
#[serde(default)]
|
||||
pub version: u8,
|
||||
}
|
||||
|
@ -49,6 +50,10 @@ const fn skinmeta_default_display_box() -> Rect<u16> {
|
|||
Rect { left: 8, top: 8, right: 8, bottom: 8 }
|
||||
}
|
||||
|
||||
const fn skinmeta_default_whimsical_star() -> Rect<u16> {
|
||||
Rect { left: 192, top: 0, right: 200, bottom: 8 }
|
||||
}
|
||||
|
||||
pub static SUPPORTED_SKINMETA_VERSIONS: [u8; 1] = [1];
|
||||
|
||||
lazy_static! {
|
||||
|
@ -62,6 +67,7 @@ lazy_static! {
|
|||
frame_size_height: 16,
|
||||
hit_box: skinmeta_default_hit_box(),
|
||||
display_box: skinmeta_default_display_box(),
|
||||
whimsical_star_rect: skinmeta_default_whimsical_star(),
|
||||
version: 1
|
||||
};
|
||||
}
|
||||
|
@ -226,4 +232,11 @@ impl PlayerSkin for BasicPlayerSkin {
|
|||
fn get_gun_offset(&self) -> (i32, i32) {
|
||||
(self.metadata.gun_offset_x as i32, self.metadata.gun_offset_y as i32)
|
||||
}
|
||||
|
||||
fn get_whimsical_star_rect(&self, index: usize) -> Rect<u16> {
|
||||
let mut rect = self.metadata.whimsical_star_rect;
|
||||
rect.top += (8 * index) as u16;
|
||||
rect.bottom = rect.top + 8;
|
||||
return rect;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,11 @@ pub trait PlayerSkin: PlayerSkinClone {
|
|||
/// Returns display bounds of skin.
|
||||
fn get_display_bounds(&self) -> Rect<u32>;
|
||||
|
||||
/// Returns gun offset
|
||||
fn get_gun_offset(&self) -> (i32, i32);
|
||||
|
||||
/// Returns Whimsical Star rect location
|
||||
fn get_whimsical_star_rect(&self, index: usize) -> Rect<u16>;
|
||||
}
|
||||
|
||||
pub trait PlayerSkinClone {
|
||||
|
|
|
@ -1594,6 +1594,7 @@ impl Scene for GameScene {
|
|||
};
|
||||
|
||||
self.pause_menu.init(state, ctx)?;
|
||||
self.whimsical_star.init(&self.player1);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue