From d4233a7d768d4a7d9976d03d2f358a5d3b77ef99 Mon Sep 17 00:00:00 2001 From: Kyle Coburn Date: Fri, 17 Apr 2015 21:13:52 -0700 Subject: [PATCH] =?UTF-8?q?Rework=20drawing=20party=20Pok=C3=A9mon,=20clea?= =?UTF-8?q?n=20up=20paint.lua?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- util/input.lua | 2 +- util/paint.lua | 74 +++++++++++++++----------------------------------- util/utils.lua | 12 +++++++- 3 files changed, 34 insertions(+), 54 deletions(-) diff --git a/util/input.lua b/util/input.lua index 16661e6..2b6b848 100644 --- a/util/input.lua +++ b/util/input.lua @@ -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" diff --git a/util/paint.lua b/util/paint.lua index a1cd39e..93f23b4 100644 --- a/util/paint.lua +++ b/util/paint.lua @@ -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 diff --git a/util/utils.lua b/util/utils.lua index 46b19d9..9d3785e 100644 --- a/util/utils.lua +++ b/util/utils.lua @@ -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