Skip to content

Instantly share code, notes, and snippets.

@undergroundmonorail
Created March 2, 2017 23:54
Show Gist options
  • Save undergroundmonorail/5e205ab62a657bbd138024768deadb83 to your computer and use it in GitHub Desktop.
Save undergroundmonorail/5e205ab62a657bbd138024768deadb83 to your computer and use it in GitHub Desktop.
local shootCats = RegisterMod("shoot cats", 1)
local player
local beelzebubItems = {}
local beelzebubCounter
function table.shallow_copy(t)
local t2 = {}
for k,v in pairs(t) do
t2[k] = v
end
return t2
end
function shootCats:init()
player = Isaac.GetPlayer(0)
beelzebubItems = {CollectibleType.COLLECTIBLE_BLUEBABYS_ONLY_FRIEND,
CollectibleType.COLLECTIBLE_BBF,
CollectibleType.COLLECTIBLE_BEST_BUD,
CollectibleType.COLLECTIBLE_BIG_FAN,
CollectibleType.COLLECTIBLE_DISTANT_ADMIRATION,
CollectibleType.COLLECTIBLE_FOREVER_ALONE,
CollectibleType.COLLECTIBLE_HALO_OF_FLIES,
CollectibleType.COLLECTIBLE_HIVE_MIND,
CollectibleType.COLLECTIBLE_SKATOLE,
CollectibleType.COLLECTIBLE_SMART_FLY,
CollectibleType.COLLECTIBLE_MULLIGAN,
CollectibleType.COLLECTIBLE_INFESTATION,
CollectibleType.COLLECTIBLE_LOST_FLY,
CollectibleType.COLLECTIBLE_PAPA_FLY,
CollectibleType.COLLECTIBLE_FRIEND_ZONE,
CollectibleType.COLLECTIBLE_OBSESSED_FAN,
CollectibleType.COLLECTIBLE_JAR_OF_FLIES}
if Game():GetFrameCount() == 0 then
local uncollected = ""
for i = 1, #beelzebubItems do
uncollected = uncollected .. "0" .. tostring(beelzebubItems[i]) .. ","
end
Isaac.SaveModData(shootCats, uncollected)
else
local savedstring = Isaac.LoadModData(shootCats)
beelzebubItemsBak = table.shallow_copy(beelzebubItems)
for i = 1, #beelzebubItemsBak do
if savedstring:find("0" .. tostring(beelzebubItemsBak[i]) .. ",") == nil then
for k,v in pairs(beelzebubItems) do
if v == beelzebubItemsBak[i] then
table.remove(beelzebubItems, k)
break
end
end
end
end
end
beelzebubCounter = 17 - #beelzebubItems
end
function shootCats:onUpdate()
if not (player == nil) then
if shootCats:playerIsBeelzebub() then
shootCats:replaceTears()
end
end
end
function shootCats:playerIsBeelzebub()
if #beelzebubItems > 0 then
local uncollected = ""
for i = 1, #beelzebubItems do
if player:HasCollectible(beelzebubItems[i]) then
beelzebubCounter = beelzebubCounter + 1
table.remove(beelzebubItems, i)
for j = 1, #beelzebubItems do
uncollected = uncollected .. "0" .. tostring(beelzebubItems[j]) .. ","
end
Isaac.SaveModData(shootCats, uncollected)
end
end
end
return beelzebubCounter >= 3
end
function shootCats:replaceTears()
for _, entity in ipairs(Isaac.GetRoomEntities()) do
local tear = entity:ToTear()
if entity.Type == EntityType.ENTITY_TEAR and (entity.FrameCount == 0 or entity.FrameCount == 1) then
local tearSprite = tear:GetSprite()
tearSprite:ReplaceSpritesheet(0, "gfx/cat_tears.png")
local myDirection = player:GetHeadDirection()
if myDirection == Direction.UP then
tearSprite.Rotation = tear.Velocity.X * 4
elseif myDirection == Direction.DOWN then
tearSprite.Rotation = 180 + (tear.Velocity.X * -4)
elseif myDirection == Direction.RIGHT then
tearSprite.Rotation = 90 + (tear.Velocity.Y * 4)
elseif myDirection == Direction.LEFT then
tearSprite.Rotation = 270 + (tear.Velocity.Y * -4)
end
tearSprite:Update()
tearSprite:LoadGraphics()
end
end
end
function shootCats:debugText()
Isaac.RenderText("Current number of Beelzebub items:", 100, 200, 255, 0, 0, 255)
Isaac.RenderText(tostring(beelzebubCounter), 310, 200, 0, 255, 0, 255)
Isaac.RenderText("(This text is not present in the release build)", 100, 210, 255, 0, 0, 255)
end
shootCats:AddCallback(ModCallbacks.MC_POST_PLAYER_INIT, shootCats.init)
shootCats:AddCallback(ModCallbacks.MC_POST_UPDATE, shootCats.onUpdate)
--shootCats:AddCallback(ModCallbacks.MC_POST_RENDER, shootCats.debugText)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment