Fix bump logic
This commit is contained in:
parent
566fc0a2d5
commit
330cf035fa
4 changed files with 70 additions and 23 deletions
|
@ -47,5 +47,6 @@ If you want a better idea of what's going on with the tile and sprite calculatio
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
* Incur penalty for non-hazardous enemy collisions to encourage neutralizing Klobber
|
[x] Incur penalty for non-hazardous enemy collisions to encourage neutralizing Klobber
|
||||||
* Make enemies neutral when held? (Klobber, Click-Clack, etc.)
|
[ ] Make enemies neutral when held? (Klobber, Click-Clack, etc.)
|
||||||
|
[ ] Multiple nets to handle different contexts s/a clicking map items
|
||||||
|
|
77
game.lua
77
game.lua
|
@ -10,25 +10,27 @@ local _M = {}
|
||||||
spritelist.InitSpriteList()
|
spritelist.InitSpriteList()
|
||||||
spritelist.InitExtSpriteList()
|
spritelist.InitExtSpriteList()
|
||||||
|
|
||||||
KREMCOINS = 0x7e08cc
|
local KREMCOINS = 0x7e08cc
|
||||||
TILE_SIZE = 32
|
local TILE_SIZE = 32
|
||||||
ENEMY_SIZE = 64
|
local ENEMY_SIZE = 64
|
||||||
TILE_COLLISION_MATH_POINTER = 0x7e17b2
|
local TILE_COLLISION_MATH_POINTER = 0x7e17b2
|
||||||
SPRITE_BASE = 0x7e0de2
|
local SPRITE_BASE = 0x7e0de2
|
||||||
VERTICAL_POINTER = 0xc414
|
local SPRITE_SIZE = 94
|
||||||
TILEDATA_POINTER = 0x7e0098
|
local SPRITE_DYING = 0x1000
|
||||||
HAVE_BOTH = 0x7e08c2
|
local VERTICAL_POINTER = 0xc414
|
||||||
CAMERA_X = 0x7e17ba
|
local TILEDATA_POINTER = 0x7e0098
|
||||||
CAMERA_Y = 0x7e17c0
|
local HAVE_BOTH = 0x7e08c2
|
||||||
LEAD_CHAR = 0x7e08a4
|
local CAMERA_X = 0x7e17ba
|
||||||
PARTY_X = 0x7e0a2a
|
local CAMERA_Y = 0x7e17c0
|
||||||
PARTY_Y = 0x7e0a2c
|
local LEAD_CHAR = 0x7e08a4
|
||||||
SOLID_LESS_THAN = 0x7e00a0
|
local PARTY_X = 0x7e0a2a
|
||||||
KONG_LETTERS = 0x7e0902
|
local PARTY_Y = 0x7e0a2c
|
||||||
MATH_LIVES = 0x7e08be
|
local SOLID_LESS_THAN = 0x7e00a0
|
||||||
DISPLAY_LIVES = 0x7e0c0
|
local KONG_LETTERS = 0x7e0902
|
||||||
MAIN_AREA_NUMBER = 0x7e08a8
|
local MATH_LIVES = 0x7e08be
|
||||||
CURRENT_AREA_NUMBER = 0x7e08c8
|
local DISPLAY_LIVES = 0x7e0c0
|
||||||
|
local MAIN_AREA_NUMBER = 0x7e08a8
|
||||||
|
local CURRENT_AREA_NUMBER = 0x7e08c8
|
||||||
|
|
||||||
function _M.getPositions()
|
function _M.getPositions()
|
||||||
leader = memory.readword(LEAD_CHAR)
|
leader = memory.readword(LEAD_CHAR)
|
||||||
|
@ -241,7 +243,7 @@ function _M.getJumpHeight()
|
||||||
end
|
end
|
||||||
|
|
||||||
function _M.getSprite(idx)
|
function _M.getSprite(idx)
|
||||||
local base_addr = idx * 94 + SPRITE_BASE
|
local base_addr = idx * SPRITE_SIZE + SPRITE_BASE
|
||||||
|
|
||||||
local control = memory.readword(base_addr)
|
local control = memory.readword(base_addr)
|
||||||
|
|
||||||
|
@ -256,6 +258,10 @@ function _M.getSprite(idx)
|
||||||
screenX = x - 256 - cameraX - 256,
|
screenX = x - 256 - cameraX - 256,
|
||||||
screenY = y - 256 - cameraY - 256,
|
screenY = y - 256 - cameraY - 256,
|
||||||
jumpHeight = memory.readword(base_addr + 0x0e),
|
jumpHeight = memory.readword(base_addr + 0x0e),
|
||||||
|
-- style bits
|
||||||
|
-- 0x4000 0: Right facing 1: Flipped
|
||||||
|
-- 0x1000 0: Alive 1: Dying
|
||||||
|
style = memory.readword(base_addr + 0x12),
|
||||||
velocityX = memory.readsword(base_addr + 0x20),
|
velocityX = memory.readsword(base_addr + 0x20),
|
||||||
velocityY = memory.readsword(base_addr + 0x24),
|
velocityY = memory.readsword(base_addr + 0x24),
|
||||||
x = x,
|
x = x,
|
||||||
|
@ -408,6 +414,34 @@ function _M.onceMapLoaded(handler)
|
||||||
table.insert(mapLoadedQueue, handler)
|
table.insert(mapLoadedQueue, handler)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local emptyHitQueue = {}
|
||||||
|
function _M.onEmptyHit(handler)
|
||||||
|
emptyHitQueue = {}
|
||||||
|
table.insert(emptyHitQueue, handler)
|
||||||
|
end
|
||||||
|
|
||||||
|
function processEmptyHit(addr, val)
|
||||||
|
local idx = math.floor((bit.band(addr, 0xffff) - bit.band(SPRITE_BASE, 0xffff)) / SPRITE_SIZE)
|
||||||
|
local pow = _M.getSprite(idx)
|
||||||
|
if pow == nil or
|
||||||
|
pow.control ~= 0x0238 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local sprites = _M.getSprites()
|
||||||
|
for i=1,#sprites,1 do
|
||||||
|
local sprite = sprites[i]
|
||||||
|
if bit.band(sprite.style, SPRITE_DYING) ~= 0 and
|
||||||
|
sprite.good == -1 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for i=#emptyHitQueue,1,-1 do
|
||||||
|
emptyHitQueue[i]()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function processAreaLoad()
|
function processAreaLoad()
|
||||||
for i=#areaLoadedQueue,1,-1 do
|
for i=#areaLoadedQueue,1,-1 do
|
||||||
table.remove(areaLoadedQueue, i)()
|
table.remove(areaLoadedQueue, i)()
|
||||||
|
@ -423,6 +457,9 @@ end
|
||||||
function _M.registerHandlers()
|
function _M.registerHandlers()
|
||||||
memory2.BUS:registerwrite(0xb517b2, processAreaLoad)
|
memory2.BUS:registerwrite(0xb517b2, processAreaLoad)
|
||||||
memory2.WRAM:registerread(0x06b1, processMapLoad)
|
memory2.WRAM:registerread(0x06b1, processMapLoad)
|
||||||
|
for i=2,22,1 do
|
||||||
|
memory2.WRAM:registerwrite(bit.band(SPRITE_BASE + SPRITE_SIZE * i, 0xffff), processEmptyHit)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
|
|
@ -19,6 +19,7 @@ netPicture = nil
|
||||||
runInitialized = {}
|
runInitialized = {}
|
||||||
frameAdvanced = {}
|
frameAdvanced = {}
|
||||||
timeout = 0
|
timeout = 0
|
||||||
|
bumps = 0
|
||||||
|
|
||||||
saveLoadFile = config.NeatConfig.SaveFile
|
saveLoadFile = config.NeatConfig.SaveFile
|
||||||
statusLine = nil
|
statusLine = nil
|
||||||
|
@ -666,6 +667,11 @@ function on_timer()
|
||||||
game.onceMapLoaded(function()
|
game.onceMapLoaded(function()
|
||||||
timeout = -100000
|
timeout = -100000
|
||||||
end)
|
end)
|
||||||
|
bumps = 0
|
||||||
|
-- Penalize player for collisions that do not result in enemy deaths
|
||||||
|
game.onEmptyHit(function()
|
||||||
|
bumps = bumps + 1
|
||||||
|
end)
|
||||||
game.clearJoypad()
|
game.clearJoypad()
|
||||||
startKong = game.getKong()
|
startKong = game.getKong()
|
||||||
startBananas = game.getBananas()
|
startBananas = game.getBananas()
|
||||||
|
@ -970,6 +976,7 @@ function mainLoop (species, genome)
|
||||||
end
|
end
|
||||||
|
|
||||||
local hitPenalty = partyHitCounter * 100
|
local hitPenalty = partyHitCounter * 100
|
||||||
|
local bumpPenalty = bumps * 100
|
||||||
local powerUpBonus = powerUpCounter * 100
|
local powerUpBonus = powerUpCounter * 100
|
||||||
|
|
||||||
local most = 0
|
local most = 0
|
||||||
|
@ -985,7 +992,7 @@ function mainLoop (species, genome)
|
||||||
most = most - pool.currentFrame / 2
|
most = most - pool.currentFrame / 2
|
||||||
end
|
end
|
||||||
|
|
||||||
local fitness = bananaCoinsFitness - hitPenalty + powerUpBonus + most + game.getJumpHeight() / 100
|
local fitness = bananaCoinsFitness - bumpPenalty - hitPenalty + powerUpBonus + most + game.getJumpHeight() / 100
|
||||||
|
|
||||||
local lives = game.getLives()
|
local lives = game.getLives()
|
||||||
|
|
||||||
|
@ -1364,6 +1371,7 @@ function displayForm()
|
||||||
gui.text(5, 95, "Krem: " .. (game.getKremCoins() - startKrem))
|
gui.text(5, 95, "Krem: " .. (game.getKremCoins() - startKrem))
|
||||||
gui.text(130, 65, "Coins: " .. (game.getCoins() - startCoins))
|
gui.text(130, 65, "Coins: " .. (game.getCoins() - startCoins))
|
||||||
gui.text(130, 80, "Lives: " .. game.getLives())
|
gui.text(130, 80, "Lives: " .. game.getLives())
|
||||||
|
gui.text(130, 95, "Bumps: " .. bumps)
|
||||||
gui.text(230, 65, "Damage: " .. partyHitCounter)
|
gui.text(230, 65, "Damage: " .. partyHitCounter)
|
||||||
gui.text(230, 80, "PowerUp: " .. powerUpCounter)
|
gui.text(230, 80, "PowerUp: " .. powerUpCounter)
|
||||||
gui.text(320, 65, string.format("Current Area: %04x", currentArea))
|
gui.text(320, 65, string.format("Current Area: %04x", currentArea))
|
||||||
|
|
|
@ -5,6 +5,7 @@ _M.Sprites = {}
|
||||||
-- Make sure this list is sorted before initialization.
|
-- Make sure this list is sorted before initialization.
|
||||||
_M.NeutralSprites = {
|
_M.NeutralSprites = {
|
||||||
0x0020, -- Krow egg fragments
|
0x0020, -- Krow egg fragments
|
||||||
|
0x0060, -- Barrel fragments
|
||||||
0x0064, -- Barrel fragments
|
0x0064, -- Barrel fragments
|
||||||
|
|
||||||
-- Our heroes
|
-- Our heroes
|
||||||
|
|
Loading…
Add table
Reference in a new issue