Advertisement
Guest User

nature simulator

a guest
Aug 23rd, 2015
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.81 KB | None | 0 0
  1. <html>
  2. <head>
  3. <style>
  4. .area{
  5. position:absolute;
  6. width:200;
  7. height:100;
  8. }
  9. #block{
  10. position:absolute;
  11. width:1000;
  12. height:1000;
  13. top:0;
  14. left:0;
  15. }
  16. </style>
  17. </head>
  18. <body onmousedown="clicked(event);">
  19. <canvas></canvas>
  20. <div class="area" style="top:220; left:20;" id="area1" onclick="chop();"></div>
  21. <div class="area" style="top:240; left:260;" id="area2" onclick="construct();"></div>
  22. <div class="area" style="top:240; left:630;" id="area3" onClick="grow();"></div>
  23. <div class="area" style="top:0; left:630;" id="sell" onClick="sellit();"></div>
  24. <div id="block"></div>
  25. <script type="text/javascript">
  26. var can=document.querySelector("canvas");
  27. var ctx=can.getContext("2d");
  28. var sky=new Image();
  29. sky.src="sky.jpg";
  30. var hills=new Image();
  31. hills.src="hills.png";
  32. var skyframe=0;
  33. var wheat = new Image;
  34. wheat.src="wheatyoung.png"
  35. var house = new Image();
  36. house.src="homeconstruct.png";
  37. var trees = new Image();
  38. trees.src="trees.jpg";
  39. var sell = new Image();
  40. sell.src = "sell.jpg";
  41. var pipe = new Image();
  42. pipe.src="pipe.jpg";
  43. can.width=sky.width;
  44. can.height=sky.height;
  45. var click=false;
  46. var mouse={x:0, y:0};
  47. var grown=false;
  48. var breadcount=0;
  49. var money=0;
  50.  
  51. var dialogue=[
  52. "Welcome to nature simulator 2015! Click to continue",
  53. "First, grow some wheat by clicking on it.",
  54. null,
  55. "Build a house to keep away from hot, dry days!",
  56. null,
  57. "Now turn the wheat into bread by clicking on it.",
  58. null,
  59. "Sell some of that bread, might as well profit!",
  60. null,
  61. "reviews: 'wow', 'great bread!'",
  62. "'I want 50 more bread!'",
  63. null,
  64. "You have to produce more bread!",
  65. "Chop down those trees to clear some land first.",
  66. null,
  67. "Now build a factory in its place!",
  68. "It will help you a lot.",
  69. null,
  70. "Great job! Have fun selling 100 bread!",
  71. null,
  72. "dont mind us we are just investigating",
  73. "dont mind us we are just investigating",
  74. "dont mind us we are just investigating",
  75. null,
  76. "Halt, you are under arrest!",
  77. "Halt, you are under arrest!",
  78. "Halt, you are under arrest!",
  79. "your charges:",
  80. "Illegal fast-growth fertelizer",
  81. "pollution of the enviroment",
  82. "and the extinction of a bird species",
  83. "you died, executed for your crimes",
  84. "you didn't understand what you did was illegal",
  85. "well, now you know",
  86. "you monster"
  87. ];
  88. var dn=0;
  89. dnlimit=1;
  90. ctx.font="20px Arial";
  91.  
  92. var backgroundsound = new Audio("Nature Background Music 1.m4a");
  93. backgroundsound.addEventListener('ended', function() {
  94. this.currentTime = 0;
  95. this.play();
  96. }, false);
  97. backgroundsound.play();
  98.  
  99. var backgroundsoundch = new Audio("chaos.mp3");
  100. backgroundsoundch.addEventListener('ended', function() {
  101. this.currentTime = 0;
  102. this.play();
  103. }, false);
  104. backgroundsoundch.volume=0;
  105. backgroundsoundch.play();
  106.  
  107. var chopping= new Audio("chopping.m4a");
  108.  
  109. var endmusic= new Audio("endmusic.m4a");
  110.  
  111. function clicked(e){
  112. click=true;
  113. mouse.x=e.clientX;
  114. mouse.y=e.clientY;
  115. }
  116.  
  117. function introduction(){
  118. ctx.fillStyle="rgb(100,100,100)";
  119. ctx.fillText(dialogue[dn], 200, 100);
  120. if(click){
  121. dn++;
  122. click=false;
  123. }
  124. }
  125.  
  126. function grow(){
  127. if(!grown){
  128. wheat.src="wheatgrown.png";
  129. dnlimit=3;
  130. grown=true;
  131. }else{
  132. wheat.src="wheatyoung.png";
  133. breadcount++;
  134. grown=false;
  135. if(dn>=6){
  136. dnlimit=7;
  137. }
  138. }
  139. }
  140.  
  141. function construct(){
  142. if(dn==4){
  143. house.src="homebuilt.png";
  144. dnlimit=5;
  145. backgroundsoundch.volume=0.1;
  146. backgroundsound.volume=0.9;
  147. }
  148. }
  149.  
  150. function sellit(){
  151. if(breadcount>0){
  152. if(dn==8){
  153. dnlimit=10;
  154. }
  155. if(dn==11 && breadcount>=50){
  156. money+=500;
  157. breadcount-=50;
  158. dnlimit=13;
  159. }
  160. if(breadcount>0){
  161. money+=10;
  162. breadcount--;
  163. }
  164. if(breadcount==250){
  165. dnlimit=22;
  166. backgroundsound.volume=0.2;
  167. backgroundsoundch.volume=0.8;
  168. }
  169. if(breadcount==300){
  170. dnlimit=30;
  171. backgroundsound.volume=0;
  172. backgroundsoundch.volume=1;
  173. }
  174. }
  175. }
  176.  
  177. function chop(){
  178. if(dn==14){
  179. trees.src="treestumps.jpg";
  180. dnlimit=16;
  181. }
  182. if(dn==17){
  183. trees.src="factory.jpg";
  184. dnlimit=18;
  185. backgroundsound.volume=0.5;
  186. backgroundsoundch.volume=0.5;
  187. }
  188. }
  189.  
  190. function loop(){
  191. clear();
  192. draw();
  193. if(dn<=dnlimit){
  194. document.getElementById("block").style.display="block";
  195. introduction();
  196. }else{
  197. document.getElementById("block").style.display="none";
  198. }
  199. producebread();
  200. skyframe++;
  201. if(dn==31){
  202. end();
  203. }else{
  204. requestAnimationFrame(loop);
  205. }
  206. }
  207.  
  208. loop();
  209.  
  210. function clear(){
  211. ctx.clearRect(0,0,can.width,can.height);
  212. }
  213.  
  214. function draw(){
  215. drawSky();
  216. ctx.drawImage(hills,0,250);
  217. ctx.drawImage(sell, 720, 20);
  218. drawWheat();
  219. drawHouse();
  220. drawTrees();
  221. drawbread();
  222. }
  223.  
  224. function drawbread(){
  225. if(dn>=6){
  226. ctx.fillText("bread: "+breadcount, 10, 20);
  227. }
  228. if(dn>=8){
  229. ctx.fillText("money: "+money, 10, 50);
  230. }
  231. //ctx.fillText(dn, 10, 80);
  232. }
  233.  
  234. function drawSky(){
  235. if(skyframe==can.width){skyframe=0;}
  236. ctx.drawImage(sky,skyframe,0);
  237. var clippedw=can.width-skyframe;
  238. ctx.drawImage(sky,0,0,sky.width,sky.height,(-1)*(sky.width-skyframe),0,sky.width,sky.height);
  239. }
  240.  
  241. function drawWheat(){
  242. ctx.drawImage(wheat, 70, 230);
  243. ctx.drawImage(wheat, 700, 253);
  244. }
  245.  
  246. function drawHouse(){
  247. ctx.drawImage(house, 220, 200);
  248. }
  249.  
  250. function drawTrees(){
  251. ctx.drawImage(trees, 20, 180);
  252. if(dn >= 19 && breadcount>=150){
  253. ctx.drawImage(pipe, 590, 276);
  254. }
  255. }
  256.  
  257. function producebread(){
  258. if(dn>=18 && money>0){
  259. breadcount++;
  260. money-=5;
  261. }
  262. }
  263.  
  264. function end(){
  265. backgroundsound.pause();
  266. backgroundsoundch.pause();
  267. endmusic.play();
  268. requestAnimationFrame(fadeoutof);
  269. }
  270.  
  271. var timescalled=1;
  272.  
  273. function fadeoutof(){
  274. timescalled++;
  275. if(timescalled%300==0){
  276. dn++;
  277. }
  278. if(dn>31 && dn<35){
  279. ctx.fillStyle="white";
  280. ctx.fillText(dialogue[dn], 200, 100);
  281. }
  282. ctx.fillStyle="rgba(0,0,0,.01)";
  283. ctx.fillRect(0,0,can.width,can.height);
  284. requestAnimationFrame(fadeoutof);
  285. }
  286. </script>
  287. </body>
  288. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement