Advertisement
vencinachev

GameTankFull

Jul 26th, 2021
1,258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.46 KB | None | 0 0
  1. float xtank = 600, ytank = 500, tankspeed = 5;
  2. boolean isfire = false;
  3. float xfire, yfire, firespeed = 10, firer = 10;
  4. float xballG, yballG, rballG;
  5. float xballR, yballR, rballR;
  6. int score = 0;
  7. int max = 0;
  8. boolean gameover = false;
  9.  
  10. void setup(){
  11.   size(1500, 900);
  12.   yballG = 50;
  13.   xballG = random(30, width);
  14.   rballG = 30;
  15.   yballR = 50;
  16.   xballR = random(30, width);
  17.   rballR = 30;
  18. }
  19.  
  20. void draw(){
  21.   if (gameover == false) {
  22.     background(204, 216, 42);
  23.    
  24.     fill(0, 255, 0);
  25.     ellipse(xballG, yballG, 2*rballG, 2*rballG);
  26.    
  27.     fill(255, 0, 0);
  28.     ellipse(xballR, yballR, 2*rballR, 2*rballR);
  29.    
  30.     fill(50, 142, 30);
  31.     rect(xtank, ytank, 120, 120);
  32.     fill(140, 67, 155);
  33.     ellipse(xtank + 60, ytank, 80, 80);
  34.     fill(193, 66, 77);
  35.     rect(xtank + 50, ytank - 100, 20, 100);
  36.    
  37.     if (keyPressed){
  38.       if (keyCode == UP){
  39.         ytank = ytank - tankspeed;
  40.       } else if (keyCode == DOWN){
  41.         ytank = ytank + tankspeed;
  42.       } else if (keyCode == LEFT){
  43.         xtank = xtank - tankspeed;
  44.       } else if (keyCode == RIGHT){
  45.         xtank = xtank + tankspeed;
  46.       }
  47.     }
  48.    
  49.     if (ytank < height / 2){
  50.       ytank = height / 2;
  51.     }
  52.     if (ytank > height - 120){
  53.       ytank = height - 120;
  54.     }
  55.     if (xtank < 0){
  56.       xtank = 0;
  57.     }
  58.     if (xtank > width - 120){
  59.       xtank = width - 120;
  60.     }
  61.    
  62.     if (keyPressed && key == ' ' && !isfire){
  63.       isfire = true;
  64.       xfire = xtank + 60;
  65.       yfire = ytank - 100;
  66.     }
  67.    
  68.     if (isfire){
  69.       fill(255, 0, 0);
  70.       ellipse(xfire, yfire, 2*firer, 2*firer);
  71.       yfire = yfire - firespeed;
  72.       if (yfire < 0){
  73.         isfire = false;
  74.       }
  75.     }
  76.    
  77.     if (dist(xfire, yfire, xballG, yballG) < firer + rballG){
  78.       xballG = random(30, width - 50);
  79.       xballR = random(30, width - 50);
  80.       score++;
  81.     }
  82.    
  83.     if (dist(xfire, yfire, xballR, yballR) < firer + rballR){
  84.       gameover = true;
  85.     }
  86.    
  87.     fill(0);
  88.     textSize(50);
  89.     text("Score: " + score, 150, 250);
  90.   } else {
  91.     background(255, 0, 0);
  92.     fill(0);
  93.     textSize(100);
  94.     text("GAMEOVER!", 100, 100);
  95.     text("Your score: " + score, 100, 250);
  96.     text("Press R to continue...", 100, 500);
  97.     if (score > max){
  98.       max = score;
  99.     }
  100.     text("Max score: " + max, 100, 350);
  101.     if (keyPressed && key == 'r'){
  102.       gameover = false;
  103.       isfire = false;
  104.       xfire = -100;
  105.       score = 0;
  106.     }
  107.   }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement