Try to increase the search radius on sprites to eliminate flicker
This commit is contained in:
parent
cef2265ace
commit
303f2f3643
6 changed files with 42 additions and 109 deletions
|
@ -20,7 +20,7 @@ _M.State = {
|
||||||
"PiratePanicKremcoin.lsmv",
|
"PiratePanicKremcoin.lsmv",
|
||||||
}
|
}
|
||||||
|
|
||||||
_M.Filename = _M.PoolDir .. _M.State[3]
|
_M.Filename = _M.PoolDir .. _M.State[1]
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Start game with specific powerup.
|
Start game with specific powerup.
|
||||||
|
|
122
donkutil.lua
122
donkutil.lua
|
@ -2,6 +2,8 @@ local base = string.gsub(@@LUA_SCRIPT_FILENAME@@, "(.*/)(.*)", "%1")
|
||||||
|
|
||||||
local util = dofile(base.."/util.lua")
|
local util = dofile(base.."/util.lua")
|
||||||
local spritelist = dofile(base.."/spritelist.lua")
|
local spritelist = dofile(base.."/spritelist.lua")
|
||||||
|
local game = dofile(base.."/game.lua")
|
||||||
|
local config = dofile(base.."/config.lua")
|
||||||
|
|
||||||
spritelist.InitSpriteList()
|
spritelist.InitSpriteList()
|
||||||
spritelist.InitExtSpriteList()
|
spritelist.InitExtSpriteList()
|
||||||
|
@ -42,8 +44,16 @@ lockdata = nil
|
||||||
incsprite = 0
|
incsprite = 0
|
||||||
questionable_tiles = false
|
questionable_tiles = false
|
||||||
|
|
||||||
function text(x, y, msg)
|
font = gui.font.load(base.."font.font")
|
||||||
gui.text(x, y, msg, FG_COLOR, BG_COLOR)
|
|
||||||
|
function text(x, y, msg, fg, bg)
|
||||||
|
if fg == nil then
|
||||||
|
fg = FG_COLOR
|
||||||
|
end
|
||||||
|
if bg == nil then
|
||||||
|
bg = BG_COLOR
|
||||||
|
end
|
||||||
|
font(x, y, msg, fg, bg)
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_keyhook (key, state)
|
function on_keyhook (key, state)
|
||||||
|
@ -134,7 +144,7 @@ function get_sprite(base_addr)
|
||||||
return {
|
return {
|
||||||
base_addr = string.format("%04x", base_addr),
|
base_addr = string.format("%04x", base_addr),
|
||||||
screenX = x - 256 - cameraX,
|
screenX = x - 256 - cameraX,
|
||||||
screenY = y - 256 - cameraY,
|
screenY = y - 256 - cameraY - TILE_SIZE / 3,
|
||||||
control = memory.readword(base_addr),
|
control = memory.readword(base_addr),
|
||||||
draworder = memory.readword(base_addr + 0x02),
|
draworder = memory.readword(base_addr + 0x02),
|
||||||
x = x,
|
x = x,
|
||||||
|
@ -256,7 +266,7 @@ Sprite Details:
|
||||||
|
|
||||||
local partyX = memory.readword(PARTY_X)
|
local partyX = memory.readword(PARTY_X)
|
||||||
local partyY = memory.readword(PARTY_Y)
|
local partyY = memory.readword(PARTY_Y)
|
||||||
local partyTileOffset = tileOffsetCalculation(partyX, partyY, vertical)
|
local partyTileOffset = game.tileOffsetCalculation(partyX, partyY, vertical)
|
||||||
|
|
||||||
local stats = string.format([[
|
local stats = string.format([[
|
||||||
%s camera %d,%d
|
%s camera %d,%d
|
||||||
|
@ -264,9 +274,10 @@ Vertical: %s
|
||||||
Tile offset: %04x
|
Tile offset: %04x
|
||||||
Stage number: %04x
|
Stage number: %04x
|
||||||
Stage (movement): %04x
|
Stage (movement): %04x
|
||||||
]], direction, cameraX, cameraY, vertical, partyTileOffset, memory.readword(STAGE_NUMBER), memory.readword(STAGE_NUMBER_MOVEMENT))
|
%s
|
||||||
|
]], direction, cameraX, cameraY, vertical, partyTileOffset, memory.readword(STAGE_NUMBER), memory.readword(STAGE_NUMBER_MOVEMENT), util.table_to_string(game.getInputs()):gsub("[\\{\\},\n\"]", ""):gsub("-1", "X"):gsub("0", "."):gsub("1", "O"):gsub("(.............)", "%1\n"))
|
||||||
|
|
||||||
text(guiWidth - 200, guiHeight - 100, stats)
|
text(guiWidth - 125, guiHeight - 200, stats)
|
||||||
|
|
||||||
text((partyX - 256 - cameraX) * 2, (partyY - 256 - cameraY) * 2 + 20, "Party")
|
text((partyX - 256 - cameraX) * 2, (partyY - 256 - cameraY) * 2 + 20, "Party")
|
||||||
|
|
||||||
|
@ -291,7 +302,7 @@ Stage (movement): %04x
|
||||||
sprcolor = 0x66009900
|
sprcolor = 0x66009900
|
||||||
end
|
end
|
||||||
|
|
||||||
gui.text(sprite.screenX * 2, sprite.screenY * 2, string.format("%04x, %04x, %04x", sprite.control, sprite.animnum, sprite.attr), FG_COLOR, sprcolor)
|
text(sprite.screenX * 2, sprite.screenY * 2, string.format("%04x, %04x, %04x", sprite.control, sprite.animnum, sprite.attr), FG_COLOR, sprcolor)
|
||||||
|
|
||||||
local filename = os.getenv("HOME").."/neat-donk/catchem/"..sprite.animnum..","..sprite.attr..".png"
|
local filename = os.getenv("HOME").."/neat-donk/catchem/"..sprite.animnum..","..sprite.attr..".png"
|
||||||
if pokemon and spriteScreenX > (guiWidth / 4) and spriteScreenX < (guiWidth / 4) * 3 and spriteScreenY > (guiHeight / 3) and spriteScreenY < guiHeight and not util.file_exists(filename) then
|
if pokemon and spriteScreenX > (guiWidth / 4) and spriteScreenX < (guiWidth / 4) * 3 and spriteScreenY > (guiHeight / 3) and spriteScreenY < guiHeight and not util.file_exists(filename) then
|
||||||
|
@ -308,13 +319,13 @@ Stage (movement): %04x
|
||||||
local cameraTileX = math.floor(cameraX / TILE_SIZE)
|
local cameraTileX = math.floor(cameraX / TILE_SIZE)
|
||||||
gui.line(0, halfHeight, guiWidth, halfHeight, BG_COLOR)
|
gui.line(0, halfHeight, guiWidth, halfHeight, BG_COLOR)
|
||||||
for i = cameraTileX, cameraTileX + guiWidth / TILE_SIZE / 2,1 do
|
for i = cameraTileX, cameraTileX + guiWidth / TILE_SIZE / 2,1 do
|
||||||
gui.text((i * TILE_SIZE - cameraX) * 2, halfHeight, tostring(i), FG_COLOR, BG_COLOR)
|
text((i * TILE_SIZE - cameraX) * 2, halfHeight, tostring(i), FG_COLOR, BG_COLOR)
|
||||||
end
|
end
|
||||||
|
|
||||||
local cameraTileY = math.floor(cameraY / TILE_SIZE)
|
local cameraTileY = math.floor(cameraY / TILE_SIZE)
|
||||||
gui.line(halfWidth, 0, halfWidth, guiHeight, BG_COLOR)
|
gui.line(halfWidth, 0, halfWidth, guiHeight, BG_COLOR)
|
||||||
for i = cameraTileY, cameraTileY + guiHeight / TILE_SIZE / 2,1 do
|
for i = cameraTileY, cameraTileY + guiHeight / TILE_SIZE / 2,1 do
|
||||||
gui.text(halfWidth, (i * TILE_SIZE - cameraY) * 2, tostring(i), FG_COLOR, BG_COLOR)
|
text(halfWidth, (i * TILE_SIZE - cameraY) * 2, tostring(i), FG_COLOR, BG_COLOR)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -325,11 +336,11 @@ Stage (movement): %04x
|
||||||
local tileX = math.floor((partyX + x * TILE_SIZE) / TILE_SIZE) * TILE_SIZE
|
local tileX = math.floor((partyX + x * TILE_SIZE) / TILE_SIZE) * TILE_SIZE
|
||||||
local tileY = math.floor((partyY + y * TILE_SIZE) / TILE_SIZE) * TILE_SIZE
|
local tileY = math.floor((partyY + y * TILE_SIZE) / TILE_SIZE) * TILE_SIZE
|
||||||
|
|
||||||
local offset = tileOffsetCalculation(tileX, tileY, vertical)
|
local offset = game.tileOffsetCalculation(tileX, tileY, vertical)
|
||||||
|
|
||||||
local tile = memory.readword(tilePtr + offset)
|
local tile = memory.readword(tilePtr + offset)
|
||||||
|
|
||||||
if not tileIsSolid(tileX, tileY, tile, offset) then
|
if not game.tileIsSolid(tileX, tileY, tile, offset) then
|
||||||
goto continue
|
goto continue
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -340,7 +351,7 @@ Stage (movement): %04x
|
||||||
--goto continue
|
--goto continue
|
||||||
end
|
end
|
||||||
|
|
||||||
gui.text(screenX, screenY, string.format("%04x\n%02x", bit.band(offset, 0xffff), tile), FG_COLOR, 0x66888800)
|
text(screenX, screenY, string.format("%04x\n%02x", bit.band(offset, 0xffff), tile), FG_COLOR, 0x66888800)
|
||||||
|
|
||||||
::continue::
|
::continue::
|
||||||
end
|
end
|
||||||
|
@ -375,7 +386,7 @@ Stage (movement): %04x
|
||||||
end
|
end
|
||||||
|
|
||||||
if bit.band(screenSprite.flags, 0x21) ~= 0x00 and screenSprite.tile >= 224 and screenSprite.tile <= 238 then
|
if bit.band(screenSprite.flags, 0x21) ~= 0x00 and screenSprite.tile >= 224 and screenSprite.tile <= 238 then
|
||||||
gui.text(screenSprite.x * 2, screenSprite.y * 2, screenSprite.tile, 0x00000000, 0x00ffff00)
|
text(screenSprite.x * 2, screenSprite.y * 2, screenSprite.tile, 0x00000000, 0x00ffff00)
|
||||||
end
|
end
|
||||||
|
|
||||||
::continue::
|
::continue::
|
||||||
|
@ -391,91 +402,6 @@ Stage (movement): %04x
|
||||||
text(guiWidth - 125, 20, "Help [Hold 0]")
|
text(guiWidth - 125, 20, "Help [Hold 0]")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Logic from 0xb5c3e1, 0xb5c414, 0xb5c82c
|
|
||||||
function tileOffsetCalculation (x, y, vertical)
|
|
||||||
local newX = x - 256
|
|
||||||
local newY = y - 256
|
|
||||||
|
|
||||||
if not vertical then
|
|
||||||
if newY < 0 then
|
|
||||||
newY = 0
|
|
||||||
elseif newY >= 0x1ff then
|
|
||||||
newY = 0x1ff
|
|
||||||
end
|
|
||||||
|
|
||||||
newY = bit.band(bit.band(bit.bnot(newY), 0xffff) + 1, 0x1e0)
|
|
||||||
|
|
||||||
newX = bit.band(newX, 0xffe0)
|
|
||||||
|
|
||||||
newY = bit.lrshift(bit.band(bit.bxor(newY, 0x1e0), 0xffff), 4)
|
|
||||||
|
|
||||||
return newY + newX
|
|
||||||
else
|
|
||||||
newY = bit.band(bit.band(bit.bnot(newY), 0xffff) + 1, 0xffe0)
|
|
||||||
|
|
||||||
newX = bit.lrshift(bit.band(newX, 0xffe0), 4)
|
|
||||||
|
|
||||||
newY = bit.band(bit.lshift(bit.band(bit.bxor(newY, 0xffe0), 0xffff), 1), 0xffff)
|
|
||||||
|
|
||||||
return newY + newX
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- 0xb5c94d
|
|
||||||
function tileIsSolid(x, y, tileVal, tileOffset)
|
|
||||||
local origTileVal = tileVal
|
|
||||||
|
|
||||||
if tileVal == 0 or tileOffset == 0 then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
if questionable_tiles then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
local a2 = bit.band(x, 0x1f)
|
|
||||||
|
|
||||||
if bit.band(tileVal, 0x4000) ~= 0 then
|
|
||||||
a2 = bit.band(bit.bxor(a2, 0x1f), 0xffff)
|
|
||||||
end
|
|
||||||
|
|
||||||
tileVal = bit.band(tileVal, 0x3fff)
|
|
||||||
|
|
||||||
local solidLessThan = memory.readword(SOLID_LESS_THAN)
|
|
||||||
|
|
||||||
if tileVal >= solidLessThan then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
tileVal = bit.band(bit.lshift(tileVal, 2), 0xffff)
|
|
||||||
|
|
||||||
if bit.band(a2, 0x10) ~= 0 then
|
|
||||||
tileVal = tileVal + 2
|
|
||||||
end
|
|
||||||
|
|
||||||
local tileMeta = memory.readword(memory.readword(0x7e009c) + tileVal)
|
|
||||||
|
|
||||||
if bit.band(tileMeta, 0x8000) ~=0 then
|
|
||||||
a2 = bit.band(bit.bxor(a2, 0x000f), 0xffff)
|
|
||||||
end
|
|
||||||
|
|
||||||
if bit.band(tileMeta, tileVal, 0x2000) ~= 0 then
|
|
||||||
tileMeta = bit.band(bit.bxor(tileMeta, 0x8000), 0xffff)
|
|
||||||
end
|
|
||||||
|
|
||||||
tileMeta = bit.band(tileMeta, 0x00ff)
|
|
||||||
|
|
||||||
if tileMeta == 0 then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
tileMeta = bit.band(bit.bxor(tileMeta, 1), 0xffff)
|
|
||||||
|
|
||||||
-- FIXME further tests?
|
|
||||||
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_timer()
|
function on_timer()
|
||||||
set_timer_timeout(100 * 1000)
|
set_timer_timeout(100 * 1000)
|
||||||
end
|
end
|
||||||
|
|
15
game.lua
15
game.lua
|
@ -359,21 +359,22 @@ function _M.getInputs()
|
||||||
|
|
||||||
for i = 1,#sprites do
|
for i = 1,#sprites do
|
||||||
local sprite = sprites[i]
|
local sprite = sprites[i]
|
||||||
distx = math.abs(sprite.x - (partyX+dx*TILE_SIZE))
|
local distx = math.abs(sprite.x - (partyX+dx*TILE_SIZE))
|
||||||
disty = math.abs(sprite.y - (partyY+dy*TILE_SIZE))
|
local disty = math.abs(sprite.y - (partyY+dy*TILE_SIZE))
|
||||||
if distx <= TILE_SIZE / 2 and disty <= TILE_SIZE / 2 then
|
local dist = math.sqrt((distx * distx) + (disty * disty))
|
||||||
|
if dist <= TILE_SIZE * 1.25 then
|
||||||
inputs[#inputs] = sprite.good
|
inputs[#inputs] = sprite.good
|
||||||
|
|
||||||
local dist = math.sqrt((distx * distx) + (disty * disty))
|
if dist > TILE_SIZE then
|
||||||
if dist > TILE_SIZE / 2 then
|
|
||||||
inputDeltaDistance[#inputDeltaDistance] = mathFunctions.squashDistance(dist)
|
inputDeltaDistance[#inputDeltaDistance] = mathFunctions.squashDistance(dist)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
::continue::
|
||||||
end
|
end
|
||||||
|
|
||||||
for i = 1,#extended do
|
for i = 1,#extended do
|
||||||
distx = math.abs(extended[i]["x"]+cameraX - (partyX+dx*TILE_SIZE))
|
local distx = math.abs(extended[i]["x"]+cameraX - (partyX+dx*TILE_SIZE))
|
||||||
disty = math.abs(extended[i]["y"]+cameraY - (partyY+dy*TILE_SIZE))
|
local disty = math.abs(extended[i]["y"]+cameraY - (partyY+dy*TILE_SIZE))
|
||||||
if distx < TILE_SIZE / 2 and disty < TILE_SIZE / 2 then
|
if distx < TILE_SIZE / 2 and disty < TILE_SIZE / 2 then
|
||||||
|
|
||||||
inputs[#inputs] = extended[i]["good"]
|
inputs[#inputs] = extended[i]["good"]
|
||||||
|
|
|
@ -18,6 +18,7 @@ form = nil
|
||||||
netPicture = nil
|
netPicture = nil
|
||||||
runInitialized = {}
|
runInitialized = {}
|
||||||
frameAdvanced = {}
|
frameAdvanced = {}
|
||||||
|
timeout = 0
|
||||||
|
|
||||||
saveLoadFile = config.NeatConfig.SaveFile
|
saveLoadFile = config.NeatConfig.SaveFile
|
||||||
statusLine = nil
|
statusLine = nil
|
||||||
|
@ -876,7 +877,9 @@ function mainLoop (species, genome)
|
||||||
|
|
||||||
-- Don't punish being launched by barrels
|
-- Don't punish being launched by barrels
|
||||||
-- FIXME Will this skew mine cart levels?
|
-- FIXME Will this skew mine cart levels?
|
||||||
if game.getVelocityY() < -1850 then
|
if game.getVelocityY() < -2104 then
|
||||||
|
statusLine = "BARREL! "..frame
|
||||||
|
statusColor = 0x00ffff00
|
||||||
timeout = timeout + 60 * 12
|
timeout = timeout + 60 * 12
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -884,6 +887,7 @@ function mainLoop (species, genome)
|
||||||
if nextArea ~= lastArea then
|
if nextArea ~= lastArea then
|
||||||
lastArea = nextArea
|
lastArea = nextArea
|
||||||
game.onceAreaLoaded(function()
|
game.onceAreaLoaded(function()
|
||||||
|
print("Loady")
|
||||||
timeout = timeout + 60 * 5
|
timeout = timeout + 60 * 5
|
||||||
currentArea = nextArea
|
currentArea = nextArea
|
||||||
lastArea = currentArea
|
lastArea = currentArea
|
||||||
|
@ -1347,7 +1351,7 @@ function displayForm()
|
||||||
gui.rectangle(0, 0, 500, guiHeight, 1, 0x00ffffff, 0x00000000)
|
gui.rectangle(0, 0, 500, guiHeight, 1, 0x00ffffff, 0x00000000)
|
||||||
gui.circle(game.screenX-84, game.screenY-84, 192 / 2, 1, 0x50000000)
|
gui.circle(game.screenX-84, game.screenY-84, 192 / 2, 1, 0x50000000)
|
||||||
|
|
||||||
--gui.text(5, 30, "Fitness: " .. math.floor(rightmost - (pool.currentFrame) / 2 - (timeout + timeoutBonus)*2/3))
|
gui.text(5, 30, "Timeout: " .. timeout)
|
||||||
gui.text(5, 5, "Generation: " .. pool.generation)
|
gui.text(5, 5, "Generation: " .. pool.generation)
|
||||||
gui.text(130, 5, "Species: " .. pool.currentSpecies)
|
gui.text(130, 5, "Species: " .. pool.currentSpecies)
|
||||||
gui.text(230, 5, "Genome: " .. pool.currentGenome)
|
gui.text(230, 5, "Genome: " .. pool.currentGenome)
|
||||||
|
|
|
@ -55,6 +55,8 @@ _M.GoodSprites = {
|
||||||
0x019c, -- Rambi
|
0x019c, -- Rambi
|
||||||
0x0304, -- Clapper
|
0x0304, -- Clapper
|
||||||
|
|
||||||
|
0x01a8, -- DK Barrel label
|
||||||
|
|
||||||
0x01b4, -- Krow's eggs
|
0x01b4, -- Krow's eggs
|
||||||
|
|
||||||
0x0220, -- Flitter (used as unavoidable platforms in some levels)
|
0x0220, -- Flitter (used as unavoidable platforms in some levels)
|
||||||
|
|
2
util.lua
2
util.lua
|
@ -10,7 +10,7 @@ function _M.table_to_string(tbl)
|
||||||
for _, k in ipairs(keys) do
|
for _, k in ipairs(keys) do
|
||||||
local v = tbl[k]
|
local v = tbl[k]
|
||||||
if type(v) == "number" and v == 0 then
|
if type(v) == "number" and v == 0 then
|
||||||
goto continue
|
--goto continue
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check the key type (ignore any numerical keys - assume its an array)
|
-- Check the key type (ignore any numerical keys - assume its an array)
|
||||||
|
|
Loading…
Add table
Reference in a new issue