Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.98 KB | None | 0 0
  1. var button;
  2. var valuemon;
  3. var valuemon = 25;
  4. var valuetime;
  5. var valuetime= 24;
  6. var valuehap;
  7. var valuehap=180;
  8. var valuehea;
  9. var valuehea=100;
  10. var showText;
  11. var showText = true;
  12. var valueday;
  13. var valueday= 0;
  14. var timesplayed;
  15. var timesplayed=0;
  16. var receivedBonushap = false;
  17. var receivedBonushea = false;
  18. var receivedBonusmon = false;
  19.  
  20.  
  21. function setup() {
  22. createCanvas(1250, 1000);
  23. background(255);
  24. textAlign(CENTER);
  25. fill(2);
  26. textSize(20);
  27. text("The Industrialization has just started.\n You lost your job as a carpenter and you are now working in a factory.\n You have no family, and you only have 25 dollars in your savings.\n Your job already pays a lot more than average, but you must work long hours and you are often tired and depressed.\n Each day, you get a little older and get a little weaker.", width/2, height/5);
  28. buttons();
  29. hidebuttons();
  30. // button that is clicked to start game
  31. game = createButton("start");
  32. game.position(600,400);
  33. game.mousePressed(play);
  34. // button that brings player back to menu
  35. back = createButton("Menu");
  36. back.position (1000,100);
  37. back.mousePressed(menu);
  38. // button that goes to achievment page
  39. ac = createButton("Achievements");
  40. ac.position(100,100);
  41. ac.mousePressed(Achievements);
  42. // button that does exact same thing as start button, but is placed at different time of the game
  43. restart = createButton("Restart");
  44. restart.mousePressed(play);
  45. restart.hide();
  46. contb = createButton("Continue");
  47. contb.position(700,400);
  48. contb.mousePressed(cont);
  49. contb.hide();
  50. BeerImg = loadImage("images/beer.jpg");
  51. HealthImg = loadImage("images/health.jpg");
  52. MoneyImg = loadImage("images/money.jpg");
  53. }
  54.  
  55.  
  56. function Achievements(){
  57. console.log("called negative");
  58. game.hide();
  59. background(255);
  60. }
  61.  
  62. function reset(){
  63. console.log("called negative");
  64. valuemon = 25;
  65. valuetime= 24;
  66. valuehap=180;
  67. valuehea=100;
  68. }
  69.  
  70. function menu(){
  71. console.log("called negative");
  72. hidebuttons();
  73. restart.hide();
  74. background(255);
  75. textAlign(CENTER);
  76. fill(2);
  77. textSize(20);
  78. text("The Industrialization has just started.\n You lost your job as a carpenter and you are now working in a factory.\n You have no family, and you only have 25 dollars in your savings.\n Your job already pays a lot more than average, but you must work long hours and you are often tired and depressed.\n Each day, you get a little older and get a little weaker.", width/2, height/5);
  79. game.show();
  80. ac.show();
  81. contb.show();
  82. hidebuttons
  83. }
  84.  
  85. function cont(){
  86. console.log("called negative");
  87. game.hide();
  88. ac.hide();
  89. contb.hide();
  90. restart.position(1000,600);
  91. restart.show();
  92. background(255);
  93. buttons();
  94. valuestext();
  95. buttonstext();
  96. }
  97.  
  98. // function so that all buttons do now show up
  99. function hidebuttons(){
  100. console.log("called negative");
  101. buttonwork1.hide();
  102. buttonwork2.hide();
  103. buttonpub.hide();
  104. buttonsleep1.hide();
  105. buttonsleep2.hide();
  106. buttoneat.hide();
  107. }
  108.  
  109.  
  110. function draw(){
  111.  
  112. }
  113.  
  114.  
  115. function play() {
  116. console.log("called negative");
  117. reset();
  118. game.hide();
  119. ac.hide();
  120. contb.hide();
  121. // cont.hide();
  122. restart.show();
  123. restart.position(1000,600);
  124. background(255);
  125. if(showText){
  126. valuestext();
  127. buttonstext();
  128. }
  129. buttons();
  130. background(255);
  131. valuestext();
  132. buttonstext();
  133. }
  134.  
  135.  
  136. function valuestext(){
  137. textSize(32);
  138. text("money", 100, 100);
  139. text(valuemon, 100, 150);
  140. text("time", 300, 100);
  141. text(valuetime, 300, 150);
  142. text("health", 500, 100);
  143. text(valuehea, 500, 150);
  144. text("happiness", 700, 100);
  145. text(valuehap, 700, 150);
  146. text("day",900,100);
  147. text(valueday, 900,150);
  148. }
  149.  
  150.  
  151. function buttonstext(){
  152. textSize(20);
  153. text("+10 money \n -8 time \n -20 health \n -20 happiness", 250,250);
  154. text("+20 money \n -15 time \n -30 health \n -25 happiness",650,250);
  155. text("-5 money \n -1 time \n -1 health \n +5 happiness",1050,250);
  156. text("-3 money \n -1 time \n +1 health \n +1 happiness",250,450);
  157. text("-5 money \n -3 time \n +5 health \n +5 happiness",650,450);
  158. text("-5 money \n -1 time \n +0 health \n +3 happiness",1050,450);
  159. }
  160.  
  161.  
  162. // ________________________________________________________________________________________________________________________________
  163.  
  164.  
  165. // all buttons for adding or subtracting valuemons
  166. function buttons(){
  167. console.log("called negative");
  168. // work #1
  169. buttonwork1 = createButton('Work #1');
  170. buttonwork1.position(225, 200);
  171. // work #2
  172. buttonwork2 = createButton('Work #2');
  173. buttonwork2.position(625, 200);
  174. // pub
  175. buttonpub = createButton('Pub');
  176. buttonpub.position(1025, 200);
  177. // sleep #1
  178. buttonsleep1 = createButton('Sleep #1');
  179. buttonsleep1.position(225, 400);
  180. // sleep #2
  181. buttonsleep2 = createButton('Sleep #2');
  182. buttonsleep2.position(625, 400);
  183. // eat
  184. buttoneat = createButton('Eat');
  185. buttoneat.position(1025, 400);
  186. // what happens when buttons are pushed
  187. buttonwork1.mousePressed(work1);
  188. buttonwork2.mousePressed(work2);
  189. buttonpub.mousePressed(pub);
  190. buttonsleep1.mousePressed(sleep1);
  191. buttonsleep2.mousePressed(sleep2);
  192. buttoneat.mousePressed(eat);
  193. }
  194.  
  195.  
  196. // ________________________________________________________________________________________________________________________________
  197.  
  198.  
  199. // functions that happen when certain buttons are pushed
  200. function work1(){
  201. // when work1 pushed, +10 money, -8 time, -20 health, -20 happiness
  202. if(!negative(-8)){
  203. valuemon= valuemon+10;
  204. valuetime= valuetime-8;
  205. valuehea= valuehea-20;
  206. valuehap= valuehap-20;
  207. background(255);
  208. valuestext();
  209. buttonstext();
  210. check();
  211. check2();
  212. }
  213. }
  214.  
  215.  
  216. function work2(){
  217. // when work2 pushed, +20 money, -15 time, -30 health, -25 happiness
  218. if(!negative(-15)){
  219. valuemon= valuemon+20;
  220. valuetime= valuetime-15;
  221. valuehea= valuehea-30;
  222. valuehap= valuehap-25;
  223. background(255);
  224. valuestext();
  225. buttonstext();
  226. check();
  227. check2();
  228. }
  229. }
  230.  
  231.  
  232. function pub(){
  233. // when pub button pushed, -5 money, -1 time, -1 health, +5 happiness'
  234. if(!negative(-1)){
  235. valuemon= valuemon-5;
  236. valuetime= valuetime-1;
  237. valuehea= valuehea-1;
  238. valuehap= valuehap+5;
  239. background(255);
  240. valuestext();
  241. buttonstext();
  242. check();
  243. check2();
  244. }
  245. }
  246.  
  247.  
  248. function sleep1(){
  249. // when sleep1 button pushed, -3 money, -1 time, +1 health, +1 happiness
  250. if(!negative(-1)){
  251. valuemon= valuemon-3;
  252. valuetime= valuetime-1;
  253. valuehea= valuehea+1;
  254. valuehap= valuehap+1;
  255. background(255);
  256. valuestext();
  257. buttonstext();
  258. check();
  259. check2();
  260. }
  261. }
  262.  
  263.  
  264. function sleep2(){
  265. // when sleep2 button pushed, -5 money, -3 time, +5 health, +5 happiness
  266. if(!negative(-3)){
  267. valuemon= valuemon-5;
  268. valuetime= valuetime-3;
  269. valuehea= valuehea+5;
  270. valuehap= valuehap+5;
  271. background(255);
  272. valuestext();
  273. buttonstext();
  274. check();
  275. check2();
  276. }
  277. }
  278.  
  279.  
  280. function eat(){
  281. // when eat button pushed, -5 money, -1 time, +0 health, +3 happiness
  282. if(!negative(-1)){
  283. valuemon= valuemon-5;
  284. valuetime= valuetime-1;
  285. valuehea= valuehea+0;
  286. valuehap= valuehap+3;
  287. background(255);
  288. valuestext();
  289. buttonstext();
  290. check();
  291. check2();
  292. }
  293. }
  294.  
  295. // ________________________________________________________________________________________________________________________________
  296.  
  297. // reset the time
  298. function resettime(){
  299. valuetime= 24;
  300. background(255);
  301. valuestext();
  302. buttonstext();
  303. buttons();
  304. }
  305.  
  306. // after gameover, reset everything.
  307. function gameover(){
  308. console.log("called negative");
  309. background(255);
  310. text(50);
  311. text("GAME OVER", 650,250);
  312. restart.show();
  313. restart.position(625,150);
  314. back.show();
  315. valuemon = 25;
  316. valuetime= 24;
  317. valuehap=100;
  318. valuehea=100;
  319. valueday=0;
  320. timesplayed=timesplayed+1
  321. firsttime();
  322. }
  323.  
  324.  
  325. // once you finish the game for the first time, gives some info about industrialization
  326. function firsttime(){
  327. console.log("called negative");
  328. if (timesplayed===1){
  329. textAlign(CENTER);
  330. textSize(25);
  331. text("Because of the creation of machines, many people lost their jobs. \n They used to stay home and hand-wove or handmake products. \n The working class people during the Industrialization had to work long hours \n and they often had many injuries, but they couldn't pay for care or medicine \n because they didn't have enough money.\n The workers only received a break for lunch and a break for dinner. \n Children couldn't get an education and this led to more idle time \n which eventually led to more crimes. \n The factories produced a lot of toxic gasses and people got lung cancer. \n During this time, there wasn't much chance for the working class to become successful.",width/2,height/2-200);
  332. }
  333. }
  334.  
  335. // ________________________________________________________________________________________________________________________________
  336.  
  337. // so that it's not possible for time to go into negative; if negative, nothing happens
  338. function negative(btime){
  339. console.log("called negative");
  340. if(valuetime+btime<0){
  341. return(true);
  342. }
  343. return(false);
  344. }
  345.  
  346. function check(){
  347. console.log("called negative");
  348. if(valuehap<=0){
  349. // if happiness goes to zero
  350. background(255);
  351. showText = false;
  352. restart.hide();
  353. back.hide();
  354. hidebuttons();
  355. textSize(30)
  356. text("you suffer from extreme depression and can no longer work", 700, 500);
  357. setTimeout(gameover,2000);
  358. image(BeerImg, 600, 200);
  359. }
  360. else if(valuehea<=0){
  361. console.log("called negative");
  362. // if health goes to zero
  363. background(255);
  364. showText = false;
  365. hidebuttons();
  366. back.hide();
  367. restart.hide();
  368. textSize(30)
  369. text("you suffer from extreme lung cancer and can no longer work", 700, 500);
  370. setTimeout(gameover,2000);
  371. image(HealthImg, 600, 300);
  372. }
  373. else if(valuemon<=0){
  374. console.log("called negative");
  375. // if money go to zero
  376. background(255);
  377. showText = false;
  378. hidebuttons();
  379. back.hide();
  380. restart.hide();
  381. textSize(30)
  382. text("you lose your job and home and can't pay for food", 700, 500);
  383. setTimeout(gameover,2000);
  384. image(MoneyImg, 500,100);
  385. }
  386. else if(valuetime<=0){
  387. console.log("called negative");
  388. // if time goes to zero
  389. background(255);
  390. showText = false;
  391. hidebuttons();
  392. restart.hide();
  393. back.hide();
  394. textSize(50)
  395. text("NEXT DAY", 600, 400);
  396. valueday= valueday+1
  397. valuehea= valuehea-2
  398. valuemon= valuemon-2
  399. valuehap= valuehap-2
  400. setTimeout(resettime,2000);
  401. }
  402. }
  403.  
  404. // ________________________________________________________________________________________________________________________________
  405.  
  406. function back2(){
  407. console.log("called negative");
  408. background(255);
  409. fill(0);
  410. valuestext();
  411. buttonstext();
  412. buttons();
  413. }
  414.  
  415. function check2(){
  416. monac();
  417. hapac();
  418. heaac();
  419. }
  420. function monac(){
  421. if(valuemon >=100 && receivedBonusmon === false){
  422. fill(0, 102, 153);
  423. textSize(50);
  424. text("100+ money", 600, 350);
  425. setTimeout(back2,500);
  426. receivedBonusmon = true;
  427. }
  428. }
  429.  
  430. function hapac(){
  431. if(valuehap >=200 && receivedBonushap === false){
  432. textSize(50);
  433. fill(0, 102, 153);
  434. text("200+ happiness", 600, 350);
  435. setTimeout(back2,500);
  436. receivedBonushap = true;
  437. }
  438. }
  439.  
  440. function heaac(){
  441. if(valuehea >=200 && receivedBonushea === false){
  442. fill(0, 102, 153);
  443. textSize(50);
  444. text("200+ health", 600, 350);
  445. setTimeout(back2,500);
  446. receivedBonushea = true;
  447. }
  448. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement