# Need some home help combining both of these

**URL:** <https://discourse.processing.org/t/need-some-home-help-combining-both-of-these/5011>\
**Category:** Coding Questions\
**Created:** [October 30, 2018, 5:52am UTC](https://discourse.processing.org/t/need-some-home-help-combining-both-of-these/5011 "2018-10-30T05:52:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![orb](https://avatars.discourse-cdn.com/v4/letter/o/e47774/32.png) [@orb](https://discourse.processing.org/u/orb)\
**Post date:** [October 30, 2018, 5:52am UTC](https://discourse.processing.org/t/need-some-home-help-combining-both-of-these/5011/1 "2018-10-30T05:52:18Z")

</div>

I’m trying make the player shoot the bullets, but I have no idea how. What I do know that is that the second code can make player shoot bullets. I just need help making them fit each other.

[code re-posted below]

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [October 30, 2018, 10:37am UTC](https://discourse.processing.org/t/need-some-home-help-combining-both-of-these/5011/2 "2018-10-30T10:37:20Z")

</div>

Hey,

First of all, there’s a lot of code, try to be as clear as possible and format your code using the `</>` button in the message editor and press `Ctrl+T` in the Processing IDE code editor.

---

<div class="post-metadata">

**Author:** ![orb](https://avatars.discourse-cdn.com/v4/letter/o/e47774/32.png) [@orb](https://discourse.processing.org/u/orb)\
**Post date:** [October 30, 2018, 4:17pm UTC](https://discourse.processing.org/t/need-some-home-help-combining-both-of-these/5011/3 "2018-10-30T16:17:05Z")

</div>

Hey!

Thanks for telling me how to do the auto format!

I incorporated both, but all I need to do is make the player shoot the bullets.

```auto
player player;

ArrayList<Bullet> bullets;
//Vars to regulate shooting speed
boolean canShoot = true;
float canShootCounter;

int i;

PImage Title;
PImage Press;
PImage TutorialImage;
PImage Matthew;

float presstint= 255;

float screen =1; 

void settings() {
  size(1024, 768);
  player = new player(400, 400, 5, 50);
  bullets = new ArrayList<Bullet>(); 

  Title=loadImage("Title.png");
  Press=loadImage("press.png");
  TutorialImage= loadImage("tutorial.png");
  Matthew= loadImage("matthew.png");
}

void draw() {
  background(0);

  smooth();
  println("mouse is at", mouseX, mouseY);
  println("frames are at", frameRate);
  smooth();
  frameRate(60);

  if (screen ==1) {
    tint(255);
    image(Title, 0, 0);

    tint(presstint);
    image(Press, 0, 0);
    presstint= presstint -4;
    if (presstint < 0) {
      presstint = 255;
    }

    if ((mousePressed == true) || (keyPressed == true)) {
      screen =2;
    }
  } else if (screen ==2) {

    noTint();
    image(TutorialImage, 0, 0);
    player.update();
    for (i = bullets.size()-1; i >= 0; i--) {
      //you need a seperate var to get the object from the bullets arraylist then use that variable to call the functions
      Bullet bullet = bullets.get(i);
      bullet.update();
    }

    if ((playerx == 920) && (playery == 361)) {
      screen =3;
    }
  }
}
void keyPressed() {
  player.keyp();
}

void keyReleased() {
  player.keyr();
}

class player {
  PVector location;
  int playerx, playery, spd, size;
  boolean[] keys=new boolean[5];
  player(int playerx1, int playery1, int spd1, int size1) {
    playerx=playerx1;
    playery=playery1;
    spd=spd1;
    size=size1;
    location = new PVector(100, 100);
  }

  void update() {
    if (keys[1]==true) {
      playery=playery-spd; 
      {
        if (playery<= 88) {
          playery = 88;
        }
      }
    }
    if (keys[2]==true) {
      playerx=playerx-spd;
      {
        if (playerx<= 110) {  
          playerx = 110;
        }
      }
    }
    if (keys[3]==true) {
      playery=playery+spd;
      {
        if (playery >= 551) {
          playery = 551;
        }
      }
    }
    if (keys[4]==true) {
      playerx=playerx+spd; 
      {
        if (playerx >= 829) {
          playerx = 829;
        }
      }
    }
    image(Matthew, playerx, playery, 49, 66);
    println("spd", spd);
    if (mousePressed == true) {
      // this regulates the shooting speed
      if (canShoot == true) {
        bullets.add( new Bullet());
        canShoot = false;
        canShootCounter = 0;
      }
    }
    // this checks if the right amount of time has passed before canShoot can = true again
    if (canShoot == false) {
      canShootCounter ++;
      //if the right amount of time has passed. make canShoot true
      if (canShootCounter == 5)/*change this number to change the duration*/ {
        canShoot = true;
      }
    }
  }

  void keyp() {
    if (key=='w') {
      keys[1]=true;
    }
    if (key=='a') {
      keys[2]=true;
    }
    if (key=='s') {
      keys[3]=true;
    }
    if (key=='d') {
      keys[4]=true;
    }
  }
  void keyr() {
    if (key=='w') {
      keys[1]=false;
    }
    if (key=='a') {
      keys[2]=false;
    }
    if (key=='s') {
      keys[3]=false;
    }
    if (key=='d') {
      keys[4]=false;
    }
  }
}

class Bullet {
  //standard PVector used for the location of the bullet
  PVector location;
  //vars used to check the angle between location and the mouse
  float oldPosX, oldPosY, rotation, speed;
  Bullet() {
    //places the bullet in the middle of the room
    location= new PVector(width/2, height/2);
    //this checks the angle
    oldPosX = mouseX;
    oldPosY = mouseY;
    rotation = atan2(oldPosY - location.y, oldPosX - location.x) / PI * 180;
    //bullet speed
    speed = 10;//change this number to change the speed
  } 
  void update() {
    //move the bullet
    location.x = location.x + cos(rotation/180*PI)*speed;
    location.y = location.y + sin(rotation/180*PI)*speed;
    ellipse(location.x, location.y, 10, 10);

    //removes the bullet from the arrayList if it is off the room
    if (location.x > 0 && location.x < width && location.y > 0 && location.x < height) {
    } else {
      bullets.remove(i);
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [October 31, 2018, 10:56am UTC](https://discourse.processing.org/t/need-some-home-help-combining-both-of-these/5011/4 "2018-10-31T10:56:26Z")

</div>

Hey,

What I don’t understand is where does the second part of the code comes from? Did you implement it?  
What don’t you understand when it comes to shoot a bullet?
