Your code could be cleaned up a bit. I played around with it myself to see how it works, but I'm not sure what's going on in your code and it's good practice to insert comments to show what each part of your code does. Using the tab button to indent lines will also make it easier to read.
Original:
Code: Select all
local cloudflowerAPI = {}
local encrypt = loadSharedAPI("encrypt")
local cloudsData = encrypt.Data(Data.DATA_WORLD,true)
local clouds = 3
local clouds_max = 0
local pressing = 0
local cloudtimer = 0
local xtimer = 0
local clouds_check = 0
local seffect = Audio.SfxOpen("cloudflowerapi\\cloud-sfx.mp3")
local cloudcounter = Graphics.loadImage(Misc.resolveFile("cloudflowerapi\\cloud_counter.png"))
function cloudflowerAPI.setAmmount(value)
if value > 0 then
clouds_max = value
end
if value == 0 then
clouds_max = -1
end
end
function cloudflowerAPI.onStart()
if cloudsData:get("cflower") == nil then
cloudsData:set("cflower",0)
end
end
function cloudflowerAPI.onInitAPI()
registerEvent(cloudflowerAPI, "onLoop", "showClouds")
registerEvent(cloudflowerAPI, "onStart", "onStart")
registerEvent(cloudflowerAPI, "onTick", "check")
end
function cloudflowerAPI.showClouds()
Audio.sounds[18].sfx = seffect
if clouds > 0 then
Graphics.placeSprite(1, cloudcounter, 24, 24)
Text.print(clouds-1, 56, 24)
end
if clouds == 0 then
Graphics.placeSprite(1, cloudcounter, 24, 24)
Text.print(clouds, 56, 24)
end
if clouds < 0 then
Graphics.placeSprite(1, cloudcounter, 24, 24)
Text.print("infinity", 56, 24)
end
if player.powerup == PLAYER_BIG then
clouds = clouds_max+1
end
if clouds >= clouds_max+1 then
clouds = clouds_max+1
end
if player.powerup == PLAYER_FIREFLOWER and player:mem(0x140, FIELD_WORD) == 0 then
if player.runKeyPressing == true and pressing == 0 and clouds ~= 0 then
clouds = clouds - 1
pressing = 1
xtimer = 2
end
if player.runKeyPressing == false then
pressing = 0
end
end
if xtimer == 1 then
for k,v in pairs(NPC.get(46,-1)) do
v.y = player.y +64
v.x = player.x
v.speedX = 0
v.speedY = 0
v.id = 212
end
end
if player.powerup == PLAYER_FIREFLOWER and clouds == 0 and player.reservePowerup == 14 then
player.reservePowerup = 0
clouds = clouds_max+1
end
end
function cloudflowerAPI.check()
for k,v in pairs(NPC.get(212,-1)) do
v.ai3 = v.ai3 + 1
if v.speedX > 1 then
v.speedX = 0
v.speedY = 0
end
if v.ai3 >= 250 then
v.y = v.y + v.ai3*10
end
end
if clouds ~= 0 then
for k,v in pairs(NPC.get(13,-1)) do
v.id = 46
end
end
if clouds == 0 then
for k,v in pairs(NPC.get(13,-1)) do
v.id = 178
end
for k,v in pairs(NPC.get(178,-1)) do
v.y = player.y
v.x = player.x
end
end
xtimer = xtimer - 1
end
return cloudflowerAPI
Revisions (from what I could make sense of):
Code: Select all
local cloudflowerAPI = {}
local encrypt = loadSharedAPI("encrypt")
local cloudsData = encrypt.Data(Data.DATA_WORLD,true)
local clouds = 0
local clouds_max = 0
local pressing = 0
local cloudtimer = 0
local xtimer = 0
local clouds_check = 0
local seffect = Audio.SfxOpen("cloudflowerapi\\cloud-sfx.mp3")
local cloudcounter = Graphics.loadImage(Misc.resolveFile("cloudflowerapi\\cloud_counter.png"))
function cloudflowerAPI.setAmmount(value)
if value > 0 then
clouds_max = value
else
clouds_max = -1
end
end
function cloudflowerAPI.onStart()
if cloudsData:get("cflower") == nil then
cloudsData:set("cflower",0)
end
end
function cloudflowerAPI.onInitAPI()
registerEvent(cloudflowerAPI, "onLoop", "showClouds")
registerEvent(cloudflowerAPI, "onStart", "onStart")
registerEvent(cloudflowerAPI, "onTick", "check")
end
function cloudflowerAPI.showClouds()
Audio.sounds[18].sfx = seffect
Graphics.placeSprite(1, cloudcounter, 24, 100)
Text.print(math.max(0, clouds - 1), 56, 100)
if (player.powerup == PLAYER_BIG) or (clouds >= clouds_max + 1) then
clouds = clouds_max + 1
end
if player.powerup == PLAYER_FIREFLOWER and player:mem(0x140, FIELD_WORD) == 0 then
if player.runKeyPressing == true and pressing == 0 and clouds > 0 then
clouds = clouds - 1
pressing = 1
xtimer = 2
end
if player.runKeyPressing == false then
pressing = 0
end
end
if xtimer == 1 then
for k,v in pairs(NPC.get(46,-1)) do
v.y = player.y + 64
v.x = player.x
v.speedX = 0
v.speedY = 0
v.id = 212
end
end
if player.powerup == PLAYER_FIREFLOWER and clouds == 0 and player.reservePowerup == 14 then
player.reservePowerup = 0
clouds = clouds_max + 1
end
end
function cloudflowerAPI.check()
for k,v in pairs(NPC.get(212,-1)) do
v.ai3 = v.ai3 + 1
if v.speedX > 1 then
v.speedX = 0
v.speedY = 0
end
if v.ai3 >= 250 then
v.y = v.y + v.ai3*10
end
end
if clouds ~= 0 then
for k,v in pairs(NPC.get(13,-1)) do
v.id = 46
end
end
if clouds == 0 then
for k,v in pairs(NPC.get(13,-1)) do
v.id = 178
end
for k,v in pairs(NPC.get(178,-1)) do
v.y = player.y
v.x = player.x
end
end
xtimer = xtimer - 1
end
return cloudflowerAPI