Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.70 KB | None | 0 0
  1. <head> <title> Miner game! </title>
  2. </head>
  3. <body>
  4.  
  5.  
  6.  
  7. <canvas id="game" width="750" height="750" style="border:1px solid #000000;">
  8. </canvas>
  9.  
  10. <script>
  11.  
  12. // VARS HERE:
  13. var x = 75;
  14. var y = 200;
  15. var yv = 0;
  16. var xv = 0;
  17. var now, then;
  18. var fps = 100;
  19. var timer = 1000/fps;
  20. var V = 3;
  21. var Fe = 0;
  22. var FeO = 0;
  23. var PLN = 0;
  24. var kopable = 0;
  25. var palable = 0;
  26. var sellable = 0;
  27. var wejdzable = 0;
  28. var bazar = 0;
  29. var kilofnr = 1;
  30. var wegielnr = 1;
  31. var stoiskonr = 1;
  32. var kupkilofable = 0;
  33. var kupwegielable = 0;
  34. var kupstoiskoable = 0;
  35. var wyjdzable = 0;
  36.  
  37. var ctr = game.getContext('2d');
  38.  
  39.  
  40. // SCANNERS FUNCTIONS HERE:
  41.  
  42. var mouseDown = 0;
  43.  
  44. document.body.onclick = function() {
  45.  
  46. if(mouse.x > 600 && mouse.x <700 && mouse.y >50 && mouse.y<100 && kopable == 1){
  47. FeO = FeO + kilofnr;
  48. }
  49.  
  50. if(mouse.x > 600 && mouse.x <700 && mouse.y >50 && mouse.y<100 && palable == 1 && FeO > (wegielnr - 1)){
  51. FeO = FeO - wegielnr;
  52. Fe = Fe + wegielnr;
  53. }
  54.  
  55. if(mouse.x > 600 && mouse.x <700 && mouse.y >50 && mouse.y<100 && sellable == 1 && Fe > (stoiskonr - 1)){
  56. Fe = Fe - stoiskonr;
  57. PLN = PLN + stoiskonr;
  58. }
  59.  
  60. if(mouse.x > 600 && mouse.x <700 && mouse.y >50 && mouse.y<100 && wejdzable == 1){
  61. bazar = 1;
  62. wejdzable = 0;
  63. }
  64.  
  65. if(mouse.x > 600 && mouse.x <700 && mouse.y >50 && mouse.y<100 && kupkilofable == 1 && PLN > 9){
  66. kilofnr = kilofnr +1;
  67. PLN = PLN - 10;
  68. }
  69.  
  70. if(mouse.x > 600 && mouse.x <700 && mouse.y >50 && mouse.y<100 && kupwegielable == 1 && PLN > 9){
  71. wegielnr = wegielnr +1;
  72. PLN = PLN - 10;
  73. }
  74.  
  75. if(mouse.x > 600 && mouse.x <700 && mouse.y >50 && mouse.y<100 && kupstoiskoable == 1 && PLN > 9){
  76. stoiskonr = stoiskonr +1;
  77. PLN = PLN - 10;
  78. }
  79.  
  80. if(mouse.x > 600 && mouse.x <700 && mouse.y >50 && mouse.y<100 && wyjdzable == 1){
  81. bazar = 0;
  82. wyjdzable = 0;
  83. }
  84.  
  85.  
  86.  
  87. }
  88. //document.body.onmouseup = function() {
  89. // mouseDown = 0;
  90. //}
  91.  
  92.  
  93. window.onkeydown = function(e) {
  94. var key = e.keyCode ? e.keyCode : e.which;
  95.  
  96. if (key == 65) {
  97. xv = -V;
  98. }else if (key == 68) {
  99. xv = V;
  100. }
  101.  
  102. if (key == 83) {
  103. yv = V;
  104. }else if (key == 87) {
  105. yv = -V;
  106. }
  107.  
  108. }
  109.  
  110. window.onkeyup = function(e) {
  111. var key = e.keyCode ? e.keyCode : e.which;
  112.  
  113. if (key == 65) {
  114. xv = 0;
  115. }else if (key == 68) {
  116. xv = 0;
  117. }
  118.  
  119. if (key == 83) {
  120. yv = 0;
  121. }else if (key == 87) {
  122. yv = 0;
  123. }
  124. }
  125.  
  126.  
  127. var mouse = {
  128. x: undefined,
  129. y: undefined
  130. }
  131.  
  132. window.addEventListener('mousemove', function(event){
  133. mouse.x = event.x;
  134. mouse.y = event.y;
  135. })
  136.  
  137. // DRAW FUNCTIONS HERE:
  138.  
  139. function draw(){
  140. kopalnia()
  141. piec()
  142. EQ()
  143. sklep()
  144. bazarek()
  145.  
  146. player()
  147. }
  148.  
  149. function drawbazar(){
  150. EQ()
  151. kilof()
  152. wegiel()
  153. sprzedawca()
  154. wyjdz()
  155.  
  156. player()
  157. }
  158.  
  159. function player(){
  160. ctr.fillStyle = 'gray';
  161. ctr.fillRect(x,y,50,50)
  162. }
  163.  
  164. function kopalnia(){
  165. ctr.fillStyle = 'black';
  166. ctr.fillRect(50,50,100,100);
  167. ctr.fillStyle = 'white';
  168. ctr.font = '20px serif';
  169. ctr.fillText('Kopalnia!', 59, 100);
  170. }
  171.  
  172. function piec(){
  173. ctr.fillStyle = 'black';
  174. ctr.fillRect(50,350,100,100);
  175. ctr.fillStyle = 'white';
  176. ctr.font = '20px serif';
  177. ctr.fillText('Piec!', 70, 400);
  178. }
  179.  
  180. function sklep(){
  181. ctr.fillStyle = 'black';
  182. ctr.fillRect(350,50,100,100);
  183. ctr.fillStyle = 'white';
  184. ctr.font = '20px serif';
  185. ctr.fillText('Skup!', 370, 100);
  186. }
  187.  
  188. function kilof(){
  189. ctr.fillStyle = 'black';
  190. ctr.fillRect(50,50,100,100);
  191. ctr.fillStyle = 'white';
  192. ctr.font = '20px serif';
  193. ctr.fillText('Kup kilof!', 59, 100);
  194. }
  195.  
  196. function wegiel(){
  197. ctr.fillStyle = 'black';
  198. ctr.fillRect(50,350,100,100);
  199. ctr.fillStyle = 'white';
  200. ctr.font = '20px serif';
  201. ctr.fillText('Kup piec!', 59, 400);
  202. }
  203.  
  204. function sprzedawca(){
  205. ctr.fillStyle = 'black';
  206. ctr.fillRect(350,50,100,100);
  207. ctr.fillStyle = 'white';
  208. ctr.font = '20px serif';
  209. ctr.fillText('Kup stoisko!', 350, 100);
  210. }
  211.  
  212.  
  213. function bazarek(){
  214. ctr.fillStyle = 'black';
  215. ctr.fillRect(350,350,100,100);
  216. ctr.fillStyle = 'white';
  217. ctr.font = '20px serif';
  218. ctr.fillText('Bazarek!', 360, 400);
  219. }
  220.  
  221. function wyjdz(){
  222. ctr.fillStyle = 'black';
  223. ctr.fillRect(350,350,100,100);
  224. ctr.fillStyle = 'white';
  225. ctr.font = '20px serif';
  226. ctr.fillText('Wyjdz!', 360, 400);
  227. }
  228.  
  229.  
  230. function EQ() {
  231. ctr.fillStyle = 'black';
  232. ctr.font = '20px serif';
  233. ctr.fillText('Ruda żelaza: ' + FeO, 600, 600);
  234. ctr.fillText('Żeliwo: ' + Fe, 600, 650);
  235. ctr.fillText('Waluta: ' + PLN, 600, 700);
  236. ctr.fillText('Kilof: ' + kilofnr + ' lvl', 450, 600);
  237. ctr.fillText('Piecyk: ' + wegielnr + ' lvl', 450, 650);
  238. ctr.fillText('Stoisko: ' + stoiskonr + ' lvl', 450, 700);
  239. }
  240.  
  241. // COLlISION MESH HERE:
  242.  
  243. function collision_detection(){
  244.  
  245. }
  246.  
  247. {
  248. var meshCount = 1;
  249. var block1 = [50,50,150,150]
  250. }
  251.  
  252. // UPDATE FUNCTIONS HERE:
  253.  
  254. function update(){
  255. travel()
  256. collision_detection()
  257. kop()
  258. pal()
  259. sell()
  260. bazarniatko()
  261. }
  262.  
  263. function updatebazar(){
  264. travel()
  265. kupkilof()
  266. kupstoisko()
  267. kupwegiel()
  268. dokopalni()
  269. }
  270.  
  271. function kop(){
  272.  
  273. dx = x +25 - 100;
  274. dy = y +25 - 100;
  275.  
  276. //dd = Math.floor(Math.sqrt(dx*dx + dy*dy));
  277.  
  278. if(dx <100 && dy <100 && dx >-100 && dy>-100){
  279. ctr.fillStyle = 'black';
  280. ctr.fillRect(600,50,100,50);ctr.fillStyle = 'white';
  281. ctr.fillStyle = 'white';
  282. ctr.font = '20px serif';
  283. ctr.fillText('Kop!', 625, 80);
  284. kopable = 1;
  285.  
  286. } else{
  287. kopable = 0
  288. }
  289. }
  290.  
  291. function kupkilof(){
  292.  
  293. dx = x +25 - 100;
  294. dy = y +25 - 100;
  295.  
  296. if(dx <100 && dy <100 && dx >-100 && dy>-100){
  297. ctr.fillStyle = 'black';
  298. ctr.fillRect(600,50,100,50);ctr.fillStyle = 'white';
  299. ctr.fillStyle = 'white';
  300. ctr.font = '20px serif';
  301. ctr.fillText('Kup!', 625, 80);
  302. kupkilofable = 1;
  303.  
  304. } else{
  305. kupkilofable = 0
  306. }
  307. }
  308.  
  309.  
  310. function pal(){
  311.  
  312. dx = x +25 - 100;
  313. dy = y +25 - 400;
  314.  
  315.  
  316. if(dx <100 && dy <100 && dx >-100 && dy>-100){
  317. ctr.fillStyle = 'black';
  318. ctr.fillRect(600,50,100,50);ctr.fillStyle = 'white';
  319. ctr.fillStyle = 'white';
  320. ctr.font = '20px serif';
  321. ctr.fillText('Pal!', 625, 80);
  322. palable = 1;
  323.  
  324. } else{
  325. palable = 0
  326. }
  327. }
  328.  
  329. function kupwegiel(){
  330.  
  331. dx = x +25 - 100;
  332. dy = y +25 - 400;
  333.  
  334.  
  335. if(dx <100 && dy <100 && dx >-100 && dy>-100){
  336. ctr.fillStyle = 'black';
  337. ctr.fillRect(600,50,100,50);ctr.fillStyle = 'white';
  338. ctr.fillStyle = 'white';
  339. ctr.font = '20px serif';
  340. ctr.fillText('Kup!', 625, 80);
  341. kupwegielable = 1;
  342.  
  343. } else{
  344. kupwegielable = 0
  345. }
  346. }
  347.  
  348. function sell() {
  349.  
  350. dx = x +25 - 400;
  351. dy = y +25 - 100;
  352.  
  353.  
  354. if(dx <100 && dy <100 && dx >-100 && dy>-100){
  355. ctr.fillStyle = 'black';
  356. ctr.fillRect(600,50,100,50);ctr.fillStyle = 'white';
  357. ctr.fillStyle = 'white';
  358. ctr.font = '20px serif';
  359. ctr.fillText('Sprzedaj!', 610, 80);
  360. sellable = 1;
  361.  
  362. } else{
  363. sellable = 0
  364. }
  365. }
  366.  
  367. function kupstoisko() {
  368.  
  369. dx = x +25 - 400;
  370. dy = y +25 - 100;
  371.  
  372.  
  373. if(dx <100 && dy <100 && dx >-100 && dy>-100){
  374. ctr.fillStyle = 'black';
  375. ctr.fillRect(600,50,100,50);ctr.fillStyle = 'white';
  376. ctr.fillStyle = 'white';
  377. ctr.font = '20px serif';
  378. ctr.fillText('Kup!', 610, 80);
  379. kupstoiskoable = 1;
  380.  
  381. } else{
  382. kupstoiskoable = 0
  383. }
  384. }
  385.  
  386. function bazarniatko() {
  387.  
  388. dx = x +25 - 400;
  389. dy = y +25 - 400;
  390.  
  391.  
  392. if(dx <100 && dy <100 && dx >-100 && dy>-100){
  393. ctr.fillStyle = 'black';
  394. ctr.fillRect(600,50,100,50);ctr.fillStyle = 'white';
  395. ctr.fillStyle = 'white';
  396. ctr.font = '20px serif';
  397. ctr.fillText('Wejdź!', 610, 80);
  398. wejdzable = 1;
  399.  
  400. } else{
  401. wejdzable = 0;
  402. }
  403. }
  404.  
  405. function dokopalni() {
  406.  
  407. dx = x +25 - 400;
  408. dy = y +25 - 400;
  409.  
  410.  
  411. if(dx <100 && dy <100 && dx >-100 && dy>-100){
  412. ctr.fillStyle = 'black';
  413. ctr.fillRect(600,50,100,50);ctr.fillStyle = 'white';
  414. ctr.fillStyle = 'white';
  415. ctr.font = '20px serif';
  416. ctr.fillText('Wyjdź!', 610, 80);
  417. wyjdzable = 1;
  418.  
  419. } else{
  420. wyjdzable = 0;
  421. }
  422. }
  423.  
  424. function travel(){
  425. x = x + xv;
  426. y = y + yv;
  427. }
  428.  
  429. //MOVE FUNCTIONS HERE:
  430.  
  431. function move(){
  432. requestAnimationFrame(move);
  433. ctr.clearRect(0,0,750,750);
  434. then = new Date();
  435. if ((then - now) >= timer){
  436.  
  437. now = new Date();
  438.  
  439. if (bazar == 0){
  440.  
  441. draw()
  442. update();
  443.  
  444. } else if(bazar == 1){
  445.  
  446. drawbazar();
  447. updatebazar();
  448.  
  449. }
  450. }
  451. }
  452.  
  453. move();
  454. now = new Date();
  455.  
  456.  
  457.  
  458. </script>
  459.  
  460.  
  461. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement