Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Bullet extends DynamicGameObject {
- private GameManager gameManager;
- private int bulletShipID;
- public float bulletSize;
- public color fColor;
- Bullet(GameManager gameManager, int bulletShipID) {
- // call the constructor of the superclass
- super(gameManager);
- this.gameManager = gameManager;
- this.bulletShipID = bulletShipID;
- }
- /*
- The debugInfo method is called in the method runGameLoopCycle
- of the GameManager class for every game object once per frame.
- Use it for debug information on the console.
- */
- public void debugInfo() {
- // call this method of superclass
- super.debugInfo();
- // .. implement me ...
- }
- public void setBulletSize(float bulletSize){
- this.bulletSize = bulletSize;
- }
- /*
- The update method is called in the method runGameLoopCycle
- of the GameManager class for every game object once per frame.
- */
- void update() {
- super.update();
- position.set(position.x+speed*cos(orientation),position.y+speed*sin(orientation));
- if (position.x < 0 || position.x > width || position.y < 0 || position.y > height){
- this.gameManager.removeObject(this);
- }
- }
- /*
- This method is called by the gameManager when this object
- collides with another GameObject (object).
- Often the response depends on the class of the colliding object.
- */
- void collidesWith(GameObject object) {
- if(object instanceof RedSpaceShip && bulletShipID == 2){
- object.hitted = true;
- gameManager.removeObject(this);
- }
- if(object instanceof BlueSpaceShip && bulletShipID == 1){
- object.hitted = true;
- gameManager.removeObject(this);
- }
- if(object instanceof EnemySpaceShip && bulletShipID == 1){
- gameManager.removeObject(this);
- gameManager.removeObject(object);
- }
- if(object instanceof BlueSpaceShip && bulletShipID == 3){
- gameManager.removeObject(this);
- }
- if(object instanceof Bullet){
- gameManager.removeObject(object);
- gameManager.removeObject(this);
- }
- }
- void renderShape() {
- fill(fColor);
- beginShape();
- ellipse(0,0,bulletSize,bulletSize);
- endShape();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement