Have separate rightmost/upmost stats per screen

This commit is contained in:
Empathic Qubit 2021-03-06 11:46:39 -05:00
parent 9d66a8865d
commit 515a6504ba
3 changed files with 61 additions and 13 deletions

View file

@ -14,6 +14,8 @@ DIDDY_X_VELOCITY = 0x7e0e02
DIDDY_Y_VELOCITY = 0x7e0e06
DIXIE_X_VELOCITY = 0x7e0e60
DIXIE_Y_VELOCITY = 0x7e0e64
STAGE_NUMBER = 0x7e08a8
STAGE_NUMBER_MOVEMENT = 0x7e08c8
CAMERA_X = 0x7e17ba
CAMERA_Y = 0x7e17c0
CAMERA_MODE = 0x7e054f
@ -256,9 +258,11 @@ Sprite Details:
%s camera %d,%d
Vertical: %s
Tile offset: %04x
]], direction, cameraX, cameraY, vertical, partyTileOffset)
Stage number: %04x
Stage (movement): %04x
]], direction, cameraX, cameraY, vertical, partyTileOffset, memory.readword(STAGE_NUMBER), memory.readword(STAGE_NUMBER_MOVEMENT))
text(guiWidth - 200, guiHeight - 60, stats)
text(guiWidth - 200, guiHeight - 100, stats)
text((partyX - 256 - cameraX) * 2, (partyY - 256 - cameraY) * 2 + 20, "Party")

View file

@ -23,6 +23,8 @@ SOLID_LESS_THAN = 0x7e00a0
KONG_LETTERS = 0x7e0902
MATH_LIVES = 0x7e08be
DISPLAY_LIVES = 0x7e0c0
MAIN_AREA_NUMBER = 0x7e08a8
CURRENT_AREA_NUMBER = 0x7e08c8
function _M.getPositions()
leader = memory.readword(LEAD_CHAR)
@ -200,6 +202,10 @@ function _M.getTile(dx, dy)
return 1
end
function _M.getCurrentArea()
return memory.readword(CURRENT_AREA_NUMBER)
end
function _M.getJumpHeight()
local sprite = _M.getSprite(leader)
return sprite.jumpHeight
@ -353,10 +359,23 @@ function _M.getInputs()
return inputs, inputDeltaDistance
end
_M.areaLoadedQueue = {}
function _M.onceAreaLoaded(handler)
table.insert(_M.areaLoadedQueue, handler)
end
function _M.clearJoypad()
for b = 1,#config.ButtonNames do
input.set(0, b - 1, 0)
end
end
function processAreaLoad()
for i=#_M.areaLoadedQueue,1,-1 do
table.remove(_M.areaLoadedQueue, i)()
end
end
memory2.BUS:registerwrite(0xb517b2, processAreaLoad)
return _M

View file

@ -12,7 +12,6 @@ local util = dofile(base.."/util.lua")
loadRequested = false
saveRequested = false
kong = 0
lastBoth = 0
form = nil
netPicture = nil
@ -661,8 +660,6 @@ function on_timer()
if config.StartPowerup ~= NIL then
game.writePowerup(config.StartPowerup)
end
rightmost = 0
upmost = 0
pool.currentFrame = 0
timeout = config.NeatConfig.TimeoutConstant
game.clearJoypad()
@ -672,6 +669,10 @@ function on_timer()
partyHitCounter = 0
powerUpCounter = 0
powerUpBefore = game.getBoth()
currentArea = game.getCurrentArea()
lastArea = currentArea
rightmost = { [currentArea] = 0 }
upmost = { [currentArea] = 0 }
local species = pool.species[pool.currentSpecies]
local genome = species.genomes[pool.currentGenome]
generateNetwork(genome)
@ -803,19 +804,33 @@ function mainLoop (species, genome)
-- Don't punish being launched by barrels
-- FIXME Will this skew mine cart levels?
if game.getVelocityY() < -1850 then
statusLine = string.format("Gotta go fast!!! %d", partyX)
statusColor = 0x0000ff00
timeout = timeoutConst + 60 * 2
end
local nextArea = game.getCurrentArea()
if nextArea ~= lastArea then
lastArea = nextArea
game.onceAreaLoaded(function()
statusLine = string.format("Area changed: %02x", currentArea)
statusColor = 0x00009900
timeout = timeoutConst + 60 * 2
currentArea = nextArea
lastArea = currentArea
if rightmost[currentArea] == nil then
rightmost[currentArea] = 0
upmost[currentArea] = 0
end
end)
end
if not vertical then
if partyX > rightmost then
rightmost = partyX
if partyX > rightmost[currentArea] then
rightmost[currentArea] = partyX
timeout = timeoutConst
end
else
if partyY > upmost then
upmost = partyY
if partyY > upmost[currentArea] then
upmost[currentArea] = partyY
timeout = timeoutConst
end
end
@ -862,9 +877,15 @@ function mainLoop (species, genome)
local most = 0
if not vertical then
most = rightmost - pool.currentFrame / 2
for k,v in pairs(rightmost) do
most = most + v
end
most = most - pool.currentFrame / 2
else
most = upmost - pool.currentFrame / 2
for k,v in pairs(upmost) do
most = most + v
end
most = most - pool.currentFrame / 2
end
@ -877,10 +898,12 @@ function mainLoop (species, genome)
end
-- FIXME sus
--[[
if rightmost > 4816 then
fitness = fitness + 1000
print("!!!!!!Beat level!!!!!!!")
end
-- ]]
if fitness == 0 then
fitness = -1
end
@ -1212,6 +1235,8 @@ function displayForm()
gui.text(130, 80, "Lives: " .. game.getLives())
gui.text(230, 65, "Damage: " .. partyHitCounter)
gui.text(230, 80, "PowerUp: " .. powerUpCounter)
gui.text(320, 65, string.format("Current Area: %04x", currentArea))
gui.text(320, 80, "Rightmost: "..rightmost[currentArea])
gui.rectangle(0, 100, 500, 50, 1, 0x000000000, 0x00990099)
gui.text(5, 129, "..."..config.NeatConfig.SaveFile:sub(#config.NeatConfig.SaveFile - 55))