Android Open Source - TileArena Tile Arena






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;
//from   w ww .  ja v  a 2  s.  c om
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

import java.util.Collections;
import java.util.Iterator;

import game.tile.arena.entity.Entity;
import game.tile.arena.entity.enemy.Enemy;
import game.tile.arena.entity.enemy.ai.EnemyRandomAI;
import game.tile.arena.entity.projectile.Projectile;
import game.tile.arena.util.MathHelper;
import game.tile.arena.util.Position;

public class TileArena extends ApplicationAdapter {

    SpriteBatch batch;
    BitmapFont font;

  @Override
  public void create() {
        font = new BitmapFont();

        Game.hudCam.position.set(Game.SCREEN.x/2, Game.SCREEN.y/2, 0);
        Game.hudCam.update();

    batch = new SpriteBatch();

        Game.entities.add(Game.player);

        for (int i=0;i<50;i++)
            Game.entities.add(new Enemy.Builder("blob_green",
                    new Position(Math.random() * (Game.WORLD.x - 256) + 128, Math.random() * (Game.WORLD.y - 256) + 128),
                    new EnemyRandomAI())
                    .createEnemy());
  }

    int cnt = 0;

  @Override
  public void render() {
        if (cnt++ < 120)
            return;

        double delta = 1;
        if (Gdx.graphics.getFramesPerSecond() != 0)
            delta = (double) Game.FPS/Gdx.graphics.getFramesPerSecond();

        update(delta);

        Gdx.gl.glClearColor(1, 1, 1, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        batch.setProjectionMatrix(Game.camera.combined);
        batch.begin();
        Collections.sort(Game.entities);
        Game.world.render(batch);
        for (Entity o : Game.entities)
            o.render(batch, delta);
        batch.setColor(1f, 1f, 1f, 1f);
        for (Projectile p : Game.projectiles)
            p.render(batch);

        batch.setProjectionMatrix(Game.hudCam.combined);
        Game.input.render(batch, delta);

        font.draw(batch, "fps: " + Gdx.graphics.getFramesPerSecond(), 20, 30);

        batch.end();
        batch.setColor(1f, 1f, 1f, 1f);
  }

    private void update(double delta) {
        for (Iterator<Entity> it = Game.entities.listIterator(); it.hasNext();) {
            Entity e  = it.next();
            boolean alive = e.update(delta);
            if (!alive)
                it.remove();
        }
        for (Iterator<Projectile> it = Game.projectiles.listIterator(); it.hasNext();) {
            Projectile p = it.next();
            boolean alive = p.update(delta);
            if (!alive)
                it.remove();
        }
        updateCameraPosition();
        Game.camera.update();
    }

    private void updateCameraPosition() {
        float minX = Game.SCREEN.x / 2;
        float maxX = Game.WORLD.x - minX;
        float minY = Game.SCREEN.y / 2;
        float maxY = Game.WORLD.y - minY;
        Game.camera.position.set(
                MathHelper.median(minX, Game.player.pos.x, maxX),
                MathHelper.median(minY, Game.player.pos.y, maxY),
                0);
    }
}




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