Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float xtank = 100, ytank = 500, tankspeed = 2.5;
- boolean isfire = false;
- float xfire, yfire, firespeed = 5, firer = 10;
- void setup(){
- size(900, 900);
- }
- void draw(){
- background(204, 216, 42);
- 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;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement