User File #638476618127648560

Upload All User Files

#638476618127648560 - INTV Flapee Bird lua script

Flapee-Bird-v2.lua
Game: Flapee Bird ( INTV, see all files )
10 downloads
Uploaded 4/2/2024 1:36 PM by Winslinator (see all 22)


while true do

	--define arrays for the 10 rows of graphics elements to be read every frame
	r1 = {}
	r2 = {}
	r3 = {}
	r4 = {}
	r5 = {}
	r6 = {}
	r7 = {}
	r8 = {}
	r9 = {}
	r10 = {}

	--look in the main ram memory domain to track the "level", which I derived from the score addresses
	memory.usememorydomain("Main RAM")
	if memory.readbyte(0x38) <= 3 and memory.readbyte(0x39) == 0
	then
		level = memory.readbyte(0x38)
	else
		level = 3
	end

	--switch to system ram memory domain
	memory.usememorydomain("System Ram")
	
	--track the player's y position
	py = memory.readbyte(0x029F)

--Read the values for 9 columns of graphics ahead of the player (initially) to extablish the environment.
--The number of columns to look ahead will progressively narrow as the level increases (to just 6 by level 3) because as the pipes spawn closer together, the script may think the gap two pipes ahead is the target and we want to eliminate that possibility.
for i=1, 18-2*level, 1 do
	-- r1[i] = memory.readbyte(0x000C+i*0x01)
	-- r2[i] = memory.readbyte(0x0034+i*0x01)
	-- r3[i] = memory.readbyte(0x005C+i*0x01)
	-- r4[i] = memory.readbyte(0x0084+i*0x01)
	-- r5[i] = memory.readbyte(0x00AC+i*0x01)
	-- r6[i] = memory.readbyte(0x00D4+i*0x01)
	-- r7[i] = memory.readbyte(0x00FC+i*0x01)
	-- r8[i] = memory.readbyte(0x0124+i*0x01)
	-- r9[i] = memory.readbyte(0x014C+i*0x01)
	-- r10[i] = memory.readbyte(0x0174+i*0x01)
	r1[i] = memory.readbyte(0x000E+i*0x01)
	r2[i] = memory.readbyte(0x0036+i*0x01)
	r3[i] = memory.readbyte(0x005E+i*0x01)
	r4[i] = memory.readbyte(0x0086+i*0x01)
	r5[i] = memory.readbyte(0x00AE+i*0x01)
	r6[i] = memory.readbyte(0x00D6+i*0x01)
	r7[i] = memory.readbyte(0x00FE+i*0x01)
	r8[i] = memory.readbyte(0x0126+i*0x01)
	r9[i] = memory.readbyte(0x014E+i*0x01)
	r10[i] = memory.readbyte(0x0176+i*0x01)
	-- r1[i] = memory.readbyte(0x0010+i*0x01)
	-- r2[i] = memory.readbyte(0x0038+i*0x01)
	-- r3[i] = memory.readbyte(0x0060+i*0x01)
	-- r4[i] = memory.readbyte(0x0088+i*0x01)
	-- r5[i] = memory.readbyte(0x00B0+i*0x01)
	-- r6[i] = memory.readbyte(0x00D8+i*0x01)
	-- r7[i] = memory.readbyte(0x0100+i*0x01)
	-- r8[i] = memory.readbyte(0x0128+i*0x01)
	-- r9[i] = memory.readbyte(0x0150+i*0x01)
	-- r10[i] = memory.readbyte(0x0178+i*0x01)
--There was some calibration as to where the start point of the "looking ahead" ought to be, hence the commented out memory reads above.
end

--Tell the script what graphics indicate the top/bottom of pipes, between which will be the gap to pass through
for i=1, 18-2*level, 1 do

	--This first IF will tell the script what to do if the gap is at the top. There is only one row of top/bottom pipe graphics in this instance, so we must also read all rows below it to establish they are walls.
	--Pipe top/bottom graphics can have a value of 41 or 37 in RAM, while pipe walls can have values of 61 or 85.
	--Two possible sets of values the pipe graphics can assume (separated by OR operator) are supplied as a failsafe.
	if (r4[i] == 41 and r5[i] == 61 and r6[i] == 61 and r7[i] == 61 and r8[i] == 61 and r9[i] == 61 and r10[i] == 61)
	or (r4[i] == 37 and r5[i] == 85 and r6[i] == 85 and r7[i] == 85 and r8[i] == 85 and r9[i] == 85 and r10[i] == 85)
	then
		--This nested IF tells the script to press the button when the y position exceeds a certain value. Each critical y position was empirically calibrated to minimize number of collisions.
		if py >= 23
		then
			joypad.set({["Key 5"]=true}, 1)
		end
	end
	
	--The number 41 will only appear as a graphics value if it is a pipe top/bottom. If graphic rows 1 and 5 contain this number, we know exactly where the gap is—one row from the top. The next 5 IF statements follow suit.
	if r1[i] == 41 and r5[i] == 41
	then
		if py >= 31
		then
			joypad.set({["Key 5"]=true}, 1)
		end
	end	
	
	if r2[i] == 41 and r6[i] == 41
	then
		if py >= 39
		then
			joypad.set({["Key 5"]=true}, 1)
		end
	end	
	
	if r3[i] == 41 and r7[i] == 41
	then
		if py >= 47
		then
			joypad.set({["Key 5"]=true}, 1)
		end
	end	
	
	if r4[i] == 41 and r8[i] == 41
	then
		if py >= 55
		then
			joypad.set({["Key 5"]=true}, 1)
		end
	end
	
	if r5[i] == 41 and r9[i] == 41
	then
		if py >= 63
		then
			joypad.set({["Key 5"]=true}, 1)
		end
	end	
	
	if r6[i] == 41 and r10[i] == 41
	then
		if py >= 71
		then
			joypad.set({["Key 5"]=true}, 1)
		end
	end
	
	--This if statement is for when the gap is at the bottom and operates similarly to when the gap is at the top.
	if (r1[i] == 61 and r2[i] == 61 and r3[i] == 61 and r4[i] == 61 and r5[i] == 61 and r6[i] == 61 and r7[i] == 41)
	or (r1[i] == 85 and r2[i] == 85 and r3[i] == 85 and r4[i] == 85 and r5[i] == 85 and r6[i] == 85 and r7[i] == 37)
	then
		if py >= 79
		then
			joypad.set({["Key 5"]=true}, 1)
		end
	end
end

	--used for starting the game—hold the button for the first 120 frames except for frame 76 (to prevent locking on the title screen)
	if emu.framecount() <= 120
	then
		joypad.set({["Key 5"]=true}, 1)
	end
	if emu.framecount() == 76
	then
		joypad.set({["Key 5"]=false}, 1)
	end

	emu.frameadvance()
end