Advertisement
Guest User

Astram Pictionary

a guest
Nov 14th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function onCreated() {
  2.   this.setShape(1, 512, 512);
  3.   blockAgain();
  4.   this.chosen = {};
  5.   this.current_artist = null;
  6.   this.game_state = -1;
  7.   this.round = 1;
  8.   this.rounds = 3;
  9.   this.words = {
  10.     "banana", "pig", "tree", "face", "birthday", "puppy", "sad", "fish", "crayon", "gun", "money", "poop", "tiger", "zebra", "trash", "skateboard",
  11.     "vacuum", "water", "chicken", "manager", "hat", "arm", "leg", "car", "boat", "eagle", "bird",
  12.     "noob", "casino", "spar", "hotel", "house", "penthouse", "rapper", "chips", "phone", "atm", "cartoon",
  13.     "hair", "bible", "wedding", "surfing", "running", "sleeping", "smoking", "fishing", "fruit", "iphone", "graal", "news",
  14.     "trophy", "bucket", "zombie", "boy", "girl", "shark", "whale", "lightning", "tadpole", "sword", "bus", "movie"
  15.   };
  16.   this.guesser_box = {8, 23};
  17.   this.drawer_box = {34, 44};
  18.   this.scoreboard = {};
  19. }
  20.  
  21. function onActionDrawInk(lx, ly, ix, iy) {
  22.   if (this.game_state != 0 && player.guild != "Events Team") return;
  23.   if (player.account != this.current_artist.account && player.guild != "Events Team") return;
  24.   this.level.triggerAction(this.x + .5, this.y + .5, "ClientDrawInk", lx, ly, ix, iy);
  25. }
  26.  
  27. function onPlayerChats() {
  28.   if (this.game_state == 0) {
  29.     if (player.guild != "Events Team" && player.chat == this.word && player.account != this.current_artist.account) {
  30.       if (!(player.account in this.scored)) {
  31.         player.chat = "I got the word! I have " @ addScore(player, int(this.time_left / 3)) @ " points!";
  32.         findplayer(this.current_artist.account).chat = "I received " @ addScore(this.current_artist, int(this.time_left / 6) @ " points!");
  33.         this.scored.add(player.account);
  34.         if (this.scored.size() == getPlayers().size() - 1)
  35.           this.time_left = 0;
  36.       } else
  37.         player.chat = "I already got the word!";
  38.     }
  39.   }
  40.  
  41.   if (player.guild != "Events Team") return;
  42.   switch(player.chat) {
  43.     case ":start":
  44.       onStartGame();
  45.       break;
  46.     case ":end":
  47.       cancelEvents("GameLoop");
  48.       onCreated();
  49.       break;
  50.     case ":clear":
  51.       onClearBoard();
  52.       break;
  53.     case ":skip":
  54.       this.time_left = 0;
  55.       break;
  56.   }
  57.   if (player.chat.starts(":rounds ")) {
  58.     this.rounds = int(player.chat.tokenize()[1]);
  59.     player.chat = "Rounds set to " @ this.rounds @ "!";
  60.   }
  61. }
  62.  
  63. function addScore(pl, score) {
  64.   for (temp.i = 0; i < this.scoreboard.size(); i ++) {
  65.     if (this.scoreboard[i][0] == pl.account) {
  66.       this.scoreboard[i][1] = this.scoreboard[i][1] + score;
  67.       return this.scoreboard[i][1];
  68.     }
  69.   }
  70.   this.scoreboard.add({pl.account, score});
  71.   return score;
  72. }
  73.  
  74. function onStartGame() {
  75.   this.game_state = 0;
  76.   onNextPlayer();
  77.   onGameLoop();
  78. }
  79.  
  80. function onNextPlayer() {
  81.   if (this.current_artist != null) {
  82.     onUpdateClientText(this.current_artist, "");
  83.     this.current_artist.x = this.guesser_box[0];
  84.     this.current_artist.y = this.guesser_box[1];
  85.   }
  86.   temp.pls = getPlayers();
  87.   this.game_state = 1;
  88.   if (this.chosen.size() == pls.size()) { // everyone went
  89.     this.game_state = 2;
  90.     this.time_left = 10;
  91.     this.current_artist = null;
  92.     onUpdateGameText("Round " @ this.round @ " is over!");
  93.     return;
  94.   }
  95.   while (true) {
  96.     this.current_artist = pls[int(random(0, pls.size()))];
  97.     if (!(this.current_artist.account in this.chosen))
  98.       break;
  99.   }
  100.   this.current_artist.x = this.drawer_box[0];
  101.   this.current_artist.y = this.drawer_box[1];
  102.   onClearBoard();
  103.   this.game_state = 0;
  104.   this.scored = {};
  105.   this.word = this.words[int(random(0, this.words.size()))];
  106.   onUpdateClientText(this.current_artist, "You are drawing: " @ this.word);
  107.   onUpdateEventsText("(ET-Only) The word is: " @ this.word);
  108.   this.time_left = 120;
  109.   this.chosen.add(this.current_artist.account);
  110. }
  111.  
  112. function onGameLoop() {
  113.   if (this.game_state == 0) {
  114.     if (this.time_left <= 0) {
  115.       this.game_state = 3;
  116.       this.time_left = 10;
  117.       onUpdateGameText("The word was " @ this.word @ "!");
  118.       onUpdateScores();
  119.     } else
  120.       onUpdateGameText(this.current_artist.account @ " is drawing - " @ getTimeString(this.time_left));
  121.   }
  122.   if (this.game_state == 1)
  123.     onUpdateGameText("Selecting next artist...");
  124.   if (this.game_state == 2) {
  125.     if (this.time_left == 5) {
  126.       if (this.round >= this.rounds) {
  127.         onUpdateGameText("Game Over!");
  128.         onGetWinnerAndReset();
  129.         onClearBoard();
  130.         return;
  131.       }
  132.       onUpdateGameText("Starting Round " @ ++this.round @ "...");
  133.     }
  134.     if (this.time_left <= 0) {
  135.       this.chosen = {};
  136.       onNextPlayer();
  137.     }
  138.   }
  139.   if (this.game_state == 3) {
  140.     if (this.time_left <= 0)
  141.       onNextPlayer();
  142.   }
  143.   this.time_left--;
  144.   this.scheduleEvent(1, "GameLoop", null);
  145. }
  146.  
  147. function onGetWinnerAndReset() {
  148.   this.winner = this.scoreboard[0];
  149.   for (temp.i = 1; i < this.scoreboard.size(); i ++) {
  150.     if (this.scoreboard[i][1] > this.winner[1])
  151.       this.winner = this.scoreboard[i];
  152.   }
  153.   if (this.current_artist != null) {
  154.     this.current_artist.x = this.guesser_box[0];
  155.     this.current_artist.y = this.guesser_box[1];
  156.   }
  157.   findplayer(this.winner[0]).x = this.drawer_box[0];
  158.   findplayer(this.winner[0]).y = this.drawer_box[1];
  159.   onUpdateGameText(this.winner[0] @ " is the winner with " @ this.winner[1] @ " points!");
  160.   onCreated();
  161. }
  162.  
  163. function getTimeString(time) {
  164.   temp.minutes = int(time / 60);
  165.   temp.seconds = time % 60;
  166.   if (seconds < 10)
  167.     return minutes @ ":0" @ seconds;
  168.   return minutes @ ":" @ seconds;
  169. }
  170.  
  171. function getPlayers() {
  172.   temp.gamePlayers = {};
  173.   for (temp.pl : this.level.players) {
  174.     if (pl.guild != "Events Team")
  175.       gamePlayers.add(pl);
  176.   }
  177.   return gamePlayers;
  178. }
  179.  
  180. function onClearBoard() {
  181.   this.level.triggerAction(this.x + .5, this.y + .5, "ClientClearBoard", "");
  182. }
  183.  
  184. function onUpdateClientText(pl, message) {
  185.   this.level.triggerAction(this.x + .5, this.y + .5, "UpdateClientText", pl.account, message);
  186. }
  187.  
  188. function onUpdateClientMass(message) {
  189.   for (temp.pl : getPlayers())
  190.     onUpdateClientText(pl, message);
  191. }
  192.  
  193. function getScore(acc) {
  194.   for (temp.i = 0; i < this.scoreboard.size(); i ++) {
  195.     if (this.scoreboard[i][0] == acc)
  196.       return this.scoreboard[i][1];
  197.   }
  198.   return 0;
  199. }
  200.  
  201. function onUpdateScores() {
  202.   for (temp.pl : getPlayers())
  203.     onUpdateClientText(pl, "You have " @ getScore(pl.account) @ " points!");
  204. }
  205.  
  206. function onUpdateGameText(message) {
  207.   this.level.triggerAction(this.x + .5, this.y + .5, "UpdateGameText", message);
  208. }
  209.  
  210. function onUpdateEventsText(message) {
  211.   for (temp.pl : this.level.players) {
  212.     if (pl.guild == "Events Team")
  213.       onUpdateClientText(pl, message);
  214.   }
  215. }  
  216.  
  217. //#CLIENTSIDE
  218. const WIDTH = 512;
  219. const HEIGHT = 512;
  220.  
  221. const STROKE_SIZE = .1;
  222.  
  223. function onCreated() {
  224.   this.setShape(1, WIDTH, HEIGHT);
  225.   blockAgain();
  226.  
  227.   onActionUpdateGameText("The game has not been started...");
  228.  
  229.   this.stroke = 0;
  230.   this.mouse_down = false;
  231.  
  232.   with (findimg(200)) {
  233.     layer = 0;
  234.     polygon = {
  235.       this.x, this.y,
  236.       this.x + WIDTH / 16, this.y,
  237.       this.x + WIDTH / 16, this.y + HEIGHT / 16,
  238.       this.x, this.y + HEIGHT / 16
  239.     };
  240.     red = green = blue = 1;
  241.   }
  242.  
  243. }
  244.  
  245. function onMouseDown(type) {
  246.   if (!isMouseInside()) return;
  247.   if (type == "left") {
  248.     this.mouse_down = true;
  249.     this.last_x = this.last_y = -1;
  250.     onUpdateMouse();
  251.   }
  252. }
  253.  
  254. function onMouseUp() {
  255.   if (this.mouse_down)
  256.     this.mouse_down = false;
  257. }
  258.  
  259. function onUpdateMouse() {
  260.   if (!isMouseInside() || !this.mouse_down) return;
  261.   onDrawInk();
  262.   this.last_x = mousex;
  263.   this.last_y = mousey;
  264.   this.scheduleEvent(.05, "UpdateMouse");
  265. }
  266.  
  267. function onDrawInk() {
  268.   if (this.last_x == -1 && this.last_y == -1) return;
  269.   triggerAction(this.x + WIDTH / 32, this.y + HEIGHT / 32, "DrawInk", this.last_x, this.last_y, mousex, mousey);
  270.   //player.chat = this.x + WIDTH / 32 SPC this.y + HEIGHT / 32;
  271. }
  272.  
  273. function onActionClientDrawInk(lx, ly, ix, iy) {
  274.   //player.chat = lx SPC ly @ " -> " @ ix SPC iy;
  275.   drawLine(201 + this.stroke++, lx, ly, ix, iy, STROKE_SIZE);
  276. }
  277.  
  278. function onActionClientClearBoard() {
  279.   this.hideimgs(201, 200 + this.stroke + 1);
  280.   this.stroke = 0;
  281. }
  282.  
  283. function isMouseInside() {
  284.   return mousex in |this.x, this.x + WIDTH / 16| && mousey in |this.y, this.y + HEIGHT / 16|;
  285. }
  286.  
  287. function createShape(temp.x, temp.y) {
  288.   temp.poly = {};
  289.   for (temp.i = 0; i < pi * 2; i += pi / 16) {
  290.     poly.add(STROKE_SIZE / 16 * cos(i) + temp.x);
  291.     poly.add(STROKE_SIZE / 16 * sin(i) + temp.y);
  292.   }
  293.   return poly;
  294. }
  295.  
  296. public function drawLine( ind, sx, sy, tx, ty, wid, r, g, b, alph ) {
  297.   temp.ang = getangle(tx - sx, ty - sy) + (pi/2);
  298.   temp.wid = ( wid == NULL ? .1 : wid );
  299.  
  300.   with ( findImg(ind) ) {
  301.     polygon = {
  302.       sx, sy,
  303.       tx, ty,
  304.       tx + cos(ang)*wid, ty - sin(ang)*wid,
  305.       sx + cos(ang)*wid, sy - sin(ang)*wid
  306.     };
  307.     red = ( r < 0 || r > 1 ? 0 : r );
  308.     green = ( g < 0 || g > 1 ? 0 : g );
  309.     blue = ( b < 0 || b > 1 ? 0 : b );
  310.     alpha = ( alph <= 0 || alph > 1 ? 1 : alph);
  311.     layer = 3;
  312.   }
  313. }
  314.  
  315. function onActionUpdateClientText(acc, message) {
  316.   if (player.account != acc) return;
  317.   with (findimg(10000)) {
  318.     layer = 2;
  319.     text = message;
  320.     style = "bc";
  321.     font = "Arial";
  322.     red = green = blue = 1;
  323.     x = thiso.x + WIDTH / 32;
  324.     y = thiso.y + HEIGHT / 16 + 1;
  325.   }
  326. }
  327.  
  328. function onActionUpdateGameText(message) {
  329.   with (findimg(10001)) {
  330.     layer = 2;
  331.     text = message;
  332.     style = "bc";
  333.     font = "Arial";
  334.     red = green = blue = 1;
  335.     x = thiso.x + WIDTH / 32;
  336.     y = thiso.y - 1.5;
  337.   }
  338. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement