vencinachev

Game-Tank01

Jul 25th, 2021
846
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. float xtank = 100, ytank = 500, tankspeed = 2.5;
  2. boolean isfire = false;
  3. float xfire, yfire, firespeed = 5, firer = 10;
  4.  
  5. void setup(){
  6.   size(900, 900);
  7. }
  8.  
  9. void draw(){
  10.   background(204, 216, 42);
  11.   fill(50, 142, 30);
  12.   rect(xtank, ytank, 120, 120);
  13.   fill(140, 67, 155);
  14.   ellipse(xtank + 60, ytank, 80, 80);
  15.   fill(193, 66, 77);
  16.   rect(xtank + 50, ytank - 100, 20, 100);
  17.  
  18.   if (keyPressed){
  19.     if (keyCode == UP){
  20.       ytank = ytank - tankspeed;
  21.     } else if (keyCode == DOWN){
  22.       ytank = ytank + tankspeed;
  23.     } else if (keyCode == LEFT){
  24.       xtank = xtank - tankspeed;
  25.     } else if (keyCode == RIGHT){
  26.       xtank = xtank + tankspeed;
  27.     }
  28.   }
  29.  
  30.   if (ytank < height / 2){
  31.     ytank = height / 2;
  32.   }
  33.   if (ytank > height - 120){
  34.     ytank = height - 120;
  35.   }
  36.   if (xtank < 0){
  37.     xtank = 0;
  38.   }
  39.   if (xtank > width - 120){
  40.     xtank = width - 120;
  41.   }
  42.  
  43.   if (keyPressed && key == ' ' && !isfire){
  44.     isfire = true;
  45.     xfire = xtank + 60;
  46.     yfire = ytank - 100;
  47.   }
  48.  
  49.   if (isfire){
  50.     fill(255, 0, 0);
  51.     ellipse(xfire, yfire, 2*firer, 2*firer);
  52.     yfire = yfire - firespeed;
  53.     if (yfire < 0){
  54.       isfire = false;
  55.     }
  56.   }
  57. }
RAW Paste Data