Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float xtank = 600, ytank = 500, tankspeed = 5;
- boolean isfire = false;
- float xfire, yfire, firespeed = 10, firer = 10;
- float xballG, yballG, rballG;
- float xballR, yballR, rballR;
- int score = 0;
- int max = 0;
- boolean gameover = false;
- void setup(){
- size(1500, 900);
- yballG = 50;
- xballG = random(30, width);
- rballG = 30;
- yballR = 50;
- xballR = random(30, width);
- rballR = 30;
- }
- void draw(){
- if (gameover == false) {
- background(204, 216, 42);
- fill(0, 255, 0);
- ellipse(xballG, yballG, 2*rballG, 2*rballG);
- fill(255, 0, 0);
- ellipse(xballR, yballR, 2*rballR, 2*rballR);
- fill(50, 142, 30);
- rect(xtank, ytank, 120, 120);
- fill(140, 67, 155);
- ellipse(xtank + 60, ytank, 80, 80);
- fill(193, 66, 77);
- rect(xtank + 50, ytank - 100, 20, 100);
- if (keyPressed){
- if (keyCode == UP){
- ytank = ytank - tankspeed;
- } else if (keyCode == DOWN){
- ytank = ytank + tankspeed;
- } else if (keyCode == LEFT){
- xtank = xtank - tankspeed;
- } else if (keyCode == RIGHT){
- xtank = xtank + tankspeed;
- }
- }
- if (ytank < height / 2){
- ytank = height / 2;
- }
- if (ytank > height - 120){
- ytank = height - 120;
- }
- if (xtank < 0){
- xtank = 0;
- }
- if (xtank > width - 120){
- xtank = width - 120;
- }
- if (keyPressed && key == ' ' && !isfire){
- isfire = true;
- xfire = xtank + 60;
- yfire = ytank - 100;
- }
- if (isfire){
- fill(255, 0, 0);
- ellipse(xfire, yfire, 2*firer, 2*firer);
- yfire = yfire - firespeed;
- if (yfire < 0){
- isfire = false;
- }
- }
- if (dist(xfire, yfire, xballG, yballG) < firer + rballG){
- xballG = random(30, width - 50);
- xballR = random(30, width - 50);
- score++;
- }
- if (dist(xfire, yfire, xballR, yballR) < firer + rballR){
- gameover = true;
- }
- fill(0);
- textSize(50);
- text("Score: " + score, 150, 250);
- } else {
- background(255, 0, 0);
- fill(0);
- textSize(100);
- text("GAMEOVER!", 100, 100);
- text("Your score: " + score, 100, 250);
- text("Press R to continue...", 100, 500);
- if (score > max){
- max = score;
- }
- text("Max score: " + max, 100, 350);
- if (keyPressed && key == 'r'){
- gameover = false;
- isfire = false;
- xfire = -100;
- score = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement