Advertisement
extremq

Untitled

Dec 25th, 2020
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.73 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 < 120 then gap = 120 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. local plrBonusImg = {}
  190. local plrMaxCandy = {}
  191. function initCandies(p)
  192. if not plrBonusImg[p] then plrBonusImg[p] = {} end
  193. if not plrMaxCandy[p] then plrMaxCandy[p] = #bonuses end
  194. for i = 1, plrMaxCandy[p] do
  195. if not plrBonusImg[p][i] then
  196. plrBonusImg[p][i] = addImage("1768226c79e.png", '!100', bonuses[i][1] - 10, bonuses[i][2] - 12, p)
  197. end
  198. end
  199. end
  200.  
  201. function initBonuses(p)
  202. for i = 1, #bonuses do
  203. tfm.exec.addBonus(0, bonuses[i][1], bonuses[i][2], i, 0, false, p)
  204. end
  205. end
  206.  
  207. local ended = false
  208. function endGame()
  209. -- Get scores and put them into topPlayers
  210. ended = true
  211.  
  212. local topPlayers = {}
  213. for p,_ in pairs(playerScore) do
  214. topPlayers[#topPlayers + 1] = {p, playerScore[p]}
  215. playerScore[p] = 0
  216. unbind(p)
  217. end
  218.  
  219. -- Sort the scores
  220. table.sort(topPlayers, function(a, b)
  221. return a[2] > b[2]
  222. end)
  223.  
  224. if topPlayers[1][2] ~= 0 then
  225. chatMessage('<i><R>Congratulations, winners!</r></i>')
  226. local colorTags = {"font color='#ffd700'", "font color='#c0c0c0'", "font color='#cd7f32'", "font color='#cd7f32'", "font color='#cd7f32'", "font color='#cd7f32'"}
  227. for i = 1, 6 do
  228. if topPlayers[i] then
  229. if topPlayers[i][2] ~= 0 then
  230. chatMessage('<'..colorTags[i]..'>'..i..'. '..topPlayers[i][1]..' - '..topPlayers[i][2]..'</'..colorTags[i]..'>')
  231. 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])
  232. end
  233. end
  234. end
  235. end
  236.  
  237. tfm.exec.setGameTime(gameTime,true)
  238. tfm.exec.setUIMapName('<R>Flappymouse: #' .. tostring(SEED))
  239.  
  240. end
  241.  
  242. function fly(p)
  243. if room.playerList[p].y < 0 then
  244. killPlayer(p)
  245. chatMessage("<ROSE><b>Don't.</b></ROSE>", p)
  246. end
  247. tfm.exec.movePlayer(p,0,0,true,0,-100,false)
  248. tfm.exec.movePlayer(p,0,0,true,45,0,false)
  249. end
  250.  
  251. function eventMouse(p,x,y)
  252. fly(p)
  253. end
  254. function eventKeyboard(p, k)
  255. if k==32 or k == 1 then
  256. fly(p)
  257. end
  258. end
  259.  
  260. local time = os.time
  261. local lastRevival = time()
  262. local lastPrint = time()
  263. function eventLoop(t,r)
  264. if ended == false then
  265. if r < 3 then
  266. endGame()
  267. tfm.exec.newGame(0)
  268. end
  269. local currentTime = time()
  270. if currentTime - lastRevival > 5 * 1000 then
  271. lastRevival = currentTime
  272. for p,P in pairs(room.playerList) do
  273. movePlayer(p,0,0,true,45,0,false)
  274. end
  275. end
  276. if currentTime - lastPrint > 60 * 1000 then
  277. lastPrint = currentTime
  278. local topPlayers = {}
  279. for p,_ in pairs(playerScore) do
  280. topPlayers[#topPlayers + 1] = {p, playerScore[p]}
  281. end
  282.  
  283. table.sort(topPlayers, function(a, b)
  284. return a[2] > b[2]
  285. end)
  286.  
  287. chatMessage('Current Scores: ')
  288. for i = 1, 6 do
  289. if topPlayers[i] then
  290. if topPlayers[i][2] ~= 0 then
  291. chatMessage(''..i..'. '..topPlayers[i][1]..' - '..topPlayers[i][2]..'')
  292. end
  293. end
  294. end
  295. end
  296. end
  297. end
  298.  
  299. tfm.exec.disableAutoTimeLeft(true)
  300. tfm.exec.disableAutoNewGame(true)
  301. tfm.exec.disableAutoShaman(true)
  302. tfm.exec.disableAutoScore(true)
  303. tfm.exec.disableAfkDeath(true)
  304. tfm.exec.setRoomMaxPlayers(50)
  305. tfm.exec.newGame(GenerateXML())
  306. tfm.exec.setGameTime(gameTime,true)
  307. tfm.exec.setUIMapName('<R>Flappymouse: #' .. tostring(SEED))
  308.  
  309. plrImg = {}
  310. function eventNewPlayer(p)
  311. chatMessage('<J>Welcome to <VP>Flappymouse - Christmas edition<J>! Made by Sharpiepoops#0020, edited by Extremq#0000.', p)
  312. chatMessage("<J>Fly using <VP>SPACE, CLICK or UP</VP>.", p)
  313.  
  314. bind(p)
  315. if not playerScore[p] then
  316. playerScore[p] = 0
  317. end
  318.  
  319. initMap(p)
  320. initCandies(p)
  321. initBonuses(p)
  322.  
  323. freezePlayer(p)
  324. plrImg[p] = addImage("176820cd5b9.png", "%"..p, -30, -50)
  325. end
  326.  
  327. function eventPlayerLeft(p)
  328. plrImg[p] = nil
  329. plrBonusImg[p] = nil
  330. plrMaxCandy[p] = nil
  331. end
  332.  
  333. function eventPlayerDied(p)
  334. respawnPlayer(p)
  335. end
  336.  
  337. function eventPlayerRespawn(p)
  338. freezePlayer(p)
  339. if plrImg[p] then
  340. removeImage(plrImg[p])
  341. end
  342. plrImg[p] = addImage("176820cd5b9.png", "%"..p, -30, -50)
  343. initCandies(p)
  344. end
  345.  
  346. function eventPlayerWon(p)
  347. playerScore[p] = playerScore[p] + 150
  348. if p:sub(1,1) == "*" then
  349. playerScore[p] = 0
  350. end
  351. chatMessage('<J>' .. p .. '<VP> finished the map!')
  352. end
  353.  
  354. function eventPlayerBonusGrabbed(p, bonusId)
  355. if not playerScore[p] then
  356. playerScore[p] = 0
  357. end
  358. playerScore[p] = playerScore[p] + 1
  359. if p:sub(1,1) == "*" then
  360. playerScore[p] = 0
  361. end
  362. plrMaxCandy[p] = tonumber(bonusId)
  363. setPlayerScore(p, playerScore[p])
  364. removeImage(plrBonusImg[p][bonusId])
  365. plrBonusImg[p][bonusId] = nil
  366. local x, y = bonuses[bonusId][1], bonuses[bonusId][2]
  367. displayParticle(29, x, y, 0.25 + random(0, 1), -0.25 - random(0, 1), 0, 0, p)
  368. displayParticle(29, x, y, -0.25 - random(0, 1), 0.25 + random(0, 1), 0, 0, p)
  369. displayParticle(29, x, y, -0.25 - random(0, 1), -0.25 - random(0, 1), 0, 0, p)
  370. displayParticle(29, x, y, 0.25 + random(0, 1), 0.25 + random(0, 1), 0, 0, p)
  371. end
  372.  
  373. for p, _ in pairs(room.playerList) do
  374. eventNewPlayer(p)
  375. setPlayerScore(p, 0)
  376. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement