Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function split(s,t) local r={}; for p in string.gmatch(s,"[^"..t.."]+") do table.insert(r,p); end;return r;end
- GROUNDS = 70
- function GenerateXML()
- local n = GROUNDS
- local xml = ""
- local r = 0
- local L = 40;
- local X, Y, Y1, Y2, H1, H2;
- local s
- local TT = { 11}
- local T = TT[math.random(#TT)]
- local R = {}
- local a
- local rst = 0
- local fr = 0
- maplength = n * 150 + 400
- local gap = 150
- tfm.exec.chatMessage("<R>#" .. tostring(SEED) .. " ground:" .. tostring(T),"sharpiepoops")
- -- start xml, random bg, with spawn ground,
- -- local bg = 'D="'
- -- local fg = 'd="'
- -- for i = 0, maplength, 800 do
- -- bg = bg..string.format('x_transformice/x_maps/x_halloween2015/jardin-citrouilles.jpg,%d,%d;', i, 0)
- -- fg = fg..string.format('x_transformice/x_maps/x_halloween2015/jardin-citrouilles-fg.png,%d,%d;',i, 293)
- -- end
- -- bg = bg .. '"'
- -- s = string.format('<C><P replaceMe '..bg..' G="0, 30" Ca="" L="%d" defilante="0,0,0,1" /><Z><S><S X="40" Y="350" H="100" L="80" T="%d" P="0,0,9999,0,0,0,0,0" />', maplength, T)
- s = string.format('<C><P replaceMe G="0, 30" Ca="" L="%d" defilante="0,0,0,1" /><Z><S><S X="40" Y="350" H="100" L="80" T="%d" P="0,0,9999,0,0,0,0,0" />', maplength, T)
- xml = xml .. s
- local oTag = ''
- bonuses = {}
- fg1 = {}
- fg2 = {}
- for i = 0,n-1,1 do
- -- Pick a random number
- r = math.random(-100, 100)
- -- X value of this ground
- X = 300 + (i * 150)
- -- Upper ground:
- -- Height
- H1 = r + 100
- Y1 = H1 / 2
- -- Lower ground:
- H2 = 400 - (H1+100)
- Y2 = H1 + gap + H2/2
- -- hmm, nudge up
- Y1 = Y1 - 20
- Y2 = Y2 - 20
- -- nudge height to make it easier towards the start
- -- H1 = H1 - (n-i)
- -- H2 = H2 - (n-i)
- bonuses[#bonuses + 1] = {X, Y1 + H1/2 + (Y2 - H2/2 - Y1 - H1/2)/2}
- fg1[#fg1 + 1] = {X-25, Y1 + H1/2 - 407}
- fg2[#fg2 + 1] = {X-25, Y2 - H2/2}
- --local bonus = string.format('<O C="6" X="%d" Y="%d" P="0" />',X,Y1 + H1/2 + (Y2 - H2/2 - Y1 - H1/2)/2)
- --oTag = oTag .. bonus
- -- Generate angle, and add upper ground (NOT NEEDED ANYMORE)
- a = 180
- --s = string.format('<S T="%d" P="0,0,%d,%d,%d,0,0,0" X="%d" Y="%d" L="%d" H="%d" c="2"/>',T,fr,rst,a,X,Y1,math.floor(L/40)*40,H1)
- --xml = xml .. s
- --fg = fg..string.format('x_transformice/x_maps/x_halloween2015/ronces'..math.random(1,2)..'.png,%d,%d;',X-25, Y1 + H1/2 - 407)
- -- add acid underneath
- s = string.format('<S T="%d" P="0,0,%d,%d,%d,0,0,0" X="%d" Y="%d" L="%d" H="%d" m=""/>',19,fr,rst,a,X,Y1,50,H1)
- xml = xml .. s
- -- Generate angle, and add lower ground
- a = 0
- -- Last ground, rest and angle 0
- --if i==n-1 then
- -- rst = 0
- -- a = 0
- -- T = 6
- -- fr = 0.3
- -- end
- --fg = fg..string.format('x_transformice/x_maps/x_halloween2015/ronces'..math.random(1,2)..'.png,%d,%d;',X-25, Y2 - H2/2)
- -- s = string.format('<S T="%d" P="0,0,%d,%d,%d,0,0,0" X="%d" Y="%d" L="%d" H="%d" c="2"/>',T,fr,rst,a,X,Y2,math.floor(L/40)*40,H2)
- -- xml = xml .. s
- -- add acid underneath
- s = string.format('<S T="%d" P="0,0,%d,%d,%d,0,0,0" X="%d" Y="%d" L="%d" H="%d" m=""/>',19,fr,rst,a,X,Y2,50,H2)
- xml = xml .. s
- L = L + 1.5
- -- textarea width
- local taw = 12;
- if i+1>=10 then
- taw = 20
- end
- gap = gap - 1
- if gap < 120 then gap = 120 end
- --ui.addTextArea(100+i, tostring(i+1), nil, X-taw/2, 26, taw, 16, 0x010101, 0xffffff, 0.5, false)
- -- table.insert(R,r)
- end
- --fg = fg..'" '
- xml = string.gsub(xml,'replaceMe','')
- xml = xml .. '</S><D>'
- -- mouse spawn
- xml = xml .. '<DS X="50" Y="300" />'
- -- holes and cheeses
- for i = 0,19,1 do
- xml = xml .. string.format('<T X="%d" Y="%d" />', maplength-100, 30 + i*20)
- end
- for i = 0,18,1 do
- xml = xml .. string.format('<F X="%d" Y="%d" />', maplength-100, 20 + i*21)
- end
- xml = xml .. '</D><O>'..oTag
- -- for i = 0,n-1,1 do
- -- X = 300 + (i * 200)
- -- Y =
- -- xml = xml .. s
- -- end
- xml = xml .. '</O></Z></C>'
- return xml
- end
- local gameTime = 60 * 10
- local freezePlayer = tfm.exec.freezePlayer
- local playerScore = {}
- local bindKeyboard = tfm.exec.bindKeyboard
- local bindMouse = system.bindMouse
- local setPlayerScore = tfm.exec.setPlayerScore
- local chatMessage = tfm.exec.chatMessage
- local addImage = tfm.exec.addImage
- local removeImage = tfm.exec.removeImage
- local room = tfm.get.room
- local random = math.random
- local movePlayer = tfm.exec.movePlayer
- local respawnPlayer = tfm.exec.respawnPlayer
- local displayParticle = tfm.exec.displayParticle
- local giveCheese = tfm.exec.giveCheese
- local removeCheese = tfm.exec.removeCheese
- local killPlayer = tfm.exec.killPlayer
- local SEED = math.random(100000)
- math.randomseed(SEED)
- function bind(p)
- bindKeyboard(p,32, true,true)
- bindKeyboard(p,1, true,true)
- bindMouse(p,true)
- end
- function unbind(p)
- bindKeyboard(p,32,true,false)
- bindKeyboard(p,1,true,false)
- bindMouse(p,false)
- end
- local imgs = {"17690e050cf.png", "17690e07927.png"}
- function initMap(p)
- for i = 0, maplength, 800 do
- addImage("1768ecb306f.png", "?1", i, 0, p)
- end
- for i = 1, #fg1 do
- addImage(imgs[random(#imgs)], '!100', fg1[i][1], fg1[i][2], p)
- addImage(imgs[random(#imgs)], '!100', fg2[i][1], fg2[i][2], p)
- end
- end
- local plrBonusImg = {}
- local plrMaxCandy = {}
- function initCandies(p)
- if not plrBonusImg[p] then plrBonusImg[p] = {} end
- if not plrMaxCandy[p] then plrMaxCandy[p] = #bonuses end
- for i = 1, plrMaxCandy[p] do
- if not plrBonusImg[p][i] then
- plrBonusImg[p][i] = addImage("1768226c79e.png", '!100', bonuses[i][1] - 10, bonuses[i][2] - 12, p)
- end
- end
- end
- function initBonuses(p)
- for i = 1, #bonuses do
- tfm.exec.addBonus(0, bonuses[i][1], bonuses[i][2], i, 0, false, p)
- end
- end
- local ended = false
- function endGame()
- -- Get scores and put them into topPlayers
- ended = true
- local topPlayers = {}
- for p,_ in pairs(playerScore) do
- topPlayers[#topPlayers + 1] = {p, playerScore[p]}
- playerScore[p] = 0
- unbind(p)
- end
- -- Sort the scores
- table.sort(topPlayers, function(a, b)
- return a[2] > b[2]
- end)
- if topPlayers[1][2] ~= 0 then
- chatMessage('<i><R>Congratulations, winners!</r></i>')
- local colorTags = {"font color='#ffd700'", "font color='#c0c0c0'", "font color='#cd7f32'", "font color='#cd7f32'", "font color='#cd7f32'", "font color='#cd7f32'"}
- for i = 1, 6 do
- if topPlayers[i] then
- if topPlayers[i][2] ~= 0 then
- chatMessage('<'..colorTags[i]..'>'..i..'. '..topPlayers[i][1]..' - '..topPlayers[i][2]..'</'..colorTags[i]..'>')
- chatMessage("Ho ho ho! Congratulations, you've won the event map!\nMake sure you'll check your inbox the next few weeks for the cheese codes.\nWe wish you a merry Christmas and a Happy New Year!", topPlayers[i][1])
- end
- end
- end
- end
- tfm.exec.setGameTime(gameTime,true)
- tfm.exec.setUIMapName('<R>Flappymouse: #' .. tostring(SEED))
- end
- function fly(p)
- if room.playerList[p].y < 0 then
- killPlayer(p)
- chatMessage("<ROSE><b>Don't.</b></ROSE>", p)
- end
- tfm.exec.movePlayer(p,0,0,true,0,-100,false)
- tfm.exec.movePlayer(p,0,0,true,45,0,false)
- end
- function eventMouse(p,x,y)
- fly(p)
- end
- function eventKeyboard(p, k)
- if k==32 or k == 1 then
- fly(p)
- end
- end
- local time = os.time
- local lastRevival = time()
- local lastPrint = time()
- function eventLoop(t,r)
- if ended == false then
- if r < 3 then
- endGame()
- tfm.exec.newGame(0)
- end
- local currentTime = time()
- if currentTime - lastRevival > 5 * 1000 then
- lastRevival = currentTime
- for p,P in pairs(room.playerList) do
- movePlayer(p,0,0,true,45,0,false)
- end
- end
- if currentTime - lastPrint > 60 * 1000 then
- lastPrint = currentTime
- local topPlayers = {}
- for p,_ in pairs(playerScore) do
- topPlayers[#topPlayers + 1] = {p, playerScore[p]}
- end
- table.sort(topPlayers, function(a, b)
- return a[2] > b[2]
- end)
- chatMessage('Current Scores: ')
- for i = 1, 6 do
- if topPlayers[i] then
- if topPlayers[i][2] ~= 0 then
- chatMessage(''..i..'. '..topPlayers[i][1]..' - '..topPlayers[i][2]..'')
- end
- end
- end
- end
- end
- end
- tfm.exec.disableAutoTimeLeft(true)
- tfm.exec.disableAutoNewGame(true)
- tfm.exec.disableAutoShaman(true)
- tfm.exec.disableAutoScore(true)
- tfm.exec.disableAfkDeath(true)
- tfm.exec.setRoomMaxPlayers(50)
- tfm.exec.newGame(GenerateXML())
- tfm.exec.setGameTime(gameTime,true)
- tfm.exec.setUIMapName('<R>Flappymouse: #' .. tostring(SEED))
- plrImg = {}
- function eventNewPlayer(p)
- chatMessage('<J>Welcome to <VP>Flappymouse - Christmas edition<J>! Made by Sharpiepoops#0020, edited by Extremq#0000.', p)
- chatMessage("<J>Fly using <VP>SPACE, CLICK or UP</VP>.", p)
- bind(p)
- if not playerScore[p] then
- playerScore[p] = 0
- end
- initMap(p)
- initCandies(p)
- initBonuses(p)
- freezePlayer(p)
- plrImg[p] = addImage("176820cd5b9.png", "%"..p, -30, -50)
- end
- function eventPlayerLeft(p)
- plrImg[p] = nil
- plrBonusImg[p] = nil
- plrMaxCandy[p] = nil
- end
- function eventPlayerDied(p)
- respawnPlayer(p)
- end
- function eventPlayerRespawn(p)
- freezePlayer(p)
- if plrImg[p] then
- removeImage(plrImg[p])
- end
- plrImg[p] = addImage("176820cd5b9.png", "%"..p, -30, -50)
- initCandies(p)
- end
- function eventPlayerWon(p)
- playerScore[p] = playerScore[p] + 150
- if p:sub(1,1) == "*" then
- playerScore[p] = 0
- end
- chatMessage('<J>' .. p .. '<VP> finished the map!')
- end
- function eventPlayerBonusGrabbed(p, bonusId)
- if not playerScore[p] then
- playerScore[p] = 0
- end
- playerScore[p] = playerScore[p] + 1
- if p:sub(1,1) == "*" then
- playerScore[p] = 0
- end
- plrMaxCandy[p] = tonumber(bonusId)
- setPlayerScore(p, playerScore[p])
- removeImage(plrBonusImg[p][bonusId])
- plrBonusImg[p][bonusId] = nil
- local x, y = bonuses[bonusId][1], bonuses[bonusId][2]
- displayParticle(29, x, y, 0.25 + random(0, 1), -0.25 - random(0, 1), 0, 0, p)
- displayParticle(29, x, y, -0.25 - random(0, 1), 0.25 + random(0, 1), 0, 0, p)
- displayParticle(29, x, y, -0.25 - random(0, 1), -0.25 - random(0, 1), 0, 0, p)
- displayParticle(29, x, y, 0.25 + random(0, 1), 0.25 + random(0, 1), 0, 0, p)
- end
- for p, _ in pairs(room.playerList) do
- eventNewPlayer(p)
- setPlayerScore(p, 0)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement