Android Open Source - rpg Game Object Factory






From Project

Back to project page rpg.

License

The source code is released under:

Apache License

If you think the Android project rpg 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 org.aschyiel.rpg;
/*from w w w .  j a  v a  2 s  .  c  o m*/
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.aschyiel.rpg.level.Player;
import org.aschyiel.rpg.level.UnitType;

/**
* The thing that creates a bunch of stuff,
* over and over like a manufacturing plant.
*/
public class GameObjectFactory
{
  private final Resorcerer rez;
  private final VertexBufferObjectManager buffy;

  private int nextId = 1;

  public GameObjectFactory( Resorcerer rez )
  {
    this.rez = rez;
    this.buffy = rez.getVertexBufferObjectManager();
  }

  /**
  * Make a new game-object of a given type, and label it under the given owner.
  */
  public GameObject makeUnit( UnitType unitType, Player owner )
  {
    GameObject unit = new GameObject( unitType, owner, nextId++,
                                      rez.getTexture( unitType ), buffy );
    switch( unitType )
    {
      case TANK:
        asTank( unit );
        break;
      default:
        throw new RuntimeException( "Invalid unit type." );
    }
    unit.setSize( targetWidth, targetHeight );
    return unit;
  }

  private void asTank( GameObject it )
  {
    it.setHealth(         100 );
    it.setMovementSpeed(  100 );
    it.setAttackDamage(   100 );
  }

  /**
  * Specify the end-goal sprite size so that it fills it's square.
  */
  public void setTargetSize( int w, int h )
  {
    targetWidth  = (float) w;
    targetHeight = (float) h;
  }
  private float targetWidth;
  private float targetHeight;

}




Java Source Code List

org.aschyiel.rpg.Coords.java
org.aschyiel.rpg.Focus.java
org.aschyiel.rpg.GameObjectFactory.java
org.aschyiel.rpg.GameObject.java
org.aschyiel.rpg.ICanHasFocus.java
org.aschyiel.rpg.IFullGameObject.java
org.aschyiel.rpg.IGameObject.java
org.aschyiel.rpg.PowerChords.java
org.aschyiel.rpg.Resorcerer.java
org.aschyiel.rpg.activities.Launcher.java
org.aschyiel.rpg.activities.Sandbox.java
org.aschyiel.rpg.activities.Terrain.java
org.aschyiel.rpg.activities.sandbox.BasicCombat.java
org.aschyiel.rpg.activities.sandbox.BasicMovement.java
org.aschyiel.rpg.activities.sandbox.MovementVsLandTypes.java
org.aschyiel.rpg.graph.ChessBoard.java
org.aschyiel.rpg.graph.DefaultPathFinder.java
org.aschyiel.rpg.graph.GirlFriend.java
org.aschyiel.rpg.graph.NavPath.java
org.aschyiel.rpg.graph.Navigator.java
org.aschyiel.rpg.graph.OnSquareClickHandler.java
org.aschyiel.rpg.graph.PathFinder.java
org.aschyiel.rpg.graph.Step.java
org.aschyiel.rpg.graph.VacancySubscriber.java
org.aschyiel.rpg.level.LandType.java
org.aschyiel.rpg.level.LevelDetail.java
org.aschyiel.rpg.level.Level.java
org.aschyiel.rpg.level.Player.java
org.aschyiel.rpg.level.UnitType.java