Android Open Source - TileArena Projectile






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.projectile;
//ww w  .j  a v  a2  s. c o m
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import game.tile.arena.Game;
import game.tile.arena.entity.Entity;
import game.tile.arena.sprite.Image;
import game.tile.arena.util.Position;

public abstract class Projectile extends Object {

    private static AtomicInteger idCounter = new AtomicInteger();
    public final int id;
    private List<Entity> alreadyHit;

    public Image sprite;

    public Position pos;
    public int hits;
    public final boolean orientation;
    public final int damage;

    public Projectile(String filePrefix, Position pos, boolean orientation, int hits, int damage) {
        id = idCounter.getAndIncrement();
        alreadyHit = new ArrayList<Entity>();
        sprite = new Image(filePrefix);
        this.orientation = orientation;
        this.pos = pos;
        this.hits = hits;
        this.damage = damage;
    }

    public abstract Position getCurrentMovement();
    public abstract boolean update(double delta);
    public abstract void render(SpriteBatch batch);

    public void draw(SpriteBatch batch, float dir) {
        draw(batch, 4, dir);
    }

    public void draw(SpriteBatch batch, float scale, float dir) {
        if (pos.inView(64))
            sprite.render(batch, pos, scale, dir);
    }

    protected boolean checkCollision() {
        for (Entity e : Game.entities) {
            if (e.orientation != orientation) {
                if (e.isCollision(this)) {
                    if (alreadyHit.contains(e))
                        continue;
                    e.hit(damage);
                    alreadyHit.add(e);
                    hits--;
                    if (hits <= 0)
                        return true;
                }
            }
        }
        return false;
    }

    protected boolean valid() {
        return pos.inWorld(64);
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || !(o instanceof Projectile))
            return false;
        return ((Projectile)o).id == id;
    }
}




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