Android Open Source - Stickman Spawner






From Project

Back to project page Stickman.

License

The source code is released under:

Apache License

If you think the Android project Stickman 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 com.wireframe.stickman;
/*from  ww w  .ja v a2 s.co m*/
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;

public class Spawner extends GameObject{
  
  public static final int SPAWNERTYPE_RED = 0;
  public static final int SPAWNERTYPE_BLUE = 1;
  public static final int spawnRate = 2;
  
  public float spawnDelay = 0f;
  
  // What this spawner is creating
  private int type;
  private Character spawned = null;
  
  public Spawner(Vector3 point, Vector2 size, int type){
    super(point, size);
    this.type = type;
  }
  
  public void update(){
    
    // Check if we already have a spawned unit
    if( spawned != null ){
      if( !spawned.isAlive() ){
        spawned = null;
      }
      else{
        return;
      }
    }
    
    // Try and spawn a new unit
    if( spawnDelay > spawnRate ){
      spawnDelay = 0f;
      spawn();
    }
    else{
      spawnDelay += Gdx.graphics.getDeltaTime();
    }
  }
  
  public void spawn(){
    if( type == SPAWNERTYPE_RED ){
      spawned = new Enemy(getX(), getY(), getZ(), getWidth(), getHeight());
    }
    else if( type == SPAWNERTYPE_BLUE ){
      spawned = new Friendly(getX(), getY(), getZ(), getWidth(), getHeight());
    }
    
    // Add to the world
    if( spawned != null ){
      World.addObject(spawned);
    }
  }

  @Override
  public void draw(SpriteBatch batch) {
  }

  @Override
  public void dispose() {
    
  }
}




Java Source Code List

com.wireframe.stickman.AICharacter.java
com.wireframe.stickman.AndroidGUI.java
com.wireframe.stickman.Brick.java
com.wireframe.stickman.Character.java
com.wireframe.stickman.Door.java
com.wireframe.stickman.Enemy.java
com.wireframe.stickman.FloatingText.java
com.wireframe.stickman.Friendly.java
com.wireframe.stickman.GUI.java
com.wireframe.stickman.GameObject.java
com.wireframe.stickman.GameRules.java
com.wireframe.stickman.Health.java
com.wireframe.stickman.Interactable.java
com.wireframe.stickman.Ladder.java
com.wireframe.stickman.Player.java
com.wireframe.stickman.Resources.java
com.wireframe.stickman.SmallButton.java
com.wireframe.stickman.Spawner.java
com.wireframe.stickman.Spikes.java
com.wireframe.stickman.StickmanGame.java
com.wireframe.stickman.StickmanResources.java
com.wireframe.stickman.Tile.java
com.wireframe.stickman.Toggleable.java
com.wireframe.stickman.WaterShore.java
com.wireframe.stickman.Water.java
com.wireframe.stickman.World.java
com.wireframe.stickman.android.AndroidLauncher.java
com.wireframe.stickman.desktop.DesktopLauncher.java
com.wireframe.stickman.desktop.EditorLauncher.java
com.wireframe.stickman.editor.MapMaker.java
com.wireframe.stickman.editor.MappingPanel.java
com.wireframe.stickman.editor.PlacedTile.java
com.wireframe.stickman.editor.SelectionPanel.java
com.wireframe.stickman.editor.SelectionTile.java
com.wireframe.stickman.editor.SizingPanel.java