Android Open Source - Stickman Stickman Game






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  w  ww  .j ava2s .  co  m

import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;

public class StickmanGame extends ApplicationAdapter {
  private SpriteBatch batch;
  private OrthographicCamera cam;
  
  public static int VIRTUAL_WIDTH;
  public static int VIRTUAL_HEIGHT;
    private static float ASPECT_RATIO;
    private Rectangle viewport;
    
  @Override
  public void create () {
    VIRTUAL_WIDTH = Gdx.graphics.getWidth();
    VIRTUAL_HEIGHT = Gdx.graphics.getHeight();
    ASPECT_RATIO = (float)VIRTUAL_WIDTH/(float)VIRTUAL_HEIGHT;
    
    batch = new SpriteBatch();
    cam = new OrthographicCamera(VIRTUAL_WIDTH/2, VIRTUAL_HEIGHT/2);
    cam.setToOrtho(true, VIRTUAL_WIDTH/2, VIRTUAL_HEIGHT/2);
    cam.update();
    
    // Import textures
    StickmanResources.initialize();
    
    // Create the world
    World.initialize();
    
    // Initialize everything for Android's controls
    if( Gdx.app.getType() != ApplicationType.Desktop ){
      AndroidGUI.initialize();
    }
  }
  
  @Override
  public void dispose(){
    batch.dispose();
    World.dispose();
  }

  @Override
  public void resize(int width, int height){
     // calculate new viewport
        float aspectRatio = (float)width/(float)height;
        float scale = 1f;
        Vector2 crop = new Vector2(0f, 0f); 
        
        if(aspectRatio > ASPECT_RATIO)
        {
            scale = (float)height/(float)VIRTUAL_HEIGHT;
            crop.x = (width - VIRTUAL_WIDTH*scale)/2f;
        }
        else if(aspectRatio < ASPECT_RATIO)
        {
            scale = (float)width/(float)VIRTUAL_WIDTH;
            crop.y = (height - VIRTUAL_HEIGHT*scale)/2f;
        }
        else
        {
            scale = (float)width/(float)VIRTUAL_WIDTH;
        }

        float w = (float)VIRTUAL_WIDTH*scale;
        float h = (float)VIRTUAL_HEIGHT*scale;
        viewport = new Rectangle(crop.x, crop.y, w, h);
        
        // Initialize everything for Android's controls
        if( Gdx.app.getType() == ApplicationType.Android ){
          AndroidGUI.updateButtons(w, h);
        }
  }
  
  @Override
  public void render () {
    // clear previous frame        
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    
    // Update the world
    World.update();
    
    // Update Camera
    Player player = World.getPlayer();
    cam.position.set(player.getX()+player.getWidth()/2, player.getY()+player.getHeight()/2, 0);
    //cam.viewportWidth = VIRTUAL_WIDTH/2;
    //cam.viewportHeight = VIRTUAL_HEIGHT/2;
    cam.update();
    batch.setProjectionMatrix(cam.combined);
    
     // set viewport
        Gdx.gl.glViewport((int) viewport.x, (int) viewport.y,
                          (int) viewport.width, (int) viewport.height);
    
    // Draw the world
    batch.begin();
    World.draw(batch, cam);
    
    // Draw the GUI
    if( Gdx.app.getType() != ApplicationType.Desktop ){
      AndroidGUI.draw(viewport);
      /*BitmapFont f = AndroidGUI.getFont();
      f.setColor(Color.RED);
      f.draw(batch, String.valueOf(GameRules.redKills), 0, 0);
      f.setColor(Color.BLUE);
      f.draw(batch, String.valueOf(GameRules.blueKills), 0, f.getCapHeight());*/
    }
    

    batch.end();
  }
}




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