From 8050beed563d1ce597dd13ad6a5bc589cf768a6f Mon Sep 17 00:00:00 2001 From: Alula Date: Sun, 1 Nov 2020 20:08:52 +0100 Subject: [PATCH] add u8 { + if let Some(&tile) = self.map.tiles.get(y * self.map.width + x) { + tile + } else { + 0 + } + } + + /// Changes map tile. Returns true if smoke should be emitted pub fn change_tile(&mut self, x: usize, y: usize, tile_type: u8) -> bool { if let Some(ptr) = self.map.tiles.get_mut(y * self.map.width + x) { if *ptr != tile_type { diff --git a/src/text_script.rs b/src/text_script.rs index 526d144..8ac3662 100644 --- a/src/text_script.rs +++ b/src/text_script.rs @@ -891,6 +891,15 @@ impl TextScriptVM { exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32); } + OpCode::SMP => { + let pos_x = read_cur_varint(&mut cursor)? as usize; + let pos_y = read_cur_varint(&mut cursor)? as usize; + + let tile_type = game_scene.stage.tile_at(pos_x, pos_y); + game_scene.stage.change_tile(pos_x, pos_y, tile_type.wrapping_sub(1)); + + exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32); + } OpCode::CMP => { let pos_x = read_cur_varint(&mut cursor)? as usize; let pos_y = read_cur_varint(&mut cursor)? as usize; @@ -1387,7 +1396,7 @@ impl TextScriptVM { exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32); } // Two operand codes - OpCode::SKJ | OpCode::SMP => { + OpCode::SKJ => { let par_a = read_cur_varint(&mut cursor)?; let par_b = read_cur_varint(&mut cursor)?;