tsc: quake effect and some additional opcodes

This commit is contained in:
Alula 2020-09-03 14:06:12 +02:00
parent 69ef0f5791
commit c8b6395fd7
No known key found for this signature in database
GPG Key ID: 3E00485503A1D8BA
3 changed files with 29 additions and 5 deletions

View File

@ -9,7 +9,7 @@ pub struct Frame {
}
impl Frame {
pub fn update(&mut self, state: &SharedGameState, player: &Player, stage: &Stage) {
pub fn update(&mut self, state: &mut SharedGameState, player: &Player, stage: &Stage) {
if (stage.map.width - 1) * 16 < state.canvas_size.0 as usize {
self.x = -(((state.canvas_size.0 as isize - ((stage.map.width - 1) * 16) as isize) * 0x200) / 2);
} else {
@ -40,6 +40,11 @@ impl Frame {
}
}
// todo quake
if state.quake_counter > 0 {
state.quake_counter -= 1;
self.x += state.effect_rng.range(-0x300..0x300) as isize;
self.y += state.effect_rng.range(-0x300..0x300) as isize;
}
}
}

View File

@ -50,7 +50,6 @@ mod caret;
mod common;
mod engine_constants;
mod entity;
mod enemy;
mod frame;
mod ggez;
mod live_debugger;
@ -103,6 +102,7 @@ pub struct SharedGameState {
pub fade_state: FadeState,
pub game_rng: RNG,
pub effect_rng: RNG,
pub quake_counter: u16,
pub carets: Vec<Caret>,
pub key_state: KeyState,
pub key_trigger: KeyState,
@ -180,6 +180,7 @@ impl Game {
fade_state: FadeState::Hidden,
game_rng: RNG::new(0),
effect_rng: RNG::new(Instant::now().elapsed().as_nanos() as i32),
quake_counter: 0,
carets: Vec::with_capacity(32),
key_state: KeyState(0),
key_trigger: KeyState(0),

View File

@ -609,6 +609,17 @@ impl TextScriptVM {
exec_state = TextScriptExecutionState::Running(event_num, 0);
}
OpCode::MOV => {
let pos_x = read_cur_varint(&mut cursor)? as isize * 16 * 0x200;
let pos_y = read_cur_varint(&mut cursor)? as isize * 16 * 0x200;
game_scene.player.vel_x = 0;
game_scene.player.vel_y = 0;
game_scene.player.x = pos_x;
game_scene.player.y = pos_y;
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
}
OpCode::FAI => {
let fade_type = read_cur_varint(&mut cursor)? as usize;
if let Some(direction) = FadeDirection::from_int(fade_type) {
@ -625,6 +636,13 @@ impl TextScriptVM {
exec_state = TextScriptExecutionState::WaitFade(event, cursor.position() as u32);
}
OpCode::QUA => {
let count = read_cur_varint(&mut cursor)? as u16;
state.quake_counter = count;
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
}
OpCode::CMU => {
let song_id = read_cur_varint(&mut cursor)? as usize;
state.sound_manager.play_song(song_id, &state.constants, ctx)?;
@ -653,7 +671,7 @@ impl TextScriptVM {
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
}
// One operand codes
OpCode::BOA | OpCode::BSL | OpCode::FOB | OpCode::FOM | OpCode::QUA | OpCode::UNI |
OpCode::BOA | OpCode::BSL | OpCode::FOB | OpCode::FOM | OpCode::UNI |
OpCode::MYB | OpCode::GIT | OpCode::NUM | OpCode::DNA | OpCode::DNP |
OpCode::MPp | OpCode::SKm | OpCode::SKp | OpCode::EQp | OpCode::EQm |
OpCode::ITp | OpCode::ITm | OpCode::AMm | OpCode::UNJ | OpCode::MPJ | OpCode::YNJ |
@ -666,7 +684,7 @@ impl TextScriptVM {
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
}
// Two operand codes
OpCode::FON | OpCode::MOV | OpCode::AMp | OpCode::NCJ | OpCode::ECJ |
OpCode::FON | OpCode::AMp | OpCode::NCJ | OpCode::ECJ |
OpCode::ITJ | OpCode::SKJ | OpCode::AMJ | OpCode::SMP | OpCode::PSp => {
let par_a = read_cur_varint(&mut cursor)?;
let par_b = read_cur_varint(&mut cursor)?;