Guest User

frozen over code

a guest
Jul 31st, 2026
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.19 KB | None | 0 0
  1. return function(self)
  2. -- Animation collection
  3. self.anims = { }
  4. self.anims.followUps = { } -- List of sprites in an animation that starts another animation when it's finished
  5.  
  6. -- Build the content in the self.anims table to make it look like proper animations usable with sprite.SetAnimation()
  7. function self.BuildAnimations()
  8. local testSprite = CreateSprite("empty", "Top")
  9. -- Check each registered entity
  10. for k, v in pairs(self.anims) do
  11. local isPlayer = v.isPlayer
  12. v.isPlayer = nil
  13. -- For each animation in the current entity
  14. for k2, v2 in pairs(v) do
  15. -- Create the animation with file paths
  16. for i = 1, #v2[1] do
  17. local file = "CreateYourKris/" .. (isPlayer and "Players/" or "Monsters/") .. k .. "/" .. k2 .. "/" .. tostring(v2[1][i])
  18. v2[1][i] = file
  19. end
  20. -- Starts the anim if preloadAnimations is true to register it in CYK
  21. if preloadAnimations then
  22. testSprite.SetAnimation(v2[1], v2[2])
  23. end
  24. end
  25. end
  26. -- Animation of the stars that appear when a Player's attack is performed perfectly
  27. self.anims.damageStar = {
  28. Idle = { { "CreateYourKris/UI/Attack/Stars/1", "CreateYourKris/UI/Attack/Stars/2", "CreateYourKris/UI/Attack/Stars/3" }, 1 / 4, { loop = "ONESHOTEMPTY" } }
  29. }
  30. testSprite.Remove()
  31. end
  32.  
  33. -- Sets a sprite object's animation
  34. function self.SetAnim(entity, animName, followUpData)
  35. local sprite = entity.sprite
  36.  
  37. if entity.hp and entity.hp <= 0 then
  38. animName = self.anims[sprite["anim"]]["Down"] and "Down" or "Idle"
  39. end
  40.  
  41. local animObject = self.anims[sprite["anim"]][animName]
  42. followUpData = followUpData or { }
  43.  
  44. -- Removes any occurence of this sprite in the followUp table
  45. for i = #self.anims.followUps, 1, -1 do
  46. if self.anims.followUps[i].entity == entity then
  47. table.remove(self.anims.followUps, i)
  48. end
  49. end
  50.  
  51. -- Check if this entity allows this animation to play
  52. if animName ~= "Hurt" and not followUpData.noAnimOverride then
  53. if ProtectedCYKCall(entity.HandleAnimationChange, animName) == false then
  54. return
  55. end
  56. elseif animName == "Hurt" and sprite["currAnim"] ~= "Defend" and entity.UI ~= nil then
  57. entity.UI.faceSprite.SetAnimation({ "CreateYourKris/Players/" .. sprite["anim"] .. "/UI/Hurt", "CreateYourKris/Players/" .. sprite["anim"] .. "/UI/Normal" }, 1/2)
  58. end
  59.  
  60. -- If the current animation doesn't exist, abort
  61. if not animObject then
  62. if CYKDebugLevel > 0 then
  63. error("[WARN] The animation " .. animName .. " of the " .. (entity.UI and "player" or "enemy") .. " " .. tostring(entity.sprite["anim"]) .. " doesn't exist.")
  64. end
  65. return
  66. end
  67. local loopmode = animObject[3].loop and animObject[3].loop or animObject[3].next and "ONESHOT" or "LOOP"
  68.  
  69. -- Doesn't change the sprite's animation if it is the same looped anim
  70. if sprite["currAnim"] == animName and loopmode == "LOOP" then
  71. return
  72. end
  73.  
  74. -- Adds the sprite to the followUp table if this anim must be followed by another anim when it ends
  75. sprite.loopmode = loopmode
  76. if animObject[3].next or followUpData.noAnimOverride or followUpData.destroyOnEnd then
  77. followUpData.entity = followUpData.entity or entity
  78. followUpData.next = followUpData.next or animObject[3].next
  79. table.insert(self.anims.followUps, followUpData)
  80. end
  81.  
  82. sprite["currAnim"] = animName
  83. sprite["lastAnimTime"] = Time.time
  84.  
  85. -- Moves the sprite if needed
  86. local posShift = animObject[3].posShift
  87. local xShift = animObject[3].posShift and animObject[3].posShift[1] or 0
  88. local yShift = animObject[3].posShift and animObject[3].posShift[2] or 0
  89. sprite.Move(xShift - (sprite["xShift"] or 0), yShift - (sprite["yShift"] or 0))
  90. sprite["xShift"] = xShift
  91. sprite["yShift"] = yShift
  92.  
  93. -- FINALLY set the animation
  94. sprite.SetAnimation(animObject[1], animObject[2])
  95. -- Don't forget the sprite's mask
  96. if sprite["mask"] then
  97. sprite["mask"].SetAnimation(animObject[1], animObject[2])
  98. end
  99. end
  100.  
  101. -- Check if any sprite animation in the followUp list has ended
  102. -- if an animation has ended, it launches the animation that is supposed to follow it
  103. function self.UpdateFollowUps()
  104. for i = #self.anims.followUps, 1, -1 do
  105. local followUp = self.anims.followUps[i]
  106. if followUp.entity.sprite.animcomplete then
  107. -- Move the sprite back where it was if the current animation was Hurt
  108. if followUp.entity.sprite["currAnim"] == "Hurt" then
  109. followUp.entity.sprite.absx = followUp.entity.posX
  110. end
  111.  
  112. -- Update the Player UI's face sprite if the followUp is one of the player and it is supposed to go back to Idle
  113. if followUp.entity.UI ~= nil and followUp.next == "Idle" then
  114. followUp.entity.UI.faceSprite.Set("CreateYourKris/Players/" .. followUp.entity.sprite["anim"] .. "/UI/Normal")
  115. end
  116.  
  117. -- Remove the sprite if it has to be removed at the end of the anim, otherwise set its followUp animation
  118. if followUp.destroyOnEnd then
  119. followUp.entity.sprite.Remove()
  120. table.remove(self.anims.followUps, i)
  121. else
  122. self.SetAnim(followUp.entity, followUp.next)
  123. end
  124.  
  125. break
  126. end
  127. end
  128. end
  129.  
  130. self.arenaAnim = nil
  131. self.arenaAnimEffects = { }
  132. self.arenaAnimHeartEffects = { }
  133. self.arenaAnimFrame = 0
  134. self.arenaAnimInfo = { x = 0, y = 0, width = 0, height = 0, rotation = 0, nostate = false, shown = false }
  135. self.arenaAnimTime = 20
  136. self.arenaAnimNotMoved = true
  137. -- Starts one of the Arena's animations
  138. function self.StartArenaAnim(show, nowave, nostate)
  139. -- If an animation is currently running, end it
  140. if self.arenaAnim then
  141. self.EndArenaAnim(true)
  142. end
  143. self.arenaAnim = show and "show" or "hide"
  144. self.arenaAnimFrame = self.frame - 1
  145.  
  146. -- The player's sprite is added to the layer Bullet so it can be visible above the arena effects at all times
  147. Player.sprite.layer = "Bullet"
  148.  
  149. -- Fill in the anim's info
  150. self.arenaAnimInfo.x = (show or nowave) and arenapos[1] or arenainfo.x
  151. self.arenaAnimInfo.y = (show or nowave) and arenapos[2] + arenasize[2] / 2 + 5 or arenainfo.y + arenainfo.height / 2 + 5
  152. self.arenaAnimInfo.width = (show or nowave) and arenasize[1] or arenainfo.width
  153. self.arenaAnimInfo.height = (show or nowave) and arenasize[2] or arenainfo.height
  154. self.arenaAnimInfo.rotation = (show or nowave) and arenarotation or arenainfo.rotation
  155. self.arenaAnimInfo.px = Player.sprite.absx
  156. self.arenaAnimInfo.py = Player.sprite.absy
  157. self.arenaAnimInfo.nostate = nostate
  158. self.arenaAnimInfo.shown = true
  159.  
  160. self.arenaAnimNotMoved = true
  161.  
  162. -- Displays the Arena if the "hide" animation is started and if the Arena will last for less than 31 frames
  163. if not show and self.arenaAnimTime <= 30 and self.Background then
  164. self.Background.Display(true, self.arenaAnimTime)
  165. end
  166.  
  167. -- Heart effect
  168. for i = 1, 3 do
  169. local heart = CreateSprite("CreateYourKris/playerWaveEffect", "Arena")
  170. local heartShift = self.players[1].animations[self.players[1].sprite["currAnim"]][3].heartShift
  171. heart.absx = self.players[1].sprite.absx + self.players[1].sprite.width / 2 + (heartShift and heartShift[1] or 0)
  172. heart.absy = self.players[1].sprite.absy + self.players[1].sprite.height / 2 + (heartShift and heartShift[2] or 0)
  173. heart.alpha = 0
  174. table.insert(self.arenaAnimHeartEffects, heart)
  175. end
  176.  
  177. self.UpdateArenaAnim()
  178. end
  179.  
  180. -- Spawns an Arena sprite during its "show" or "hide" animation
  181. function self.SpawnArenaSpriteForAnim(frame)
  182. local effect = { }
  183. local scale = frame / self.arenaAnimTime
  184.  
  185. local rotation = self.arenaAnimInfo.rotation - (self.arenaAnimTime - frame) * 4
  186. -- Creates 4 sides + the center sprite
  187. for i = 1, 5 do
  188. local side = CreateSprite("px", "Arena")
  189. side.color = i < 5 and arenacolor or { 0, 0, 0 }
  190. side.rotation = rotation
  191. if i < 5 then
  192. -- Moves and scales the side sprite
  193. side.Scale((i % 2 == 0 and self.arenaAnimInfo.width + 10 or 5) * scale, (i % 2 == 1 and self.arenaAnimInfo.height or 5) * scale)
  194. local distance = ((i % 2 == 0 and self.arenaAnimInfo.height or self.arenaAnimInfo.width) + 5) / 2 * scale
  195. local angle = math.rad((side.rotation + 90 * (i - 1)) % 360)
  196. side.x = self.arenaAnimInfo.x + math.cos(angle) * distance
  197. side.y = self.arenaAnimInfo.y + math.sin(angle) * distance
  198. else
  199. -- Moves and scales the center sprite
  200. side.Scale(self.arenaAnimInfo.width * scale, self.arenaAnimInfo.height * scale)
  201. side.x = self.arenaAnimInfo.x
  202. side.y = self.arenaAnimInfo.y
  203. end
  204. table.insert(effect, side)
  205. if self.arenaAnim == "show" then
  206. side.SendToBottom()
  207. end
  208. end
  209.  
  210. effect.frame = self.frame
  211. effect.angle = rotation
  212.  
  213. table.insert(self.arenaAnimEffects, effect)
  214. end
  215.  
  216. -- Updates the Arena's animation
  217. function self.UpdateArenaAnim()
  218. if self.arenaAnim then
  219. local frame = self.arenaAnim == "show" and self.frame - self.arenaAnimFrame or self.arenaAnimTime - (self.frame - self.arenaAnimFrame)
  220. local scale = frame / self.arenaAnimTime
  221.  
  222. -- Update the arena
  223. local effectCount = #self.arenaAnimEffects
  224. for i = effectCount, 1, -1 do
  225. local effect = self.arenaAnimEffects[i]
  226. local effectFrame = self.frame - effect.frame
  227. local isEnd = false
  228. -- For each part of each arena
  229. for j = 1, #effect do
  230. local effectPart = effect[j]
  231. -- Hide it over time
  232. effectPart.alpha = 0.8 - effectFrame / 20
  233. -- Hide it quicker if we're close to the end of the animation
  234. if frame < 10 then
  235. effectPart.alpha = effectPart.alpha * frame / 10
  236. end
  237. -- Only one trailing sprite out of two is kept to match Deltarune's animation
  238. if frame % 2 == 0 and i == effectCount then
  239. effectPart.alpha = 0
  240. end
  241. -- If the effect is not visible, delete it
  242. if effectPart.alpha == 0 then
  243. effectPart.Remove()
  244. isEnd = true
  245. -- We don't need the middle part when we're hiding the arena
  246. elseif self.arenaAnim ~= "show" and i ~= effectCount and j == 5 then
  247. effectPart.Remove()
  248. table.remove(effect, 5)
  249. end
  250. end
  251. if isEnd then
  252. table.remove(self.arenaAnimEffects, i)
  253. end
  254. end
  255. self.SpawnArenaSpriteForAnim(frame)
  256.  
  257. -- Updates the heart
  258. if frame <= 30 then
  259. if frame == self.arenaAnimTime - 30 and self.arenaAnim ~= "show" and self.Background then
  260. self.Background.Display(true, 30)
  261. end
  262. -- Updates the heart's little spawn effects
  263. for i = 1, #self.arenaAnimHeartEffects do
  264. local heart = self.arenaAnimHeartEffects[i]
  265. local coeff = frame * (1.25 - (i * 0.25))
  266. heart.Scale(coeff / 4, coeff / 6)
  267. heart.alpha = 1 - ((2 * (i - 1) + frame) / 20)
  268. end
  269. -- Move the player's soul from the first Player's position to the Arena or from the Arena to the first Player's position
  270. if frame <= 20 and (Player.sprite.layer == "Arena" or Player.sprite.layer == "Bullet") then
  271. Player.sprite.alpha = frame / 10
  272. local coeff = frame * 0.05
  273. local startingPos = self.arenaAnim == "show" and { x = self.arenaAnimInfo.x, y = self.arenaAnimInfo.y } or { x = self.arenaAnimInfo.px, y = self.arenaAnimInfo.py }
  274. Player.MoveToAbs(self.arenaAnimHeartEffects[1].absx + (startingPos.x - self.arenaAnimHeartEffects[1].absx) * coeff,
  275. self.arenaAnimHeartEffects[1].absy + (startingPos.y - self.arenaAnimHeartEffects[1].absy) * coeff, true)
  276. end
  277. end
  278.  
  279. -- End of the animation
  280. if frame == self.arenaAnimTime or frame == 0 then
  281. self.EndArenaAnim()
  282. end
  283. end
  284. end
  285.  
  286. -- Ends the current arena animation
  287. function self.EndArenaAnim(nostate)
  288. -- Destroys the heart effects
  289. for i = #self.arenaAnimHeartEffects, 1, -1 do
  290. self.arenaAnimHeartEffects[i].Remove()
  291. table.remove(self.arenaAnimHeartEffects, i)
  292. end
  293. -- Destroys the arena effects
  294. for i = #self.arenaAnimEffects, 1, -1 do
  295. while #self.arenaAnimEffects[i] > 0 do
  296. self.arenaAnimEffects[i][1].Remove()
  297. table.remove(self.arenaAnimEffects[i], 1)
  298. end
  299. table.remove(self.arenaAnimEffects, i)
  300. end
  301. self.arenaAnimInfo.shown = oldArenaAnim == "show"
  302. local oldArenaAnim = self.arenaAnim
  303. self.arenaAnim = nil
  304. -- If this is the end of the "show" animation, start the wave
  305. if oldArenaAnim == "show" then
  306. if #Wave == 0 then
  307. self.StartArenaAnim(false, true)
  308. return
  309. end
  310. Wave[1].Call("ShowArenaAfterEndAnim")
  311. nextwaves = self.nextwaves
  312. -- Don't ask me why there's two calls to "DEFENDING", I don't remember why and I'm afraid to touch it!
  313. OldState("DEFENDING")
  314. OldState("DEFENDING")
  315. Player.sprite.MoveToAbs(self.arenaAnimInfo.x, self.arenaAnimInfo.y)
  316. -- If this is the end of the "hide" animation, start another Player turn
  317. elseif not self.arenaAnimInfo.nostate and not nostate then
  318. Player.sprite.SetParent(self.UI.hider)
  319. -- Time for a new turn!
  320. self.turn = 0
  321. self.State("ACTIONSELECT")
  322. end
  323. end
  324. end
Advertisement
Add Comment
Please, Sign In to add comment