Skip to content

Commit

Permalink
#3 - Refactor
Browse files Browse the repository at this point in the history
#4 - Refactor
  • Loading branch information
VincentVeluwenkamp committed May 28, 2018
1 parent 4a0342f commit aeebbd5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
18 changes: 10 additions & 8 deletions S0R - Small Cookie/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

local Mod = RegisterMod("S0R_SmallCookie", 1)
local game = Game()
local sound = SFXManager()
local sfx = SFXManager()

local trinketId = {
TRINKET_SMALLCOOKIE = Isaac.GetTrinketIdByName("Small Cookie")
}
--TrinketType.TRINKET_SMALLCOOKIE = Isaac.GetTrinketIdByName("Small Cookie")
CollectibleType.TRINKET_SMALLCOOKIE = Isaac.GetTrinketIdByName("Small Cookie")
SoundEffect.SOUND_HEAL = Isaac.GetSoundIdByName("heal")

local smallCookieStats = {
hasTrinket = false,
Expand All @@ -21,25 +21,27 @@ local smallCookieStats = {
if not __eidTrinketDescriptions then
__eidTrinketDescriptions = {}
end
__eidTrinketDescriptions[trinketId.TRINKET_SMALLCOOKIE] = "Auto-regen over time#10 uses"
__eidTrinketDescriptions[CollectibleType.TRINKET_SMALLCOOKIE] = "Auto-regen over time#10 uses"

function Mod:postRender()
local player = Isaac.GetPlayer(0)

if player:HasTrinket(trinketId.TRINKET_SMALLCOOKIE) then
if player:HasTrinket(CollectibleType.TRINKET_SMALLCOOKIE) then
-- TODO: Time based instead of random?
if math.random(1000) == 1 and smallCookieStats.uses > 0 and player:GetHearts() < player:GetMaxHearts() then
smallCookieStats.uses = smallCookieStats.uses - 1
player:AddHearts(1)

-- Play sound when healed
-- Play sound when healed ?
local dummy = Isaac.Spawn(EntityType.ENTITY_FLY, 0, 0, Vector(0,0), Vector(0,0), Isaac.GetPlayer(0)):ToNPC()
dummy:ClearEntityFlags(EntityFlag.FLAG_APPEAR)
dummy.CanShutDoors = false
dummy:PlaySound(157, 1, 0, false, 1.0)
dummy:Remove()

sfx:Play(SoundEffect.SOUND_HEAL, 1, 0, false, 1.0)
elseif smallCookieStats.uses == 0 then
player:TryRemoveTrinket(trinketId.TRINKET_SMALLCOOKIE)
player:TryRemoveTrinket(CollectibleType.TRINKET_SMALLCOOKIE)
end
end
end
Expand Down
36 changes: 16 additions & 20 deletions S0R - Test/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ local MIN_FIRE_DELAY = 5 -- TODO: ?
-- require("calculations.lua")

--
-- Define Ids to easy-to-use names
-- Define Ids //to easy-to-use names
--
local ItemsId = {
COLLECTIBLE_LILLEME = Isaac.GetItemIdByName("Lil Leme!"), -- item ID
COLLECTIBLE_LILMELLO = Isaac.GetItemIdByName("Lil Mello") -- item ID
}
CollectibleType.COLLECTIBLE_LILLEME = Isaac.GetItemIdByName("Lil Leme!")
CollectibleType.COLLECTIBLE_LILMELLO = Isaac.GetItemIdByName("Lil Mello")
SoundEffect.SOUND_LEME_SING = Isaac.GetSoundIdByName("leme_sing")
SoundEffect.SOUND_MELLO_SING = Isaac.GetSoundIdByName("mello_sing")
TearVariant.MUSIC_NOTE_TEAR = Isaac.GetEntityVariantByName("Music Note Tear")

-- Direction vars
local Dir = {
Expand All @@ -27,19 +28,14 @@ local Dir = {
[Direction.RIGHT] = Vector(1,0)
}

--
SoundEffect.SOUND_LEME_SING = Isaac.GetSoundIdByName("leme_sing")
SoundEffect.SOUND_MELLO_SING = Isaac.GetSoundIdByName("mello_sing")
TearVariant.MUSIC_NOTE_TEAR = Isaac.GetEntityVariantByName("Music Note Tear")

---
--- EID Comparability
---
if not __eidItemDescriptions then
__eidItemDescriptions = {}
end
__eidItemDescriptions[ItemsId.COLLECTIBLE_LILLEME] = "Shooting orbital#When Isaac is hurt it moves around the room shooting tears towards enemies"
__eidItemDescriptions[ItemsId.COLLECTIBLE_LILMELLO] = "Shooting orbital#When Isaac is hurt it moves around the room shooting tears towards enemies"
__eidItemDescriptions[CollectibleType.COLLECTIBLE_LILLEME] = "Shooting orbital#When Isaac is hurt it moves around the room shooting tears towards enemies"
__eidItemDescriptions[CollectibleType.COLLECTIBLE_LILMELLO] = "Shooting orbital#When Isaac is hurt it moves around the room shooting tears towards enemies"

--- Debugging text TODO: Delete on release
--
Expand Down Expand Up @@ -85,10 +81,10 @@ function Mod:onUpdate()
-- Beginning of run init
if Game():GetFrameCount() == 1 then
-- Working Item spawns (For testing only)
Isaac.Spawn(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_COLLECTIBLE, ItemsId.COLLECTIBLE_LILLEME, Vector(470,350), Vector(0,0), nil)
Isaac.Spawn(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_COLLECTIBLE, ItemsId.COLLECTIBLE_LILMELLO, Vector(520,350), Vector(0,0), nil)
Isaac.Spawn(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_COLLECTIBLE, ItemsId.COLLECTIBLE_LILLEME, Vector(270,350), Vector(0,0), nil)
Isaac.Spawn(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_COLLECTIBLE, ItemsId.COLLECTIBLE_LILMELLO, Vector(320,350), Vector(0,0), nil)
Isaac.Spawn(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_COLLECTIBLE, CollectibleType.COLLECTIBLE_LILLEME, Vector(470,350), Vector(0,0), nil)
Isaac.Spawn(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_COLLECTIBLE, CollectibleType.COLLECTIBLE_LILMELLO, Vector(520,350), Vector(0,0), nil)
Isaac.Spawn(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_COLLECTIBLE, CollectibleType.COLLECTIBLE_LILLEME, Vector(270,350), Vector(0,0), nil)
Isaac.Spawn(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_COLLECTIBLE, CollectibleType.COLLECTIBLE_LILMELLO, Vector(320,350), Vector(0,0), nil)

Isaac.Spawn(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_COLLECTIBLE, Isaac.GetItemIdByName("Planetoids"), Vector(270,300), Vector(0,0), nil)
Isaac.Spawn(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_COLLECTIBLE, Isaac.GetItemIdByName("Planetoids"), Vector(320,300), Vector(0,0), nil)
Expand Down Expand Up @@ -603,13 +599,13 @@ local function updateCache(_, player, cache_flag)


-- Leme
local leme_pickups = player:GetCollectibleNum(ItemsId.COLLECTIBLE_LILLEME) -- number of 'Planetoids' items
local leme_rng = player:GetCollectibleRNG(ItemsId.COLLECTIBLE_LILLEME) -- respective RNG reference
local leme_pickups = player:GetCollectibleNum(CollectibleType.COLLECTIBLE_LILLEME) -- number of 'Planetoids' items
local leme_rng = player:GetCollectibleRNG(CollectibleType.COLLECTIBLE_LILLEME) -- respective RNG reference
player:CheckFamiliar(lemeStats.VARIANT, leme_pickups, leme_rng)

-- Mello
local mello_pickups = player:GetCollectibleNum(ItemsId.COLLECTIBLE_LILMELLO)
local mello_rng = player:GetCollectibleRNG(ItemsId.COLLECTIBLE_LILMELLO)
local mello_pickups = player:GetCollectibleNum(CollectibleType.COLLECTIBLE_LILMELLO)
local mello_rng = player:GetCollectibleRNG(CollectibleType.COLLECTIBLE_LILMELLO)
player:CheckFamiliar(melloStats.VARIANT, mello_pickups, mello_rng)
end
end
Expand Down

0 comments on commit aeebbd5

Please sign in to comment.