Android Open Source - Stickman Door






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  . ja  v a2  s  . co  m*/
import java.util.HashMap;
import java.util.Map;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;

public class Door extends Tile implements Toggleable{

  public static final int MOVEDISTANCE = 1;
  public static final int UNLOCKED_LOCK = 0;
  public static final int RED = 1;
  public static final int BLUE = 2;
  public static final int GREEN = 3;
  public static Map<Integer, String> valueToString = new HashMap<Integer,String>(){
    private static final long serialVersionUID = -7407507921104760839L;
  {
    put(RED, "RED");
    put(BLUE, "BLUE");
    put(GREEN, "GREEN");
  }};
  

  private int type = UNLOCKED_LOCK;
  
  private Vector2 move = new Vector2(0,0); // Distance moved from the original position
  private boolean opening = false;

  public Door(Vector3 position, Vector2 size, int type){
    super(position, size, StickmanResources.getImage(valueToString.get(type).toLowerCase() +"door.png"));    
  }
  
  private void open(){
    if( move.y > -getHeight() ){
      move.y -= MOVEDISTANCE;
      moveBy(0,-MOVEDISTANCE);
      checkCollison();
    }    
  }

  private void close(){
    if( move.y < 0 ){
      move.y += MOVEDISTANCE;
      moveBy(0,MOVEDISTANCE);
      checkCollison();
    }    
  }
  
  private void checkCollison() {
    
    // Check Colliding with charcters
    /*List<Character> characters = World.getCharactersInArea(getBounds());
    if( !characters.isEmpty()) {
      for( Character c : characters){
        c.moveBy(0, opening ? -MOVEDISTANCE : MOVEDISTANCE);
      }
    }*/
  }

  @Override
  public void update() {
    if( opening ){
      open();
    }
    else{
      close();
    }
    
  }
  
  @Override
  public void toggle() {
    opening = !opening;
  }

  @Override
  public void draw(SpriteBatch batch) {
    batch.draw(getTexture(), getX(), getY(), getWidth(), getHeight());    
  }

  public int getType() {
    return type;
  }
}




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