Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <head> <title> Miner game! </title>
- </head>
- <body>
- <canvas id="game" width="750" height="750" style="border:1px solid #000000;">
- </canvas>
- <script>
- // VARS HERE:
- var x = 75;
- var y = 200;
- var yv = 0;
- var xv = 0;
- var now, then;
- var fps = 100;
- var timer = 1000/fps;
- var V = 3;
- var Fe = 0;
- var FeO = 0;
- var PLN = 0;
- var kopable = 0;
- var palable = 0;
- var sellable = 0;
- var wejdzable = 0;
- var bazar = 0;
- var kilofnr = 1;
- var wegielnr = 1;
- var stoiskonr = 1;
- var kupkilofable = 0;
- var kupwegielable = 0;
- var kupstoiskoable = 0;
- var wyjdzable = 0;
- var ctr = game.getContext('2d');
- // SCANNERS FUNCTIONS HERE:
- var mouseDown = 0;
- document.body.onclick = function() {
- if(mouse.x > 600 && mouse.x <700 && mouse.y >50 && mouse.y<100 && kopable == 1){
- FeO = FeO + kilofnr;
- }
- if(mouse.x > 600 && mouse.x <700 && mouse.y >50 && mouse.y<100 && palable == 1 && FeO > (wegielnr - 1)){
- FeO = FeO - wegielnr;
- Fe = Fe + wegielnr;
- }
- if(mouse.x > 600 && mouse.x <700 && mouse.y >50 && mouse.y<100 && sellable == 1 && Fe > (stoiskonr - 1)){
- Fe = Fe - stoiskonr;
- PLN = PLN + stoiskonr;
- }
- if(mouse.x > 600 && mouse.x <700 && mouse.y >50 && mouse.y<100 && wejdzable == 1){
- bazar = 1;
- wejdzable = 0;
- }
- if(mouse.x > 600 && mouse.x <700 && mouse.y >50 && mouse.y<100 && kupkilofable == 1 && PLN > 9){
- kilofnr = kilofnr +1;
- PLN = PLN - 10;
- }
- if(mouse.x > 600 && mouse.x <700 && mouse.y >50 && mouse.y<100 && kupwegielable == 1 && PLN > 9){
- wegielnr = wegielnr +1;
- PLN = PLN - 10;
- }
- if(mouse.x > 600 && mouse.x <700 && mouse.y >50 && mouse.y<100 && kupstoiskoable == 1 && PLN > 9){
- stoiskonr = stoiskonr +1;
- PLN = PLN - 10;
- }
- if(mouse.x > 600 && mouse.x <700 && mouse.y >50 && mouse.y<100 && wyjdzable == 1){
- bazar = 0;
- wyjdzable = 0;
- }
- }
- //document.body.onmouseup = function() {
- // mouseDown = 0;
- //}
- window.onkeydown = function(e) {
- var key = e.keyCode ? e.keyCode : e.which;
- if (key == 65) {
- xv = -V;
- }else if (key == 68) {
- xv = V;
- }
- if (key == 83) {
- yv = V;
- }else if (key == 87) {
- yv = -V;
- }
- }
- window.onkeyup = function(e) {
- var key = e.keyCode ? e.keyCode : e.which;
- if (key == 65) {
- xv = 0;
- }else if (key == 68) {
- xv = 0;
- }
- if (key == 83) {
- yv = 0;
- }else if (key == 87) {
- yv = 0;
- }
- }
- var mouse = {
- x: undefined,
- y: undefined
- }
- window.addEventListener('mousemove', function(event){
- mouse.x = event.x;
- mouse.y = event.y;
- })
- // DRAW FUNCTIONS HERE:
- function draw(){
- kopalnia()
- piec()
- EQ()
- sklep()
- bazarek()
- player()
- }
- function drawbazar(){
- EQ()
- kilof()
- wegiel()
- sprzedawca()
- wyjdz()
- player()
- }
- function player(){
- ctr.fillStyle = 'gray';
- ctr.fillRect(x,y,50,50)
- }
- function kopalnia(){
- ctr.fillStyle = 'black';
- ctr.fillRect(50,50,100,100);
- ctr.fillStyle = 'white';
- ctr.font = '20px serif';
- ctr.fillText('Kopalnia!', 59, 100);
- }
- function piec(){
- ctr.fillStyle = 'black';
- ctr.fillRect(50,350,100,100);
- ctr.fillStyle = 'white';
- ctr.font = '20px serif';
- ctr.fillText('Piec!', 70, 400);
- }
- function sklep(){
- ctr.fillStyle = 'black';
- ctr.fillRect(350,50,100,100);
- ctr.fillStyle = 'white';
- ctr.font = '20px serif';
- ctr.fillText('Skup!', 370, 100);
- }
- function kilof(){
- ctr.fillStyle = 'black';
- ctr.fillRect(50,50,100,100);
- ctr.fillStyle = 'white';
- ctr.font = '20px serif';
- ctr.fillText('Kup kilof!', 59, 100);
- }
- function wegiel(){
- ctr.fillStyle = 'black';
- ctr.fillRect(50,350,100,100);
- ctr.fillStyle = 'white';
- ctr.font = '20px serif';
- ctr.fillText('Kup piec!', 59, 400);
- }
- function sprzedawca(){
- ctr.fillStyle = 'black';
- ctr.fillRect(350,50,100,100);
- ctr.fillStyle = 'white';
- ctr.font = '20px serif';
- ctr.fillText('Kup stoisko!', 350, 100);
- }
- function bazarek(){
- ctr.fillStyle = 'black';
- ctr.fillRect(350,350,100,100);
- ctr.fillStyle = 'white';
- ctr.font = '20px serif';
- ctr.fillText('Bazarek!', 360, 400);
- }
- function wyjdz(){
- ctr.fillStyle = 'black';
- ctr.fillRect(350,350,100,100);
- ctr.fillStyle = 'white';
- ctr.font = '20px serif';
- ctr.fillText('Wyjdz!', 360, 400);
- }
- function EQ() {
- ctr.fillStyle = 'black';
- ctr.font = '20px serif';
- ctr.fillText('Ruda żelaza: ' + FeO, 600, 600);
- ctr.fillText('Żeliwo: ' + Fe, 600, 650);
- ctr.fillText('Waluta: ' + PLN, 600, 700);
- ctr.fillText('Kilof: ' + kilofnr + ' lvl', 450, 600);
- ctr.fillText('Piecyk: ' + wegielnr + ' lvl', 450, 650);
- ctr.fillText('Stoisko: ' + stoiskonr + ' lvl', 450, 700);
- }
- // COLlISION MESH HERE:
- function collision_detection(){
- }
- {
- var meshCount = 1;
- var block1 = [50,50,150,150]
- }
- // UPDATE FUNCTIONS HERE:
- function update(){
- travel()
- collision_detection()
- kop()
- pal()
- sell()
- bazarniatko()
- }
- function updatebazar(){
- travel()
- kupkilof()
- kupstoisko()
- kupwegiel()
- dokopalni()
- }
- function kop(){
- dx = x +25 - 100;
- dy = y +25 - 100;
- //dd = Math.floor(Math.sqrt(dx*dx + dy*dy));
- if(dx <100 && dy <100 && dx >-100 && dy>-100){
- ctr.fillStyle = 'black';
- ctr.fillRect(600,50,100,50);ctr.fillStyle = 'white';
- ctr.fillStyle = 'white';
- ctr.font = '20px serif';
- ctr.fillText('Kop!', 625, 80);
- kopable = 1;
- } else{
- kopable = 0
- }
- }
- function kupkilof(){
- dx = x +25 - 100;
- dy = y +25 - 100;
- if(dx <100 && dy <100 && dx >-100 && dy>-100){
- ctr.fillStyle = 'black';
- ctr.fillRect(600,50,100,50);ctr.fillStyle = 'white';
- ctr.fillStyle = 'white';
- ctr.font = '20px serif';
- ctr.fillText('Kup!', 625, 80);
- kupkilofable = 1;
- } else{
- kupkilofable = 0
- }
- }
- function pal(){
- dx = x +25 - 100;
- dy = y +25 - 400;
- if(dx <100 && dy <100 && dx >-100 && dy>-100){
- ctr.fillStyle = 'black';
- ctr.fillRect(600,50,100,50);ctr.fillStyle = 'white';
- ctr.fillStyle = 'white';
- ctr.font = '20px serif';
- ctr.fillText('Pal!', 625, 80);
- palable = 1;
- } else{
- palable = 0
- }
- }
- function kupwegiel(){
- dx = x +25 - 100;
- dy = y +25 - 400;
- if(dx <100 && dy <100 && dx >-100 && dy>-100){
- ctr.fillStyle = 'black';
- ctr.fillRect(600,50,100,50);ctr.fillStyle = 'white';
- ctr.fillStyle = 'white';
- ctr.font = '20px serif';
- ctr.fillText('Kup!', 625, 80);
- kupwegielable = 1;
- } else{
- kupwegielable = 0
- }
- }
- function sell() {
- dx = x +25 - 400;
- dy = y +25 - 100;
- if(dx <100 && dy <100 && dx >-100 && dy>-100){
- ctr.fillStyle = 'black';
- ctr.fillRect(600,50,100,50);ctr.fillStyle = 'white';
- ctr.fillStyle = 'white';
- ctr.font = '20px serif';
- ctr.fillText('Sprzedaj!', 610, 80);
- sellable = 1;
- } else{
- sellable = 0
- }
- }
- function kupstoisko() {
- dx = x +25 - 400;
- dy = y +25 - 100;
- if(dx <100 && dy <100 && dx >-100 && dy>-100){
- ctr.fillStyle = 'black';
- ctr.fillRect(600,50,100,50);ctr.fillStyle = 'white';
- ctr.fillStyle = 'white';
- ctr.font = '20px serif';
- ctr.fillText('Kup!', 610, 80);
- kupstoiskoable = 1;
- } else{
- kupstoiskoable = 0
- }
- }
- function bazarniatko() {
- dx = x +25 - 400;
- dy = y +25 - 400;
- if(dx <100 && dy <100 && dx >-100 && dy>-100){
- ctr.fillStyle = 'black';
- ctr.fillRect(600,50,100,50);ctr.fillStyle = 'white';
- ctr.fillStyle = 'white';
- ctr.font = '20px serif';
- ctr.fillText('Wejdź!', 610, 80);
- wejdzable = 1;
- } else{
- wejdzable = 0;
- }
- }
- function dokopalni() {
- dx = x +25 - 400;
- dy = y +25 - 400;
- if(dx <100 && dy <100 && dx >-100 && dy>-100){
- ctr.fillStyle = 'black';
- ctr.fillRect(600,50,100,50);ctr.fillStyle = 'white';
- ctr.fillStyle = 'white';
- ctr.font = '20px serif';
- ctr.fillText('Wyjdź!', 610, 80);
- wyjdzable = 1;
- } else{
- wyjdzable = 0;
- }
- }
- function travel(){
- x = x + xv;
- y = y + yv;
- }
- //MOVE FUNCTIONS HERE:
- function move(){
- requestAnimationFrame(move);
- ctr.clearRect(0,0,750,750);
- then = new Date();
- if ((then - now) >= timer){
- now = new Date();
- if (bazar == 0){
- draw()
- update();
- } else if(bazar == 1){
- drawbazar();
- updatebazar();
- }
- }
- }
- move();
- now = new Date();
- </script>
- </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement