Push tile animations
This commit is contained in:
parent
d32cd87532
commit
6302258817
|
@ -28,6 +28,7 @@ impl Tilemap {
|
|||
layer: TileLayer,
|
||||
textures: &StageTexturePaths,
|
||||
stage: &Stage,
|
||||
tick: u32,
|
||||
) -> GameResult {
|
||||
if stage.map.tile_size == TileSize::Tile8x8 && layer == TileLayer::Snack {
|
||||
return Ok(());
|
||||
|
@ -40,20 +41,20 @@ impl Tilemap {
|
|||
TileLayer::Foreground => &textures.tileset_fg,
|
||||
};
|
||||
|
||||
let (layer_offset, layer_width, layer_height, uses_layers) =
|
||||
if let Some(pxpack_data) = &stage.data.pxpack_data {
|
||||
match layer {
|
||||
TileLayer::Background => {
|
||||
(pxpack_data.offset_bg as usize, pxpack_data.size_bg.0, pxpack_data.size_bg.1, true)
|
||||
}
|
||||
TileLayer::Middleground => {
|
||||
(pxpack_data.offset_mg as usize, pxpack_data.size_mg.0, pxpack_data.size_mg.1, true)
|
||||
}
|
||||
_ => (0, pxpack_data.size_fg.0, pxpack_data.size_fg.1, true),
|
||||
let (layer_offset, layer_width, layer_height, uses_layers) = if let Some(pxpack_data) = &stage.data.pxpack_data
|
||||
{
|
||||
match layer {
|
||||
TileLayer::Background => {
|
||||
(pxpack_data.offset_bg as usize, pxpack_data.size_bg.0, pxpack_data.size_bg.1, true)
|
||||
}
|
||||
} else {
|
||||
(0, stage.map.width, stage.map.height, false)
|
||||
};
|
||||
TileLayer::Middleground => {
|
||||
(pxpack_data.offset_mg as usize, pxpack_data.size_mg.0, pxpack_data.size_mg.1, true)
|
||||
}
|
||||
_ => (0, pxpack_data.size_fg.0, pxpack_data.size_fg.1, true),
|
||||
}
|
||||
} else {
|
||||
(0, stage.map.width, stage.map.height, false)
|
||||
};
|
||||
|
||||
if !uses_layers && layer == TileLayer::Middleground {
|
||||
return Ok(());
|
||||
|
@ -168,6 +169,52 @@ impl Tilemap {
|
|||
batch.draw(ctx)?;
|
||||
}
|
||||
|
||||
if layer == TileLayer::Foreground {
|
||||
let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, "Caret")?;
|
||||
|
||||
for y in tile_start_y..tile_end_y {
|
||||
for x in tile_start_x..tile_end_x {
|
||||
let tile = *stage.map.tiles.get((y * layer_width as usize) + x + layer_offset).unwrap();
|
||||
let attr = stage.map.attrib[tile as usize];
|
||||
|
||||
if ![0x80, 0x81, 0x82, 0x83, 0xA0, 0xA1, 0xA2, 0xA3].contains(&attr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let shift = ((tick as f64 + state.frame_time) * 2.0) as u16 % 16;
|
||||
let mut push_rect = state.constants.world.water_push_rect;
|
||||
|
||||
match attr {
|
||||
0x80 | 0xA0 => {
|
||||
push_rect.left = push_rect.left + shift;
|
||||
push_rect.right = push_rect.right + shift;
|
||||
}
|
||||
0x81 | 0xA1 => {
|
||||
push_rect.top = push_rect.top + shift;
|
||||
push_rect.bottom = push_rect.bottom + shift;
|
||||
}
|
||||
0x82 | 0xA2 => {
|
||||
push_rect.left = push_rect.left - shift + state.tile_size.as_int() as u16;
|
||||
push_rect.right = push_rect.right - shift + state.tile_size.as_int() as u16;
|
||||
}
|
||||
0x83 | 0xA3 => {
|
||||
push_rect.top = push_rect.top - shift + state.tile_size.as_int() as u16;
|
||||
push_rect.bottom = push_rect.bottom - shift + state.tile_size.as_int() as u16;
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
batch.add_rect(
|
||||
(x as f32 * tile_sizef - halftf) - frame_x,
|
||||
(y as f32 * tile_sizef - halftf) - frame_y,
|
||||
&push_rect,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
batch.draw(ctx)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -214,10 +214,10 @@ impl EditorInstance {
|
|||
let paths = self.stage_textures.deref().borrow();
|
||||
self.background.draw(state, ctx, &self.frame, &*paths, &self.stage)?;
|
||||
|
||||
self.tilemap.draw(state, ctx, &self.frame, TileLayer::Background, &*paths, &self.stage)?;
|
||||
self.tilemap.draw(state, ctx, &self.frame, TileLayer::Middleground, &*paths, &self.stage)?;
|
||||
self.tilemap.draw(state, ctx, &self.frame, TileLayer::Foreground, &*paths, &self.stage)?;
|
||||
self.tilemap.draw(state, ctx, &self.frame, TileLayer::Snack, &*paths, &self.stage)?;
|
||||
self.tilemap.draw(state, ctx, &self.frame, TileLayer::Background, &*paths, &self.stage, 0)?;
|
||||
self.tilemap.draw(state, ctx, &self.frame, TileLayer::Middleground, &*paths, &self.stage, 0)?;
|
||||
self.tilemap.draw(state, ctx, &self.frame, TileLayer::Foreground, &*paths, &self.stage, 0)?;
|
||||
self.tilemap.draw(state, ctx, &self.frame, TileLayer::Snack, &*paths, &self.stage, 0)?;
|
||||
|
||||
self.draw_black_bars(state, ctx)?;
|
||||
|
||||
|
|
|
@ -179,6 +179,7 @@ impl Clone for WeaponConsts {
|
|||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct WorldConsts {
|
||||
pub snack_rect: Rect<u16>,
|
||||
pub water_push_rect: Rect<u16>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
|
@ -480,7 +481,10 @@ impl EngineConstants {
|
|||
question_left_rect: Rect { left: 0, top: 80, right: 16, bottom: 96 },
|
||||
question_right_rect: Rect { left: 48, top: 64, right: 64, bottom: 80 },
|
||||
},
|
||||
world: WorldConsts { snack_rect: Rect { left: 256, top: 48, right: 272, bottom: 64 } },
|
||||
world: WorldConsts {
|
||||
snack_rect: Rect { left: 256, top: 48, right: 272, bottom: 64 },
|
||||
water_push_rect: Rect { left: 224, top: 48, right: 240, bottom: 64 },
|
||||
},
|
||||
npc: serde_json::from_str("{}").unwrap(),
|
||||
weapon: WeaponConsts {
|
||||
bullet_table: vec![
|
||||
|
@ -1513,7 +1517,7 @@ impl EngineConstants {
|
|||
credit_illustration_paths: vec![
|
||||
"".to_owned(),
|
||||
"Resource/BITMAP/".to_owned(), // CSE2E
|
||||
"endpic/".to_owned(), // NXEngine
|
||||
"endpic/".to_owned(), // NXEngine
|
||||
],
|
||||
}
|
||||
}
|
||||
|
|
|
@ -324,6 +324,18 @@ impl GameScene {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn set_ironhead_clip(&self, state: &mut SharedGameState, ctx: &mut Context) -> GameResult {
|
||||
let x_size = if !state.constants.is_switch { 320.0 } else { 426.0 };
|
||||
let clip_rect: Rect = Rect::new_size(
|
||||
(((state.canvas_size.0 - x_size) * 0.5) * state.scale) as _,
|
||||
(((state.canvas_size.1 - 240.0) * 0.5) * state.scale) as _,
|
||||
(x_size * state.scale) as _,
|
||||
(240.0 * state.scale) as _,
|
||||
);
|
||||
graphics::set_clip_rect(ctx, Some(clip_rect))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn draw_light(&self, x: f32, y: f32, size: f32, color: (u8, u8, u8), batch: &mut Box<dyn SpriteBatch>) {
|
||||
batch.add_rect_scaled_tinted(
|
||||
x - size * 32.0,
|
||||
|
@ -1609,7 +1621,7 @@ impl Scene for GameScene {
|
|||
}
|
||||
|
||||
if self.player1.controller.trigger_menu_pause() {
|
||||
self.pause_menu.pause();
|
||||
self.pause_menu.pause(state);
|
||||
}
|
||||
|
||||
if self.pause_menu.is_paused() {
|
||||
|
@ -1748,21 +1760,30 @@ impl Scene for GameScene {
|
|||
//graphics::set_canvas(ctx, Some(&state.game_canvas));
|
||||
|
||||
if self.player1.control_mode == ControlMode::IronHead {
|
||||
let x_size = if !state.constants.is_switch { 320.0 } else { 426.0 };
|
||||
let clip_rect: Rect = Rect::new_size(
|
||||
(((state.canvas_size.0 - x_size) * 0.5) * state.scale) as _,
|
||||
(((state.canvas_size.1 - 240.0) * 0.5) * state.scale) as _,
|
||||
(x_size * state.scale) as _,
|
||||
(240.0 * state.scale) as _,
|
||||
);
|
||||
graphics::set_clip_rect(ctx, Some(clip_rect))?;
|
||||
self.set_ironhead_clip(state, ctx)?;
|
||||
}
|
||||
|
||||
let stage_textures_ref = &*self.stage_textures.deref().borrow();
|
||||
self.background.draw(state, ctx, &self.frame, stage_textures_ref, &self.stage)?;
|
||||
self.tilemap.draw(state, ctx, &self.frame, TileLayer::Background, stage_textures_ref, &self.stage)?;
|
||||
self.tilemap.draw(
|
||||
state,
|
||||
ctx,
|
||||
&self.frame,
|
||||
TileLayer::Background,
|
||||
stage_textures_ref,
|
||||
&self.stage,
|
||||
self.tick,
|
||||
)?;
|
||||
self.draw_npc_layer(state, ctx, NPCLayer::Background)?;
|
||||
self.tilemap.draw(state, ctx, &self.frame, TileLayer::Middleground, stage_textures_ref, &self.stage)?;
|
||||
self.tilemap.draw(
|
||||
state,
|
||||
ctx,
|
||||
&self.frame,
|
||||
TileLayer::Middleground,
|
||||
stage_textures_ref,
|
||||
&self.stage,
|
||||
self.tick,
|
||||
)?;
|
||||
|
||||
if state.settings.shader_effects && self.lighting_mode == LightingMode::BackgroundOnly {
|
||||
self.draw_light_map(state, ctx)?;
|
||||
|
@ -1779,8 +1800,16 @@ impl Scene for GameScene {
|
|||
}
|
||||
|
||||
self.water_renderer.draw(state, ctx, &self.frame)?;
|
||||
self.tilemap.draw(state, ctx, &self.frame, TileLayer::Foreground, stage_textures_ref, &self.stage)?;
|
||||
self.tilemap.draw(state, ctx, &self.frame, TileLayer::Snack, stage_textures_ref, &self.stage)?;
|
||||
self.tilemap.draw(
|
||||
state,
|
||||
ctx,
|
||||
&self.frame,
|
||||
TileLayer::Foreground,
|
||||
stage_textures_ref,
|
||||
&self.stage,
|
||||
self.tick,
|
||||
)?;
|
||||
self.tilemap.draw(state, ctx, &self.frame, TileLayer::Snack, stage_textures_ref, &self.stage, self.tick)?;
|
||||
|
||||
self.draw_carets(state, ctx)?;
|
||||
self.player1.popup.draw(state, ctx, &self.frame)?;
|
||||
|
|
Loading…
Reference in New Issue