Rework drawing party Pokémon, clean up paint.lua

This commit is contained in:
Kyle Coburn 2015-04-17 21:13:52 -07:00
parent 38aa916669
commit d4233a7d76
3 changed files with 34 additions and 54 deletions

View File

@ -20,7 +20,7 @@ local function sendButton(button, ab)
local inputTable = {[button] = true}
joypad.set(inputTable)
if debug then
Utils.drawText(0, 7, button.." "..remainingFrames)
Utils.drawText(0, 14, button.." "..remainingFrames)
end
if ab then
button = "A,B"

View File

@ -6,14 +6,16 @@ local Utils = require "util.utils"
local Pokemon = require "storage.pokemon"
local RIGHT_EDGE, BOTTOM_EDGE = 158, 135
local encounters = 0
local elapsedTime = Utils.elapsedTime
local drawText = Utils.drawText
function Paint.draw(currentMap)
local px, py = Player.position()
drawText(0, 14, currentMap..": "..px.." "..py)
drawText(0, 0, elapsedTime())
drawText(0, 7, currentMap..": "..px.." "..py)
if Memory.value("battle", "our_id") > 0 then
local curr_hp = Pokemon.index(0, "hp")
@ -24,68 +26,36 @@ function Paint.draw(currentMap)
hpStatus = "RED"
end
if hpStatus then
drawText(120, 7, hpStatus)
drawText(RIGHT_EDGE, 7, hpStatus, true)
end
end
local xPokemon = 125
local yPokemon = 15
drawText(xPokemon,yPokemon,"Pokemons: ")
local squirtx = Pokemon.indexOf("squirtle")
if squirtx ~= -1 then
drawText(xPokemon,yPokemon +5,"Squirtle")
local caughtPokemon = {
{"squirtle"},
{"nidoran", "nidorino", "nidoking"},
{"spearow", "pidgey"},
{"paras", "oddish", "sandshrew", "charmander"},
}
local partyY = BOTTOM_EDGE
for i,pokemonCategory in ipairs(caughtPokemon) do
local pokemon = Pokemon.inParty(unpack(pokemonCategory))
if pokemon then
drawText(RIGHT_EDGE, partyY, Utils.capitalize(pokemon), true)
partyY = partyY - 7
end
end
local pidgeyx = Pokemon.indexOf("pidgey")
if pidgeyx ~= -1 then
drawText(xPokemon,yPokemon+15,"Pidgey")
end
local spearowx = Pokemon.indexOf("spearow")
if spearowx ~= -1 then
drawText(xPokemon,yPokemon+15,"Spearow")
end
local parasx = Pokemon.indexOf("paras")
if parasx ~= -1 then
drawText(xPokemon,yPokemon+20,"Paras")
end
local oddishx = Pokemon.indexOf("oddish")
if oddishx ~= -1 then
drawText(xPokemon,yPokemon+20,"Oddish")
end
local nidx = Pokemon.indexOf("nidoran", "nidorino", "nidoking")
if nidx ~= -1 then
local att = Pokemon.index(nidx, "attack")
local def = Pokemon.index(nidx, "defense")
local spd = Pokemon.index(nidx, "speed")
local scl = Pokemon.index(nidx, "special")
drawText(60, 0,"Nido stats: "..att.." "..def.." "..spd.." "..scl)
drawText(RIGHT_EDGE, 0, att.." "..def.." "..spd.." "..scl, true)
end
nidx = Pokemon.indexOf("nidoran")
if nidx == -1 then
nidx = Pokemon.indexOf("nidorino")
if nidx == -1 then
nidx = Pokemon.indexOf("nidoking")
if nidx ~= -1 then
drawText(xPokemon,yPokemon+10,"Nidoking")
end
else
drawText(xPokemon,yPokemon+10,"Nidorino")
end
else
drawText(xPokemon,yPokemon+10,"Nidoran")
end
local enc = " encounter"
if encounters ~= 1 then
enc = enc.."s"
end
drawText(0, 116, Memory.value("battle", "critical"))
drawText(0, 125, Memory.value("player", "repel"))
drawText(0, 134, encounters..enc)
drawText(0, BOTTOM_EDGE-7, "Repel: "..Memory.value("player", "repel"))
drawText(0, BOTTOM_EDGE, Utils.pluralize(encounters, "encounter"))
return true
end

View File

@ -94,6 +94,13 @@ function Utils.multiplyString(string, times)
return result
end
function Utils.pluralize(amount, description)
if amount ~= 1 then
description = description.."s"
end
return amount.." "..description
end
-- GAME
function Utils.canPotionWith(potion, forDamage, curr_hp, max_hp)
@ -112,7 +119,10 @@ function Utils.ingame()
return Memory.raw(0x020E) > 0
end
function Utils.drawText(x, y, message)
function Utils.drawText(x, y, message, right)
if right then
x = x - #message * 5
end
gui.text(x * EMP, y * EMP, message)
end