Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.97 KB | None | 0 0
  1. var Ball_601 = '{"name":"Ball","level":6,"model":1,"size":2.4,"zoom":0.5,"specs":{"shield":{"capacity":[10000,10000],"reload":[1000,1000]},"generator":{"capacity":[1,1],"reload":[1,1]},"ship":{"mass":200,"speed":[80,80],"rotation":[30,30],"acceleration":[60,60]}},"bodies":{"side1":{"section_segments":6,"angle":0,"offset":{"x":0,"y":0,"z":0},"position":{"x":[0,0,0,0,0,0,0,0,0,0],"y":[-80,-75,-60,-50,-30,0],"z":[0,0,0,0,0,0,0,0,0,0]},"width":[0,20,30,10,25,25],"height":[0,10,12,8,22,22],"texture":[16.8,63,0.9,10,17]},"side2":{"section_segments":6,"angle":60,"offset":{"x":0,"y":0,"z":0},"position":{"x":[0,0,0,0,0,0,0,0,0,0],"y":[-80,-75,-60,-50,-30,0],"z":[0,0,0,0,0,0,0,0,0,0]},"width":[0,20,30,10,25,25],"height":[0,10,12,8,22,22],"texture":[16.8,63,0.9,10,17]},"side3":{"section_segments":6,"angle":120,"offset":{"x":0,"y":0,"z":0},"position":{"x":[0,0,0,0,0,0,0,0,0,0],"y":[-80,-75,-60,-50,-30,0],"z":[0,0,0,0,0,0,0,0,0,0]},"width":[0,20,30,10,25,25],"height":[0,10,12,8,22,22],"texture":[16.8,63,0.9,10,17]},"side4":{"section_segments":6,"angle":180,"offset":{"x":0,"y":0,"z":0},"position":{"x":[0,0,0,0,0,0,0,0,0,0],"y":[-80,-75,-60,-50,-30,0],"z":[0,0,0,0,0,0,0,0,0,0]},"width":[0,20,30,10,25,25],"height":[0,10,12,8,22,22],"texture":[16.8,63,0.9,10,17]},"side5":{"section_segments":6,"angle":240,"offset":{"x":0,"y":0,"z":0},"position":{"x":[0,0,0,0,0,0,0,0,0,0],"y":[-80,-75,-60,-50,-30,0],"z":[0,0,0,0,0,0,0,0,0,0]},"width":[0,20,30,10,25,25],"height":[0,10,12,8,22,22],"texture":[16.8,63,0.9,10,17]},"side6":{"section_segments":6,"angle":300,"offset":{"x":0,"y":0,"z":0},"position":{"x":[0,0,0,0,0,0,0,0,0,0],"y":[-80,-75,-60,-50,-30,0],"z":[0,0,0,0,0,0,0,0,0,0]},"width":[0,20,30,10,25,25],"height":[0,10,12,8,22,22],"texture":[16.8,63,0.9,10,17]},"side7":{"section_segments":6,"angle":30,"offset":{"x":0,"y":0,"z":0},"position":{"x":[0,0,0,0,0,0,0,0,0,0],"y":[-80,-75,-60,-50,-30,0],"z":[0,0,0,0,0,0,0,0,0,0]},"width":[0,20,30,10,25,25],"height":[0,10,12,8,22,22],"texture":[16.8,63,0.9,10,17]},"side8":{"section_segments":6,"angle":90,"offset":{"x":0,"y":0,"z":0},"position":{"x":[0,0,0,0,0,0,0,0,0,0],"y":[-80,-75,-60,-50,-30,0],"z":[0,0,0,0,0,0,0,0,0,0]},"width":[0,20,30,10,25,25],"height":[0,10,12,8,22,22],"texture":[16.8,63,0.9,10,17]},"side9":{"section_segments":6,"angle":150,"offset":{"x":0,"y":0,"z":0},"position":{"x":[0,0,0,0,0,0,0,0,0,0],"y":[-80,-75,-60,-50,-30,0],"z":[0,0,0,0,0,0,0,0,0,0]},"width":[0,20,30,10,25,25],"height":[0,10,12,8,22,22],"texture":[16.8,63,0.9,10,17]},"side10":{"section_segments":6,"angle":210,"offset":{"x":0,"y":0,"z":0},"position":{"x":[0,0,0,0,0,0,0,0,0,0],"y":[-80,-75,-60,-50,-30,0],"z":[0,0,0,0,0,0,0,0,0,0]},"width":[0,20,30,10,25,25],"height":[0,10,12,8,22,22],"texture":[16.8,63,0.9,10,17]},"side11":{"section_segments":6,"angle":270,"offset":{"x":0,"y":0,"z":0},"position":{"x":[0,0,0,0,0,0,0,0,0,0],"y":[-80,-75,-60,-50,-30,0],"z":[0,0,0,0,0,0,0,0,0,0]},"width":[0,20,30,10,25,25],"height":[0,10,12,8,22,22],"texture":[16.8,63,0.9,10,17]},"side12":{"section_segments":6,"angle":330,"offset":{"x":0,"y":0,"z":0},"position":{"x":[0,0,0,0,0,0,0,0,0,0],"y":[-80,-75,-60,-50,-30,0],"z":[0,0,0,0,0,0,0,0,0,0]},"width":[0,20,30,10,25,25],"height":[0,10,12,8,22,22],"texture":[16.8,63,0.9,10,17]},"t1":{"section_segments":12,"angle":30,"offset":{"x":0,"y":0,"z":0},"position":{"x":[0,0,0,0,0,0,0,0,0,0],"y":[-10,-10,0,10,10,0,-10],"z":[0,0,0,0,0,0,0,0,0,0]},"width":[60,75,77,75,60,50,60],"height":[60,75,77,75,60,50,60],"texture":[3.8,63,63,3.8]},"t2":{"section_segments":12,"angle":90,"offset":{"x":0,"y":0,"z":0},"position":{"x":[0,0,0,0,0,0,0,0,0,0],"y":[-10,-10,0,10,10,0,-10],"z":[0,0,0,0,0,0,0,0,0,0]},"width":[60,75,77,75,60,50,60],"height":[60,75,77,75,60,50,60],"texture":[3.8,63,63,3.8]},"t3":{"section_segments":12,"angle":150,"offset":{"x":0,"y":0,"z":0},"position":{"x":[0,0,0,0,0,0,0,0,0,0],"y":[-10,-10,0,10,10,0,-10],"z":[0,0,0,0,0,0,0,0,0,0]},"width":[60,75,77,75,60,50,60],"height":[60,75,77,75,60,50,60],"texture":[3.8,63,63,3.8]}},'+
  2. '"typespec":{"name":"Ball","level":6,"model":1,"code":601,"specs":{"shield":{"capacity":[10000,10000],"reload":[1000,1000]},"generator":{"capacity":[1,1],"reload":[1,1]},"ship":{"mass":200,"speed":[80,80],"rotation":[30,30],"acceleration":[60,60]}},"shape":[3.84,3.778,3.705,3.762,3.84,3.796,3.713,3.746,3.84,3.817,3.722,3.733,3.838,3.84,3.733,3.722,3.817,3.84,3.746,3.713,3.796,3.84,3.762,3.705,3.778,3.84,3.778,3.705,3.762,3.84,3.796,3.713,3.746,3.84,3.817,3.722,3.733,3.838,3.84,3.733,3.722,3.817,3.84,3.746,3.713,3.796,3.84,3.762,3.705,3.778],"lasers":[],"radius":3.84}}';
  3. var Barracuda_602 = '{"name":"Barracuda","level":6,"model":2,"size":2.4,"zoom":0.7,"specs":{"shield":{"capacity":[400,400],"reload":[12,12]},"generator":{"capacity":[150,150],"reload":[14,14]},"ship":{"mass":675,"speed":[90,90],"rotation":[45,45],"acceleration":[150,150],"dash":{"rate":2,"burst_speed":[200,200],"speed":[150,150],"acceleration":[70,70],"initial_energy":[75,75],"energy":[30,30]}}},"bodies":{"body":{"section_segments":12,"offset":{"x":0,"y":0,"z":0},"position":{"x":[0,0,0,0,0,0,0,0,0,0],"y":[-90,-100,-60,-10,0,20,50,80,100,90],"z":[0,0,0,0,0,0,0,0,0,0,0]},"width":[0,5,20,25,35,40,40,35,30,0],"height":[0,5,40,45,40,60,70,60,30,0],"texture":[10,2,10,2,3,13,13,63,12],"propeller":true},"front":{"section_segments":8,"offset":{"x":0,"y":-20,"z":0},"position":{"x":[0,0,0,0,0],"y":[-90,-85,-70,-60,-20],"z":[0,0,0,0,0]},"width":[0,40,45,10,12],"height":[0,15,18,8,12],"texture":[8,63,4,4,4],"propeller":true},"propeller":{"section_segments":10,"offset":{"x":40,"y":40,"z":0},"position":{"x":[0,0,0,0,0,0,0,0,0,0],"y":[-20,-15,0,10,20,25,30,40,70,60],"z":[0,0,0,0,0,0,0,0,0,0]},"width":[0,10,15,15,15,10,10,20,15,0],"height":[0,10,15,15,15,10,10,18,8,0],"texture":[4,4,10,3,3,63,4,63,12],"propeller":true},"sides":{"section_segments":6,"angle":90,"offset":{"x":0,"y":0,"z":0},"position":{"x":[0,0,0,0,0,0,0,0,0,0],"y":[-80,-75,-60,-50,-10,10,50,60,75,80],"z":[0,0,0,0,0,0,0,0,0,0]},"width":[0,30,35,10,12,12,10,35,30,0],"height":[0,10,12,8,12,12,8,12,10,0],"texture":[4,63,4,4,4,4,4,63,4]},"cockpit":{"section_segments":12,"offset":{"x":0,"y":-20,"z":30},"position":{"x":[0,0,0,0,0,0,0,0],"y":[-50,-20,0,10,30,50],"z":[0,0,0,0,0,0]},"width":[0,12,18,20,15,0],"height":[0,20,22,24,20,0],"texture":[9]}},"wings":{"top":{"doubleside":true,"offset":{"x":0,"y":20,"z":15},"length":[70],"width":[70,30],"angle":[90],"position":[0,30],"texture":[63],"bump":{"position":10,"size":30}},"top2":{"doubleside":true,"offset":{"x":0,"y":51,"z":5},"length":[70],"width":[50,20],"angle":[90],"position":[0,60],"texture":[63],"bump":{"position":10,"size":30}}},'+
  4. '"typespec":{"name":"Barracuda","level":6,"model":2,"code":602,"specs":{"shield":{"capacity":[400,400],"reload":[12,12]},"generator":{"capacity":[150,150],"reload":[14,14]},"ship":{"mass":675,"speed":[90,90],"rotation":[45,45],"acceleration":[150,150],"dash":{"rate":2,"burst_speed":[200,200],"speed":[150,150],"acceleration":[70,70],"initial_energy":[75,75],"energy":[30,30]}}},"shape":[5.28,5.25,5.332,5.393,4.944,1.997,1.745,1.556,1.435,3.587,3.81,3.779,3.838,3.84,3.779,3.81,3.587,3.205,3.571,3.9,5.132,5.888,5.835,5.551,4.886,5.808,4.886,5.551,5.835,5.888,5.132,3.9,3.571,3.205,3.587,3.81,3.779,3.838,3.84,3.779,3.81,3.587,1.435,1.556,1.745,1.997,4.944,5.393,5.332,5.25],"lasers":[],"radius":5.888}}';
  5.  
  6. ships=[Ball_601, Barracuda_602]
  7.  
  8. var vocabulary = [
  9. { text: "You", icon:"\u004e", key:"O" },
  10. { text: "Me", icon:"\u004f", key:"E" },
  11. { text: "Yes", icon:"\u004c", key:"Y" },
  12. { text: "No", icon:"\u004d", key:"N" },
  13.  
  14. { text: "Attack", icon:"(", key:"A" },
  15. { text: "Follow", icon:"\u0050", key:"F" },
  16. { text: "Nice", icon:"\u{1F525}", key:"M" },
  17. { text: "Defend", icon:"\u0025", key:"D" },
  18.  
  19. { text: "Wait", icon:"\u0048", key:"T" },
  20. { text: "Ball", icon:"\u26BD", key:"B" },
  21. { text: "Hmm", icon:"\u004b", key:"Q" },
  22. { text: "Shot", icon:"`", key:"W" },
  23. { text: "Flank", icon:"i", key:"U" },
  24.  
  25. { text: "Goal", icon:"\u{1F945}", key:"G" },
  26. { text: "No Prob", icon:"\u0047", key:"P" },
  27. { text: "Thanks", icon:"\u0041", key:"X" },
  28. { text: "Sorry", icon:"\u00a1", key:"S" }
  29. ] ;
  30.  
  31. mapsize = 50;
  32. fieldSizeX = 0.7;
  33. fieldSizeY = 0.4;
  34.  
  35. ms = mapsize/2
  36.  
  37. map = "";
  38. for(y=-ms-1;y<ms;y++){
  39. for(x=-ms;x<ms;x++){
  40. if(Math.abs(x)>fieldSizeX*ms||Math.abs(y)>fieldSizeY*ms)
  41. map = map+"9"
  42. else map = map+" ";
  43. }
  44. map = map+"\n";
  45. }
  46.  
  47. this.options = {
  48. // see documentation for options reference
  49. //root_mode: "survival",
  50. weapons_store:false,
  51. friendly_colors:10,
  52. invulnerable_ships: true,
  53. ships:ships,
  54. map_size: mapsize,
  55. custom_map: map,
  56. vocabulary: vocabulary,
  57. asteroids_strength: 100000,
  58. radar_zoom: 1.5,
  59. max_players:13
  60. };
  61.  
  62. map_size = this.options.map_size*5;
  63.  
  64. betweenmatchesdelay = 60;
  65. matchlength = 60*10;
  66. goalDelay = 10;
  67.  
  68. goalSize = 15;
  69. goalTriggerSize = 20;
  70.  
  71. playersNeeded = 2;
  72.  
  73. matchinprogress = false;
  74. matchTimer = 60;
  75. goalTimer = 0;
  76.  
  77. teamneedsplayers = 1;
  78.  
  79. teams = [];
  80.  
  81. teams.push({name:"Red",goal:[-map_size/2,0],hue:0,color:"#FF0000",playerAmount:0})
  82. teams.push({name:"Blue",goal:[map_size/2,0],hue:180,color:"#0000FF",playerAmount:0})
  83.  
  84. score = [0,0]
  85.  
  86. log = function(s){
  87. game.modding.terminal.echo(s);
  88. }
  89.  
  90. distance = function(x, y){
  91. return Math.sqrt(x*x+y*y);
  92. };
  93.  
  94. shortestPath = function(x1, y1, x2, y2){
  95.  
  96. shortestDist = 10000;
  97.  
  98.  
  99. coords = [];
  100.  
  101. xx = x2-x1;
  102. yy = y2-y1;
  103. coords.push(xx, yy);
  104. shortest = [xx, yy];
  105.  
  106. xx = x2+map_size*2-x1;
  107. yy = y2-y1;
  108. coords.push(xx, yy);
  109.  
  110. xx = x2-map_size*2-x1;
  111. yy = y2-y1;
  112. coords.push(xx, yy);
  113.  
  114. xx = x2-x1;
  115. yy = y2+map_size*2-y1;
  116. coords.push(xx, yy);
  117.  
  118. xx = x2-x1;
  119. yy = y2-map_size*2-y1;
  120. coords.push(xx, yy);
  121.  
  122.  
  123. xx = x2+map_size*2-x1;
  124. yy = y2+map_size*2-y1;
  125. coords.push(xx, yy);
  126.  
  127. xx = x2+map_size*2-x1;
  128. yy = y2-map_size*2-y1;
  129. coords.push(xx, yy);
  130.  
  131. xx = x2-map_size*2-x1;
  132. yy = y2+map_size*2-y1;
  133. coords.push(xx, yy);
  134.  
  135. xx = x2-map_size*2-x1;
  136. yy = y2-map_size*2-y1;
  137. coords.push(xx, yy);
  138.  
  139. for(var i = 0; i<9; i++){
  140. dist = distance(coords[i*2], coords[i*2+1]);
  141. if(dist<shortestDist){
  142. shortestDist = dist;
  143. shortest = [coords[i*2], coords[i*2+1]];
  144. }
  145. }
  146.  
  147. return shortest;
  148.  
  149. };
  150.  
  151. goal1 = {
  152. id: "goal1",
  153. obj: "https://raw.githubusercontent.com/rvan-der/Starblast.io-modding/master/starblast-1531720874914.obj",
  154. emissive: "https://raw.githubusercontent.com/rvan-der/Starblast.io-modding/master/images/textures/ship_emissive_texture.png",
  155. // specular: "https://starblast.data.neuronality.com/models/aliens/10/lambert.jpg",
  156. diffuse: "https://raw.githubusercontent.com/rvan-der/Starblast.io-modding/master/images/textures/ship_lambert_texture.png",
  157. shininess: 100,
  158. emissiveColor: 0xFF5555,
  159. specularColor: 0xFF0000,
  160. bump: "https://raw.githubusercontent.com/rvan-der/Starblast.io-modding/master/images/textures/ship_lambert_texture.png"
  161. } ;
  162.  
  163. goal2 = {
  164. id: "goal2",
  165. obj: "https://raw.githubusercontent.com/rvan-der/Starblast.io-modding/master/starblast-1531720874914.obj",
  166. emissive: "https://raw.githubusercontent.com/rvan-der/Starblast.io-modding/master/images/textures/ship_emissive_texture.png",
  167. // specular: "https://starblast.data.neuronality.com/models/aliens/10/lambert.jpg",
  168. diffuse: "https://raw.githubusercontent.com/rvan-der/Starblast.io-modding/master/images/textures/ship_lambert_texture.png",
  169. shininess: 100,
  170. emissiveColor: 0x5555FF,
  171. specularColor: 0x0000FF,
  172. bump: "https://raw.githubusercontent.com/rvan-der/Starblast.io-modding/master/images/textures/ship_lambert_texture.png"
  173. } ;
  174.  
  175. game.setObject({
  176. id: "g1",
  177. type: goal1,
  178. position: {x:teams[0].goal[0]+5,y:teams[0].goal[1],z:-10},
  179. rotation: {x:0,y:Math.PI/2,z:0},
  180. scale: {x:12,y:12,z:12}
  181. }) ;
  182.  
  183. game.setObject({
  184. id: "g2",
  185. type: goal2,
  186. position: {x:teams[1].goal[0]+5,y:teams[1].goal[1],z:-10},
  187. rotation: {x:0,y:Math.PI/2,z:0},
  188. scale: {x:12,y:12,z:12}
  189. }) ;
  190.  
  191. matchTick = function(){
  192. ball = game.ships[0];
  193. ball.set({type:601,idle:false,team:0});
  194.  
  195. if(game.ships.length-1<playersNeeded)matchTimer = -1;
  196.  
  197. returnBall = false;
  198. xx = ball.x;
  199. yy = ball.y;
  200. if(ball.x>map_size*fieldSizeX+10){xx = map_size*fieldSizeX+5; returnBall = true;}
  201. if(ball.x<-map_size*fieldSizeX){xx = -map_size*fieldSizeX+5; returnBall = true;}
  202. if(ball.y>map_size*fieldSizeY){yy = map_size*fieldSizeY-5; returnBall = true;}
  203. if(ball.y<-map_size*fieldSizeY-10){yy = -map_size*fieldSizeY-5; returnBall = true;}
  204. if(returnBall)ball.set({x:xx,y:yy});
  205.  
  206. scoreComps = [];
  207. highestScore = 0;
  208. highestScoreTeams = [];
  209. for(t=0;t<teams.length;t++){
  210. if(matchTimer<0&&score[t]>highestScore){
  211. highestScoreTeams = [t];
  212. highestScore = score[t];
  213. }else if(matchTimer<0&&score[t]==highestScore){
  214. highestScoreTeams.push(t);
  215. }
  216. pos = (100/teams.length)*(t)
  217. scoreComps.push({ type: "text",position:[pos,0,100/teams.length,100],value:score[t],color:teams[t].color})
  218. if(t<teams.length-1)
  219. scoreComps.push({ type: "text",position:[(100/(teams.length))*(t+1)-10/teams.length,0,20/teams.length,100],value:":",color:"#CDE"})
  220.  
  221. }
  222.  
  223. if(matchTimer<0){
  224. if(highestScoreTeams.length>1){
  225. text = "Draw between "
  226. for(t=0;t<highestScoreTeams.length;t++){
  227. if(t==highestScoreTeams.length-1)
  228. text = text + teams[highestScoreTeams[t]].name
  229. else
  230. if(t==highestScoreTeams.length-2)
  231. text = text + teams[highestScoreTeams[t]].name + " and "
  232. else
  233. text = text + teams[highestScoreTeams[t]].name +", "
  234. }
  235.  
  236. }else text = teams[highestScoreTeams[0]].name+" won!"
  237.  
  238. for(i=1;i<game.ships.length;i++){
  239. ship = game.ships[i];
  240. ship.setUIComponent({
  241. id:"timeLeft",
  242. position:[30,30,40,5],
  243. clickable: false,
  244. visible: true,
  245. components: [
  246. { type: "text",position:[10,10,80,30],value:text,color:"#CDE"}
  247. ]
  248. });
  249. }
  250. log("Game ends: "+text);
  251. matchinprogress = false;
  252. matchTimer = betweenmatchesdelay;
  253. return;
  254. }
  255.  
  256. for(i=1;i<game.ships.length;i++){
  257. ship = game.ships[i];
  258. if(!ship.custom.init){
  259. ship.custom.init = true;
  260. ship.custom.team = teamneedsplayers;
  261. ship.set({type:602,team:1,hue:teams[teamneedsplayers].hue});
  262. log(ship.name+" joined, assigned to "+teams[teamneedsplayers].name);
  263. }
  264.  
  265. teams[ship.custom.team].playerAmount++;
  266.  
  267. //show directions to stuff
  268. sp = shortestPath(ship.x, ship.y, ball.x, ball.y);
  269. dist = distance(sp[0],sp[1]);
  270. x = sp[0]/dist;
  271. y = sp[1]/dist;
  272. ship.setUIComponent({
  273. id:"ballIndicator",
  274. position:[45+x*30,45-y*30,10,10],
  275. clickable: false,
  276. visible: true,
  277. components: [
  278. { type:"box",position:[45,45,10,10],fill:"#AA0000",stroke:"#CDE",width:2},
  279. { type: "text",position:[10,10,80,30],value:"ball",color:"#CDE"}
  280. ]
  281. });
  282.  
  283. scsize = teams.length*10
  284. ship.setUIComponent({
  285. id:"score",
  286. position:[50-scsize/2,10,scsize,20],
  287. clickable: false,
  288. visible: true,
  289. components: scoreComps
  290. });
  291.  
  292. ship.setUIComponent({
  293. id:"timeLeft",
  294. position:[30,30,40,5],
  295. clickable: false,
  296. visible: true,
  297. components: [
  298. { type: "text",position:[10,10,80,30],value:Math.floor(matchTimer/60)+"m "+matchTimer%60+"s left",color:"#CDE"}
  299. ]
  300. });
  301.  
  302. if(goalTimer>0)
  303. b = true
  304. else
  305. b = false
  306.  
  307. if(goalTimer>=0)
  308. ship.setUIComponent({
  309. id:"goalText",
  310. position:[30,40,40,40],
  311. clickable: false,
  312. visible: b,
  313. components: [
  314. { type: "text",position:[0,0,100,100],value:"GOAL",color:"#CDE"}
  315. ]
  316. });
  317.  
  318. if(goalTimer==0){
  319. x=teams[ship.custom.team].goal[0]+Math.random()*goalTriggerSize-goalTriggerSize/2;
  320. y=teams[ship.custom.team].goal[1]+Math.random()*goalTriggerSize-goalTriggerSize/2;
  321. ship.set({type:602,team:1,hue:teams[ship.custom.team].hue,x:x,y:y});
  322. }
  323.  
  324. for(t=0;t<teams.length;t++){
  325. ourT = (t == ship.custom.team);
  326. sp = shortestPath(ship.x, ship.y, teams[t].goal[0], teams[t].goal[1]);
  327. dist = distance(sp[0],sp[1]);
  328. x = sp[0]/dist;
  329. y = sp[1]/dist;
  330. text = "their goal"
  331. if(ourT)
  332. text = "our goal"
  333. ship.setUIComponent({
  334. id:"tmarker"+t,
  335. position:[45+x*30,45-y*30,10,10],
  336. clickable: false,
  337. visible: true,
  338. components: [
  339. { type:"box",position:[45,45,10,10],fill:teams[t].color,stroke:"#CDE",width:2},
  340. { type: "text",position:[10,10,80,30],value:text,color:"#CDE"}
  341. ]
  342. });
  343. }
  344. }
  345.  
  346. if(goalTimer>=0){
  347. goalTimer--;
  348. if(goalTimer<goalDelay/2)
  349. ball.set({x:0,y:0,vx:0,vy:0,idle:true})
  350. }else matchTimer--;
  351.  
  352. lowestPlayers = game.ships.length
  353. lowestPlTeam = 0;
  354. for(t=0;t<teams.length;t++){
  355. if(teams[t].playerAmount<lowestPlayers){
  356. lowestPlayers = teams[t].playerAmount;
  357. lowestPlTeam = t;
  358. }
  359. teams[t].playerAmount = 0;
  360. }
  361. teamneedsplayers = lowestPlTeam;
  362. }
  363.  
  364. checkGoals = function(){
  365. if(goalTimer>0)return;
  366. ball = game.ships[0];
  367. for(t=0;t<teams.length;t++){
  368. sp = shortestPath(ball.x, ball.y, teams[t].goal[0], teams[t].goal[1]);
  369. dist = distance(sp[0],sp[1]);
  370. if(dist<goalTriggerSize){
  371.  
  372. log("GOAL! Into "+teams[t].name+"'s goal")
  373.  
  374. for(tt=0;tt<teams.length;tt++){
  375. if(tt!=t)
  376. score[tt]++;
  377. }
  378. goalTimer = goalDelay;
  379.  
  380. break;
  381. }
  382. }
  383. }
  384.  
  385. startMatch = function(){
  386. log("Game starts NOW.");
  387. matchinprogress = true;
  388. t = 0;
  389. randomizeTeams = [];
  390. for(i=1;i<game.ships.length;i++){
  391. randomizeTeams.push(i);
  392. }
  393. for (i = randomizeTeams.length - 1; i > 0; i--) {
  394. j = Math.floor(Math.random() * (i + 1));
  395. x = randomizeTeams[i];
  396. randomizeTeams[i] = randomizeTeams[j];
  397. randomizeTeams[j] = x;
  398. }
  399. for(i=0;i<randomizeTeams.length;i++){
  400. ship = game.ships[randomizeTeams[i]];
  401. ship.custom.team = t;
  402. x=teams[t].goal[0]+Math.random()*goalTriggerSize-goalTriggerSize/2;
  403. y=teams[t].goal[1]+Math.random()*goalTriggerSize-goalTriggerSize/2;
  404. ship.set({type:602,team:1,hue:teams[t].hue,x:x,y:y});
  405. ship.setUIComponent({
  406. id:"awaiting",
  407. position:[30,20,40,20],
  408. clickable: false,
  409. visible: false,
  410. });
  411. log("Player "+ship.name+" on team "+teams[t].name)
  412. t++;
  413. if(t>=teams.length)t=0;
  414.  
  415. }
  416. game.ships[0].set({x:0,y:0});
  417. score = [];
  418. log("Game started");
  419. for(t=0;t<teams.length;t++){
  420. score.push(0);
  421. }
  422. matchTimer = matchlength;
  423. }
  424.  
  425. awaitingNextMatch = function(){
  426. ball = game.ships[0];
  427. ball.set({type:601, team:0,idle:false});
  428.  
  429. for(i=1;i<game.ships.length;i++){
  430. ship = game.ships[i];
  431. if(!ship.custom.init){
  432. ship.custom.init = true;
  433. ship.set({type:602, team:1});
  434. log(ship.name+" joined");
  435. }
  436. if(game.ships.length-1<playersNeeded){
  437. ship.setUIComponent({
  438. id:"awaiting",
  439. position:[30,40,40,20],
  440. clickable: false,
  441. visible: true,
  442. components: [
  443. { type: "text",position:[0,0,100,100],value:"Not enough players - "+playersNeeded +" needed",color:"#CDE"}
  444. ]
  445. });
  446.  
  447. }else{
  448. ship.setUIComponent({
  449. id:"awaiting",
  450. position:[30,40,40,20],
  451. clickable: false,
  452. visible: true,
  453. components: [
  454. { type: "text",position:[0,0,100,100],value:"Starting in "+matchTimer +" seconds",color:"#CDE"}
  455. ]
  456. });
  457.  
  458. }
  459. }
  460.  
  461. if(game.ships.length-1<playersNeeded)matchTimer = betweenmatchesdelay;
  462.  
  463. matchTimer--;
  464.  
  465. if(matchTimer<0)
  466. startMatch();
  467. }
  468.  
  469. this.tick = function(game) {
  470. if(game.ships.length<1)return;
  471. // do mod stuff here ; see documentation
  472. if(matchinprogress){
  473. if(game.step%60==0){
  474. matchTick();
  475. }
  476. if(goalTimer<0)
  477. checkGoals();
  478. }else{
  479. if(game.step%60==0)
  480. awaitingNextMatch();
  481. }
  482.  
  483.  
  484. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement