Android Open Source - Stickman Small Button






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;
/*  w w w  . j a  va 2 s. co m*/
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;

public class SmallButton extends GameObject implements Interactable{
  public static final int RED = 0;
  public static final int GREEN = 1;
  public static final int BLUE = 2;
  public static final int OFF = 3;
  
  public static final int MAXCOLOURS = 4;
  
  
  private int type;
  private TextureRegion[] frames;
  

  public SmallButton(Vector3 point, Vector2 size, int type){
    super(point, size);    
    this.setType(type);
    
    Texture characterTexture = StickmanResources.getImage("smallbutton.png");
    TextureRegion[][] tmp = TextureRegion.split(characterTexture, characterTexture.getWidth()/MAXCOLOURS, characterTexture.getHeight());
    frames = new TextureRegion[tmp[0].length];
    frames[0] = tmp[0][0];
    frames[1] = tmp[0][1];
    frames[2] = tmp[0][2];
    frames[3] = tmp[0][3];
  }
  
  public void setType(int type){
    if( type >= MAXCOLOURS ){
      throw new RuntimeException("UNKNOWN TYPE!!! " + type);
    }
    this.type = type;
  }
  
  @Override
  public void update(){
    if( type == OFF ) return;
    
    Player player = World.getPlayer();
    if( player.getBounds().overlaps(getBounds()) ){
      interact(player);
    }
  }
    

  @Override
  public void draw(SpriteBatch batch) {
    batch.draw(frames[type], getX(), getY(), getWidth(), getHeight());
  }

  @Override
  public void interact(GameObject triggerer) {
    World.getDoor(type).toggle();    
    setType(OFF);
  }

  @Override
  public void dispose() {
    for(TextureRegion t : frames){
      t.getTexture().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