Android Open Source - TileArena Attack Bow






From Project

Back to project page TileArena.

License

The source code is released under:

MIT License

If you think the Android project TileArena listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package game.tile.arena.entity.attack;
//  w  ww  .j  a v a  2s  . co m
import game.tile.arena.Game;
import game.tile.arena.entity.projectile.LinearProjectile;
import game.tile.arena.util.Position;

public class AttackBow implements Attack {

    public static class Builder {

        private int fireTime = 600;
        private int reloadTime = 0;
        private int spreadShots = 1;
        private int spreadAngle = 0;
        private int barrageShots = 0;
        private int pierce = 1;
        private int damage = 1;

        public Builder setFireTime(int fireTime) {
            this.fireTime = fireTime;
            return this;
        }

        public Builder setReloadTime(int reloadTime) {
            this.reloadTime = reloadTime;
            return this;
        }

        public Builder setSpreadShots(int spreadShots) {
            this.spreadShots = spreadShots;
            return this;
        }

        public Builder setSpreadAngle(int spreadAngle) {
            this.spreadAngle = spreadAngle;
            return this;
        }

        public Builder setBarrageShots(int barrageShots) {
            this.barrageShots = barrageShots;
            return this;
        }

        public Builder setPierce(int pierce) {
            this.pierce = pierce;
            return this;
        }

        public AttackBow create() {
            if (reloadTime == 0)
                reloadTime = fireTime;
            return new AttackBow(fireTime, reloadTime, spreadShots, barrageShots, spreadAngle, pierce, damage);
        }
    }

    private int timer;
    private int shotCounter;
    private final int fireTime;
    private final int reloadTime;
    private final int barrageShots;
    private final int spreadShots;
    private final double spread;
    private final int pierce;
    private final int damage;

    private AttackBow(int fireTime, int reloadTime, int spreadShots, int barrageShots, int spread, int pierce, int damage) {
        this.fireTime = fireTime;
        this.reloadTime = reloadTime;
        this.spread = spread * Math.PI / 180;
        this.spreadShots = spreadShots;
        this.barrageShots = barrageShots;
        this.pierce = pierce;
        this.damage = damage;
    }

    @Override
    public void equip() {
        shotCounter = 0;
        timer = fireTime;
    }

    @Override
    public void dequip() {
        shotCounter = 0;
        timer = fireTime;
    }

    @Override
    public void update(double delta, Position target, boolean orientation) {
        if (timer<0 && !target.isZero()) {
            double startDir = target.getDir() - spread * spreadShots /2;
            for(int i=0;i< spreadShots;i++) {
                Game.projectiles.add(new LinearProjectile.Builder("arrow", Game.player.pos,
                        new Position(startDir + i * spread, 24), orientation)
                        .setHits(pierce)
                        .setDamage(damage)
                        .create());
            }
            if (shotCounter <= 0) {
                timer = reloadTime;
                shotCounter = barrageShots;
            } else {
                timer = fireTime;
                shotCounter--;
            }
        }
        timer -= delta*Game.FPS;
    }
}




Java Source Code List

game.tile.arena.Game.java
game.tile.arena.TileArena.java
game.tile.arena.android.AndroidLauncher.java
game.tile.arena.client.HtmlLauncher.java
game.tile.arena.desktop.DesktopLauncher.java
game.tile.arena.entity.Entity.java
game.tile.arena.entity.Player.java
game.tile.arena.entity.attack.AttackBow.java
game.tile.arena.entity.attack.AttackList.java
game.tile.arena.entity.attack.Attack.java
game.tile.arena.entity.enemy.Enemy.java
game.tile.arena.entity.enemy.ai.EnemyAI.java
game.tile.arena.entity.enemy.ai.EnemyDodgeAI.java
game.tile.arena.entity.enemy.ai.EnemyRandomAI.java
game.tile.arena.entity.projectile.LinearProjectile.java
game.tile.arena.entity.projectile.Projectile.java
game.tile.arena.sprite.EntitySprite.java
game.tile.arena.sprite.Image.java
game.tile.arena.util.MathHelper.java
game.tile.arena.util.Position.java
game.tile.arena.util.Preferences.java
game.tile.arena.util.controller.Joystick.java
game.tile.arena.util.controller.KeyboardController.java
game.tile.arena.util.controller.MouseAttackInput.java
game.tile.arena.util.controller.PlayerController.java
game.tile.arena.util.controller.TouchController.java
game.tile.arena.util.input.InputManager.java
game.tile.arena.util.input.JoystickInput.java
game.tile.arena.util.input.KeyboardMoveInput.java
game.tile.arena.util.input.WeaponSwitchInput.java
game.tile.arena.world.Tile.java
game.tile.arena.world.World.java