Android Open Source - FlappyCow Cow






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 cow that is controlled by the player
 * /*from w w w . ja  va 2s .  com*/
 * @author Lars Harmsen
 * Copyright (c) <2014> <Lars Harmsen - Quchen>
 */

package com.quchen.flappycow.sprites;

import com.quchen.flappycow.Game;
import com.quchen.flappycow.GameView;
import com.quchen.flappycow.MainActivity;
import com.quchen.flappycow.R;
import com.quchen.flappycow.Util;

import android.graphics.Bitmap;

public class Cow extends PlayableCharacter {
  
  /** Static bitmap to reduce memory usage. */
  public static Bitmap globalBitmap;

  /** The moo sound */
  private static int sound = -1;

  public Cow(GameView view, Game game) {
    super(view, game);
    if(globalBitmap == null){
      globalBitmap = Util.getScaledBitmapAlpha8(game, R.drawable.cow);
    }
    this.bitmap = globalBitmap;
    this.width = this.bitmap.getWidth()/(colNr = 8);  // The image has 8 frames in a row
    this.height = this.bitmap.getHeight()/4;      // and 4 in a column
    this.frameTime = 3;    // the frame will change every 3 runs
    this.y = game.getResources().getDisplayMetrics().heightPixels / 2;  // Startposition in in the middle of the screen
    
    if(sound == -1){
      sound = Game.soundPool.load(game, R.raw.cow, 1);
    }
  }
  
  private void playSound(){
    Game.soundPool.play(sound, MainActivity.volume, MainActivity.volume, 0, 0, 1);
  }

  @Override
  public void onTap(){
    super.onTap();
    playSound();
  }
  
  /**
   * Calls super.move
   * and manages the frames. (flattering cape)
   */
  @Override
  public void move(){
    changeToNextFrame();
    super.move();
    
    // manage frames
    if(row != 3){
      // not dead
      if(speedY > getTabSpeed() / 3 && speedY < getMaxSpeed() * 1/3){
        row = 0;
      }else if(speedY > 0){
        row = 1;
      }else{
        row = 2;
      }
    }
  }

  /**
   * Calls super.dead
   * And changes the frame to a dead cow -.-
   */
  @Override
  public void dead() {
    this.row = 3;
    this.frameTime = 3;
    super.dead();
  }
}




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