Intro NPCs

This commit is contained in:
Alula 2020-10-30 14:50:10 +01:00
parent f7e7a8563e
commit 43a756fcc2
No known key found for this signature in database
GPG Key ID: 3E00485503A1D8BA
5 changed files with 212 additions and 15 deletions

View File

@ -249,11 +249,11 @@ impl Caret {
if self.anim_num == 0 {
match self.direction {
Direction::Left => {
self.vel_x = rng.range(-0x300..0x300) as isize; // -1.5fix9..1.5fix9
self.vel_y = rng.range(-0x100..0x100) as isize; // -0.5fix9..0.5fix9
self.vel_x = rng.range(-0x600..0x600) as isize; // -3.0fix9..3.0fix9
self.vel_y = rng.range(-0x200..0x200) as isize; // -1.0fix9..1.0fix9
}
Direction::Up => {
self.vel_y = rng.range(1..3) as isize * 0x100;
self.vel_y = rng.range(-3..-1) as isize * 0x200;
}
_ => {}
}
@ -269,7 +269,8 @@ impl Caret {
self.x += self.vel_x;
self.y += self.vel_y;
if self.anim_num == 20 {
self.anim_counter += 1;
if self.anim_counter > 20 {
self.cond.set_alive(false);
return;
}

View File

@ -227,8 +227,11 @@ pub struct NPCConsts {
pub n129_fireball_snake_trail: [Rect<usize>; 18],
pub n149_horizontal_moving_block: Rect<usize>,
pub n157_vertical_moving_block: Rect<usize>,
pub n199_wind_particles: [Rect<usize>; 5],
pub n211_small_spikes: [Rect<usize>; 4],
pub n199_wind_particles: [Rect<usize>; 5]
pub n298_intro_doctor: [Rect<usize>; 8],
pub n299_intro_balrog_misery: [Rect<usize>; 2],
pub n300_intro_demon_crown: Rect<usize>,
}
#[derive(Debug, Copy, Clone)]
@ -251,8 +254,9 @@ pub struct TextScriptConsts {
}
#[derive(Debug, Copy, Clone)]
#[derive(Debug)]
pub struct TitleConsts {
pub intro_text: String,
pub logo_rect: Rect<usize>,
pub menu_left_top: Rect<usize>,
pub menu_right_top: Rect<usize>,
@ -265,6 +269,24 @@ pub struct TitleConsts {
pub menu_right: Rect<usize>,
}
impl Clone for TitleConsts {
fn clone(&self) -> TitleConsts {
TitleConsts {
intro_text: self.intro_text.clone(),
logo_rect: self.logo_rect,
menu_left_top: self.menu_left_top,
menu_right_top: self.menu_right_top,
menu_left_bottom: self.menu_left_bottom,
menu_right_bottom: self.menu_right_bottom,
menu_top: self.menu_top,
menu_bottom: self.menu_bottom,
menu_middle: self.menu_middle,
menu_left: self.menu_left,
menu_right: self.menu_right,
}
}
}
#[derive(Debug)]
pub struct EngineConstants {
pub is_cs_plus: bool,
@ -292,12 +314,12 @@ impl Clone for EngineConstants {
my_char: self.my_char,
booster: self.booster,
caret: self.caret.clone(),
world: self.world.clone(),
npc: self.npc.clone(),
world: self.world,
npc: self.npc,
weapon: self.weapon.clone(),
tex_sizes: self.tex_sizes.clone(),
textscript: self.textscript.clone(),
title: self.title,
textscript: self.textscript,
title: self.title.clone(),
font_path: self.font_path.clone(),
font_scale: self.font_scale,
font_space_offset: self.font_space_offset,
@ -1238,6 +1260,21 @@ impl EngineConstants {
Rect { left: 288, top: 200, right: 304, bottom: 216 },
Rect { left: 304, top: 200, right: 320, bottom: 216 },
],
n298_intro_doctor: [
Rect { left: 72, top: 128, right: 88, bottom: 160 },
Rect { left: 88, top: 128, right: 104, bottom: 160 },
Rect { left: 104, top: 128, right: 120, bottom: 160 },
Rect { left: 72, top: 128, right: 88, bottom: 160 },
Rect { left: 120, top: 128, right: 136, bottom: 160 },
Rect { left: 72, top: 128, right: 88, bottom: 160 },
Rect { left: 104, top: 160, right: 120, bottom: 192 },
Rect { left: 120, top: 160, right: 136, bottom: 192 },
],
n299_intro_balrog_misery: [
Rect { left: 0, top: 0, right: 48, bottom: 48 },
Rect { left: 48, top: 0, right: 96, bottom: 48 },
],
n300_intro_demon_crown: Rect { left: 192, top: 80, right: 208, bottom: 96 },
},
weapon: WeaponConsts {
bullet_table: vec![
@ -1548,6 +1585,7 @@ impl EngineConstants {
],
},
title: TitleConsts {
intro_text: "Studio Pixel presents".to_string(),
logo_rect: Rect { left: 0, top: 0, right: 144, bottom: 40 },
menu_left_top: Rect { left: 0, top: 0, right: 8, bottom: 8 },
menu_right_top: Rect { left: 236, top: 0, right: 244, bottom: 8 },
@ -1559,12 +1597,12 @@ impl EngineConstants {
menu_left: Rect { left: 0, top: 8, right: 8, bottom: 16 },
menu_right: Rect { left: 236, top: 8, right: 244, bottom: 16 },
},
font_path: str!("builtin/builtin_font.fnt"),
font_path: "builtin/builtin_font.fnt".to_string(),
font_scale: 1.0,
font_space_offset: -3.0,
organya_paths: vec![
str!("/org/"), // NXEngine
str!("/base/Org/"), // CS+ PC
str!("/base/Org/"), // CS+
str!("/Resource/ORG/"), // CSE2E
],
}

137
src/npc/intro.rs Normal file
View File

@ -0,0 +1,137 @@
use crate::caret::CaretType;
use crate::common::Direction;
use crate::ggez::GameResult;
use crate::npc::NPC;
use crate::shared_game_state::SharedGameState;
impl NPC {
pub(crate) fn tick_n298_intro_doctor(&mut self, state: &mut SharedGameState) -> GameResult {
match self.action_num {
0 | 1 => {
if self.action_num == 0 {
self.action_num = 1;
self.y -= 8 * 0x200;
}
self.anim_num = 0;
}
10 | 11 => {
if self.action_num == 10 {
self.action_num = 11;
self.anim_num = 0;
self.anim_counter = 0;
self.action_counter2 = 0;
}
self.anim_counter += 1;
if self.anim_counter > 6 {
self.anim_counter = 0;
self.anim_num += 1;
if self.anim_num > 1 {
self.anim_num = 0;
self.action_counter2 += 1;
if self.action_counter2 > 7 {
self.anim_num = 0;
self.action_num = 1;
}
}
}
}
20 | 21 => {
if self.action_num == 20 {
self.action_num = 21;
self.anim_num = 2;
self.anim_counter = 0;
}
self.anim_counter += 1;
if self.anim_counter > 10 {
self.anim_counter = 0;
self.anim_num += 1;
if self.anim_num > 5 {
self.anim_num = 2;
}
}
self.x += 0x100;
}
30 => {
self.anim_num = 6;
}
40 | 41 => {
if self.action_num == 40 {
self.action_num = 41;
self.anim_num = 6;
self.anim_counter = 0;
self.action_counter2 = 0;
}
self.anim_counter += 1;
if self.anim_counter > 6 {
self.anim_counter = 0;
self.anim_num += 1;
if self.anim_num > 7 {
self.anim_num = 6;
self.action_counter2 += 1;
if self.action_counter2 > 7 {
self.anim_num = 6;
self.action_num = 30;
}
}
}
}
_ => {}
}
self.anim_rect = state.constants.npc.n298_intro_doctor[self.anim_num as usize];
Ok(())
}
pub(crate) fn tick_n299_intro_balrog_misery(&mut self, state: &mut SharedGameState) -> GameResult {
if self.action_num == 0 {
self.action_num = 1;
match self.direction {
Direction::Left => {
self.anim_num = 1;
self.action_counter = 25;
self.y -= 0x40 * 25;
}
Direction::Right => {
self.anim_num = 0;
self.action_counter = 0;
}
_ => {}
}
}
self.action_counter += 1;
self.y += if (self.action_counter / 50) % 2 != 0 {
0x40
} else {
-0x40
};
self.anim_rect = state.constants.npc.n299_intro_balrog_misery[self.anim_num as usize];
Ok(())
}
pub(crate) fn tick_n300_intro_demon_crown(&mut self, state: &mut SharedGameState) -> GameResult {
if self.action_num == 0 {
self.action_num = 1;
self.y += 6 * 0x200;
self.anim_rect = state.constants.npc.n300_intro_demon_crown;
}
self.anim_counter += 1;
if (self.anim_counter % 8) == 1 {
state.create_caret(self.x + state.effect_rng.range(-8..8) as isize * 0x200,
self.y + 8 * 0x200,
CaretType::LittleParticles, Direction::Up);
}
Ok(())
}
}

View File

@ -30,12 +30,14 @@ pub mod egg_corridor;
pub mod first_cave;
pub mod grasstown;
pub mod igor;
pub mod intro;
pub mod maze;
pub mod mimiga_village;
pub mod misc;
pub mod misery;
pub mod pickups;
pub mod sand_zone;
pub mod santa;
pub mod sue;
pub mod toroko;
pub mod weapon_trail;
@ -218,6 +220,9 @@ impl GameEntity<(&mut Player, &HashMap<u16, RefCell<NPC>>, &mut Stage)> for NPC
157 => self.tick_n157_vertical_moving_block(state, player),
199 => self.tick_n199_wind_particles(state),
211 => self.tick_n211_small_spikes(state),
298 => self.tick_n298_intro_doctor(state),
299 => self.tick_n299_intro_balrog_misery(state),
300 => self.tick_n300_intro_demon_crown(state),
_ => Ok(()),
}?;

View File

@ -664,6 +664,16 @@ impl GameScene {
2.1, color2, batch);
}
}
299 => {
self.draw_light(fix9_scale(npc.x - self.frame.x, scale),
fix9_scale(npc.y - self.frame.y, scale),
4.0, (30, 30, 200), batch);
}
300 => {
self.draw_light(fix9_scale(npc.x - self.frame.x, scale),
fix9_scale(npc.y - self.frame.y, scale),
1.5, (200, 10, 10), batch);
}
_ => {}
}
}
@ -1103,7 +1113,7 @@ impl Scene for GameScene {
fn tick(&mut self, state: &mut SharedGameState, ctx: &mut Context) -> GameResult {
state.update_key_trigger();
if self.intro_mode && (state.key_trigger.jump() || self.tick >= 500){
if self.intro_mode && (state.key_trigger.jump() || self.tick >= 500) {
state.next_scene = Some(Box::new(TitleScene::new()));
}
@ -1190,8 +1200,14 @@ impl Scene for GameScene {
self.draw_fade(state, ctx)?;
if self.map_name_counter > 0 {
let width = state.font.text_width(self.stage.data.name.chars(), &state.constants);
state.font.draw_text(self.stage.data.name.chars(),
let map_name = if self.intro_mode {
state.constants.title.intro_text.chars()
} else {
self.stage.data.name.chars()
};
let width = state.font.text_width(map_name.clone(), &state.constants);
state.font.draw_text(map_name,
((state.canvas_size.0 - width) / 2.0).floor(), 80.0,
&state.constants, &mut state.texture_set, ctx)?;
}