package com.hyperling.apps.games; import android.graphics.Bitmap; import android.graphics.Canvas; /** * Created by ling on 12/26/16. */ public class BirdEnemy extends GameObject { protected Bitmap image; private Animation animation; private int speed, damage; public BirdEnemy(Bitmap b, int w, int h, int numFrames, int x, int y, int speed, int damage){ image = b; width = w; height = h; this.x = x; this.y = y; this.speed = speed; this.damage = damage; if (speed > -1){ speed = -1; } if (this.y >= GameView.HEIGHT - this.height){ this.y = GameView.HEIGHT - this.height; } // Create animation Bitmap[] image = new Bitmap[numFrames]; animation = new Animation(); for (int i = 0; i < numFrames; i++){ image[i] = Bitmap.createBitmap(b, width * i, 0, width, height); } animation.setFrames(image); //animation.setDelay(100); int delay = 25 * Math.abs(speed); if (delay > 125){ delay = 125; } else if (delay < 75){ delay = 75; } animation.setDelay(delay); animation.setCurrentFrame((int)(Math.random() * numFrames)); } public void update(){ animation.update(); // Move the object x += speed; } public void draw(Canvas canvas) { // Draw the object canvas.drawBitmap(animation.getImage(), getX(), getY(), null); } public int getDamage() { return damage; } }