Advertisement
Guest User

Super C Collision viewer

a guest
Sep 30th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.43 KB | None | 0 0
  1. --Author Pasky 13
  2.  
  3. --Player
  4. local px = 0x54C
  5. local py = 0x532
  6.  
  7. --Player projectiles
  8. local projxbase = 0x588
  9. local projybase = 0x578
  10.  
  11. --Enemies
  12. local ex = 0x53C
  13. local ey = 0x522
  14.  
  15. local function hex(val)
  16.     val = string.format("%X",val)
  17.     return val
  18. end
  19.  
  20. local function draw_axis(x,y,color)
  21.     gui.line(x,y-4,x,y+4,color)
  22.     gui.line(x-4,y,x+4,y,color)
  23. end
  24.  
  25. local function sign(val)
  26.     if val > 0x7F then
  27.         val = 256 + (val * -1)
  28.     end
  29.     return val
  30. end
  31.  
  32. local box_data = {
  33. 0xEA,0xF4,0x2A,0x16,0xF0,0xFA,0x1E,0x0A,0xE5,0xF7,0x34,0x10,0xE1,0xEB,0x3C,0x28,
  34. 0xF1,0xEF,0x28,0x20,0xE1,0xD3,0x3C,0x58,0xD1,0xDB,0x6C,0x48,0xD1,0xEB,0x5C,0x28,
  35. 0xF2,0xF2,0x1A,0x1A,0xF8,0xF8,0x0E,0x0E,0xED,0xF5,0x24,0x14,0xE9,0xE9,0x2C,0x2C,
  36. 0xF9,0xED,0x18,0x24,0xE9,0xD1,0x2C,0x5C,0xD9,0xD9,0x5C,0x4C,0xD9,0xE9,0x4C,0x2C,
  37. 0xEA,0xEA,0x16,0x2A,0xF0,0xF0,0x0A,0x1E,0xE5,0xED,0x20,0x24,0xE1,0xE1,0x28,0x3C,
  38. 0xF1,0xE5,0x14,0x34,0xE1,0xC9,0x28,0x6C,0xD1,0xD1,0x58,0x5C,0xD1,0xE1,0x48,0x3C,
  39. 0xEA,0xF4,0x22,0x16,0xF0,0xFA,0x16,0x0A,0xE5,0xF7,0x2C,0x10,0xE1,0xEB,0x34,0x28,
  40. 0xF1,0xEF,0x20,0x20,0xE1,0xD3,0x34,0x58,0xD1,0xDB,0x64,0x48,0xD1,0xEB,0x54,0x28,
  41. 0xF8,0xF4,0x1A,0x16,0xFE,0xFA,0x0E,0x0A,0xF3,0xF7,0x24,0x10,0xEF,0xEB,0x2C,0x28,
  42. 0xFF,0xEF,0x18,0x20,0xEF,0xD3,0x2C,0x58,0xDF,0xDB,0x5C,0x48,0xDF,0xEB,0x4C,0x28,
  43. 0xF3,0xF3,0x18,0x18,0xF7,0xF7,0x10,0x10,0xEC,0xF3,0x26,0x18,0xEB,0xEB,0x28,0x28,
  44. 0xFB,0xEF,0x14,0x20,0xEB,0xD3,0x28,0x58,0xD3,0xEB,0x28,0x28,0xDB,0xEB,0x48,0x28,
  45. 0xF0,0xF4,0x1E,0x16,0xF6,0xFA,0x12,0x0A,0xEB,0xF7,0x28,0x10,0xE7,0xEB,0x30,0x28,
  46. 0xF7,0xEF,0x1C,0x20,0xE7,0xD3,0x30,0x58,0xD7,0xDB,0x60,0x48,0xD7,0xEB,0x50,0x28,
  47. 0xA5,0x5B,0x29,0x01,0xAA,0xB5,0xC6,0x38,0x65,0x07,0xA8,0xBD,0x4C,0x05,0xF9,0x01,
  48. 0xA0,0xE5,0x05,0xD9,0x03,0xA0,0xB0,0x0D,0xBD,0x32,0x05,0xF9,0x00,0xA0,0xE5,0x06 }
  49.  
  50. local function Player()
  51.     -- Player 1
  52.     if memory.readbyte(0xC6) ~= 0 then
  53.         local x = memory.readbyte(px)
  54.         local y = memory.readbyte(py)
  55.         draw_axis(x,y,"#0000FFFF")
  56.     end
  57.     -- Player 2
  58.     if memory.readbyte(0xC7) ~= 0 then
  59.         x = memory.readbyte(px+1)
  60.         y = memory.readbyte(py+1)
  61.         draw_axis(x,y,"#0000FFFF")
  62.     end
  63. end
  64.  
  65. local function bullets()
  66.     -- P1
  67.     if memory.readbyte(0xC6) ~= 0 then
  68.         for i = 0,9,1 do
  69.             local x = memory.readbyte(projxbase + i)
  70.             local y = memory.readbyte(projybase + i)
  71.            
  72.             if memory.readbyte(0x638 + i) > 0 then
  73.                 gui.box(x-2,y-2,x+2,y+2,"#FFFFFF40","#FFFFFFFF")
  74.             end
  75.         end
  76.     end
  77.     -- P2
  78.     if memory.readbyte(0xC7) ~= 0 then
  79.         for i = 0,9,1 do
  80.             local x = memory.readbyte(0x592 + i)
  81.             local y = memory.readbyte(0x582 + i)
  82.            
  83.             if memory.readbyte(0x642 + i) > 0 then
  84.                 gui.box(x-2,y-2,x+2,y+2,"#FFFFFF40","#FFFFFFFF")
  85.             end
  86.         end
  87.     end
  88.    
  89. end
  90.  
  91.  
  92. local function enemies()
  93.     local active
  94.     local etype
  95.     local fill
  96.     local outl
  97.     for i = 0,0x0D,1 do
  98.         active = memory.readbyte(0x508+i)  -- sprite frame
  99.         etype = memory.readbyte(0x73A + i)
  100.        
  101.         if etype == 4 or etype == 0x0C then  -- Enemy projectiles
  102.             fill = "#00FF00FF"
  103.             outl = "#00FF0035"
  104.         else
  105.             fill = "#FF0000FF"
  106.             outl = "#FF000035"
  107.         end
  108.        
  109.         local x = memory.readbyte(ex + i)
  110.         local y = memory.readbyte(ey + i)
  111.        
  112.         -- Collision detection player 1
  113.         if memory.readbyte(0xC6) ~= 0 then
  114.             if active > 0 then 
  115.                 local offset = ((memory.readbyte(0xC6) + etype + 1) % 0x100)
  116.                 local xoff = sign(box_data[1 + 1 + offset]) + 1
  117.                 local xrad = box_data[1 + 3 + offset]
  118.                 local yoff = sign(box_data[1 + offset]) + 1
  119.                 local yrad = box_data[1 + 2 + offset]
  120.                 gui.box(x-xoff,y-yoff,x-xoff+xrad,y-yoff+yrad,outl,fill)
  121.             end
  122.         end
  123.        
  124.         -- Collision detection player 2
  125.         if memory.readbyte(0xC7) ~= 0 then
  126.             if active > 0 then
  127.                 local offset = ((memory.readbyte(0xC7) + etype + 1) % 0x100)
  128.                 local xoff = sign(box_data[1 + 1 + offset]) + 1
  129.                 local xrad = box_data[1 + 3 + offset]
  130.                 local yoff = sign(box_data[1 + offset]) + 1
  131.                 local yrad = box_data[1 + 2 + offset]
  132.                 gui.box(x-xoff,y-yoff,x-xoff+xrad,y-yoff+yrad,outl,fill)
  133.             end
  134.         end
  135.        
  136.         -- Projectile collision
  137.         if active > 0 and etype ~= 4 and etype ~= 0x0C then
  138.             local poffset = etype + 0xA0
  139.             local pxoff = sign(box_data[1 + 1 + poffset]) + 1
  140.             local pxrad = box_data[1 + 3 + poffset] - 2
  141.             local pyoff = sign(box_data[1 + poffset]) + 1
  142.             local pyrad = box_data[1 + 2 + poffset] - 2
  143.             gui.box(x-pxoff,y-pyoff,x-pxoff+pxrad,y-pyoff+pyrad,"#FFFF0040","#FFFF00FF")
  144.         end
  145.        
  146.        
  147.     end
  148. end
  149.  
  150. while true do
  151.     Player()
  152.     bullets()
  153.     enemies()
  154.     emu.frameadvance()
  155. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement