/** Remove bullet from Shooter's list of bullets and GameActivity's list */ public void removeGameObject() { theOneWhoShotMe.getMyBullets().remove(this); if (theOneWhoShotMe.isFriendly()) { GameLoop.friendlyBullets.remove(this); } else { GameLoop.enemyBullets.remove(this); } this.defaultCleanupOnRemoval(); // needs to be the last thing called for handler to remove all // callbacks }
public void setBulletRotation() { float rotVal = 0; double arcTan = Math.atan(this.getSpeedX() / Math.abs(this.getSpeedY())); if (!theOneWhoShotMe.isFriendly()) { arcTan = Math.atan(-this.getSpeedX() / Math.abs(this.getSpeedY())); arcTan += Math.PI; // flip bullet image around so it is pointing downwards } rotVal = (float) Math.toDegrees(arcTan); this.setRotation(rotVal); }
public BulletView( RelativeLayout layout, Shooter shooter, float bulletSpeedY, int bulletDamage, int width, int height, int imageId) { super(layout, bulletSpeedY, 0, bulletDamage, 1, width, height, imageId); // set instance variables theOneWhoShotMe = shooter; // position bullet behind shooter ViewGroup parent = (ViewGroup) theOneWhoShotMe.getParent(); if (parent != null) { parent.removeView(this); // bullet already added to parent in MovingView's instantiation int shooterIndex = parent.indexOfChild((View) theOneWhoShotMe); parent.addView(this, shooterIndex); // position bullet in middle of shooter // if(shooter.isFriendly()){ this.setY(theOneWhoShotMe.getY() + theOneWhoShotMe.getHeight() / 2); // middle // }else{ // this.setY(theOneWhoShotMe.getY() - theOneWhoShotMe.getHeight()/2);//middle // } if (theOneWhoShotMe.isFriendly()) { setSpeedY(-Math.abs(bulletSpeedY)); GameLoop.friendlyBullets.add(this); } else { setSpeedY(Math.abs(bulletSpeedY)); GameLoop.enemyBullets.add(this); } theOneWhoShotMe.getMyBullets().add(this); } else { this.removeGameObject(); // for some reason, shooters continue to fire even after being killed. This simple check // ensure that the shooter // has not been removed from his parent. If he has, then remove this bullet } }