From 97fee28208e405f4f1f4e5a51cc82d299b23ed36 Mon Sep 17 00:00:00 2001 From: KevinW1998 Date: Sat, 14 Nov 2015 07:44:01 +0100 Subject: [PATCH] Update submodules --- LuaScriptsLibExt/apc.lua | 107 ++++++++++++++++++ LuaScriptsLibExt/hudoftime.lua | 23 ++-- LuaScriptsLibExt/inputs.lua | 179 +++++++++++++++++++++++++++++++ LuaScriptsLibExt/multipoints.lua | 7 +- LuaScriptsLibExt/npcconfig.lua | 138 ++++++++++++++++++++++++ LuaScriptsLibExt/raocoin2.lua | 96 ++++++++++++----- 6 files changed, 506 insertions(+), 44 deletions(-) create mode 100644 LuaScriptsLibExt/apc.lua create mode 100644 LuaScriptsLibExt/inputs.lua create mode 100644 LuaScriptsLibExt/npcconfig.lua diff --git a/LuaScriptsLibExt/apc.lua b/LuaScriptsLibExt/apc.lua new file mode 100644 index 000000000..d8c439c60 --- /dev/null +++ b/LuaScriptsLibExt/apc.lua @@ -0,0 +1,107 @@ +--Advanced Player Collisions API (WIP - Not reccomended for personal use) +--Created by Sambo +--Requires Colliders and Vectors libraries + +--API values +local apc = {} +colliders = loadSharedAPI("colliders") +local r = 0 +local ropeCheck = 0 +local ropeBox = {} + +function apc.onInitAPI() + registerEvent(apc, "onLoop") +end + +function apc.onLoop() + --Player 1 + local p1hitbox = colliders.getAABB(player) --Load P1's hitbox + --Create a 8 px thick collision sensor on each side of the player + p1colliders = { + top = colliders.Box(player.x, player.y - 8, p1hitbox.width, 8), + left = colliders.Box(player.x - 8, player.y, 8, p1hitbox.height), + right = colliders.Box(player.x + p1hitbox.width, player.y, 8, p1hitbox.height), + bottom = colliders.Box(player.x, player.y + p1hitbox.height, p1hitbox.width, 8), + } + if apc.debug then + p1colliders["top"]:Draw(0xff000099) + p1colliders["left"]:Draw(0x00ff0099) + p1colliders["right"]:Draw(0x0000ff99) + p1colliders["bottom"]:Draw(0xffff0099) + end + if ropeBlocks then + for k,v in pairs(ropeBlocks) do + for a,b in pairs(Block.get(v)) do + if (b:collidesWith(player) == 1) and (player.downKeyPressing) then + player.y = player.y + 2 --Move the player down 2 pixels. This effectively causes the player to "fall through" a cloud block, but is too small to glitch solid blocks. :) + end + end + end + end + if bouncySpikes then + for k,v in pairs(bouncySpikes) do + for a,b in pairs(Block.get(v)) do + if (b:collidesWith(player) == 1) then + if player:mem(0x50, FIELD_WORD) == -1 then + colliders.bounceResponse(player) + else + player:harm() + end + end + end + end + end +--Player 2 (if there is one) + if player2 then + local p2hitbox = colliders.getAABB(player2) --Load P2's hitbox + --Create a 8 px thick collision sensor on each side of player2 + p2colliders = { + top = colliders.Box(player2.x, player2.y - 8, p2hitbox.width, 8), + left = colliders.Box(player2.x - 8, player2.y, 8, p2hitbox.height), + right = colliders.Box(player2.x + p2hitbox.width, player2.y, 8, p2hitbox.height), + bottom = colliders.Box(player2.x, player2.y + p2hitbox.height, p2hitbox.width, 8), + } + if apc.debug then + p2colliders["top"]:Draw(0xff000099) + p2colliders["left"]:Draw(0x00ff0099) + p2colliders["right"]:Draw(0x0000ff99) + p2colliders["bottom"]:Draw(0xffff0099) + end + if ropeBlocks then + for k,v in pairs(ropeBlocks) do + for a,b in pairs(Block.get(v)) do + if (b:collidesWith(player2) == 1) and (player2.downKeyPressing) then + player2.y = player2.y + 2 --Move the player2 down 2 pixels. This effectively causes the player2 to "fall through" a cloud block, but is too small to glitch solid blocks. :) + end + end + end + end + if bouncySpikes then + for k,v in pairs(bouncySpikes) do + for a,b in pairs(Block.get(v)) do + if (b:collidesWith(player2) == 1) then + if player2:mem(0x50, FIELD_WORD) == -1 then + colliders.bounceResponse(player2) + else + player2:harm() + end + end + end + end + end + end +end + +--This function makes a block behave like a "rope-type" block. If you play SMW hacks, you may have seen these. A "rope-type" block behaves like a cloud block, but you can go through it if you press DOWN. This only works if used on a cloud-type block. +function apc.rope(ids) --Argument must be a table of integers between 1 and 638 + ropeBlocks = ids +end + +--This function makes a block act like an upward pointing spike block, but spinjumping on it will bounce +--the player instead of harming him. The block must NOT already harm the player, or it won't work. +--It is not reccomended to place this block on a moving layer, as it may not work correctly. +function apc.bouncySpike(ids) --Argument must be a table of integers between 1 and 638 + bouncySpikes = ids +end + +return apc \ No newline at end of file diff --git a/LuaScriptsLibExt/hudoftime.lua b/LuaScriptsLibExt/hudoftime.lua index 84f318a4f..d5e147236 100644 --- a/LuaScriptsLibExt/hudoftime.lua +++ b/LuaScriptsLibExt/hudoftime.lua @@ -10,7 +10,7 @@ --------------------------------Created by Hoeloe - 2015-------------------------------- ----------------------------Open-Source Zelda HUD Framework----------------------------- ---------------------------------For Super Mario Bros X--------------------------------- -----------------------------------------v1.0.1------------------------------------------ +----------------------------------------v1.0.2------------------------------------------ local zelda = {} @@ -31,7 +31,7 @@ zelda.TRIFORCE = Graphics.loadImage(getSMBXPath().."\\LuaScriptsLib\\hudoftime\\ zelda.FAIRY = Graphics.loadImage(getSMBXPath().."\\LuaScriptsLib\\hudoftime\\lives.png"); zelda.hearts = 0; -zelda.maxhearts = 3; +zelda.maxhearts = 6; zelda.magic = 1; @@ -68,9 +68,6 @@ zelda.auto_navi = true; --Automatically enables and disables the HUD based on whether the player is Link. zelda.auto_enable = true; ---Keep powerups when hurt and have more than one heart. -zelda.keep_powerups = true; - --HUD show flags. zelda.show_hearts = true; zelda.show_magic = true; @@ -171,11 +168,7 @@ local function UpdateHearts() end if (player.powerup == PLAYER_SMALL) and (zelda.hearts >= 2) then - if(zelda.keep_powerups) then - player.powerup = powercache; - else - player.powerup = PLAYER_BIG; - end + player.powerup = powercache; end end end @@ -314,7 +307,15 @@ local function DrawMagic(y) pts[8] = 16+158*zelda.magic; pts[9] = y; pts[10] = 16+158*zelda.magic; pts[11] = y+16; - Graphics.glDrawTriangles(pts, {0,0,0,1,1,0,1,0,0,1,1,1}, 6); + local tx = {}; + tx[0] = 0; tx[1] = 0; + tx[2] = 1; tx[3] = 0; + tx[4] = 0; tx[5] = 1; + tx[6] = 0; tx[7] = 1; + tx[8] = 1; tx[9] = 0; + tx[10] = 1; tx[11] = 1; + + Graphics.glDrawTriangles(pts, tx, 6); Graphics.glSetTextureRGBA(nil, 0xFFFFFFFF); end diff --git a/LuaScriptsLibExt/inputs.lua b/LuaScriptsLibExt/inputs.lua new file mode 100644 index 000000000..d6798e775 --- /dev/null +++ b/LuaScriptsLibExt/inputs.lua @@ -0,0 +1,179 @@ +--*************************************************************************************** +-- * +-- inputs.lua * +-- v1.1 * +-- * +--*************************************************************************************** + + +--[[ + Vars: + inputs.locked[keystr] -- if true, SMBX does not process this input, but the state + is still recorded by this library. + + inputs.state[keystr] -- the current state of that key (read-only) + + keystrings are same as the respective fields, all lowercase + (I.E. player.leftKeyPressing --> "left", player.dropItemKeyPressing --> "dropItem") + + state constants are inputs.UP + inputs.PRESS + inputs.HOLD + inputs.RELEASE +--]] + + + +local inputs = {} --Package table + + function inputs.onInitAPI() + registerEvent(inputs, "onLoop", "onLoop", true) + registerEvent(inputs, "onInputUpdate", "onInputUpdate", true) + end + + + + --*********************************************************************************** + -- * + -- State constants * + -- * + --*********************************************************************************** + + do + inputs.UP = 0 + inputs.PRESS = 1 + inputs.HOLD = 2 + inputs.RELEASE = 3 + end + + + + --*********************************************************************************** + -- * + -- State table * + -- * + --*********************************************************************************** + + do + inputs.state = {} + inputs.state["up"] = inputs.UP + inputs.state["down"] = inputs.UP + inputs.state["left"] = inputs.UP + inputs.state["right"] = inputs.UP + inputs.state["jump"] = inputs.UP + inputs.state["altjump"] = inputs.UP + inputs.state["run"] = inputs.UP + inputs.state["altrun"] = inputs.UP + inputs.state["dropitem"] = inputs.UP + inputs.state["pause"] = inputs.UP + end + + + + --*********************************************************************************** + -- * + -- Lock table * + -- * + --*********************************************************************************** + + do + inputs.locked = {} + inputs.locked["up"] = false + inputs.locked["down"] = false + inputs.locked["left"] = false + inputs.locked["right"] = false + inputs.locked["jump"] = false + inputs.locked["altjump"] = false + inputs.locked["run"] = false + inputs.locked["altrun"] = false + inputs.locked["dropitem"] = false + inputs.locked["pause"] = false + end + + + inputs.key = {} + + + inputs.debug = false + + + --*********************************************************************************** + -- * + -- Update input * + -- * + --*********************************************************************************** + + + function inputs.onLoop () + i = 0 + + for k,v in pairs(inputs.state) do + + -- Debug + if inputs.debug == true then + local debugStr = tostring(k)..": "..tostring(inputs.state[k]) + + if inputs.locked[k] == true then + debugStr = debugStr.." (L)" + end + + Text.print (debugStr, 20, 80 + 20*i) + end + i = i+1 + end + end + + + + function inputs.onInputUpdate () + inputs.key["up"] = player.upKeyPressing + inputs.key["down"] = player.downKeyPressing + inputs.key["left"] = player.leftKeyPressing + inputs.key["right"] = player.rightKeyPressing + inputs.key["jump"] = player.jumpKeyPressing + inputs.key["altjump"] = player.altJumpKeyPressing + inputs.key["run"] = player.runKeyPressing + inputs.key["altrun"] = player.altRunKeyPressing + inputs.key["dropitem"] = player.dropItemKeyPressing + inputs.key["pause"] = player.pauseKeyPressing + + + -- STORE INPUT STATE FOR EACH KEY + local i = 0 + + for k,v in pairs(inputs.state) do + if inputs.state[k] == inputs.UP then + if inputs.key[k] == true then + inputs.state[k] = inputs.PRESS + end + + elseif inputs.state[k] == inputs.PRESS then + inputs.state[k] = inputs.HOLD + + elseif inputs.state[k] == inputs.HOLD then + if inputs.key[k] == false then + inputs.state[k] = inputs.RELEASE + end + + elseif inputs.state[k] == inputs.RELEASE then + inputs.state[k] = inputs.UP + + end + end + + + -- Disable locked keys + if inputs.locked["up"] == true then player.upKeyPressing = false; end + if inputs.locked["down"] == true then player.downKeyPressing = false; end + if inputs.locked["left"] == true then player.leftKeyPressing = false; end + if inputs.locked["right"] == true then player.rightKeyPressing = false; end + if inputs.locked["jump"] == true then player.jumpKeyPressing = false; end + if inputs.locked["altjump"] == true then player.altJumpKeyPressing = false; end + if inputs.locked["run"] == true then player.runKeyPressing = false; end + if inputs.locked["altrun"] == true then player.altRunKeyPressing = false; end + if inputs.locked["dropitem"] == true then player.dropItemKeyPressing = false; end + if inputs.locked["pause"] == true then player.pauseKeyPressing = false; end + + end + +return inputs \ No newline at end of file diff --git a/LuaScriptsLibExt/multipoints.lua b/LuaScriptsLibExt/multipoints.lua index af92f26e4..7c1643dae 100644 --- a/LuaScriptsLibExt/multipoints.lua +++ b/LuaScriptsLibExt/multipoints.lua @@ -13,7 +13,7 @@ -----------With help from Rednaxella----------- --------Open-Source Checkpoint Library--------- ------------For Super Mario Bros X------------- --------------------v3.0.4---------------------- +-------------------v3.0.6---------------------- local multipoints = {} local playerMP = { sec = 0, x = 0, y = 0, act = nil } @@ -75,7 +75,7 @@ local function getMP(i) if(player:mem(0x112,FIELD_WORD) < p and player:mem(0x122,FIELD_WORD) ~= 1 and player:mem(0x122,FIELD_WORD) ~= 2) then player:mem(0x112,FIELD_WORD, p); end - if(player2:mem(0x112,FIELD_WORD) < p and player2:mem(0x122,FIELD_WORD) ~= 1 and player2:mem(0x122,FIELD_WORD) ~= 2) then + if(player2 ~= nil and player2:mem(0x112,FIELD_WORD) < p and player2:mem(0x122,FIELD_WORD) ~= 1 and player2:mem(0x122,FIELD_WORD) ~= 2) then player2:mem(0x112,FIELD_WORD, p); end elseif(plyr:mem(0x112,FIELD_WORD) < p and plyr:mem(0x122,FIELD_WORD) ~= 1 and plyr:mem(0x122,FIELD_WORD) ~= 2) then @@ -312,8 +312,7 @@ function multipoints.update() for k,v in pairs(mpLuaTrigs) do if(not v.spawnAt and not multipoints.getCheckpointStatus(k) and v.obj.visible) then - - Graphics.placeSprite(2,multipoints.IMG,v.x,v.y,"",2); + Graphics.drawImageToScene(multipoints.IMG,v.x,v.y); if(player.x < v.x+multipoints.IMG_SIZE.width and player.x+player:mem(0xD8, FIELD_DFLOAT) > v.x and player.y < v.y+multipoints.IMG_SIZE.height and player.y + player:mem(0xD0, FIELD_DFLOAT) > v.y)then v.func(player); end diff --git a/LuaScriptsLibExt/npcconfig.lua b/LuaScriptsLibExt/npcconfig.lua new file mode 100644 index 000000000..7699a41ea --- /dev/null +++ b/LuaScriptsLibExt/npcconfig.lua @@ -0,0 +1,138 @@ +--npcconfig.lua +--v0.0.1a +--Created by Hoeloe, 2015 +local npcconfig = {} + +local npcmt = {} + +local ptrs = { + gfxoffsetx = 0x00B25B70, + gfxoffsety = 0x00B25B8C, + width = 0x00B25BA8, + height = 0x00B25BC4, + gfxwidth = 0x00B25BE0, + gfxheight = 0x00B25BFC, + speed = 0x00B25C18, + isshell = 0x00B25C34, + blocknpc = 0x00B25C50, + blocknpctop = 0x00B25C6C, + isinteractable = 0x00B25C88, + iscoin = 0x00B25CA4, + isvine = 0x00B25CC0, + iscollectablegoal = 0x00B25CDC, + isflying = 0x00B25CF8, + iswaternpc = 0x00B25D14, + jumphurt = 0x00B25D30, + noblockcollision = 0x00B25D4C, + score = 0x00B25D68, + blockplayertop = 0x00B25D84, + grabtop = 0x00B25DA0, + cliffturn = 0x00B25DBC, + nohurt = 0x00B25DD8, + blockplayer = 0x00B25DF4, + grabside = 0x00B25E2C, + isshoe = 0x00B25E48, + isyoshi = 0x00B25E64, + noyoshi = 0x00B25E9C, + foreground = 0x00B25EB8, + isbot = 0x00B25ED4, + isvegetable = 0x00B25F0C, + nofireball = 0x00B25F28, + noiceball = 0x00B25F44, + nogravity = 0x00B25F60, + frames = 0x00B25F7C, + framespeed = 0x00B25F98, + framestyle = 0x00B25FB4, + + --Default values + def_gfxoffsetx = 0x00B25FC0, + def_gfxoffsety = 0x00B2621A, + def_width = 0x00B26474, + def_height = 0x00B266CE, + def_gfxwidth = 0x00B26928, + def_gfxheight = 0x00B26B82, + def_speed = 0x00B2AD5C, + def_isshell = 0x00B26DDC, + def_blocknpc = 0x00B27036, + def_blocknpctop = 0x00B27290, + def_isinteractable = 0x00B274EA, + def_iscoin = 0x00B27744, + def_isvine = 0x00B2799E, + def_iscollectablegoal = 0x00B27BF8, + def_isflying = 0x00B27E52, + def_iswaternpc = 0x00B280AC, + def_jumphurt = 0x00B28306, + def_noblockcollision = 0x00B28560, + def_score = 0x00B287BA, + def_blockplayertop = 0x00B28A14, + def_grabtop = 0x00B28C6E, + def_cliffturn = 0x00B28EC8, + def_nohurt = 0x00B29122, + def_blockplayer = 0x00B2937C, + def_grabside = 0x00B29830, + def_isshoe = 0x00B29A8A, + def_isyoshi = 0x00B29CE4, + def_noyoshi = 0x00B2A198, + def_foreground = 0x00B2A3F2, + def_isbot = 0x00B2A64C, + def_isvegetable = 0x00B2AB00, + def_nofireball = 0x00B2B210, + def_noiceball = 0x00B2B46A, + def_nogravity = 0x00B2B6C4 + } + +local function getBytes(field) + if(field == FIELD_WORD) then return 2; + elseif(field == FIELD_DWORD) then return 4; + elseif(field == FIELD_BYTE) then return 1; + elseif(field == FIELD_FLOAT) then return 4; + elseif(field == FIELD_DFLOAT) then return 8; + elseif(field == FIELD_STRING) then return 4; + else + error("ERROR: Unknown data type when accessing NPC config.", 2); + end +end + +local function getDataType(key) + if(key == "speed" or key == "def_speed") then + return FIELD_FLOAT + else + return FIELD_WORD + end; +end + +npcmt = { + __newindex = function (tbl, key, value) + if(ptrs[key] ~= nil) then + local ptr = mem(ptrs[key], FIELD_DWORD); + local dat = getDataType(key); + mem(ptr + getBytes(dat)*(tbl.id),dat, value); + end + end, + __index = function (tbl, key) + if(ptrs[key] ~= nil) then + local ptr = mem(ptrs[key], FIELD_DWORD); + local dat = getDataType(key); + return mem(ptr + getBytes(dat)*(tbl.id),dat); + else + return nil; + end + end +} + +setmetatable(npcconfig, { + __newindex = function (tbl, key, value) + error("Cannot assign directly to NPC config. Try assigning to a field instead.", 2) + end, + __index = function (tbl, key) + if(type(key) == "number" and key >= 1 and key <= 292) then + local val = { id = key }; + setmetatable(val, npcmt); + return val; + else + return nil; + end + end +}) + +return npcconfig; \ No newline at end of file diff --git a/LuaScriptsLibExt/raocoin2.lua b/LuaScriptsLibExt/raocoin2.lua index 83bf13fa5..70177f859 100644 --- a/LuaScriptsLibExt/raocoin2.lua +++ b/LuaScriptsLibExt/raocoin2.lua @@ -34,7 +34,7 @@ --------------------Created by Hoeloe - 2015------------------- -------------Open-Source Currency and Shop Library------------- ---------------------For Super Mario Bros X-------------------- -----------------------------v2.0.0----------------------------- +----------------------------v2.0.5----------------------------- ----------------------REQUIRES ENCRYPT.dll--------------------- ---------------------REQUIRES COLLIDERS.lua-------------------- -----------------------REQUIRES PNPC.lua----------------------- @@ -103,13 +103,14 @@ function currencyMT:set(value) --self:save(); end -function raocoin.registerCurrency(npcID, showUI, UIx, UIy, imgPath) +function raocoin.registerCurrency(npcID, showUI, UIx, UIy, imgPath, ignoreHud) showUI = showUI or (showUI == nil and false); UIx = UIx or 0; UIy = UIy or 0; imgPath = imgPath or getSMBXPath().."\\LuaScriptsLib\\raocoin\\dragoncoin.png"; + ignoreHud = ignoreHud or (ignoreHud == nil and false); - local c = { visible = showUI, img = Graphics.loadImage(imgPath), x = UIx, y = UIy, path = imgPath }; + local c = { visible = showUI, ignoreHud = ignoreHud, img = Graphics.loadImage(imgPath), x = UIx, y = UIy, path = imgPath, onCollect = function(currency) end }; setmetatable(c,currencyMT.createMT(npcID,-1)); c:refreshUI(); @@ -126,14 +127,15 @@ function raocoin.registerCurrency(npcID, showUI, UIx, UIy, imgPath) end -function raocoin.registerMemCurrency(memaddress, memType, restore, showUI, UIx, UIy, imgPath) +function raocoin.registerMemCurrency(memaddress, memType, restore, showUI, UIx, UIy, imgPath, ignoreHud) restore = restore or (restore == nil and true); showUI = showUI or (showUI == nil and false); UIx = UIx or 0; UIy = UIy or 0; imgPath = imgPath or getSMBXPath().."\\LuaScriptsLib\\raocoin\\dragoncoin.png"; + ignoreHud = ignoreHud or (ignoreHud == nil and false); - local c = { visible = showUI, img = Graphics.loadImage(imgPath), x = UIx, y = UIy, path = imgPath }; + local c = { visible = showUI, ignoreHud = ignoreHud, img = Graphics.loadImage(imgPath), x = UIx, y = UIy, path = imgPath, onCollect = function(currency) end }; setmetatable(c,currencyMT.createMT(memaddress,memType)); c:refreshUI(); @@ -179,6 +181,8 @@ raocoin.CODE_ALREADYBOUGHT = 1; local itemMT = {} +local drawQueue = {}; + function itemMT.createMT(id) local mt = {} mt.__index = @@ -202,16 +206,18 @@ function itemMT:canAfford() end function itemMT:showPrice(x,y,screenSpace) - screenSpace = screenSpace or (screenSpace == nil); - - if(not screenSpace) then - x,y = raocoin.worldToScreen(x,y); - end - - local v = self.currency; - Graphics.placeSprite(1, v.img, x, y, "", 2); - local val = tostring(self.price); - Text.print(val, 1, x + 98-18*(string.len(val)), y); + table.insert(drawQueue, function() + screenSpace = screenSpace or (screenSpace == nil); + + if(not screenSpace) then + x,y = raocoin.worldToScreen(x,y); + end + + local v = self.currency; + Graphics.placeSprite(1, v.img, x, y, "", 2); + local val = tostring(self.price); + Text.print(val, 1, x + 98-18*(string.len(val)), y); + end) end function itemMT:buy() @@ -322,11 +328,11 @@ function raocoin.update() actionQueue = {}; for k,v in pairs(currencies) do - if(v.visible) then + --[[if(v.visible) then Graphics.placeSprite(1, v.img, v.x, v.y, "", 2); local val = tostring(v:get()); Text.print(val, 1, v.x + 98-18*(string.len(val)), v.y); - end + end]] currencyCache[k].count = 0; for _,_ in pairs(findnpcs(k,-1)) do @@ -334,20 +340,22 @@ function raocoin.update() end if(currencyCache[k].count < currencyCache[k].lastCount) then currencyCache[k].value = currencyCache[k].value + currencyCache[k].lastCount - currencyCache[k].count; - raocoin.onCollect(v); + raocoin.onCollect(v, currencyCache[k].lastCount - currencyCache[k].count); + v:onCollect(currencyCache[k].lastCount - currencyCache[k].count); end currencyCache[k].lastCount = currencyCache[k].count; end for k,v in pairs(memcurrencies) do - if(v.visible) then + --[[if(v.visible) then Graphics.placeSprite(1, v.img, v.x, v.y, "", 2); local val = tostring(v:get()); Text.print(val, 1, v.x + 98-18*(string.len(val)), v.y); - end + end]] if(memcurrencyCache[v.id] < mem(v.id,v.type)) then - raocoin.onCollect(v); + raocoin.onCollect(v, currencyCache[k].lastCount - currencyCache[k].count); + v:onCollect(currencyCache[k].lastCount - currencyCache[k].count); end memcurrencyCache[v.id] = mem(v.id,v.type); end @@ -416,13 +424,15 @@ function raocoin.update() --bmp icon if(v.image ~= nil and v.enableTimer <= 0) then - Graphics.placeSprite(2,v.image,v.x,v.y-70-64,"",2); + Graphics.drawImageWP(v.image,v.x,v.y-70-64,1); end --text if(v.text ~= nil and v.enableTimer <= 0) then - local x1,y1 = raocoin.worldToScreen(v.x,v.y-64); - Text.print(v.text,x1+8-string.len(v.text)*9,y1-26); + table.insert(drawQueue, function() + local x1,y1 = raocoin.worldToScreen(v.x+12,v.y-72); + Text.printWP(v.text,x1+8-string.len(v.text)*9,y1-26,1); + end); end local img = raocoin.IMG_TOKEN_T; @@ -432,7 +442,7 @@ function raocoin.update() if(v.enableTimer <= 0) then Graphics.placeSprite(2,img,v.x,v.y-64,"",2); - k:showPrice(v.x-48,v.y-8-64,false); + k:showPrice(v.x-32,v.y-82,false); if(colliders.collide(player,v.hitbox)) then Graphics.drawImageToScene(raocoin.IMG_ARROW,v.x,v.y-32,math.abs(arrowalpha)) @@ -466,13 +476,38 @@ function raocoin.update() tryBuy = false; end +function raocoin.drawhud() + for _,v in ipairs(drawQueue) do + v(); + end + + drawQueue = {}; + + for k,v in pairs(currencies) do + if(v.visible and (v.ignoreHud or Graphics.isHudActivated())) then + Graphics.drawImage(v.img, v.x, v.y); + local val = tostring(v:get()); + Text.print(val, 1, v.x + 90-18*(string.len(val)), v.y); + end + end + + for k,v in pairs(memcurrencies) do + if(v.visible and (v.ignoreHud or Graphics.isHudActivated())) then + Graphics.drawImage(v.img, v.x, v.y); + local val = tostring(v:get()); + Text.print(val, 1, v.x + 90-18*(string.len(val)), v.y); + end + end +end + function raocoin.onInitAPI() registerEvent(raocoin, "onLoop", "update", true) --Register the loop event registerEvent(raocoin, "onInputUpdate", "inputupdate", true) --Register the input event + registerEvent(raocoin, "onHUDDraw", "drawhud", true) --Register the draw event end -function raocoin.onCollect(currency) +function raocoin.onCollect(currency, increment) end function raocoin.onBuy(item) @@ -484,7 +519,10 @@ end function raocoin.getScreenBounds() - local h = (player:mem(0xD0, FIELD_DFLOAT)); + local c = Camera.get()[1]; + local b = {left = c.x, right = c.x + 800, top = c.y, bottom = c.y+600}; + + --[[local h = (player:mem(0xD0, FIELD_DFLOAT)); local b = { left = player.x-400+player.speedX, right = player.x+400+player.speedX, top = player.y-260+player.speedY, bottom = player.y+340+player.speedY }; local sect = Section(player.section); @@ -508,7 +546,7 @@ function raocoin.getScreenBounds() if(b.bottom > bounds.bottom+40-h) then b.bottom = bounds.bottom+40-h; b.top = b.bottom - 600; - end + end]] return b; @@ -517,7 +555,7 @@ end function raocoin.worldToScreen(x,y) local b = raocoin.getScreenBounds(); local x1 = x-b.left; - local y1 = y-b.top-(player:mem(0xD0, FIELD_DFLOAT))+30; + local y1 = y-b.top; return x1,y1; end