Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.62 KB | None | 0 0
  1. --[[===========================
  2. ** Tetris
  3. By Feoxys
  4. --]]---------------------------
  5.  
  6. --[[---------------------------
  7. * Database
  8. --]]---------------------------
  9. local admin = "Boredofme#1332"
  10.  
  11. local MAP_TIME = 90
  12. local MOUSE_HEIGHT = 40
  13. local BLOCK_WIDTH = 60
  14. local BLOCK_HEIGHT = 40
  15. local BLOCK_START_Y = -1200--
  16. local BLOCK_PROPERTIES = {
  17. {id = 0, f = 0.3, r = 0.2, mc = true },
  18. {id = 1, f = 0, r = 0.2, mc = true },
  19. {id = 2, f = 0, r = 1.2, mc = true},
  20. {id = 3, f = 0.2, r = 20, mc = true },
  21. {id = 4, f = 20, r = 0.3, mc = true },
  22. {id = 5, f = 0.3, r = 0.2, mc = true },
  23. {id = 6, f = 0.3, r = 0.2, mc = true },
  24. {id = 7, f = 0.1, r = 0.2, mc = true },
  25. --{id = 8, f = 0.3, r = 0.2, mc = false },
  26. {id = 9, f = 0.1, r = 0.2, mc = false },
  27. {id = 10, f = 0.3, r = 0, mc = true },
  28. {id = 11, f = 0.05, r = 0.1, mc = true },
  29. --{id = 15, f = 0.3, r = 0.1, mc = false }
  30. }
  31.  
  32. local alivePlayers = {}
  33. local blockDat = {}
  34. local AABBsMask = {}
  35. local startTime
  36.  
  37. local N_SPAWNED_BLOCKS = 0
  38. local N_ALIVE_PLAYERS = 0
  39.  
  40. --[[---------------------------
  41. * Miscs functions
  42. --]]---------------------------
  43. -- Allow to call a function from a string
  44. function pfuncall(str, ...)
  45. if not pcall(_G[str], arg) then
  46. print("Failed to call function '"..str.."' from string.") -- Error handling
  47. end
  48. end
  49.  
  50. --[[---------------------------
  51. * Script functions
  52. --]]---------------------------
  53. function registerBlockDat(i, l, x, y, w, h, t, f, r, mc)
  54. blockDat[#blockDat+1] = { id = i, spawnTime = 0, linearDamping = l, x = x, y = y, width = w, height = h, type = t, restitution = r, friction = f, miceCollision = mc, state = 0, a1 = x-w/2, a2 = x+w/2, b1 = y-h/2, b2 = y+h/2 }
  55. end
  56. function spawnBlock(b, st)
  57. b.state = 1
  58. b.spawnTime = st
  59.  
  60. tfm.exec.addPhysicObject(b.id, b.x, b.y,
  61. {type = b.type,
  62. width = b.width,
  63. height = b.height,
  64. restitution = 0,
  65. friction = b.friction,
  66. mass = 1081343,
  67. miceCollision = b.miceCollision,
  68. groundCollision = true,
  69. dynamic = true,
  70. fixedRotation = true,
  71. linearDamping = b.linearDamping})
  72.  
  73.  
  74. end
  75. function freezeBlock(b, blockY)
  76. b.state = 2
  77. b.y = blockY
  78. b.b1 = b.y-b.height/2
  79. b.b2 = b.y+b.height/2
  80.  
  81.  
  82. tfm.exec.addPhysicObject(b.id, b.x, b.y,
  83. {type = b.type,
  84. width = b.width,
  85. height = b.height,
  86. restitution = 0,
  87. friction = 0,--b.friction,
  88. miceCollision = false,
  89. groundCollision = true,
  90. dynamic = false,
  91. fixedRotation = true})
  92. if (b.miceCollision) then
  93. tfm.exec.addPhysicObject(b.id+1000, b.x, b.y,
  94. {type = b.type,
  95. width = b.width,
  96. height = b.height,
  97. restitution = b.restitution,
  98. friction = b.friction,--b.friction,
  99. miceCollision = b.miceCollision,
  100. groundCollision = false,
  101. dynamic = false,
  102. fixedRotation = true})
  103. end
  104. table.insert(AABBsMask, 1, {b.a1, b.b1, b.a2, b.b2})
  105. end
  106. function particleY(startY, t)
  107. return startY + 100.0 * t * t
  108. end
  109. function getFloorYAt(b, blockY)
  110. local feed = 400-5
  111.  
  112. for i=#AABBsMask,1,-1 do
  113. if (b.a1 < AABBsMask[i][3] and b.a2 > AABBsMask[i][1] and feed > AABBsMask[i][2]) then
  114. feed = AABBsMask[i][2]
  115. --break
  116. end
  117. end
  118. return feed;
  119. end
  120. function addRandomBlock(et, x)
  121. local p = BLOCK_PROPERTIES[math.random(1, #BLOCK_PROPERTIES)]
  122.  
  123. N_SPAWNED_BLOCKS = N_SPAWNED_BLOCKS + 1
  124. registerBlockDat(N_SPAWNED_BLOCKS, 0, x, BLOCK_START_Y, BLOCK_WIDTH, BLOCK_HEIGHT, p.id, p.f, p.r, p.mc)
  125. spawnBlock(blockDat[#blockDat], et)
  126. end
  127. function dataFlush()
  128. alivePlayers = {}
  129. blockDat = {}
  130. AABBsMask = {}
  131. N_ALIVE_PLAYERS = 0
  132. N_SPAWNED_BLOCKS = 0
  133. end
  134. --[[---------------------------
  135. * Transformice built-in functions
  136. --]]---------------------------
  137. function eventNewGame()
  138. tfm.exec.setGameTime(MAP_TIME, true)
  139. startTime = os.time()
  140. dataFlush()
  141. for n,p in pairs(tfm.get.room.playerList) do
  142. eventPlayerRespawn(n)
  143. end
  144. end
  145. function eventNewPlayer(p)
  146.  
  147. end
  148. function eventPlayerDied(p)
  149. system.bindMouse(p, true)
  150. alivePlayers[p] = nil
  151. N_ALIVE_PLAYERS = N_ALIVE_PLAYERS - 1
  152.  
  153. newAlivePlayers = {}
  154. for n, b in pairs(alivePlayers) do
  155. newAlivePlayers[n] = true
  156. end
  157. alivePlayers = newAlivePlayers
  158. end
  159. function eventPlayerRespawn(p)
  160. system.bindMouse(p, true)
  161. alivePlayers[p] = true
  162. N_ALIVE_PLAYERS = N_ALIVE_PLAYERS + 1
  163. end
  164. function eventChatCommand(p, m)
  165. system.exit()
  166. end
  167. function eventMouse(p, x, y)
  168. addRandomBlock(os.time() - startTime, x)
  169. end
  170.  
  171. function eventLoop(et, rt)
  172.  
  173. for i=1,1,1 do
  174. addRandomBlock(et, math.random(BLOCK_WIDTH, 800-BLOCK_WIDTH))
  175. end
  176. local blockY
  177. local floorY
  178. local players = tfm.get.room.playerList
  179. local b
  180.  
  181. local newBlockDat = {}
  182.  
  183. for i=1,#blockDat,1 do
  184. b = blockDat[i]
  185. blockY = particleY(b.y, (et - b.spawnTime) / 1000.0)
  186. floorY = getFloorYAt(b, blockY)
  187. if (b.miceCollision and blockY + b.height/2 >= floorY - MOUSE_HEIGHT ) then
  188. for p,v in pairs(alivePlayers) do
  189. if (floorY-MOUSE_HEIGHT<=players[p].y-MOUSE_HEIGHT/2 and floorY>=players[p].y+MOUSE_HEIGHT/2-5 and players[p].x >= b.a1 and players[p].x <= b.a2) then
  190. tfm.exec.killPlayer(p)
  191. end
  192. end
  193. end
  194. if (blockY >= floorY-b.height/2) then
  195. freezeBlock(b, floorY-b.height/2)
  196. else
  197. table.insert(newBlockDat, b)
  198. end
  199. end
  200. blockDat = newBlockDat
  201. if (N_SPAWNED_BLOCKS == 60 or rt <= 500 or N_ALIVE_PLAYERS == 0) then
  202. tfm.exec.setGameTime(500, true)
  203. tfm.exec.newGame("@6630519")
  204. end
  205. end
  206.  
  207. --[[---------------------------
  208. * Actual code
  209. --]]---------------------------
  210. function main()
  211. tfm.exec.disableAutoNewGame(true)
  212. tfm.exec.disableAutoShaman(true)
  213. tfm.exec.disablePhysicalConsumables(true)
  214. tfm.exec.disableAfkDeath(true)
  215. tfm.exec.disableAutoScore(true)
  216. tfm.exec.newGame("@6630519")
  217.  
  218. end
  219. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement