CheatMaker 论坛

注册

 

发新话题 回复该主题

FC-自动射击鸭子 [复制链接]

1#

C++源代码

附件: 你需要登录才可以下载或查看附件。没有帐号? 注册



lua代码:
lua用法:
使用Debug>Script Window>Open加载或复制粘贴到Script Window

需要启用Script>Settings>Debugger Settings>Allow access to I/O and OS functions
会在Mesen同目录下生成log.txt文件.


附件: 你需要登录才可以下载或查看附件。没有帐号? 注册


ROM

附件: 你需要登录才可以下载或查看附件。没有帐号? 注册





演示视频:
https://www.bilibili.com/video/BV1DhkAYqEVk/
最后编辑dfzetcc 最后编辑于 2024-12-19 08:52:51
分享 转发
我来人间一趟 奔着自由与光
TOP
2#

光线枪游戏,怀念!!!!
TOP
3#

楼主会不会做FC那个运动会用枪打飞球那个
TOP
4#

楼主会不会做FC那个运动会用枪打飞球那个
ckyun 发表于 2024/12/21 14:19:38
好像没有玩过
我来人间一趟 奔着自由与光
TOP
5#

回复 4楼dfzetcc的帖子

这个奥运会打枪游戏

TOP
6#

回复 4楼dfzetcc的帖子

这个奥运会打枪游戏



ckyun 发表于 2024/12/24 7:45:08


油管有见到真大佬做的街机版(MAME 0.210+0.257)的自动脚本演示视频(打枪游戏在02:2x处).
油管视频(含视频所有游戏的lua脚本下载):
https://www.youtube.com/watch?v=q4CecLFUelU
打枪游戏在 Hyper Sports 这个mame rom和自动打枪代码在HyperSportsBot脚本里. 代码有原版和0.257修改版,原版我的0.210亲测可用.
最后编辑dfzetcc 最后编辑于 2024-12-24 13:27:51
我来人间一趟 奔着自由与光
TOP
7#

回复 4楼dfzetcc的帖子

这个奥运会打枪游戏



ckyun 发表于 2024/12/24 7:45:08

我参考大佬的mame脚本为奥运会的打枪游戏写的代码..目前效果并不完美.p.s:需要启用Script>Settings>Allow access to I/O and OS functions
  1. -- 射击目标
  2. local targetSpriteIds = {0x27}
  3. -- 瞄准框
  4. local shootingBoxSpriteIds = {0x73}
  5. -- 防止射击到射击目标的阴影
  6. local excludedSpriteIds = {0x00, 0x29, 0x2b, 0x1a, 0x1c, 0x0f}
  7. for i = 0x2d, 0x2f do table.insert(excludedSpriteIds, i) end
  8. for i = 0x3b, 0x3c do table.insert(excludedSpriteIds, i) end
  9. table.insert(excludedSpriteIds, 0x41)
  10. for i = 0x43, 0x48 do table.insert(excludedSpriteIds, i) end

  11. local screenCenterX = 256 / 2
  12. -- 迭代计数
  13. local lastInputTime = 0
  14. -- 延迟计数
  15. local inputDelay = 5

  16. -- 检查精灵的值是否有效
  17. local function isSpriteExcluded(spriteId)
  18.     for _, id in ipairs(excludedSpriteIds) do
  19.         if spriteId == id then
  20.             return true
  21.         end
  22.     end
  23.     return false
  24. end

  25. local function processSprites()
  26.     local nesSpriteRam = emu.memType.nesSpriteRam
  27.     local largeSprites = emu.getState()["ppu.control.largeSprites"]
  28.     local height = largeSprites and 16 or 8
  29.     local sprites = {}

  30.     for address = 0x00, 0xFF, 4 do
  31.         local y = emu.read(address, nesSpriteRam)
  32.         local tileIndex = emu.read(address + 1, nesSpriteRam)
  33.         local x = emu.read(address + 3, nesSpriteRam)

  34.         if y < 240 then
  35.             table.insert(sprites, {x = x, y = y + 1, id = tileIndex})  
  36.         end
  37.     end

  38.     local targetSprite = nil
  39.     local leftBox = nil
  40.     local rightBox = nil

  41.     for _, sprite in ipairs(sprites) do
  42.         if sprite.x ~= 0 and sprite.x ~= 0xF8 and not isSpriteExcluded(sprite.id) then  -- 获取射击精灵的类型,避免射击阴影
  43.             if table.contains(targetSpriteIds, sprite.id) then
  44.                 targetSprite = sprite
  45.             elseif table.contains(shootingBoxSpriteIds, sprite.id) then
  46.                 if sprite.x < screenCenterX then
  47.                     leftBox = sprite
  48.                 else
  49.                     rightBox = sprite
  50.                 end
  51.             end
  52.         end
  53.     end

  54.     _G.targetSprite = targetSprite
  55.     _G.leftBox = leftBox
  56.     _G.rightBox = rightBox
  57. end

  58. local function handleInput()
  59.     local targetSprite = _G.targetSprite
  60.     local leftBox = _G.leftBox
  61.     local rightBox = _G.rightBox

  62.     if targetSprite and leftBox and rightBox then
  63.         local now = os.clock()
  64.         if now - lastInputTime > inputDelay / 60 then
  65.             local input = {
  66.                 ["left"] = false,  
  67.                 ["a"] = false
  68.             }

  69.             local diffLeft = math.abs(targetSprite.x - leftBox.x)
  70.             local diffRight = math.abs(targetSprite.x - rightBox.x)

  71.             emu.log("Target X: " .. targetSprite.x .. ", Left Box X: " .. leftBox.x .. ", Right Box X: " .. rightBox.x)
  72.             emu.log("Diff Left: " .. diffLeft)
  73.             emu.log("Diff Right: " .. diffRight)

  74.             if diffLeft <= 3 then
  75.                 input["left"] = true
  76.                 emu.log("Simulating Left press.")
  77.             elseif diffRight <= 3 then
  78.                 input["a"] = true
  79.                 emu.log("Simulating A press.")
  80.             end

  81.             emu.setInput(input, 0)
  82.             lastInputTime = now
  83.         end
  84.     end
  85.         emu.log("inputPolled is running.")
  86. end


  87. local endFrameCallbackId = emu.addEventCallback(processSprites, emu.eventType.endFrame)
  88. local inputPolledCallbackId = emu.addEventCallback(handleInput, emu.eventType.inputPolled)

  89. if not table.contains then
  90.     function table.contains(table, element)
  91.         for _, value in pairs(table) do
  92.             if value == element then
  93.                 return true
  94.             end
  95.         end
  96.         return false
  97.     end
  98. end
复制代码
最后编辑dfzetcc 最后编辑于 2024-12-24 21:38:06
我来人间一趟 奔着自由与光
TOP
发新话题 回复该主题