package com.hyperling.apps.games;

import android.graphics.Bitmap;

/**
 * Created by ling on 12/23/16.
 */

public class Bird extends Player {

    private boolean flapping = false;

    private int lives = 0;

    public Bird(Bitmap b, int w, int h, int numFrames){
        super(b, w, h, numFrames);
    }

    public boolean isFlapping() {
        return flapping;
    }

    public void setFlapping(boolean flapping) {
        this.flapping = flapping;
    }

    public int getLives() {
        return lives;
    }

    public void addLives(int lives) {
        this.lives += lives;
    }

    public void subtractLives(int lives) {
        this.lives -= lives;
    }

    @Override
    public void update() {
        // Go up!
        if (flapping){
            dy += -1;
        }
        // Otherwise fall
        else{
            dy += 2;
        }

        // Do not fly up faster than this
        if (dy < -5){
            dy = -5;
        }
        // Do not fall faster than this
        if (dy > 7){
            dy = 7;
        }

        /***** Map limits *****/
        if (y < GameView.HEIGHT - getHeight() || dy < 0) {
            y += dy;
        }
        // Do not leave bottom of map
        else{
            y = GameView.HEIGHT - getHeight();
            dy = 0;
        }

        // Do not leave top of map
        if (y < 0){
            y = 0;
        }

        super.update();
    }
}
