Advertisement
squidingtin

PacMan (LUA)

Jan 27th, 2018
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.10 KB | None | 0 0
  1. PacManX = $1A
  2. PacManX_decimal = $1B
  3.  
  4. PacManY = $1C
  5. PacManY_decimal = $1D
  6.  
  7. BlinkyX = $1E
  8. BlinkyX_decimal = $1F
  9.  
  10. BlinkyY = $20
  11. BlinkyY_decimal = $21
  12.  
  13. PinkyX = $22
  14. PinkyX_decimal = $23
  15.  
  16. PinkyY = $24
  17. PinkyY_decimal = $25
  18.  
  19. InkyX = $26
  20. InkyX_decimal = $27
  21.  
  22. InkyY = $28
  23. InkyY_decimal = $29
  24.  
  25. ClydeX = $2A
  26. ClydeX_decimal = $2B
  27.  
  28. ClydeY = $2C
  29. ClydeY_decimal = $2D
  30.  
  31.  
  32. PacMan_CHR_pattern = $32
  33. Blinky_CHR_pattern = $33
  34. Pinky_CHR_pattern = $34
  35. Inky_CHR_pattern = $35
  36. Clyde_CHR_pattern = $36
  37.  
  38. GhoatPallet = $39-$3C
  39.  
  40. PlayingFlag = $48
  41.  
  42. Direction = $50
  43. DirectionBuffer = $51
  44.  
  45. HiScore = $61-$66
  46.  
  47. RemainingLives = $67
  48. StageCount = $68
  49. RestartFlag = $69
  50. DotCount = $6A
  51. ExtendsCount = $6B
  52. PowerPillState1 = $6C
  53. PowerPillState2 = $6D
  54. PowerPillState3 = $6E
  55. PowerPillState4 = $6F
  56. Score = $70-$75
  57.  
  58.  
  59. AnotherPlayerBuffer = $77-$86
  60.  
  61. FrightFlag = $88
  62. FrightTimerSeconds = $89
  63. FrightTimerFrames = $8A
  64.  
  65. BrinkySpeedCounter1 = $8D
  66. BrinkySpeedCounter2 = $8E
  67.  
  68.  
  69. ModeTimer = $97-$9E
  70. SpeedTable = $9F-$B4
  71.  
  72. CurrentPacManSpeed = $B5-$B6
  73.  
  74. PacManRunCounter = $B7
  75.  
  76.  
  77. BlinkyStatus = $B8
  78. BlinkyDirection = $B9
  79.  
  80. PinkyStatus = $BA
  81. PinkyDirection = $BB
  82.  
  83. InkyStatus = $BC
  84. InkyDirection = $BD
  85.  
  86. ClydeStatus = $BE
  87. ClydeDirection = $BF
  88.  
  89. TargetX = $CD
  90. TargetY = $CE
  91.  
  92. ModeCounterSeconds = $CF
  93. GhostMode = $D0
  94. ModeCounterFrames = $D1
  95.  
  96. FruitsTimerSeconds = $D7
  97. FruitsTimerFrames = $D8
  98.  
  99. PacMan_Current_VRAM_Address = $0200-$0201
  100.  
  101. PacMan_Upside_VRAM_Address = $0202-$0203
  102. PacMan_Left_VRAM_Address = $0204-$0205
  103. PacMan_Downside_VRAM_Address = $0206-$0207
  104. PacMan_Rightside_VRAM_Address = $0208-$0209
  105.  
  106. Blinky_Upside_VRAM_Address = $020A-$020B
  107. Blinky_Left_VRAM_Address = $020C-$020D
  108. Blinky_Downside_VRAM_Address = $020E-$020F
  109. Blinky_Rightside_VRAM_Address = $0210-$0211
  110.  
  111. Pinky_Upside_VRAM_Address = $0212-$0213
  112. Pinky_Left_VRAM_Address = $0214-$0215
  113. Pinky_Downside_VRAM_Address = $0216-$0217
  114. Pinky_Rightside_VRAM_Address = $0218-$0219
  115.  
  116. Inky_Upside_VRAM_Address = $021A-$021B
  117. Inky_Left_VRAM_Address = $021C-$021D
  118. Inky_Downside_VRAM_Address = $021E-$021F
  119. Inky_Rightside_VRAM_Address = $0220-$0221
  120.  
  121. Clyde_Upside_VRAM_Address = $0222-$0223
  122. Clyde_Left_VRAM_Address = $0224-$0225
  123. Clyde_Downside_VRAM_Address = $0226-$0227
  124. Clyde_Rightside_VRAM_Address = $0228-$0229
  125.  
  126. PacMan_CurrentBlock = $022A
  127.  
  128. PacMan_UpsideBlock = $022B
  129. PacMan_LeftsideBlock = $022C
  130. PacMan_DownsideBlock = $022D
  131. PacMan_RightsideBlock = $022E
  132.  
  133. Blinky_UpsideBlock = $022F
  134. Blinky_LeftsideBlock = $0230
  135. Blinky_DownsideBlock = $0231
  136. Blinky_RightsideBlock = $0232
  137.  
  138. Pinky_UpsideBlock = $0233
  139. Pinky_LeftsideBlock = $0234
  140. Pinky_DownsideBlock = $0235
  141. Pinky_RightsideBlock = $0236
  142.  
  143. Inky_UpsideBlock = $0237
  144. Inky_LeftsideBlock = $0238
  145. Inky_DownsideBlock = $0239
  146. Inky_RightsideBlock = $023A
  147.  
  148. Clyde_UpsideBlock = $023B
  149. Clyde_LeftsideBlock = $023C
  150. Clyde_DownsideBlock = $023D
  151. Clyde_RightsideBlock = $023E
  152.  
  153. ]]
  154.  
  155.  
  156.  
  157. Direction = {"U","L","D","R"}
  158. ColorTable = {"#FC9838","#A40000","#D4C8FC","#3CBCFC","#C84C0C","#0070EC","#C84C0C70"}
  159. TargetPosition = {0,0,0,0,0,0,0,0}
  160.  
  161. InvincibleMode = true
  162. DisplayParameter = false
  163. KeyBuffer = {}
  164. KeyInput = {}
  165.  
  166.  
  167. GhostPattern = 0x33
  168. PacManX = 0x1A
  169. PacManY = 0x1C
  170. GhostX = 0x1E
  171. GhostY = 0x20
  172. FruitsTargetFlag = 0x30
  173. FruitsOBJ_No = 0x37
  174. PlayingFlag = 0x48
  175. PauseCounter = 0x4A
  176. StageCount = 0x68
  177. DotCount = 0x6A
  178. FrightTimerSeconds = 0x89
  179. FrightTimerFrames = 0x8A
  180. BrinkySpeedCounter1 = 0x8D
  181. BrinkySpeedCounter2 = 0x8E
  182. CurrentPacManSpeed = 0xB5
  183. GhostStatus = 0xB8
  184. GhostDirection = 0xB9
  185. CurrentBlinkySpeed = 0xC2
  186. CurrentPinkySpeed = 0xC4
  187. CurrentInkySpeed = 0xC6
  188. CurrentClydeSpeed = 0xC8
  189. ModeCounterSeconds = 0xCF
  190. GhostMode = 0xD0
  191. ModeCounterFrames = 0xD1
  192. ElroyModeFlag = 0xD2
  193. FruitsTargetTimerS = 0xD7
  194. FruitsTargetTimerF = 0xD8
  195.  
  196.  
  197. function IsPress()
  198. KeyBuffer = KeyInput
  199. KeyInput = joypad.get(1)
  200. return false
  201. end
  202.  
  203. function Invincible()
  204. if InvincibleMode then
  205. memory.setregister("pc", 0xD2B0)
  206. end
  207. end
  208.  
  209. function BDash()
  210. if KeyInput["B"] then
  211. memory.writebyte(0xB5, 0xE0)
  212. memory.writebyte(0xB6, 0x01)
  213. end
  214. end
  215.  
  216. function Brinky_taeget()
  217. TargetPosition[1] = memory.readbyte(0xCD)
  218. TargetPosition[2] = memory.readbyte(0xCE)
  219. end
  220.  
  221. function Pinky_taeget()
  222. TargetPosition[3] = memory.readbyte(0xCD)
  223. TargetPosition[4] = memory.readbyte(0xCE)
  224. end
  225.  
  226. function Inky_taeget()
  227. TargetPosition[5] = memory.readbyte(0xCD)
  228. TargetPosition[6] = memory.readbyte(0xCE)
  229. end
  230.  
  231. function Clyde_taeget()
  232. TargetPosition[7] = memory.readbyte(0xCD)
  233. TargetPosition[8] = memory.readbyte(0xCE)
  234. end
  235.  
  236.  
  237. memory.registerexecute(0xD2A2,Invincible)
  238. memory.register(0x00B6, BDash)
  239.  
  240. memory.register(0x00B9, Brinky_taeget)
  241. memory.register(0x00BB, Pinky_taeget)
  242. memory.register(0x00BD, Inky_taeget)
  243. memory.register(0x00BF, Clyde_taeget)
  244.  
  245. while true do
  246. if KeyInput["A"] and not KeyBuffer["A"] and not KeyInput["B"] then
  247. DisplayParameter = not(DisplayParameter)
  248. end
  249.  
  250. IsPress()
  251.  
  252. if KeyInput["select"] and not KeyBuffer["select"] then
  253. InvincibleMode = not(InvincibleMode)
  254. end
  255.  
  256. if InvincibleMode then
  257. gui.text(180, 220, "Invincible Mode", white)
  258. end
  259.  
  260. if
  261. KeyInput["A"] and KeyInput["B"] and not KeyBuffer["A"] and
  262. memory.readbyte(0x3F) ~= 0x10 and
  263. memory.readbyte(0x3F) ~= 0x00 and
  264. memory.readbyte(PlayingFlag) ~= 0xFF then
  265.  
  266. -- memory.writebyte(0x6A, 0x00)
  267. memory.writebyte(0x3F, 0x0C)
  268. memory.writebyte(0x87, 0x00)
  269. -- memory.writebyte(0x4C, 0x48)
  270.  
  271. memory.writebyte(0x6C, 0x07)
  272. memory.writebyte(0x6D, 0x07)
  273. memory.writebyte(0x6E, 0x07)
  274. memory.writebyte(0x6F, 0x07)
  275.  
  276. for i=0, 0x3B do
  277. memory.writebyte(0x0760 + i, 0x00)
  278. end
  279. end
  280.  
  281. -- for i=0, 16, 4 do
  282. -- gui.drawbox(memory.readbyte(PacManX + i) - 12, memory.readbyte(PacManY + i) + 4, memory.readbyte(PacManX + i) + 3, memory.readbyte(PacManY + i) + 19, 0, ColorTable[i / 4 + 1])
  283. -- end
  284.  
  285. keys = input.get()
  286. DrugX = keys.xmouse - keys.xmouse % 8 + 8
  287. DrugY = keys.ymouse - keys.ymouse % 8 - 8
  288.  
  289. if keys["leftclick"] then
  290. for i=0, 16, 4 do
  291. if
  292. memory.readbyte(PacManX + i) - 20 <= keys.xmouse and
  293. keys.xmouse <= memory.readbyte(PacManX + i) + 11 and
  294. memory.readbyte(PacManY + i) - 4 <= keys.ymouse and
  295. keys.ymouse <= memory.readbyte(PacManY + i) + 27 then
  296. memory.writebyte(PacManX + i, DrugX)
  297. memory.writebyte(PacManY + i, DrugY)
  298. end
  299. end
  300. end
  301.  
  302.  
  303. if
  304. memory.readbyte(0x6C) ~= 0x2D then
  305. if
  306. DisplayParameter and
  307. memory.readbyte(0x3F) ~= 0x00 and
  308. memory.readbyte(0x3F) ~= 0x10 then
  309.  
  310.  
  311. gui.drawbox(176, 24, 248, 219, "#000000")
  312.  
  313. Stage = string.sub(" " .. memory.readbyte(StageCount) + 1, -3)
  314. gui.text(180, 20, "Stage", ColorTable[6], 0)
  315. gui.text(183, 28, string.sub(" " .. Stage, -11), white, 0)
  316.  
  317.  
  318. --ゴーストモードタイマー表示
  319. if memory.readbyte(GhostMode) % 2 == 0x00 then
  320. Mode = "Scatter"
  321. TextColor = "black"
  322. ModeColor = "green"
  323. else
  324. Mode = " Chase "
  325. TextColor = "white"
  326. ModeColor = "red"
  327. end
  328.  
  329. ModeFrames = string.sub("0" .. 59 - memory.readbyte(ModeCounterFrames), -2)
  330. ModeSeconds = string.sub("0" .. memory.readbyte(ModeCounterSeconds), -2)
  331.  
  332. if memory.readbyte(ModeCounterSeconds) == 255 then
  333. count = "__:__"
  334. else
  335. count = ModeSeconds .. ":" .. ModeFrames
  336. end
  337.  
  338. gui.text(180,36, "Ghost Mode", ColorTable[6], 0)
  339. gui.text(180,44, Mode, TextColor, ModeColor)
  340. gui.text(180,44, string.sub(" " .. count, -12), white, 0)
  341.  
  342. TimerFrames = string.sub("0" .. 59 - memory.readbyte(FrightTimerFrames), -2)
  343. TimerSeconds = string.sub("0" .. memory.readbyte(FrightTimerSeconds), -2)
  344.  
  345. if memory.readbyte(FrightTimerSeconds) == 255 then
  346. FrightTimer = "__:__"
  347. FrightColor = "white"
  348. else
  349. FrightTimer = TimerSeconds .. ":" .. TimerFrames
  350. FrightColor = "red"
  351. end
  352.  
  353. gui.text(180, 52, "Fright Timer", ColorTable[6], 0)
  354. gui.text(180, 60, string.sub(" " .. FrightTimer, -12), white, 0)
  355.  
  356. DotsLeft = memory.readbyte(DotCount)
  357. EatenDots = 192 - DotsLeft
  358.  
  359. gui.text(180, 68, "Dots Left", ColorTable[6], 0)
  360. gui.text(183, 76, string.sub(" " .. DotsLeft, -11), white, 0)
  361.  
  362.  
  363. FruitsFrames = string.sub("0" .. memory.readbyte(FruitsTargetTimerF) -1, -2)
  364. FruitsSeconds = string.sub("0" .. memory.readbyte(FruitsTargetTimerS), -2)
  365.  
  366. if
  367. memory.readbyte(FruitsTargetFlag) == 0x80 and
  368. memory.readbyte(FruitsOBJ_No) >= 0x24 and
  369. memory.readbyte(FruitsOBJ_No) <= 0x2B then
  370.  
  371. Ftimer = FruitsSeconds .. ":" .. FruitsFrames
  372. else
  373. Ftimer = "__:__"
  374. end
  375.  
  376. gui.text(180, 84, "Fruits Target", ColorTable[6], 0)
  377. gui.text(180, 92, string.sub(" " .. Ftimer, -12), white, 0)
  378.  
  379.  
  380. if EatenDots > 58 then
  381. Fruits1st = "__"
  382. else
  383. Fruits1st = "0" .. 58 - EatenDots
  384. end
  385.  
  386. if EatenDots > 137 then
  387. Fruits2nd = "___"
  388. else
  389. Fruits2nd = "00" .. 137 - EatenDots
  390. end
  391.  
  392. gui.text(180, 92, string.sub(Fruits1st, -2) .. "/" .. string.sub(Fruits2nd, -3), white, 0)
  393.  
  394. BSCount1 = memory.readbyte(BrinkySpeedCounter1)
  395. BSCount2 = memory.readbyte(BrinkySpeedCounter2)
  396.  
  397. if DotsLeft > BSCount1 then
  398. BSpeed1 = "00" .. DotsLeft - BSCount1
  399. else
  400. BSpeed1 = "___"
  401. end
  402.  
  403. if DotsLeft > BSCount2 then
  404. BSpeed2 = "00" .. DotsLeft - BSCount2
  405. else
  406. BSpeed2 = "___"
  407. end
  408.  
  409. if memory.readbyte(ElroyModeFlag) == 1 then
  410. ElroyColor = "red"
  411. else
  412. ElroyColor = "white"
  413. end
  414.  
  415. gui.text(180, 100, "Cruise Elroy ", ColorTable[6], 0)
  416. gui.text(178, 108, " " .. string.sub(BSpeed1, -3) .. "/" .. string.sub(BSpeed2, -3), ElroyColor, 0)
  417.  
  418. PSpeed =(memory.readbyte(CurrentPacManSpeed) + memory.readbyte(CurrentPacManSpeed+1)*256)/16 .. "/16"
  419. gui.text(180, 116, "PacMan Speed", ColorTable[6], 0)
  420. gui.text(184, 124, string.sub(" " .. PSpeed, -11), FrightColor, 0)
  421.  
  422.  
  423. BSpeed =(memory.readbyte(CurrentBlinkySpeed) + memory.readbyte(CurrentBlinkySpeed+1)*256)/16 .. "/16"
  424. gui.text(180, 132, "Blinky Speed", ColorTable[6], 0)
  425. gui.text(184, 140, string.sub(" " .. BSpeed, -11), ElroyColor, 0)
  426.  
  427.  
  428. OSpeed =(memory.readbyte(CurrentPinkySpeed) + memory.readbyte(CurrentPinkySpeed+1)*256)/16 .. "/16"
  429. gui.text(180, 148, "Pinky Speed", ColorTable[6], 0)
  430. gui.text(184, 156, string.sub(" " .. OSpeed, -11), white, 0)
  431.  
  432. OSpeed =(memory.readbyte(CurrentInkySpeed) + memory.readbyte(CurrentInkySpeed+1)*256)/16 .. "/16"
  433. gui.text(180, 164, "Inky Speed", ColorTable[6], 0)
  434. gui.text(184, 172, string.sub(" " .. OSpeed, -11), white, 0)
  435.  
  436. OSpeed =(memory.readbyte(CurrentClydeSpeed) + memory.readbyte(CurrentClydeSpeed+1)*256)/16 .. "/16"
  437. gui.text(180, 180, "Clyde Speed", ColorTable[6], 0)
  438. gui.text(184, 188, string.sub(" " .. OSpeed, -11), white, 0)
  439.  
  440. end
  441.  
  442. if
  443. memory.readbyte(0x20) ~= 0x00 and
  444. TargetPosition[1] ~= 0x00 then
  445.  
  446. if
  447. memory.readbyte(GhostStatus + 6) ~= 0x00 and
  448. memory.readbyte(GhostStatus + 6) ~= 0x02 and
  449. memory.readbyte(GhostPattern + 6 / 2) ~= 0x1E and
  450. memory.readbyte(GhostPattern + 6 / 2) ~= 0x1F and
  451. memory.readbyte(GhostPattern + 6 / 2) ~= 0x2D and
  452. memory.readbyte(GhostPattern + 6 / 2) ~= 0x2F and
  453. memory.readbyte(GhostPattern + 6 / 2) ~= 0x32 and
  454. memory.readbyte(GhostPattern + 6 / 2) ~= 0x34 then
  455.  
  456. if
  457. math.abs(memory.readbyte(PacManX) - memory.readbyte(GhostX + 12)) < 32 and
  458. math.abs(memory.readbyte(PacManY) - memory.readbyte(GhostY + 12)) < 32 and
  459. memory.readbyte(GhostMode) % 2 ~= 0x00 and
  460. memory.readbyte(GhostPattern + 6 / 2) ~= 0x20 and
  461. memory.readbyte(GhostPattern + 6 / 2) ~= 0x21 and
  462. memory.readbyte(GhostPattern + 6 / 2) ~= 0x22 and
  463. memory.readbyte(GhostPattern + 6 / 2) ~= 0x23 then
  464. gui.drawbox(memory.readbyte(PacManX) - 4 - 25, memory.readbyte(PacManY) + 12 - 25, memory.readbyte(PacManX) - 4 + 24, memory.readbyte(PacManY) + 12 + 24, 0, ColorTable[5])
  465. else
  466. gui.drawbox(memory.readbyte(PacManX) - 4 - 25, memory.readbyte(PacManY) + 12 - 25, memory.readbyte(PacManX) - 4 + 24, memory.readbyte(PacManY) + 12 + 24, 0, ColorTable[7])
  467. gui.drawbox(TargetPosition[7] - 7, TargetPosition[8] + 9, TargetPosition[7] - 2, TargetPosition[8] + 14, ColorTable[5])
  468. gui.drawline(TargetPosition[7] - 4, TargetPosition[8] + 12, memory.readbyte(GhostX + 12) - 4, memory.readbyte(GhostY + 12) + 12, ColorTable[5])
  469. end
  470. end
  471.  
  472. for i=0, 4, 2 do
  473. if
  474. memory.readbyte(GhostStatus + i) ~= 0x00 and
  475. memory.readbyte(GhostStatus + i) ~= 0x02 and
  476. memory.readbyte(GhostPattern + i / 2) ~= 0x1E and
  477. memory.readbyte(GhostPattern + i / 2) ~= 0x1F and
  478. memory.readbyte(GhostPattern + i / 2) ~= 0x2D and
  479. memory.readbyte(GhostPattern + i / 2) ~= 0x2F and
  480. memory.readbyte(GhostPattern + i / 2) ~= 0x32 and
  481. memory.readbyte(GhostPattern + i / 2) ~= 0x34 then
  482. gui.drawbox(TargetPosition[i + 1] - 7, TargetPosition[i + 2] + 9, TargetPosition[i + 1] - 2, TargetPosition[i + 2] + 14, ColorTable[i / 2 + 2])
  483. gui.drawline(TargetPosition[i + 1] - 4, TargetPosition[i + 2] + 12, memory.readbyte(GhostX + i * 2) - 4, memory.readbyte(GhostY + i * 2) + 12, ColorTable[i / 2 + 2])
  484. end
  485. end
  486. end
  487. end
  488.  
  489. if
  490. memory.readbyte(PauseCounter) % 2 == 1 and
  491. memory.readbyte(PlayingFlag) ~= 0xFF then
  492. gui.text(60, 120, " P A U S E ")
  493. end
  494.  
  495.  
  496. FCEU.frameadvance()
  497.  
  498. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement