Advertisement
extremq

Untitled

Dec 25th, 2020
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.86 KB | None | 0 0
  1. function split(s,t) local r={}; for p in string.gmatch(s,"[^"..t.."]+") do table.insert(r,p); end;return r;end
  2.  
  3. GROUNDS = 70
  4.  
  5. function GenerateXML()
  6.  
  7.  
  8. local n = GROUNDS
  9. local xml = ""
  10. local r = 0
  11. local L = 40;
  12. local X, Y, Y1, Y2, H1, H2;
  13. local s
  14. local TT = { 11}
  15. local T = TT[math.random(#TT)]
  16. local R = {}
  17. local a
  18. local rst = 0
  19. local fr = 0
  20. maplength = n * 150 + 400
  21. local gap = 150
  22.  
  23. tfm.exec.chatMessage("<R>#" .. tostring(SEED) .. " ground:" .. tostring(T),"sharpiepoops")
  24.  
  25. -- start xml, random bg, with spawn ground,
  26. -- local bg = 'D="'
  27. -- local fg = 'd="'
  28. -- for i = 0, maplength, 800 do
  29. -- bg = bg..string.format('x_transformice/x_maps/x_halloween2015/jardin-citrouilles.jpg,%d,%d;', i, 0)
  30. -- fg = fg..string.format('x_transformice/x_maps/x_halloween2015/jardin-citrouilles-fg.png,%d,%d;',i, 293)
  31. -- end
  32. -- bg = bg .. '"'
  33. -- 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)
  34. 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)
  35. xml = xml .. s
  36. local oTag = ''
  37.  
  38. bonuses = {}
  39. fg1 = {}
  40. fg2 = {}
  41. for i = 0,n-1,1 do
  42. -- Pick a random number
  43. r = math.random(-100, 100)
  44.  
  45. -- X value of this ground
  46. X = 300 + (i * 150)
  47.  
  48. -- Upper ground:
  49. -- Height
  50. H1 = r + 100
  51. Y1 = H1 / 2
  52.  
  53. -- Lower ground:
  54. H2 = 400 - (H1+100)
  55. Y2 = H1 + gap + H2/2
  56.  
  57. -- hmm, nudge up
  58. Y1 = Y1 - 20
  59. Y2 = Y2 - 20
  60.  
  61. -- nudge height to make it easier towards the start
  62. -- H1 = H1 - (n-i)
  63. -- H2 = H2 - (n-i)
  64.  
  65. bonuses[#bonuses + 1] = {X, Y1 + H1/2 + (Y2 - H2/2 - Y1 - H1/2)/2}
  66. fg1[#fg1 + 1] = {X-25, Y1 + H1/2 - 407}
  67. fg2[#fg2 + 1] = {X-25, Y2 - H2/2}
  68. --local bonus = string.format('<O C="6" X="%d" Y="%d" P="0" />',X,Y1 + H1/2 + (Y2 - H2/2 - Y1 - H1/2)/2)
  69. --oTag = oTag .. bonus
  70.  
  71. -- Generate angle, and add upper ground (NOT NEEDED ANYMORE)
  72. a = 180
  73.  
  74. --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)
  75. --xml = xml .. s
  76. --fg = fg..string.format('x_transformice/x_maps/x_halloween2015/ronces'..math.random(1,2)..'.png,%d,%d;',X-25, Y1 + H1/2 - 407)
  77.  
  78. -- add acid underneath
  79. 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)
  80. xml = xml .. s
  81.  
  82. -- Generate angle, and add lower ground
  83. a = 0
  84.  
  85. -- Last ground, rest and angle 0
  86. --if i==n-1 then
  87. -- rst = 0
  88. -- a = 0
  89. -- T = 6
  90. -- fr = 0.3
  91. -- end
  92.  
  93.  
  94. --fg = fg..string.format('x_transformice/x_maps/x_halloween2015/ronces'..math.random(1,2)..'.png,%d,%d;',X-25, Y2 - H2/2)
  95. -- 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)
  96. -- xml = xml .. s
  97. -- add acid underneath
  98. 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)
  99. xml = xml .. s
  100.  
  101.  
  102. L = L + 1.5
  103.  
  104. -- textarea width
  105. local taw = 12;
  106. if i+1>=10 then
  107. taw = 20
  108. end
  109.  
  110. gap = gap - 1
  111. if gap < 130 then gap = 130 end
  112. --ui.addTextArea(100+i, tostring(i+1), nil, X-taw/2, 26, taw, 16, 0x010101, 0xffffff, 0.5, false)
  113.  
  114. -- table.insert(R,r)
  115. end
  116. --fg = fg..'" '
  117. xml = string.gsub(xml,'replaceMe','')
  118. xml = xml .. '</S><D>'
  119.  
  120. -- mouse spawn
  121. xml = xml .. '<DS X="50" Y="300" />'
  122.  
  123. -- holes and cheeses
  124. for i = 0,19,1 do
  125. xml = xml .. string.format('<T X="%d" Y="%d" />', maplength-100, 30 + i*20)
  126. end
  127. for i = 0,18,1 do
  128. xml = xml .. string.format('<F X="%d" Y="%d" />', maplength-100, 20 + i*21)
  129. end
  130.  
  131. xml = xml .. '</D><O>'..oTag
  132.  
  133. -- for i = 0,n-1,1 do
  134. -- X = 300 + (i * 200)
  135. -- Y =
  136.  
  137. -- xml = xml .. s
  138. -- end
  139.  
  140. xml = xml .. '</O></Z></C>'
  141.  
  142. return xml
  143. end
  144.  
  145. local gameTime = 60 * 10
  146. local freezePlayer = tfm.exec.freezePlayer
  147. local playerScore = {}
  148. local bindKeyboard = tfm.exec.bindKeyboard
  149. local bindMouse = system.bindMouse
  150. local setPlayerScore = tfm.exec.setPlayerScore
  151. local chatMessage = tfm.exec.chatMessage
  152. local addImage = tfm.exec.addImage
  153. local removeImage = tfm.exec.removeImage
  154. local room = tfm.get.room
  155. local random = math.random
  156. local movePlayer = tfm.exec.movePlayer
  157. local respawnPlayer = tfm.exec.respawnPlayer
  158. local displayParticle = tfm.exec.displayParticle
  159. local giveCheese = tfm.exec.giveCheese
  160. local removeCheese = tfm.exec.removeCheese
  161. local killPlayer = tfm.exec.killPlayer
  162.  
  163. local SEED = math.random(100000)
  164. math.randomseed(SEED)
  165.  
  166. function bind(p)
  167. bindKeyboard(p,32, true,true)
  168. bindKeyboard(p,1, true,true)
  169. bindMouse(p,true)
  170. end
  171.  
  172. function unbind(p)
  173. bindKeyboard(p,32,true,false)
  174. bindKeyboard(p,1,true,false)
  175. bindMouse(p,false)
  176. end
  177.  
  178. local imgs = {"17690e050cf.png", "17690e07927.png"}
  179. function initMap(p)
  180. for i = 0, maplength, 800 do
  181. addImage("1768ecb306f.png", "?1", i, 0, p)
  182. end
  183. for i = 1, #fg1 do
  184. addImage(imgs[random(#imgs)], '!100', fg1[i][1], fg1[i][2], p)
  185. addImage(imgs[random(#imgs)], '!100', fg2[i][1], fg2[i][2], p)
  186. end
  187. end
  188.  
  189. -- initCandies is not used
  190. local plrBonusImg = {}
  191. local plrMaxCandy = {}
  192. function initCandies(p)
  193. if not plrBonusImg[p] then plrBonusImg[p] = {} end
  194. if not plrMaxCandy[p] then plrMaxCandy[p] = #bonuses end
  195. for i = 1, plrMaxCandy[p] do
  196. if not plrBonusImg[p][i] then
  197. plrBonusImg[p][i] = addImage("1768226c79e.png", '!100', bonuses[i][1] - 10, bonuses[i][2] - 12, p)
  198. end
  199. end
  200. end
  201.  
  202. function initBonuses(p)
  203. for i = 1, #bonuses do
  204. tfm.exec.addBonus(0, bonuses[i][1], bonuses[i][2], i, 0, true, p)
  205. end
  206. end
  207.  
  208. local ended = false
  209. function endGame()
  210. -- Get scores and put them into topPlayers
  211. ended = true
  212.  
  213. local topPlayers = {}
  214. for p,_ in pairs(playerScore) do
  215. topPlayers[#topPlayers + 1] = {p, playerScore[p]}
  216. playerScore[p] = 0
  217. unbind(p)
  218. end
  219.  
  220. -- Sort the scores
  221. table.sort(topPlayers, function(a, b)
  222. return a[2] > b[2]
  223. end)
  224.  
  225. if topPlayers[1][2] ~= 0 then
  226. chatMessage('<i><R>Congratulations, winners!</r></i>')
  227. local colorTags = {"font color='#ffd700'", "font color='#c0c0c0'", "font color='#cd7f32'", "font color='#cd7f32'", "font color='#cd7f32'", "font color='#cd7f32'"}
  228. for i = 1, 6 do
  229. if topPlayers[i] then
  230. if topPlayers[i][2] ~= 0 then
  231. chatMessage('<'..colorTags[i]..'>'..i..'. '..topPlayers[i][1]..' - '..topPlayers[i][2]..'</'..colorTags[i]..'>')
  232. 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])
  233. end
  234. end
  235. end
  236. end
  237.  
  238. tfm.exec.setGameTime(gameTime,true)
  239. tfm.exec.setUIMapName('<R>Flappymouse: #' .. tostring(SEED))
  240.  
  241. end
  242.  
  243. function fly(p)
  244. if room.playerList[p].y < 0 then
  245. killPlayer(p)
  246. chatMessage("<ROSE><b>Don't.</b></ROSE>", p)
  247. end
  248. tfm.exec.movePlayer(p,0,0,true,0,-100,false)
  249. tfm.exec.movePlayer(p,0,0,true,45,0,false)
  250. end
  251.  
  252. function eventMouse(p,x,y)
  253. fly(p)
  254. end
  255. function eventKeyboard(p, k)
  256. if k==32 or k == 1 then
  257. fly(p)
  258. end
  259. end
  260.  
  261. local time = os.time
  262. local lastRevival = time()
  263. local lastPrint = time()
  264. function eventLoop(t,r)
  265. if ended == false then
  266. if r < 3 then
  267. endGame()
  268. tfm.exec.newGame(0)
  269. end
  270. local currentTime = time()
  271. if currentTime - lastRevival > 5 * 1000 then
  272. lastRevival = currentTime
  273. for p,P in pairs(room.playerList) do
  274. movePlayer(p,0,0,true,45,0,false)
  275. end
  276. end
  277. if currentTime - lastPrint > 60 * 1000 then
  278. lastPrint = currentTime
  279. local topPlayers = {}
  280. for p,_ in pairs(playerScore) do
  281. topPlayers[#topPlayers + 1] = {p, playerScore[p]}
  282. end
  283.  
  284. table.sort(topPlayers, function(a, b)
  285. return a[2] > b[2]
  286. end)
  287.  
  288. chatMessage('Current Scores: ')
  289. for i = 1, 6 do
  290. if topPlayers[i] then
  291. if topPlayers[i][2] ~= 0 then
  292. chatMessage(''..i..'. '..topPlayers[i][1]..' - '..topPlayers[i][2]..'')
  293. end
  294. end
  295. end
  296. end
  297. end
  298. end
  299.  
  300. tfm.exec.disableAutoTimeLeft(true)
  301. tfm.exec.disableAutoNewGame(true)
  302. tfm.exec.disableAutoShaman(true)
  303. tfm.exec.disableAutoScore(true)
  304. tfm.exec.disableAfkDeath(true)
  305. tfm.exec.setRoomMaxPlayers(50)
  306. tfm.exec.newGame(GenerateXML())
  307. tfm.exec.setGameTime(gameTime,true)
  308. tfm.exec.setUIMapName('<R>Flappymouse: #' .. tostring(SEED))
  309.  
  310. plrImg = {}
  311. function eventNewPlayer(p)
  312. chatMessage('<J>Welcome to <VP>Flappymouse - Christmas edition<J>! Made by Sharpiepoops#0020, edited by Extremq#0000.', p)
  313. chatMessage("<J>Fly using <VP>SPACE, CLICK or UP</VP>.", p)
  314.  
  315. bind(p)
  316. if not playerScore[p] then
  317. playerScore[p] = 0
  318. end
  319.  
  320. initMap(p)
  321. initBonuses(p)
  322. -- initCandies(p)
  323.  
  324. respawnPlayer(p)
  325. freezePlayer(p)
  326. plrImg[p] = addImage("176820cd5b9.png", "%"..p, -30, -50)
  327. end
  328.  
  329. function eventPlayerLeft(p)
  330. plrImg[p] = nil
  331. -- plrBonusImg[p] = nil
  332. -- plrMaxCandy[p] = nil
  333. end
  334.  
  335. function eventPlayerDied(p)
  336. respawnPlayer(p)
  337. end
  338.  
  339. function eventPlayerWon(p)
  340. respawnPlayer(p)
  341. end
  342.  
  343. function eventPlayerRespawn(p)
  344. freezePlayer(p)
  345. if plrImg[p] then
  346. removeImage(plrImg[p])
  347. end
  348. plrImg[p] = addImage("176820cd5b9.png", "%"..p, -30, -50)
  349. -- initCandies(p)
  350. end
  351.  
  352. function eventPlayerWon(p)
  353. playerScore[p] = playerScore[p] + 150
  354. if p:sub(1,1) == "*" then
  355. playerScore[p] = 0
  356. end
  357. chatMessage('<J>' .. p .. '<VP> finished the map!')
  358. end
  359.  
  360. function eventPlayerBonusGrabbed(p, bonusId)
  361. if not playerScore[p] then
  362. playerScore[p] = 0
  363. end
  364. playerScore[p] = playerScore[p] + 1
  365. if p:sub(1,1) == "*" then
  366. playerScore[p] = 0
  367. end
  368. plrMaxCandy[p] = tonumber(bonusId)
  369. setPlayerScore(p, playerScore[p])
  370. -- removeImage(plrBonusImg[p][bonusId])
  371. -- plrBonusImg[p][bonusId] = nil
  372. -- local x, y = bonuses[bonusId][1], bonuses[bonusId][2]
  373. -- displayParticle(29, x, y, 0.25 + random(0, 1), -0.25 - random(0, 1), 0, 0, p)
  374. -- displayParticle(29, x, y, -0.25 - random(0, 1), 0.25 + random(0, 1), 0, 0, p)
  375. -- displayParticle(29, x, y, -0.25 - random(0, 1), -0.25 - random(0, 1), 0, 0, p)
  376. -- displayParticle(29, x, y, 0.25 + random(0, 1), 0.25 + random(0, 1), 0, 0, p)
  377. end
  378.  
  379. for p, _ in pairs(room.playerList) do
  380. eventNewPlayer(p)
  381. setPlayerScore(p, 0)
  382. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement