Advertisement
Guest User

SM5 falling sprites

a guest
Jan 18th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.65 KB | None | 0 0
  1. local maxZ = 100
  2. local maxZoom = 4
  3. local minZoom = 1
  4. local targetHalfWidth=16
  5. local startingOffset=128
  6. local minZ = 0
  7. local minFallTime = 6
  8. local fallTimeRange = 4
  9. local numItems = 64
  10.  
  11.  
  12. local function CalculateSpawnPosition()
  13.     --1 is x, 2 is y
  14.     local output = {0,0}
  15.     local mode = math.random(1,4)
  16.     if mode <= 2 then --top or bottom
  17.         output[1]=(math.random(SCREEN_LEFT-startingOffset,SCREEN_RIGHT+startingOffset))
  18.     else
  19.         output[2]=(math.random(SCREEN_TOP-startingOffset,SCREEN_BOTTOM+startingOffset))
  20.     end
  21.    
  22.     if mode==1 then
  23.         output[2]=(SCREEN_TOP-startingOffset)
  24.     elseif mode==2 then
  25.         output[2]=(SCREEN_BOTTOM+startingOffset)
  26.     elseif mode==3 then
  27.         output[1]=(SCREEN_RIGHT+startingOffset)
  28.     elseif mode==4 then
  29.         output[1]=(SCREEN_LEFT-startingOffset)
  30.     end
  31.     return unpack(output)
  32. end
  33.  
  34. local function CalculateTargetDestination()
  35.     return math.random(SCREEN_CENTER_X-targetHalfWidth, SCREEN_CENTER_X+targetHalfWidth),
  36.     math.random(SCREEN_CENTER_Y-targetHalfWidth, SCREEN_CENTER_Y+targetHalfWidth)
  37. end
  38.  
  39. local fallingItem = Def.Sprite{
  40.     Texture=THEME:GetPathG("Common", "window icon"),
  41.     InitCommand=function(self) self:queuecommand("Fall") end,
  42.     FallCommand=function(self) self:linear(0):xy(CalculateSpawnPosition(self)):z(maxZ):zoom(maxZoom)
  43.     :linear(minFallTime+math.random()*fallTimeRange):xy(CalculateTargetDestination()):z(minZ):zoom(minZoom)
  44.     :queuecommand("Fall") end,
  45. }
  46.  
  47. local t = Def.ActorFrame{InitCommand=function(s) s:fov(60):SetDrawByZPosition(true) end}
  48. t[#t+1] = Def.Quad{InitCommand=function(s) s:diffuse(color"#000000"):zoomx(SCREEN_WIDTH):zoomy(SCREEN_HEIGHT) end}
  49. for i=1,numItems do
  50.     t[i] = fallingItem
  51. end
  52. return t
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement