Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[===========================
- ** Tetris
- By Feoxys
- --]]---------------------------
- --[[---------------------------
- * Database
- --]]---------------------------
- local admin = "Boredofme#1332"
- local MAP_TIME = 90
- local MOUSE_HEIGHT = 40
- local BLOCK_WIDTH = 60
- local BLOCK_HEIGHT = 40
- local BLOCK_START_Y = -1200--
- local BLOCK_PROPERTIES = {
- {id = 0, f = 0.3, r = 0.2, mc = true },
- {id = 1, f = 0, r = 0.2, mc = true },
- {id = 2, f = 0, r = 1.2, mc = true},
- {id = 3, f = 0.2, r = 20, mc = true },
- {id = 4, f = 20, r = 0.3, mc = true },
- {id = 5, f = 0.3, r = 0.2, mc = true },
- {id = 6, f = 0.3, r = 0.2, mc = true },
- {id = 7, f = 0.1, r = 0.2, mc = true },
- --{id = 8, f = 0.3, r = 0.2, mc = false },
- {id = 9, f = 0.1, r = 0.2, mc = false },
- {id = 10, f = 0.3, r = 0, mc = true },
- {id = 11, f = 0.05, r = 0.1, mc = true },
- --{id = 15, f = 0.3, r = 0.1, mc = false }
- }
- local alivePlayers = {}
- local blockDat = {}
- local AABBsMask = {}
- local startTime
- local N_SPAWNED_BLOCKS = 0
- local N_ALIVE_PLAYERS = 0
- --[[---------------------------
- * Miscs functions
- --]]---------------------------
- -- Allow to call a function from a string
- function pfuncall(str, ...)
- if not pcall(_G[str], arg) then
- print("Failed to call function '"..str.."' from string.") -- Error handling
- end
- end
- --[[---------------------------
- * Script functions
- --]]---------------------------
- function registerBlockDat(i, l, x, y, w, h, t, f, r, mc)
- 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 }
- end
- function spawnBlock(b, st)
- b.state = 1
- b.spawnTime = st
- tfm.exec.addPhysicObject(b.id, b.x, b.y,
- {type = b.type,
- width = b.width,
- height = b.height,
- restitution = 0,
- friction = b.friction,
- mass = 1081343,
- miceCollision = b.miceCollision,
- groundCollision = true,
- dynamic = true,
- fixedRotation = true,
- linearDamping = b.linearDamping})
- end
- function freezeBlock(b, blockY)
- b.state = 2
- b.y = blockY
- b.b1 = b.y-b.height/2
- b.b2 = b.y+b.height/2
- tfm.exec.addPhysicObject(b.id, b.x, b.y,
- {type = b.type,
- width = b.width,
- height = b.height,
- restitution = 0,
- friction = 0,--b.friction,
- miceCollision = false,
- groundCollision = true,
- dynamic = false,
- fixedRotation = true})
- if (b.miceCollision) then
- tfm.exec.addPhysicObject(b.id+1000, b.x, b.y,
- {type = b.type,
- width = b.width,
- height = b.height,
- restitution = b.restitution,
- friction = b.friction,--b.friction,
- miceCollision = b.miceCollision,
- groundCollision = false,
- dynamic = false,
- fixedRotation = true})
- end
- table.insert(AABBsMask, 1, {b.a1, b.b1, b.a2, b.b2})
- end
- function particleY(startY, t)
- return startY + 100.0 * t * t
- end
- function getFloorYAt(b, blockY)
- local feed = 400-5
- for i=#AABBsMask,1,-1 do
- if (b.a1 < AABBsMask[i][3] and b.a2 > AABBsMask[i][1] and feed > AABBsMask[i][2]) then
- feed = AABBsMask[i][2]
- --break
- end
- end
- return feed;
- end
- function addRandomBlock(et, x)
- local p = BLOCK_PROPERTIES[math.random(1, #BLOCK_PROPERTIES)]
- N_SPAWNED_BLOCKS = N_SPAWNED_BLOCKS + 1
- registerBlockDat(N_SPAWNED_BLOCKS, 0, x, BLOCK_START_Y, BLOCK_WIDTH, BLOCK_HEIGHT, p.id, p.f, p.r, p.mc)
- spawnBlock(blockDat[#blockDat], et)
- end
- function dataFlush()
- alivePlayers = {}
- blockDat = {}
- AABBsMask = {}
- N_ALIVE_PLAYERS = 0
- N_SPAWNED_BLOCKS = 0
- end
- --[[---------------------------
- * Transformice built-in functions
- --]]---------------------------
- function eventNewGame()
- tfm.exec.setGameTime(MAP_TIME, true)
- startTime = os.time()
- dataFlush()
- for n,p in pairs(tfm.get.room.playerList) do
- eventPlayerRespawn(n)
- end
- end
- function eventNewPlayer(p)
- end
- function eventPlayerDied(p)
- system.bindMouse(p, true)
- alivePlayers[p] = nil
- N_ALIVE_PLAYERS = N_ALIVE_PLAYERS - 1
- newAlivePlayers = {}
- for n, b in pairs(alivePlayers) do
- newAlivePlayers[n] = true
- end
- alivePlayers = newAlivePlayers
- end
- function eventPlayerRespawn(p)
- system.bindMouse(p, true)
- alivePlayers[p] = true
- N_ALIVE_PLAYERS = N_ALIVE_PLAYERS + 1
- end
- function eventChatCommand(p, m)
- system.exit()
- end
- function eventMouse(p, x, y)
- addRandomBlock(os.time() - startTime, x)
- end
- function eventLoop(et, rt)
- for i=1,1,1 do
- addRandomBlock(et, math.random(BLOCK_WIDTH, 800-BLOCK_WIDTH))
- end
- local blockY
- local floorY
- local players = tfm.get.room.playerList
- local b
- local newBlockDat = {}
- for i=1,#blockDat,1 do
- b = blockDat[i]
- blockY = particleY(b.y, (et - b.spawnTime) / 1000.0)
- floorY = getFloorYAt(b, blockY)
- if (b.miceCollision and blockY + b.height/2 >= floorY - MOUSE_HEIGHT ) then
- for p,v in pairs(alivePlayers) do
- 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
- tfm.exec.killPlayer(p)
- end
- end
- end
- if (blockY >= floorY-b.height/2) then
- freezeBlock(b, floorY-b.height/2)
- else
- table.insert(newBlockDat, b)
- end
- end
- blockDat = newBlockDat
- if (N_SPAWNED_BLOCKS == 60 or rt <= 500 or N_ALIVE_PLAYERS == 0) then
- tfm.exec.setGameTime(500, true)
- tfm.exec.newGame("@6630519")
- end
- end
- --[[---------------------------
- * Actual code
- --]]---------------------------
- function main()
- tfm.exec.disableAutoNewGame(true)
- tfm.exec.disableAutoShaman(true)
- tfm.exec.disablePhysicalConsumables(true)
- tfm.exec.disableAfkDeath(true)
- tfm.exec.disableAutoScore(true)
- tfm.exec.newGame("@6630519")
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement