refactor co-op skins
This commit is contained in:
parent
4be3dd518b
commit
356f4230b5
|
@ -337,6 +337,7 @@ pub struct EngineConstants {
|
|||
pub music_table: Vec<String>,
|
||||
pub organya_paths: Vec<String>,
|
||||
pub credit_illustration_paths: Vec<String>,
|
||||
pub player_skin_paths: Vec<String>,
|
||||
pub animated_face_table: Vec<AnimatedFace>,
|
||||
pub string_table: HashMap<String, String>,
|
||||
pub missile_flags: Vec<u16>,
|
||||
|
@ -369,6 +370,7 @@ impl Clone for EngineConstants {
|
|||
music_table: self.music_table.clone(),
|
||||
organya_paths: self.organya_paths.clone(),
|
||||
credit_illustration_paths: self.credit_illustration_paths.clone(),
|
||||
player_skin_paths: self.player_skin_paths.clone(),
|
||||
animated_face_table: self.animated_face_table.clone(),
|
||||
string_table: self.string_table.clone(),
|
||||
missile_flags: self.missile_flags.clone(),
|
||||
|
@ -1666,6 +1668,7 @@ impl EngineConstants {
|
|||
"Resource/BITMAP/".to_owned(), // CSE2E
|
||||
"endpic/".to_owned(), // NXEngine
|
||||
],
|
||||
player_skin_paths: vec!["MyChar".to_owned()],
|
||||
animated_face_table: vec![AnimatedFace { face_id: 0, anim_id: 0, anim_frames: vec![(0, 0)] }],
|
||||
string_table: HashMap::new(),
|
||||
missile_flags: vec![200, 201, 202, 218, 550, 766, 880, 920, 1551],
|
||||
|
@ -1770,6 +1773,7 @@ impl EngineConstants {
|
|||
self.textscript.fade_ticks = 21;
|
||||
self.game.tile_offset_x = 3;
|
||||
self.game.new_game_player_pos = (13, 8);
|
||||
self.player_skin_paths.push("mychar_p2".to_owned());
|
||||
}
|
||||
|
||||
pub fn apply_csdemo_patches(&mut self) {
|
||||
|
|
|
@ -251,6 +251,24 @@ impl TileSize {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Copy, Clone)]
|
||||
pub struct PlayerSkinLocation {
|
||||
pub texture_index: u16,
|
||||
pub offset: u16,
|
||||
}
|
||||
|
||||
impl PlayerSkinLocation {
|
||||
pub const fn new(texture_index: u16, offset: u16) -> PlayerSkinLocation {
|
||||
PlayerSkinLocation { texture_index, offset }
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for PlayerSkinLocation {
|
||||
fn default() -> PlayerSkinLocation {
|
||||
PlayerSkinLocation::new(0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SharedGameState {
|
||||
pub control_flags: ControlFlags,
|
||||
pub game_flags: BitVec,
|
||||
|
@ -301,8 +319,7 @@ pub struct SharedGameState {
|
|||
pub difficulty: GameDifficulty,
|
||||
pub player_count: PlayerCount,
|
||||
pub player_count_modified_in_game: bool,
|
||||
pub player2_skin: u16,
|
||||
pub player2_uses_p2_skinsheet: bool,
|
||||
pub player2_skin_location: PlayerSkinLocation,
|
||||
pub replay_state: ReplayState,
|
||||
pub mod_requirements: ModRequirements,
|
||||
pub loc: Locale,
|
||||
|
@ -455,8 +472,7 @@ impl SharedGameState {
|
|||
difficulty: GameDifficulty::Normal,
|
||||
player_count: PlayerCount::One,
|
||||
player_count_modified_in_game: false,
|
||||
player2_skin: 0,
|
||||
player2_uses_p2_skinsheet: false,
|
||||
player2_skin_location: PlayerSkinLocation::default(),
|
||||
replay_state: ReplayState::None,
|
||||
mod_requirements,
|
||||
loc: locale,
|
||||
|
|
|
@ -3,9 +3,9 @@ use itertools::Itertools;
|
|||
|
||||
use crate::framework::context::Context;
|
||||
use crate::framework::error::GameResult;
|
||||
use crate::game::scripting::tsc::text_script::TextScriptExecutionState;
|
||||
use crate::game::shared_game_state::SharedGameState;
|
||||
use crate::scene::game_scene::GameScene;
|
||||
use crate::game::scripting::tsc::text_script::TextScriptExecutionState;
|
||||
|
||||
use self::command_line::CommandLineParser;
|
||||
|
||||
|
@ -187,22 +187,22 @@ impl LiveDebugger {
|
|||
}
|
||||
|
||||
#[cfg(feature = "scripting-lua")]
|
||||
{
|
||||
ui.same_line();
|
||||
if ui.button("Reload Lua Scripts") {
|
||||
if let Err(err) = state.lua.reload_scripts(ctx) {
|
||||
log::error!("Error reloading scripts: {:?}", err);
|
||||
self.error = Some(ImString::new(err.to_string()));
|
||||
}
|
||||
{
|
||||
ui.same_line();
|
||||
if ui.button("Reload Lua Scripts") {
|
||||
if let Err(err) = state.lua.reload_scripts(ctx) {
|
||||
log::error!("Error reloading scripts: {:?}", err);
|
||||
self.error = Some(ImString::new(err.to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if game_scene.player2.cond.alive() {
|
||||
if ui.button("Drop Player 2") {
|
||||
game_scene.drop_player2();
|
||||
}
|
||||
} else if ui.button("Add Player 2") {
|
||||
game_scene.add_player2(state);
|
||||
game_scene.add_player2(state, ctx);
|
||||
}
|
||||
ui.same_line();
|
||||
|
||||
|
@ -216,7 +216,8 @@ impl LiveDebugger {
|
|||
let _ = state.save_game(game_scene, ctx);
|
||||
state.sound_manager.play_sfx(18);
|
||||
}
|
||||
} else if ui.button("Busy") {}
|
||||
} else if ui.button("Busy") {
|
||||
}
|
||||
|
||||
ui.same_line();
|
||||
if ui.button("Hotkey List") {
|
||||
|
|
|
@ -142,20 +142,26 @@ impl PlayerCountMenu {
|
|||
}
|
||||
}
|
||||
MenuSelectionResult::Selected(SkinMenuEntry::Skin, _) => {
|
||||
state.player2_skin += 2;
|
||||
state.player2_skin_location.offset += 2;
|
||||
|
||||
if state.player2_uses_p2_skinsheet && state.player2_skin == 2 {
|
||||
state.player2_skin += 2;
|
||||
if state.player2_skin_location.texture_index == 1 && state.player2_skin_location.offset == 2 {
|
||||
state.player2_skin_location.offset += 2;
|
||||
}
|
||||
|
||||
let current_skin_spritesheet = if state.player2_uses_p2_skinsheet { "mychar_p2" } else { "mychar" };
|
||||
let current_skin_spritesheet_name =
|
||||
state.constants.player_skin_paths[state.player2_skin_location.texture_index as usize].as_str();
|
||||
|
||||
if let Some(tex_size) = state.constants.tex_sizes.get(current_skin_spritesheet) {
|
||||
if let Some(tex_size) = state.constants.tex_sizes.get(current_skin_spritesheet_name) {
|
||||
// TODO: should probably have a way to figure out the height from the spritesheet ahead of time
|
||||
|
||||
if state.player2_skin * 2 * 16 >= tex_size.1 {
|
||||
state.player2_skin = 0;
|
||||
state.player2_uses_p2_skinsheet = !state.player2_uses_p2_skinsheet;
|
||||
if state.player2_skin_location.offset * 2 * 16 >= tex_size.1 {
|
||||
state.player2_skin_location.offset = 0;
|
||||
|
||||
if state.player2_skin_location.texture_index == 1 {
|
||||
state.player2_skin_location.texture_index = 0;
|
||||
} else {
|
||||
state.player2_skin_location.texture_index = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -512,13 +512,14 @@ impl<T: std::cmp::PartialEq + std::default::Default + Clone> Menu<T> {
|
|||
&mut state.texture_set,
|
||||
)?;
|
||||
|
||||
let spritesheet_name = if state.player2_uses_p2_skinsheet { "mychar_p2" } else { "MyChar" };
|
||||
let spritesheet_name =
|
||||
state.constants.player_skin_paths[state.player2_skin_location.texture_index as usize].as_str();
|
||||
|
||||
let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, spritesheet_name)?;
|
||||
batch.add_rect(
|
||||
self.x as f32 + 88.0,
|
||||
y - 4.0,
|
||||
&Rect::new_size(0, (state.player2_skin).saturating_mul(2 * 16), 16, 16),
|
||||
&Rect::new_size(0, (state.player2_skin_location.offset).saturating_mul(2 * 16), 16, 16),
|
||||
);
|
||||
batch.draw(ctx)?;
|
||||
}
|
||||
|
|
|
@ -140,8 +140,10 @@ impl GameScene {
|
|||
|
||||
let mut player2 = Player::new(state, ctx);
|
||||
|
||||
if state.player2_uses_p2_skinsheet {
|
||||
player2.load_skin("mychar_p2".to_owned(), state, ctx);
|
||||
if state.player2_skin_location.texture_index != 0 {
|
||||
let skinsheet_name =
|
||||
state.constants.player_skin_paths[state.player2_skin_location.texture_index as usize].as_str();
|
||||
player2.load_skin(skinsheet_name.to_owned(), state, ctx);
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
|
@ -187,10 +189,16 @@ impl GameScene {
|
|||
pub fn display_map_name(&mut self, ticks: u16) {
|
||||
self.map_name_counter = ticks;
|
||||
}
|
||||
pub fn add_player2(&mut self, state: &mut SharedGameState) {
|
||||
|
||||
pub fn add_player2(&mut self, state: &mut SharedGameState, ctx: &mut Context) {
|
||||
self.player2.cond.set_alive(true);
|
||||
self.player2.cond.set_hidden(self.player1.cond.hidden());
|
||||
self.player2.skin.set_skinsheet_offset(state.player2_skin);
|
||||
|
||||
let skinsheet_name =
|
||||
state.constants.player_skin_paths[state.player2_skin_location.texture_index as usize].as_str();
|
||||
self.player2.load_skin(skinsheet_name.to_owned(), state, ctx);
|
||||
self.player2.skin.set_skinsheet_offset(state.player2_skin_location.offset);
|
||||
|
||||
self.player2.x = self.player1.x;
|
||||
self.player2.y = self.player1.y;
|
||||
self.player2.vel_x = self.player1.vel_x;
|
||||
|
@ -1637,7 +1645,7 @@ impl Scene for GameScene {
|
|||
self.replay.initialize_recording(state);
|
||||
}
|
||||
if state.player_count == PlayerCount::Two {
|
||||
self.add_player2(state);
|
||||
self.add_player2(state, ctx);
|
||||
} else {
|
||||
self.drop_player2();
|
||||
}
|
||||
|
@ -1743,7 +1751,7 @@ impl Scene for GameScene {
|
|||
|
||||
if state.player_count_modified_in_game {
|
||||
if state.player_count == PlayerCount::Two {
|
||||
self.add_player2(state);
|
||||
self.add_player2(state, ctx);
|
||||
} else {
|
||||
self.drop_player2();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue