Correct lives calculation. Add input for pool name
This commit is contained in:
parent
9c0c1014c0
commit
3814061f47
3 changed files with 123 additions and 24 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@ state/
|
||||||
crashsave*
|
crashsave*
|
||||||
*.backup
|
*.backup
|
||||||
*.pool*
|
*.pool*
|
||||||
|
config.lua
|
||||||
|
|
5
game.lua
5
game.lua
|
@ -107,7 +107,7 @@ function _M.getHit(alreadyHit)
|
||||||
end
|
end
|
||||||
|
|
||||||
function _M.getHitTimer(lastBoth)
|
function _M.getHitTimer(lastBoth)
|
||||||
return (memory.readword(DISPLAY_LIVES) - memory.readword(MATH_LIVES))
|
return (memory.readsbyte(DISPLAY_LIVES) - memory.readsbyte(MATH_LIVES))
|
||||||
+ lastBoth - _M.getBoth()
|
+ lastBoth - _M.getBoth()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -217,6 +217,9 @@ end
|
||||||
|
|
||||||
function _M.getJumpHeight()
|
function _M.getJumpHeight()
|
||||||
local sprite = _M.getSprite(leader)
|
local sprite = _M.getSprite(leader)
|
||||||
|
if sprite == nil then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
return sprite.jumpHeight
|
return sprite.jumpHeight
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
135
neat-donk.lua
135
neat-donk.lua
|
@ -728,10 +728,77 @@ function evaluateCurrent()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
inputmode = false
|
||||||
function on_input()
|
function on_input()
|
||||||
|
local sec, usec = utime()
|
||||||
for i=#frameAdvanced,1,-1 do
|
for i=#frameAdvanced,1,-1 do
|
||||||
table.remove(frameAdvanced, i)()
|
table.remove(frameAdvanced, i)()
|
||||||
end
|
end
|
||||||
|
if frame % 60 == 0 then
|
||||||
|
local sec2, usec2 = utime()
|
||||||
|
print(string.format("Frame took %d msec", (sec2 - sec + (usec2 - usec) / 100000) * 1000))
|
||||||
|
end
|
||||||
|
|
||||||
|
local inputs = input.raw()
|
||||||
|
if not inputmode then
|
||||||
|
saveLoadFile = config.NeatConfig.SaveFile
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if helddown == nil then
|
||||||
|
local mapping = {
|
||||||
|
backslash = "\\",
|
||||||
|
colon = ":",
|
||||||
|
comma = ",",
|
||||||
|
exclaim = "!",
|
||||||
|
dollar = "$",
|
||||||
|
hash = "#",
|
||||||
|
caret = "^",
|
||||||
|
ampersand = "&",
|
||||||
|
asterisk = "*",
|
||||||
|
leftparen = "(",
|
||||||
|
rightparen = ")",
|
||||||
|
less = "<",
|
||||||
|
greater = ">",
|
||||||
|
quote = "'",
|
||||||
|
quotedbl = "\"",
|
||||||
|
semicolon = ";",
|
||||||
|
slash = "/",
|
||||||
|
question = "?",
|
||||||
|
leftcurly = "{",
|
||||||
|
leftbracket = "[",
|
||||||
|
rightcurly = "}",
|
||||||
|
rightbracket = "]",
|
||||||
|
pipe = "|",
|
||||||
|
tilde = "~",
|
||||||
|
underscore = "_",
|
||||||
|
at = "@",
|
||||||
|
period = ".",
|
||||||
|
equals = "=",
|
||||||
|
plus = "+",
|
||||||
|
}
|
||||||
|
for k,v in pairs(inputs) do
|
||||||
|
if v["type"] ~= "key" or v["value"] ~= 1 then
|
||||||
|
goto continue
|
||||||
|
end
|
||||||
|
if k == "back" then
|
||||||
|
config.NeatConfig.SaveFile = config.NeatConfig.SaveFile:sub(1, #config.NeatConfig.SaveFile-1)
|
||||||
|
helddown = k
|
||||||
|
goto continue
|
||||||
|
end
|
||||||
|
local m = k
|
||||||
|
if mapping[k] ~= nil then
|
||||||
|
m = mapping[k]
|
||||||
|
end
|
||||||
|
if #m ~= 1 then
|
||||||
|
goto continue
|
||||||
|
end
|
||||||
|
config.NeatConfig.SaveFile = config.NeatConfig.SaveFile..m
|
||||||
|
helddown = k
|
||||||
|
::continue::
|
||||||
|
end
|
||||||
|
elseif helddown ~= nil and inputs[helddown]["value"] ~= 1 then
|
||||||
|
helddown = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function advanceFrame(after)
|
function advanceFrame(after)
|
||||||
|
@ -741,6 +808,10 @@ end
|
||||||
|
|
||||||
function mainLoop (species, genome)
|
function mainLoop (species, genome)
|
||||||
advanceFrame(function()
|
advanceFrame(function()
|
||||||
|
if loadRequested or saveRequested then
|
||||||
|
saveLoadFile = config.NeatConfig.SaveFile
|
||||||
|
end
|
||||||
|
|
||||||
if loadRequested then
|
if loadRequested then
|
||||||
loadRequested = false
|
loadRequested = false
|
||||||
loadPool(mainLoop)
|
loadPool(mainLoop)
|
||||||
|
@ -806,14 +877,14 @@ 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() < -1850 then
|
||||||
timeout = timeoutConst + 60 * 2
|
timeout = timeout + 60 * 12
|
||||||
end
|
end
|
||||||
|
|
||||||
local nextArea = game.getCurrentArea()
|
local nextArea = game.getCurrentArea()
|
||||||
if nextArea ~= lastArea then
|
if nextArea ~= lastArea then
|
||||||
lastArea = nextArea
|
lastArea = nextArea
|
||||||
game.onceAreaLoaded(function()
|
game.onceAreaLoaded(function()
|
||||||
timeout = timeoutConst + 60 * 2
|
timeout = timeout + 60 * 5
|
||||||
currentArea = nextArea
|
currentArea = nextArea
|
||||||
lastArea = currentArea
|
lastArea = currentArea
|
||||||
if rightmost[currentArea] == nil then
|
if rightmost[currentArea] == nil then
|
||||||
|
@ -826,14 +897,18 @@ function mainLoop (species, genome)
|
||||||
if not vertical then
|
if not vertical then
|
||||||
if partyX > rightmost[currentArea] then
|
if partyX > rightmost[currentArea] then
|
||||||
rightmost[currentArea] = partyX
|
rightmost[currentArea] = partyX
|
||||||
|
if timeout < timeoutConst then
|
||||||
timeout = timeoutConst
|
timeout = timeoutConst
|
||||||
end
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
if partyY > upmost[currentArea] then
|
if partyY > upmost[currentArea] then
|
||||||
upmost[currentArea] = partyY
|
upmost[currentArea] = partyY
|
||||||
|
if timeout < timeoutConst then
|
||||||
timeout = timeoutConst
|
timeout = timeoutConst
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
-- FIXME Measure distance to target / area exit
|
-- FIXME Measure distance to target / area exit
|
||||||
-- We might not always be horizontal
|
-- We might not always be horizontal
|
||||||
|
|
||||||
|
@ -853,16 +928,21 @@ function mainLoop (species, genome)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local lives = game.getLives()
|
|
||||||
|
|
||||||
timeout = timeout - 1
|
|
||||||
|
|
||||||
local krem = game.getKremCoins() - startKrem
|
local krem = game.getKremCoins() - startKrem
|
||||||
if krem > lastKrem then
|
if krem > lastKrem then
|
||||||
|
statusLine = string.format("Kremcoin grabbed: %d", timeout)
|
||||||
|
statusColor = 0x00009900
|
||||||
lastKrem = krem
|
lastKrem = krem
|
||||||
timeout = timeoutConst + 60 * 5
|
timeout = timeout + 60 * 10
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local lives = game.getLives()
|
||||||
|
if lives == 0 then
|
||||||
|
timeout = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
timeout = timeout - 1
|
||||||
|
|
||||||
-- Continue if we haven't timed out
|
-- Continue if we haven't timed out
|
||||||
local timeoutBonus = pool.currentFrame / 4
|
local timeoutBonus = pool.currentFrame / 4
|
||||||
if timeout + timeoutBonus > 0 then
|
if timeout + timeoutBonus > 0 then
|
||||||
|
@ -1064,13 +1144,12 @@ else
|
||||||
end
|
end
|
||||||
|
|
||||||
buttons = nil
|
buttons = nil
|
||||||
buttonCtx = gui.renderctx.new(500, 50)
|
buttonCtx = gui.renderctx.new(500, 70)
|
||||||
function displayButtons()
|
function displayButtons()
|
||||||
buttonCtx:set()
|
buttonCtx:set()
|
||||||
buttonCtx:clear()
|
buttonCtx:clear()
|
||||||
|
|
||||||
gui.rectangle(0, 0, 500, 50, 1, 0x000000000, 0x00990099)
|
gui.rectangle(0, 0, 500, 70, 1, 0x000000000, 0x00990099)
|
||||||
gui.text(5, 29, "..."..config.NeatConfig.SaveFile:sub(#config.NeatConfig.SaveFile - 55))
|
|
||||||
local startStop = ""
|
local startStop = ""
|
||||||
if config.Running then
|
if config.Running then
|
||||||
startStop = "Stop"
|
startStop = "Stop"
|
||||||
|
@ -1087,6 +1166,17 @@ function displayButtons()
|
||||||
gui.text(320, 2, "[8] Load")
|
gui.text(320, 2, "[8] Load")
|
||||||
gui.text(400, 2, "[9] Restart")
|
gui.text(400, 2, "[9] Restart")
|
||||||
|
|
||||||
|
local insert = ""
|
||||||
|
local confirm = "[Tab] Type in filename"
|
||||||
|
if inputmode then
|
||||||
|
insert = "_"
|
||||||
|
confirm = "[Tab] Confirm filename"
|
||||||
|
end
|
||||||
|
|
||||||
|
gui.text(5, 29, "..."..config.NeatConfig.SaveFile:sub(-55)..insert)
|
||||||
|
|
||||||
|
gui.text(5, 50, confirm)
|
||||||
|
|
||||||
buttons = buttonCtx:render()
|
buttons = buttonCtx:render()
|
||||||
gui.renderctx.setnull()
|
gui.renderctx.setnull()
|
||||||
end
|
end
|
||||||
|
@ -1311,27 +1401,32 @@ function on_paint()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
helddown = false
|
helddown = nil
|
||||||
function on_keyhook (key, state)
|
function on_keyhook (key, state)
|
||||||
if not helddown and state.value == 1 then
|
if state.value == 1 then
|
||||||
if key == "1" then
|
if key == "tab" then
|
||||||
helddown = true
|
inputmode = not inputmode
|
||||||
|
helddown = key
|
||||||
|
elseif inputmode then
|
||||||
|
return
|
||||||
|
elseif key == "1" then
|
||||||
|
helddown = key
|
||||||
config.Running = not config.Running
|
config.Running = not config.Running
|
||||||
elseif key == "4" then
|
elseif key == "4" then
|
||||||
helddown = true
|
helddown = key
|
||||||
playTop()
|
playTop()
|
||||||
elseif key == "6" then
|
elseif key == "6" then
|
||||||
helddown = true
|
helddown = key
|
||||||
saveRequested = true
|
saveRequested = true
|
||||||
elseif key == "8" then
|
elseif key == "8" then
|
||||||
helddown = true
|
helddown = key
|
||||||
loadRequested = true
|
loadRequested = true
|
||||||
elseif key == "9" then
|
elseif key == "9" then
|
||||||
helddown = true
|
helddown = key
|
||||||
initializePool()
|
initializePool()
|
||||||
end
|
end
|
||||||
elseif state.value == 0 then
|
elseif state.value == 0 then
|
||||||
helddown = false
|
helddown = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1340,4 +1435,4 @@ input.keyhook("4", true)
|
||||||
input.keyhook("6", true)
|
input.keyhook("6", true)
|
||||||
input.keyhook("8", true)
|
input.keyhook("8", true)
|
||||||
input.keyhook("9", true)
|
input.keyhook("9", true)
|
||||||
|
input.keyhook("tab", true)
|
||||||
|
|
Loading…
Add table
Reference in a new issue