Android Open Source - FlappyCow Playable Character






From Project

Back to project page FlappyCow.

License

The source code is released under:

MIT License

If you think the Android project FlappyCow 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

/**
 * The SuperClass of every character that is controlled by the player
 * /*from w w w .ja  v  a  2  s  . c  om*/
 * @author Lars Harmsen
 * Copyright (c) <2014> <Lars Harmsen - Quchen>
 */

package com.quchen.flappycow.sprites;

import com.quchen.flappycow.Game;
import com.quchen.flappycow.GameView;

public abstract class PlayableCharacter extends Sprite {
  
  public PlayableCharacter(GameView view, Game game) {
    super(view, game);
    move();
  }
  
  /**
   * Calls super.move
   * Moves the character to 1/6 of the horizontal screen
   * Manages the speed changes -> Falling
   */
  @Override
  public void move(){
    this.x = this.view.getWidth() / 6;
    
    if(speedY < 0){
      // The character is moving up
      speedY = speedY * 2 / 3 + getSpeedTimeDecrease() / 2;
    }else{
      // the character is moving down
      this.speedY += getSpeedTimeDecrease();
    }
    
    if(this.speedY > getMaxSpeed()){
      // speed limit
      this.speedY = getMaxSpeed();
    }
    
    super.move();
  }

  /**
   * A dead character falls slowly to the ground.
   */
  public void dead(){
    this.speedY = getMaxSpeed()/2;
  }
  
  /**
   * Let the character flap up.
   */
  public void onTap(){
    this.speedY = getTabSpeed();
    this.y += getPosTabIncrease();
  }
  
  /**
   * Falling speed limit
   * @return
   */
  protected float getMaxSpeed(){
    // 25 @ 720x1280 px
    return view.getHeight() / 51.2f;
  }
  
  /**
   * Every run cycle the speed towards the ground will increase.
   * @return
   */
  protected float getSpeedTimeDecrease(){
    // 4 @ 720x1280 px
    return view.getHeight() / 320;
  }
  
  /**
   * The character gets this speed when taped.
   * @return
   */
  protected float getTabSpeed(){
    // -80 @ 720x1280 px
    return - view.getHeight() / 16f;
  }
  
  /**
   * The character jumps up the pixel height of this value.
   * @return
   */
  protected int getPosTabIncrease(){
    // -12 @ 720x1280 px
    return - view.getHeight() / 100;
  }
  
  public void revive(){
    this.row = 0;
  }
}




Java Source Code List

com.quchen.flappycow.About.java
com.quchen.flappycow.AccomplishmentBox.java
com.quchen.flappycow.GameOverDialog.java
com.quchen.flappycow.GameView.java
com.quchen.flappycow.Game.java
com.quchen.flappycow.MainActivity.java
com.quchen.flappycow.StartscreenView.java
com.quchen.flappycow.Util.java
com.quchen.flappycow.sprites.Background.java
com.quchen.flappycow.sprites.Coin.java
com.quchen.flappycow.sprites.Cow.java
com.quchen.flappycow.sprites.Frontground.java
com.quchen.flappycow.sprites.NyanCat.java
com.quchen.flappycow.sprites.Obstacle.java
com.quchen.flappycow.sprites.PauseButton.java
com.quchen.flappycow.sprites.PlayableCharacter.java
com.quchen.flappycow.sprites.PowerUp.java
com.quchen.flappycow.sprites.Rainbow.java
com.quchen.flappycow.sprites.Spider.java
com.quchen.flappycow.sprites.Sprite.java
com.quchen.flappycow.sprites.Toast.java
com.quchen.flappycow.sprites.Tutorial.java
com.quchen.flappycow.sprites.WoodLog.java