Josh64

main.lua

Jan 5th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. local ArunesMod = RegisterMod("Arunes", 1)
  2. local game = Game()
  3.  
  4. --Stats--
  5. local ArunesStats = {
  6. Arunes1 = 10
  7. }
  8.  
  9. local Dir = {
  10. [Direction.UP] = Vector(0,-1),
  11. [Direction.DOWN] = Vector(0,1),
  12. [Direction.LEFT] = Vector(-1,0),
  13. [Direction.RIGHT] = Vector(1,0)
  14. }
  15.  
  16. local Arunes_item = Isaac.GetItemIdByName("Arunes")
  17. local Costume_Anim = Isaac.GetCostumeIdByPath("gfx/characters/arunesanim.anm2")
  18. EffectVariant.ARUNES_COSTUME = Isaac.GetEntityVariantByName("Arunes Body")
  19.  
  20. function ArunesMod:onUpdate(player)
  21. local MoveDir = player:GetMovementDirection()
  22. for _, entities in pairs(Isaac.GetRoomEntities()) do
  23. if entities.Type == EntityType.ENTITY_EFFECT
  24. and entities.Variant == EffectVariant.ARUNES_COSTUME then
  25. local costumeEffect = entities
  26. local sprite = costumeEffect:GetSprite()
  27. -- set the offset
  28. effect.Velocity = player.Position - effect.Position
  29.  
  30. -- check the fire direction to set the offset
  31. if MoveDir == Direction.DOWN then
  32. if not (sprite:IsPlaying(“WalkDown“) then
  33. sprite:Play(“WalkDown“, true)
  34. end
  35. elseif MoveDir == Direction.RIGHT then
  36. if not (sprite:IsPlaying(“WalkRight“) then
  37. sprite:Play(“WalkRight“, true)
  38. end
  39. elseif MoveDir == Direction.UP then
  40. if not (sprite:IsPlaying(“WalkUp“) then
  41. sprite:Play(“WalkUp“, true)
  42. end
  43. elseif MoveDir == Direction.LEFT then
  44. if not (sprite:IsPlaying(“WalkLeft“) then
  45. sprite:Play(“WalkLeft“, true)
  46. end
  47. else
  48. sprite:Play(“WalkDown“, true)
  49. end
  50. end
  51. end
  52. end
  53. ArunesMod:AddCallback( ModCallbacks.MC_POST_PLAYER_UPDATE, ArunesMod.onUpdate)
  54.  
  55. --When effect updates + costume for item--
  56. --Cache Updates for stats--
  57. function ArunesMod:cacheUpdate(player, cacheFlag)
  58. player = Isaac.GetPlayer(0)
  59.  
  60. --costume finally
  61. if player:HasCollectible(Arunes_item) then
  62. if HasArunes ~= true then
  63. player:AddNullCostume(Costume_Anim)
  64. Isaac.Spawn(EntityType.ENTITY_EFFECT, EffectVariant.ARUNES_COSTUME, 0, player.Position, Vector(0,0), player):ToEffect()
  65. HasArunes = true
  66. end
  67. elseif HasArunes == true and player:HasCollectible(Arunes_item) == false then
  68. player:TryRemoveNullCostume(Costume_Anim)
  69. HasArunes = false
  70. end
  71. --
  72. --stats update
  73. if cacheFlag == CacheFlag.CACHE_LUCK then
  74. if player:HasCollectible(Arunes_item) then
  75. player.Luck = player.Luck + ArunesStats.Arunes1
  76. end
  77. end
  78. if cacheFlag == CacheFlag.CACHE_FLYING then
  79. if player:HasCollectible(Arunes_item) then
  80. player.CanFly = true
  81. end
  82. end
  83. end
  84. ArunesMod:AddCallback( ModCallbacks.MC_EVALUATE_CACHE, ArunesMod.cacheUpdate)
  85.  
  86. function ArunesMod:onCostume(effect)
  87. local sprite = effect:GetSprite()
  88. local player = Isaac.GetPlayer(0)
  89. local MoveDir = player:GetMovementDirection()
  90.  
  91. effect.RenderZOffset = 4900 -- 1300 is enough for most obstacles, but not for the player
  92. effect.Velocity = player.Position - effect.Position
  93.  
  94. if effect:GetData().Init == nil then
  95. -- Isaac.ConsoleOutput("Appear ")
  96. -- play the correct animation
  97. if MoveDir == Direction.DOWN then
  98. sprite:Play(“WalkDown“, true)
  99. elseif MoveDir == Direction.RIGHT then
  100. sprite:Play(“WalkRight“, true)
  101.  
  102. elseif MoveDir == Direction.UP then
  103. sprite:Play(“WalkUp“, true)
  104.  
  105. elseif MoveDir == Direction.LEFT then
  106. sprite:Play(“WalkLeft“, true)
  107. else
  108. sprite:Play(“WalkDown“, true)
  109. end
  110. effect:GetData().Init = true
  111. end
  112. end
  113. ArunesMod:AddCallback(ModCallbacks.MC_POST_EFFECT_INIT, ArunesMod.onCostume, EffectVariant.ARUNES_COSTUME)
  114.  
  115.  
  116. function ArunesMod.onNewRoom(_)
  117. local player = Isaac.GetPlayer(0)
  118. local roomType = game:GetRoom():GetType()
  119.  
  120. -- give the costume to the player
  121. if player:HasCollectible(Arunes_item) then
  122.  
  123. Isaac.Spawn(EntityType.ENTITY_EFFECT, EffectVariant.ARUNES_COSTUME, 0, player.Position, Vector(0,0), player):ToEffect()
  124. end
  125.  
  126. end
  127. ArunesMod:AddCallback(ModCallbacks.MC_POST_NEW_ROOM, ArunesMod.onNewRoom)
Advertisement
Add Comment
Please, Sign In to add comment