Basically, improved Smash TV (NES and Genesis) "1 player 2 controllers" mode by using mouse for second controller.
Unuseful for TASing, probably fun for casual playing.
-- Play Smash TV (NES/Genesis) using mouse for aim!
-- For testing: Set 0x287 = 1 or 0xA302 = 1 to be invincible.
-- Configuration
local autoshoot = true
-- Shoot automatically. If false, you can shoot with mouse click.
-- Game detection
if gameinfo.getromhash() == 'DCD64D1BC14B8A32A86B4554B00BC37EC42992FF' then
-- If rom is NES version
memory.usememorydomain("RAM")
readplayerx = function() return memory.read_u8(0x0018) end
readplayery = function() return memory.read_u8(0x001A) - 8 end
good_game_mode = memory.read_u8(0x0638) == 1
u = 'Left'
d = 'Right'
l = 'Down'
r = 'Up'
elseif gameinfo.getromhash() == '6858C543DD27B9F1D5AA260A25AB1B83' then
-- If rom is Genesis version
memory.usememorydomain("68K RAM")
readplayerx = function() return 8 + memory.read_u16_be(0xA2FE) end
readplayery = function() return 186 - memory.read_u16_be(0xA300) end
good_game_mode = memory.read_u8(0xA250) == 64
u = 'Up'
d = 'Down'
l = 'Left'
r = 'Right'
else
print('ERROR! This script is made for\n"Smash T.V." NES and Genesis')
return
end
-- Controller 2 needs to be connected
c = joypad.get(2)
if c[u] == nil then
print('ERROR! Controller 2 is not connected.')
return
end
-- Check game mode
if not good_game_mode then
print('WARNING! This script is made for\n"1 Player 2 Controller" mode.')
-- Won't return so you can continue, but expect weird behavior
end
-- Actual program process
-- event.onframestart(function()
while true do
-- c = Controller (declared above)
for k,v in pairs(c) do c[k] = false end
mx = input.getmouse()['X'] -- Mouse X
my = input.getmouse()['Y'] -- Mouse Y
mb = input.getmouse()['Left'] or input.getmouse()['Right']
px = readplayerx() -- Player X
py = readplayery() -- Player Y
pi = math.pi
angle = math.atan(py-my,px-mx) + pi
-- Note: "angle" is in radians
if autoshoot then mb = not mb end
if mb then
c[u] = angle < (pi *11 / 6) and angle > (pi * 7 / 6) -- up = 210° ~ 330°
c[d] = angle < (pi * 5 / 6) and angle > (pi / 6) -- down = 30° ~ 150°
c[l] = angle < (pi * 4 / 3) and angle > (pi * 2 / 3) -- left = 120° ~ 240°
c[r] = angle < (pi / 3) or angle > (pi * 5 / 3) -- right = 300° ~ 60°
end
joypad.set(c,2)
emu.frameadvance()
end--)