Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int a=1; //background colour selector
- int b=1; // snake colour selector
- int c=1; // sound on/off
- int d=1; // powerups on/off
- int screen=0;
- int selected;
- PImage photo; //Title Screen
- PImage photo2; //Gamemodes
- PImage photo3; //How to Play
- PImage photo4; //Settings Menu
- PImage photo5; //Credits
- PImage photo6; //haste
- PImage photo7; //double length
- PImage photo8; //ghost
- PImage photo9; //nausea
- PImage photo10; //gameover
- int growAmount;
- int g=3; //grow
- int h=3; //grow 2
- import processing.sound.*;
- SoundFile file1;
- SoundFile file2;
- //SoundFile file3 = new SoundFile(this, "powerupsound.wav");
- class Powerup
- {
- int x;
- int y;
- long m = 30000;
- /*********************************************************
- * Purpose: Increase the snake speed by 50% for 5 seconds *
- * Parameters: m, time in milliseconds *
- * Returns: 6 *
- * 9 *
- *********************************************************/
- int haste()
- {
- m--;
- if (m>0)
- return 9;
- else
- return 6;
- }
- /*** Powerup ******************************************
- * Purpose: To spawn a powerup *
- * Parameters: none *
- * Returns: none *
- ******************************************************/
- Powerup()
- {
- movePowerup();
- }
- /*** movePowerup **************************************
- * Purpose: To move powerup to random location *
- * Parameters: x, x coordinate of powerup *
- * y, y coordinate of powerup *
- * Returns: none *
- ******************************************************/
- void movePowerup()
- {
- x = (int)random(1,40);
- y = (int)random(1,40);
- }
- /*** getPowerup ***************************************
- * Purpose: To activate the powerup *
- * Parameters: x, x coordinate of snake *
- * y, y coordinate of snake *
- * _x, x coordinate of powerup *
- * _y, y coordinate of powerup *
- * Returns: none *
- ******************************************************/
- boolean getPowerup(int _x, int _y)
- {
- if ( x == _x && y == _y)
- {
- delay(5000);
- movePowerup();
- return true;
- }
- return false;
- }
- boolean isPowerup(int _x, int _y)
- {
- if ( x == _x && y == _y)
- {
- return true;
- }
- return false;
- }
- }
- color backgroundColour() //return background colour
- {
- if (a == 1)
- return #5ba4d8;
- else if (a == 2)
- return #000000;
- else
- return #0000FF;
- }
- class Colours
- {
- color snakeColour() //return snake colour
- {
- if (b==1)
- return #FF0000;
- else if (b==2)
- return #00FF00;
- else if (b==3)
- return #FFFF00;
- else if (b==4)
- return #FFA500;
- else
- return #800080;
- }
- }
- void draw()
- {
- background(255);
- if (screen == 0)//main menu
- {
- image(photo,0,0);
- }
- else if (screen == 1)//Gamemodes
- {
- image(photo2,0,0);
- }
- else if (screen == 2)//How to play
- {
- image(photo3,0,0);
- }
- else if (screen == 4)//Credits
- {
- image(photo5,0,0);
- }
- else if (screen == -1) //settings menu
- {
- image(photo4,0,0);
- }
- else if (screen==5)
- {
- //chooseGameMode(1);
- }
- else if (screen ==6)
- {
- }
- else if (screen ==7)
- {
- }
- //Selected boxes for settings menu
- if (screen == -1)
- {
- if (a == 1)
- {
- stroke(224,255,255);
- strokeWeight(3);
- noFill();
- rect(465,175,80,70);
- }
- else if (a == 2)
- {
- stroke(224,255,255);
- strokeWeight(3);
- noFill();
- rect(583,180,65,63);
- }
- else if (a == 3)
- {
- stroke(224,255,255);
- strokeWeight(3);
- noFill();
- rect(695,177,60,68);
- }
- if (b==1)
- {
- stroke(224,255,255);
- strokeWeight(3);
- noFill();
- rect(350,280,350,43);
- }
- else if (b==2)
- {
- stroke(224,255,255);
- strokeWeight(3);
- noFill();
- rect(40,368,360,40);
- }
- else if (b==3)
- {
- stroke(224,255,255);
- strokeWeight(3);
- noFill();
- rect(440,367,320,40);
- }
- else if (b==4)
- {
- stroke(224,255,255);
- strokeWeight(3);
- noFill();
- rect(440,445,300,40);
- }
- else if (b==5)
- {
- stroke(224,255,255);
- strokeWeight(3);
- noFill();
- rect(20,443,370,40);
- }
- if (c==1)
- {
- stroke(224,255,255);
- strokeWeight(3);
- noFill();
- rect(415,670,90,55);
- }
- else if (c==2)
- {
- stroke(224,255,255);
- strokeWeight(3);
- noFill();
- rect(675,670,140,55);
- }
- if (d==1)
- {
- stroke(224,255,255);
- strokeWeight(3);
- noFill();
- rect(425,823,90,55);
- }
- else if (d==2)
- {
- stroke(224,255,255);
- strokeWeight(3);
- noFill();
- rect(685,823,130,55);
- }
- }
- //actual game
- if (!gameOver && (screen ==5 || screen==6 || screen==7))
- {
- if (mode == 1)
- {
- if(s1.drawSnake())
- {
- renderer.drawCollision();
- println("game over");
- gameOver = true;
- }
- else
- {
- if (mode == 2) renderer.drawBoardMulti();
- if (mode == 1) renderer.drawBoardSingle();
- }
- }
- else if (mode == 2)
- {
- if(s1.drawSnake() || s2.drawSnake())
- {
- renderer.drawCollision();
- println("game over");
- gameOver = true;
- }
- else
- {
- if (mode == 2) renderer.drawBoardMulti();
- if (mode == 1) renderer.drawBoardSingle();
- }
- }
- if(screen ==6)
- {
- fill(0);
- textSize(14);
- text("Score = " + g , 850,100);
- }
- else if(screen==8)
- {
- fill(0);
- textSize(14);
- text("Score = " + g , 850,100);
- }
- else if(screen==7)
- {
- fill(0);
- textSize(14);
- text("Score = " + g , 850,50);
- fill(255,0,255);
- textSize(14);
- text("Score = " + h, 850, 100);
- }
- //restart the game
- if (gameOver && (screen == 6 || screen == 7 || screen == 8))
- {
- if(gameOver && (screen == 6 || screen == 7 || screen == 8))
- image (photo10,0,0);
- if (restart)
- {
- gameOver = false;
- s1 = new Snake (10, "arrows");
- if (mode == 2)
- {
- s2 = new Snake(20, "wasd");
- s1.setOtherSnake(s2);
- s2.setOtherSnake(s1);
- }
- println("restart");
- restart = false;
- }
- }
- }
- }
- void mouseReleased()
- {
- if (screen == 2 || screen == 3 || screen == 4)
- screen = 0;
- else if(gameOver && (screen == 6 || screen == 7 || screen == 8))
- screen = 0;
- else if (screen == 0 && mouseX >= 310 && mouseX <= 690 && mouseY >= 500 && mouseY <= 545)
- screen = 1;
- else if (screen == 1 && mouseX>=940 && mouseY>=740 || mouseX<=80 && mouseY<=370)
- screen = 0;
- else if (screen == 0 && mouseX >= 360 && mouseX <= 740 && mouseY >= 370 && mouseY <= 430)
- screen = 2;
- else if (screen == 0 && mouseX >= 360 && mouseX <= 740 && mouseY >= 370 && mouseY <= 430)
- screen = 3;
- else if (screen == 0 && mouseX >= 330 && mouseX <= 670 && mouseY >= 640 && mouseY <= 700)
- screen = -1;
- else if (screen == 0 && mouseX >= 350 && mouseX <= 640 && mouseY >= 790 && mouseY <= 835)
- screen = 4;
- //settings
- else if (screen == -1 && mouseX >= 465 && mouseX <= 545 && mouseY >= 175 && mouseY <= 245) //pale blue
- a = 1;
- else if (screen == -1 && mouseX >= 580 && mouseX <= 650 && mouseY >= 180 && mouseY <= 240) //black
- a = 2;
- else if (screen == -1 && mouseX >= 695 && mouseX <= 760 && mouseY >= 180 && mouseY <= 245) //blue
- a = 3;
- else if (screen == -1 && mouseX >= 350 && mouseX <= 700 && mouseY >= 280 && mouseY <= 320) // red snake
- b = 1;
- else if (screen == -1 && mouseX >= 40 && mouseX <= 400 && mouseY >= 370 && mouseY <= 410) // lime green snake
- b = 2;
- else if (screen == -1 && mouseX >= 440 && mouseX <= 760 && mouseY >= 360 && mouseY <= 410) // yellow snake
- b = 3;
- else if (screen == -1 && mouseX >= 440 && mouseX <= 730 && mouseY >= 450 && mouseY <= 480) // purple
- b = 4;
- else if (screen == -1 && mouseX >= 20 && mouseX <= 390 && mouseY >= 443 && mouseY <= 480) // orange
- b = 5;
- else if (screen == -1 && mouseX >= 420 && mouseX <= 500 && mouseY >= 675 && mouseY <= 710) // sound on
- {
- c = 1;
- file1.play();
- }
- else if (screen == -1 && mouseX >= 675 && mouseX <= 800 && mouseY >= 675 && mouseY <= 720) // sound off
- {
- c = 2;
- file1.stop();
- }
- else if (screen == -1 && mouseX >= 425 && mouseX <= 510 && mouseY >= 823 && mouseY <= 870) // powerups on
- d = 1;
- else if (screen == -1 && mouseX >= 690 && mouseX <= 810 && mouseY >= 825 && mouseY <= 870) // powerups off
- d = 2;
- else if (screen == 1 && screen != 0 && (mouseX>=240 && mouseX>=770 || mouseX<=205 && mouseY<=270))
- {
- screen = 5;
- chooseGameMode(2);
- println("Screen = 5");
- }
- else if (screen == 1 && screen != 0 && (mouseX>=260 && mouseX>=750 || mouseY<=335 && mouseY<=400))
- {
- screen = 6;
- chooseGameMode(1);
- }
- else if (screen == 1 && screen != 0 && (mouseX>=90 && mouseX>=895 || mouseY<=480 && mouseY<=530))
- {
- screen = 7;
- chooseGameMode(2);
- }
- else
- {
- }
- print (b);
- println (a); //check if this works
- print (c);
- print (d);
- println(screen);
- println("Gamemode: " + mode);
- }
- void setup()
- {
- file1 = new SoundFile(this, "Despacito - 8 bit Version, as 80s Computer Game Music.mp3");
- if (c==1)
- {
- file1 = new SoundFile(this, "Despacito - 8 bit Version, as 80s Computer Game Music.mp3");
- file1.play();
- }
- size(1000,1000);
- background(color(255));
- smooth();
- photo = loadImage("titleScreen.jpg");
- photo2 = loadImage("gamemodes.jpg");
- photo3 = loadImage("howToPlay.png");
- photo4 = loadImage("settingsMenu.png");
- photo5 = loadImage("credits.png");
- photo10 = loadImage("gameOver.png");
- gameOver = false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement