Advertisement
Guest User

SuperSnake Charles and Jonathan 5 draw and setup

a guest
May 21st, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.19 KB | None | 0 0
  1. int a=1; //background colour selector
  2. int b=1; // snake colour selector
  3. int c=1; // sound on/off
  4. int d=1; // powerups on/off
  5. int screen=0;
  6. int selected;
  7. PImage photo; //Title Screen
  8. PImage photo2; //Gamemodes
  9. PImage photo3; //How to Play
  10. PImage photo4; //Settings Menu
  11. PImage photo5; //Credits
  12. PImage photo6; //haste
  13. PImage photo7; //double length
  14. PImage photo8; //ghost
  15. PImage photo9; //nausea
  16. PImage photo10; //gameover
  17. int growAmount;
  18. int g=3; //grow
  19. int h=3; //grow 2
  20. import processing.sound.*;
  21. SoundFile file1;
  22. SoundFile file2;
  23. //SoundFile file3 = new SoundFile(this, "powerupsound.wav");
  24. class Powerup
  25. {
  26. int x;
  27. int y;
  28. long m = 30000;
  29. /*********************************************************
  30. * Purpose: Increase the snake speed by 50% for 5 seconds *
  31. * Parameters: m, time in milliseconds *
  32. * Returns: 6 *
  33. * 9 *
  34. *********************************************************/
  35. int haste()
  36. {
  37. m--;
  38. if (m>0)
  39. return 9;
  40. else
  41. return 6;
  42. }
  43. /*** Powerup ******************************************
  44. * Purpose: To spawn a powerup *
  45. * Parameters: none *
  46. * Returns: none *
  47. ******************************************************/
  48. Powerup()
  49. {
  50. movePowerup();
  51. }
  52. /*** movePowerup **************************************
  53. * Purpose: To move powerup to random location *
  54. * Parameters: x, x coordinate of powerup *
  55. * y, y coordinate of powerup *
  56. * Returns: none *
  57. ******************************************************/
  58. void movePowerup()
  59. {
  60. x = (int)random(1,40);
  61. y = (int)random(1,40);
  62. }
  63. /*** getPowerup ***************************************
  64. * Purpose: To activate the powerup *
  65. * Parameters: x, x coordinate of snake *
  66. * y, y coordinate of snake *
  67. * _x, x coordinate of powerup *
  68. * _y, y coordinate of powerup *
  69. * Returns: none *
  70. ******************************************************/
  71.  
  72. boolean getPowerup(int _x, int _y)
  73. {
  74. if ( x == _x && y == _y)
  75. {
  76. delay(5000);
  77. movePowerup();
  78. return true;
  79. }
  80. return false;
  81. }
  82.  
  83. boolean isPowerup(int _x, int _y)
  84. {
  85. if ( x == _x && y == _y)
  86. {
  87. return true;
  88. }
  89. return false;
  90. }
  91. }
  92. color backgroundColour() //return background colour
  93. {
  94. if (a == 1)
  95. return #5ba4d8;
  96. else if (a == 2)
  97. return #000000;
  98. else
  99. return #0000FF;
  100. }
  101. class Colours
  102. {
  103.  
  104. color snakeColour() //return snake colour
  105. {
  106. if (b==1)
  107. return #FF0000;
  108. else if (b==2)
  109. return #00FF00;
  110. else if (b==3)
  111. return #FFFF00;
  112. else if (b==4)
  113. return #FFA500;
  114. else
  115. return #800080;
  116. }
  117.  
  118. }
  119. void draw()
  120. {
  121. background(255);
  122. if (screen == 0)//main menu
  123. {
  124. image(photo,0,0);
  125. }
  126. else if (screen == 1)//Gamemodes
  127. {
  128. image(photo2,0,0);
  129. }
  130. else if (screen == 2)//How to play
  131. {
  132. image(photo3,0,0);
  133. }
  134. else if (screen == 4)//Credits
  135. {
  136. image(photo5,0,0);
  137. }
  138. else if (screen == -1) //settings menu
  139. {
  140. image(photo4,0,0);
  141. }
  142. else if (screen==5)
  143. {
  144. //chooseGameMode(1);
  145. }
  146. else if (screen ==6)
  147. {
  148. }
  149. else if (screen ==7)
  150. {
  151. }
  152. //Selected boxes for settings menu
  153. if (screen == -1)
  154. {
  155. if (a == 1)
  156. {
  157. stroke(224,255,255);
  158. strokeWeight(3);
  159. noFill();
  160. rect(465,175,80,70);
  161. }
  162. else if (a == 2)
  163. {
  164. stroke(224,255,255);
  165. strokeWeight(3);
  166. noFill();
  167. rect(583,180,65,63);
  168. }
  169. else if (a == 3)
  170. {
  171. stroke(224,255,255);
  172. strokeWeight(3);
  173. noFill();
  174. rect(695,177,60,68);
  175. }
  176. if (b==1)
  177. {
  178. stroke(224,255,255);
  179. strokeWeight(3);
  180. noFill();
  181. rect(350,280,350,43);
  182. }
  183. else if (b==2)
  184. {
  185. stroke(224,255,255);
  186. strokeWeight(3);
  187. noFill();
  188. rect(40,368,360,40);
  189. }
  190. else if (b==3)
  191. {
  192. stroke(224,255,255);
  193. strokeWeight(3);
  194. noFill();
  195. rect(440,367,320,40);
  196. }
  197. else if (b==4)
  198. {
  199. stroke(224,255,255);
  200. strokeWeight(3);
  201. noFill();
  202. rect(440,445,300,40);
  203. }
  204. else if (b==5)
  205. {
  206. stroke(224,255,255);
  207. strokeWeight(3);
  208. noFill();
  209. rect(20,443,370,40);
  210. }
  211. if (c==1)
  212. {
  213. stroke(224,255,255);
  214. strokeWeight(3);
  215. noFill();
  216. rect(415,670,90,55);
  217. }
  218. else if (c==2)
  219. {
  220. stroke(224,255,255);
  221. strokeWeight(3);
  222. noFill();
  223. rect(675,670,140,55);
  224. }
  225. if (d==1)
  226. {
  227. stroke(224,255,255);
  228. strokeWeight(3);
  229. noFill();
  230. rect(425,823,90,55);
  231. }
  232. else if (d==2)
  233. {
  234. stroke(224,255,255);
  235. strokeWeight(3);
  236. noFill();
  237. rect(685,823,130,55);
  238. }
  239. }
  240. //actual game
  241. if (!gameOver && (screen ==5 || screen==6 || screen==7))
  242. {
  243. if (mode == 1)
  244. {
  245. if(s1.drawSnake())
  246. {
  247. renderer.drawCollision();
  248. println("game over");
  249. gameOver = true;
  250. }
  251. else
  252. {
  253. if (mode == 2) renderer.drawBoardMulti();
  254. if (mode == 1) renderer.drawBoardSingle();
  255. }
  256. }
  257. else if (mode == 2)
  258. {
  259. if(s1.drawSnake() || s2.drawSnake())
  260. {
  261. renderer.drawCollision();
  262. println("game over");
  263. gameOver = true;
  264. }
  265. else
  266. {
  267. if (mode == 2) renderer.drawBoardMulti();
  268. if (mode == 1) renderer.drawBoardSingle();
  269. }
  270. }
  271. if(screen ==6)
  272. {
  273. fill(0);
  274. textSize(14);
  275. text("Score = " + g , 850,100);
  276. }
  277. else if(screen==8)
  278. {
  279. fill(0);
  280. textSize(14);
  281. text("Score = " + g , 850,100);
  282. }
  283. else if(screen==7)
  284. {
  285. fill(0);
  286. textSize(14);
  287. text("Score = " + g , 850,50);
  288. fill(255,0,255);
  289. textSize(14);
  290. text("Score = " + h, 850, 100);
  291. }
  292. //restart the game
  293. if (gameOver && (screen == 6 || screen == 7 || screen == 8))
  294. {
  295. if(gameOver && (screen == 6 || screen == 7 || screen == 8))
  296. image (photo10,0,0);
  297. if (restart)
  298. {
  299. gameOver = false;
  300. s1 = new Snake (10, "arrows");
  301. if (mode == 2)
  302. {
  303. s2 = new Snake(20, "wasd");
  304. s1.setOtherSnake(s2);
  305. s2.setOtherSnake(s1);
  306. }
  307. println("restart");
  308. restart = false;
  309. }
  310. }
  311. }
  312. }
  313.  
  314. void mouseReleased()
  315. {
  316. if (screen == 2 || screen == 3 || screen == 4)
  317. screen = 0;
  318. else if(gameOver && (screen == 6 || screen == 7 || screen == 8))
  319. screen = 0;
  320. else if (screen == 0 && mouseX >= 310 && mouseX <= 690 && mouseY >= 500 && mouseY <= 545)
  321. screen = 1;
  322. else if (screen == 1 && mouseX>=940 && mouseY>=740 || mouseX<=80 && mouseY<=370)
  323. screen = 0;
  324. else if (screen == 0 && mouseX >= 360 && mouseX <= 740 && mouseY >= 370 && mouseY <= 430)
  325. screen = 2;
  326. else if (screen == 0 && mouseX >= 360 && mouseX <= 740 && mouseY >= 370 && mouseY <= 430)
  327. screen = 3;
  328. else if (screen == 0 && mouseX >= 330 && mouseX <= 670 && mouseY >= 640 && mouseY <= 700)
  329. screen = -1;
  330. else if (screen == 0 && mouseX >= 350 && mouseX <= 640 && mouseY >= 790 && mouseY <= 835)
  331. screen = 4;
  332. //settings
  333. else if (screen == -1 && mouseX >= 465 && mouseX <= 545 && mouseY >= 175 && mouseY <= 245) //pale blue
  334. a = 1;
  335. else if (screen == -1 && mouseX >= 580 && mouseX <= 650 && mouseY >= 180 && mouseY <= 240) //black
  336. a = 2;
  337. else if (screen == -1 && mouseX >= 695 && mouseX <= 760 && mouseY >= 180 && mouseY <= 245) //blue
  338. a = 3;
  339. else if (screen == -1 && mouseX >= 350 && mouseX <= 700 && mouseY >= 280 && mouseY <= 320) // red snake
  340. b = 1;
  341. else if (screen == -1 && mouseX >= 40 && mouseX <= 400 && mouseY >= 370 && mouseY <= 410) // lime green snake
  342. b = 2;
  343. else if (screen == -1 && mouseX >= 440 && mouseX <= 760 && mouseY >= 360 && mouseY <= 410) // yellow snake
  344. b = 3;
  345. else if (screen == -1 && mouseX >= 440 && mouseX <= 730 && mouseY >= 450 && mouseY <= 480) // purple
  346. b = 4;
  347. else if (screen == -1 && mouseX >= 20 && mouseX <= 390 && mouseY >= 443 && mouseY <= 480) // orange
  348. b = 5;
  349. else if (screen == -1 && mouseX >= 420 && mouseX <= 500 && mouseY >= 675 && mouseY <= 710) // sound on
  350. {
  351. c = 1;
  352. file1.play();
  353. }
  354. else if (screen == -1 && mouseX >= 675 && mouseX <= 800 && mouseY >= 675 && mouseY <= 720) // sound off
  355. {
  356. c = 2;
  357. file1.stop();
  358. }
  359. else if (screen == -1 && mouseX >= 425 && mouseX <= 510 && mouseY >= 823 && mouseY <= 870) // powerups on
  360. d = 1;
  361. else if (screen == -1 && mouseX >= 690 && mouseX <= 810 && mouseY >= 825 && mouseY <= 870) // powerups off
  362. d = 2;
  363. else if (screen == 1 && screen != 0 && (mouseX>=240 && mouseX>=770 || mouseX<=205 && mouseY<=270))
  364. {
  365. screen = 5;
  366. chooseGameMode(2);
  367. println("Screen = 5");
  368. }
  369. else if (screen == 1 && screen != 0 && (mouseX>=260 && mouseX>=750 || mouseY<=335 && mouseY<=400))
  370. {
  371. screen = 6;
  372. chooseGameMode(1);
  373. }
  374. else if (screen == 1 && screen != 0 && (mouseX>=90 && mouseX>=895 || mouseY<=480 && mouseY<=530))
  375. {
  376. screen = 7;
  377. chooseGameMode(2);
  378. }
  379. else
  380. {
  381. }
  382. print (b);
  383. println (a); //check if this works
  384. print (c);
  385. print (d);
  386. println(screen);
  387. println("Gamemode: " + mode);
  388. }
  389. void setup()
  390. {
  391. file1 = new SoundFile(this, "Despacito - 8 bit Version, as 80s Computer Game Music.mp3");
  392. if (c==1)
  393. {
  394. file1 = new SoundFile(this, "Despacito - 8 bit Version, as 80s Computer Game Music.mp3");
  395. file1.play();
  396. }
  397. size(1000,1000);
  398. background(color(255));
  399. smooth();
  400. photo = loadImage("titleScreen.jpg");
  401. photo2 = loadImage("gamemodes.jpg");
  402. photo3 = loadImage("howToPlay.png");
  403. photo4 = loadImage("settingsMenu.png");
  404. photo5 = loadImage("credits.png");
  405. photo10 = loadImage("gameOver.png");
  406. gameOver = false;
  407. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement