User File #38688648943863044

Upload All User Files

#38688648943863044 - ZMZX4 Show enemy spawns v1

Zook_draw_enemy_spawns.lua
837 downloads
Uploaded 4/30/2017 8:04 AM by Dacicus (see all 26)
This script shows the enemy spawn locations in the current segment (white squares), as well as boxes that should indicate where the camera needs to be to spawn the enemies. The blue rectangles are the spots when moving right and the green are the spots when moving left. If the top of the rectangle is above the top of the screen, the enemy should not spawn. This does not account for vertical movements (jumping, climbing, etc.).
local stage_pointers = 0x3CCF68
local current_stage, current_segment, camera_x, camera_y
local current_stage_address, current_segment_address
local current_enemy_number, current_enemy_address
local current_enemy_x, current_enemy_y = {}, {}

memory.usememorydomain("IWRAM")

while true do
  camera_x = memory.read_s32_le(0x1500)
  camera_y = memory.read_s32_le(0x1504)
  current_stage = memory.readbyte(0x152C)
  current_segment = memory.readbyte(0x1530)

  current_stage_address = memory.read_u24_le(stage_pointers + current_stage * 4, "ROM")
  current_segment_address = memory.read_u24_le(current_stage_address + current_segment * 4, "ROM")

-- Generate table of spawn locations
  current_enemy_number = 0
  while true do
-- The first set of coordinates is always (0, 0) and does not correspond to an enemy, so skip it
    current_enemy_address = current_segment_address + current_enemy_number * 18 + 18
    if memory.read_u16_le(current_enemy_address, "ROM") == 0xFFFF then break end
    current_enemy_x[current_enemy_number] = memory.read_u16_le(current_enemy_address, "ROM")
    current_enemy_y[current_enemy_number] = memory.read_u16_le(current_enemy_address + 2, "ROM")
    current_enemy_number = current_enemy_number + 1
  end

  for i = 0, current_enemy_number - 1 do
    if current_enemy_number == 0 then break end
    gui.drawBox(current_enemy_x[i] - 300 - camera_x, current_enemy_y[i] - camera_y, current_enemy_x[i] - 248 - camera_x, current_enemy_y[i] + 160 - camera_y, 0x800000FF, 0x8000007F)
    gui.drawBox(current_enemy_x[i] + 32 - camera_x, current_enemy_y[i] - camera_y, current_enemy_x[i] + 40 - camera_x, current_enemy_y[i] + 160 - camera_y, 0x8000FF00, 0x80007F00)
    gui.drawRectangle(current_enemy_x[i] - camera_x, current_enemy_y[i] - camera_y, 4, 4)
  end

  emu.frameadvance()
end

-- 30 x 20