Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onCreated() {
- this.setShape(1, 512, 512);
- blockAgain();
- this.chosen = {};
- this.current_artist = null;
- this.game_state = -1;
- this.round = 1;
- this.rounds = 3;
- this.words = {
- "banana", "pig", "tree", "face", "birthday", "puppy", "sad", "fish", "crayon", "gun", "money", "poop", "tiger", "zebra", "trash", "skateboard",
- "vacuum", "water", "chicken", "manager", "hat", "arm", "leg", "car", "boat", "eagle", "bird",
- "noob", "casino", "spar", "hotel", "house", "penthouse", "rapper", "chips", "phone", "atm", "cartoon",
- "hair", "bible", "wedding", "surfing", "running", "sleeping", "smoking", "fishing", "fruit", "iphone", "graal", "news",
- "trophy", "bucket", "zombie", "boy", "girl", "shark", "whale", "lightning", "tadpole", "sword", "bus", "movie"
- };
- this.guesser_box = {8, 23};
- this.drawer_box = {34, 44};
- this.scoreboard = {};
- }
- function onActionDrawInk(lx, ly, ix, iy) {
- if (this.game_state != 0 && player.guild != "Events Team") return;
- if (player.account != this.current_artist.account && player.guild != "Events Team") return;
- this.level.triggerAction(this.x + .5, this.y + .5, "ClientDrawInk", lx, ly, ix, iy);
- }
- function onPlayerChats() {
- if (this.game_state == 0) {
- if (player.guild != "Events Team" && player.chat == this.word && player.account != this.current_artist.account) {
- if (!(player.account in this.scored)) {
- player.chat = "I got the word! I have " @ addScore(player, int(this.time_left / 3)) @ " points!";
- findplayer(this.current_artist.account).chat = "I received " @ addScore(this.current_artist, int(this.time_left / 6) @ " points!");
- this.scored.add(player.account);
- if (this.scored.size() == getPlayers().size() - 1)
- this.time_left = 0;
- } else
- player.chat = "I already got the word!";
- }
- }
- if (player.guild != "Events Team") return;
- switch(player.chat) {
- case ":start":
- onStartGame();
- break;
- case ":end":
- cancelEvents("GameLoop");
- onCreated();
- break;
- case ":clear":
- onClearBoard();
- break;
- case ":skip":
- this.time_left = 0;
- break;
- }
- if (player.chat.starts(":rounds ")) {
- this.rounds = int(player.chat.tokenize()[1]);
- player.chat = "Rounds set to " @ this.rounds @ "!";
- }
- }
- function addScore(pl, score) {
- for (temp.i = 0; i < this.scoreboard.size(); i ++) {
- if (this.scoreboard[i][0] == pl.account) {
- this.scoreboard[i][1] = this.scoreboard[i][1] + score;
- return this.scoreboard[i][1];
- }
- }
- this.scoreboard.add({pl.account, score});
- return score;
- }
- function onStartGame() {
- this.game_state = 0;
- onNextPlayer();
- onGameLoop();
- }
- function onNextPlayer() {
- if (this.current_artist != null) {
- onUpdateClientText(this.current_artist, "");
- this.current_artist.x = this.guesser_box[0];
- this.current_artist.y = this.guesser_box[1];
- }
- temp.pls = getPlayers();
- this.game_state = 1;
- if (this.chosen.size() == pls.size()) { // everyone went
- this.game_state = 2;
- this.time_left = 10;
- this.current_artist = null;
- onUpdateGameText("Round " @ this.round @ " is over!");
- return;
- }
- while (true) {
- this.current_artist = pls[int(random(0, pls.size()))];
- if (!(this.current_artist.account in this.chosen))
- break;
- }
- this.current_artist.x = this.drawer_box[0];
- this.current_artist.y = this.drawer_box[1];
- onClearBoard();
- this.game_state = 0;
- this.scored = {};
- this.word = this.words[int(random(0, this.words.size()))];
- onUpdateClientText(this.current_artist, "You are drawing: " @ this.word);
- onUpdateEventsText("(ET-Only) The word is: " @ this.word);
- this.time_left = 120;
- this.chosen.add(this.current_artist.account);
- }
- function onGameLoop() {
- if (this.game_state == 0) {
- if (this.time_left <= 0) {
- this.game_state = 3;
- this.time_left = 10;
- onUpdateGameText("The word was " @ this.word @ "!");
- onUpdateScores();
- } else
- onUpdateGameText(this.current_artist.account @ " is drawing - " @ getTimeString(this.time_left));
- }
- if (this.game_state == 1)
- onUpdateGameText("Selecting next artist...");
- if (this.game_state == 2) {
- if (this.time_left == 5) {
- if (this.round >= this.rounds) {
- onUpdateGameText("Game Over!");
- onGetWinnerAndReset();
- onClearBoard();
- return;
- }
- onUpdateGameText("Starting Round " @ ++this.round @ "...");
- }
- if (this.time_left <= 0) {
- this.chosen = {};
- onNextPlayer();
- }
- }
- if (this.game_state == 3) {
- if (this.time_left <= 0)
- onNextPlayer();
- }
- this.time_left--;
- this.scheduleEvent(1, "GameLoop", null);
- }
- function onGetWinnerAndReset() {
- this.winner = this.scoreboard[0];
- for (temp.i = 1; i < this.scoreboard.size(); i ++) {
- if (this.scoreboard[i][1] > this.winner[1])
- this.winner = this.scoreboard[i];
- }
- if (this.current_artist != null) {
- this.current_artist.x = this.guesser_box[0];
- this.current_artist.y = this.guesser_box[1];
- }
- findplayer(this.winner[0]).x = this.drawer_box[0];
- findplayer(this.winner[0]).y = this.drawer_box[1];
- onUpdateGameText(this.winner[0] @ " is the winner with " @ this.winner[1] @ " points!");
- onCreated();
- }
- function getTimeString(time) {
- temp.minutes = int(time / 60);
- temp.seconds = time % 60;
- if (seconds < 10)
- return minutes @ ":0" @ seconds;
- return minutes @ ":" @ seconds;
- }
- function getPlayers() {
- temp.gamePlayers = {};
- for (temp.pl : this.level.players) {
- if (pl.guild != "Events Team")
- gamePlayers.add(pl);
- }
- return gamePlayers;
- }
- function onClearBoard() {
- this.level.triggerAction(this.x + .5, this.y + .5, "ClientClearBoard", "");
- }
- function onUpdateClientText(pl, message) {
- this.level.triggerAction(this.x + .5, this.y + .5, "UpdateClientText", pl.account, message);
- }
- function onUpdateClientMass(message) {
- for (temp.pl : getPlayers())
- onUpdateClientText(pl, message);
- }
- function getScore(acc) {
- for (temp.i = 0; i < this.scoreboard.size(); i ++) {
- if (this.scoreboard[i][0] == acc)
- return this.scoreboard[i][1];
- }
- return 0;
- }
- function onUpdateScores() {
- for (temp.pl : getPlayers())
- onUpdateClientText(pl, "You have " @ getScore(pl.account) @ " points!");
- }
- function onUpdateGameText(message) {
- this.level.triggerAction(this.x + .5, this.y + .5, "UpdateGameText", message);
- }
- function onUpdateEventsText(message) {
- for (temp.pl : this.level.players) {
- if (pl.guild == "Events Team")
- onUpdateClientText(pl, message);
- }
- }
- //#CLIENTSIDE
- const WIDTH = 512;
- const HEIGHT = 512;
- const STROKE_SIZE = .1;
- function onCreated() {
- this.setShape(1, WIDTH, HEIGHT);
- blockAgain();
- onActionUpdateGameText("The game has not been started...");
- this.stroke = 0;
- this.mouse_down = false;
- with (findimg(200)) {
- layer = 0;
- polygon = {
- this.x, this.y,
- this.x + WIDTH / 16, this.y,
- this.x + WIDTH / 16, this.y + HEIGHT / 16,
- this.x, this.y + HEIGHT / 16
- };
- red = green = blue = 1;
- }
- }
- function onMouseDown(type) {
- if (!isMouseInside()) return;
- if (type == "left") {
- this.mouse_down = true;
- this.last_x = this.last_y = -1;
- onUpdateMouse();
- }
- }
- function onMouseUp() {
- if (this.mouse_down)
- this.mouse_down = false;
- }
- function onUpdateMouse() {
- if (!isMouseInside() || !this.mouse_down) return;
- onDrawInk();
- this.last_x = mousex;
- this.last_y = mousey;
- this.scheduleEvent(.05, "UpdateMouse");
- }
- function onDrawInk() {
- if (this.last_x == -1 && this.last_y == -1) return;
- triggerAction(this.x + WIDTH / 32, this.y + HEIGHT / 32, "DrawInk", this.last_x, this.last_y, mousex, mousey);
- //player.chat = this.x + WIDTH / 32 SPC this.y + HEIGHT / 32;
- }
- function onActionClientDrawInk(lx, ly, ix, iy) {
- //player.chat = lx SPC ly @ " -> " @ ix SPC iy;
- drawLine(201 + this.stroke++, lx, ly, ix, iy, STROKE_SIZE);
- }
- function onActionClientClearBoard() {
- this.hideimgs(201, 200 + this.stroke + 1);
- this.stroke = 0;
- }
- function isMouseInside() {
- return mousex in |this.x, this.x + WIDTH / 16| && mousey in |this.y, this.y + HEIGHT / 16|;
- }
- function createShape(temp.x, temp.y) {
- temp.poly = {};
- for (temp.i = 0; i < pi * 2; i += pi / 16) {
- poly.add(STROKE_SIZE / 16 * cos(i) + temp.x);
- poly.add(STROKE_SIZE / 16 * sin(i) + temp.y);
- }
- return poly;
- }
- public function drawLine( ind, sx, sy, tx, ty, wid, r, g, b, alph ) {
- temp.ang = getangle(tx - sx, ty - sy) + (pi/2);
- temp.wid = ( wid == NULL ? .1 : wid );
- with ( findImg(ind) ) {
- polygon = {
- sx, sy,
- tx, ty,
- tx + cos(ang)*wid, ty - sin(ang)*wid,
- sx + cos(ang)*wid, sy - sin(ang)*wid
- };
- red = ( r < 0 || r > 1 ? 0 : r );
- green = ( g < 0 || g > 1 ? 0 : g );
- blue = ( b < 0 || b > 1 ? 0 : b );
- alpha = ( alph <= 0 || alph > 1 ? 1 : alph);
- layer = 3;
- }
- }
- function onActionUpdateClientText(acc, message) {
- if (player.account != acc) return;
- with (findimg(10000)) {
- layer = 2;
- text = message;
- style = "bc";
- font = "Arial";
- red = green = blue = 1;
- x = thiso.x + WIDTH / 32;
- y = thiso.y + HEIGHT / 16 + 1;
- }
- }
- function onActionUpdateGameText(message) {
- with (findimg(10001)) {
- layer = 2;
- text = message;
- style = "bc";
- font = "Arial";
- red = green = blue = 1;
- x = thiso.x + WIDTH / 32;
- y = thiso.y - 1.5;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement