User File #27241108696817705

Upload All User Files

#27241108696817705 - Mario Bros (Classic)

Mario Bros (Classic).lua
775 downloads
Uploaded 12/1/2015 7:02 PM by jlun2 (see all 165)
Automatically plays the Rainshower game in Classic mode from Game & Watch gallery 4.
memory.usememorydomain("Combined WRAM")
block = 0x03C140
Lworker = 0x03C139
Rworker = 0x03C138

while true do
--[[memory.readbyte(0x03C12A) when the next tick occurs
--memory.readbyte(0x03C12D) timer for this minigame; always 1 less than above before next tick
	(memory.readbyte(0x03C12A) - memory.readbyte(0x03C12D) > 2) 
	]]--
	gui.drawText(0,0,"Timer: "..memory.readbyte(0x03C12A) - memory.readbyte(0x03C12D).."\nSpeed: "..memory.readbyte(0x03C12A),'Red')
	for i = block, 0x03C17D, 4 do
		if (memory.readbyte(0x03C12A) - memory.readbyte(0x03C12D) > 2) and memory.readbyte(i) ~= 0 then	--Test before it's about to fall; useful to prevent false postives. The other statement tests for existence.
			if (memory.readbyte(i+1) == 2 and memory.readbyte(i) ~= 5) then	--To prevent the case where there's another gift about to reach this but hasn't been shifted yet
				gui.drawText(0,0,"ERROR",'Red')
				if memory.readbyte(Rworker) ~= 0 then
					joypad.set({B = 1})
					emu.frameadvance()
				end
				while (memory.readbyte(i+1) == 3 and memory.readbyte(i) ~= 5) and memory.readbyte(Rworker) == 0 do	--Need to check again so it won't leave the place too soon
					emu.frameadvance()	--This is ok since the game won't let 2 gifts about to fall at the same time
				end
			elseif (memory.readbyte(i+1) == 11 and memory.readbyte(i) ~= 5) then
				if memory.readbyte(Lworker) ~= 0 then
					joypad.set({Down = 1})
					emu.frameadvance()
				end
				while (memory.readbyte(i+1) == 11 and memory.readbyte(i) ~= 5) and memory.readbyte(Lworker) == 0 do
					emu.frameadvance()
				end
			elseif (memory.readbyte(i+1) == 20 and memory.readbyte(i) ~= 5) then
				if memory.readbyte(Rworker) > 1 then
					joypad.set({B = 1})
					emu.frameadvance()
				elseif memory.readbyte(Rworker) < 1 then
					joypad.set({A = 1})
					emu.frameadvance()
				end
				while (memory.readbyte(i+1) == 20 and memory.readbyte(i) ~= 5) and memory.readbyte(Rworker) == 1 do
					emu.frameadvance()
				end
			elseif (memory.readbyte(i+1) == 29 and memory.readbyte(i) ~= 5) then
				if memory.readbyte(Lworker) > 1 then
					joypad.set({Down = 1})
					emu.frameadvance()
				elseif memory.readbyte(Lworker) < 1 then
					joypad.set({Up = 1})
					emu.frameadvance()
				end
				while (memory.readbyte(i+1) == 29 and memory.readbyte(i) ~= 5) and memory.readbyte(Lworker) == 1 do
					emu.frameadvance()
				end
			elseif (memory.readbyte(i+1) == 38 and memory.readbyte(i) ~= 5) then
				if memory.readbyte(Rworker) ~= 2 then
					joypad.set({A = 1})
					emu.frameadvance()
				end 
				while (memory.readbyte(i+1) == 38 and memory.readbyte(i) ~= 5) and memory.readbyte(Rworker) == 2 do
					emu.frameadvance()
				end 
			elseif (memory.readbyte(i+1) == 47 and memory.readbyte(i) ~= 5) then
				if memory.readbyte(Lworker) ~= 2 then
					joypad.set({Up = 1})
					emu.frameadvance()
				end
				while (memory.readbyte(i+1) == 47 and memory.readbyte(i) ~= 5) and memory.readbyte(Lworker) == 2 do
					emu.frameadvance()
				end
			end
		end
	end
	emu.frameadvance()
end