Android Open Source - funnyboat-Android Enemy






From Project

Back to project page funnyboat-Android.

License

The source code is released under:

GNU General Public License

If you think the Android project funnyboat-Android 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.ankit.funnyboat;
//from  w  w w.  java  2s  . co  m
import java.util.Random;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Paint;

public class Enemy extends GameObject {

  static Bitmap sharkImg;
  static Bitmap mineImg;
  static Bitmap shipImg;
  boolean isMine = false;
  boolean isShark = false;
  boolean isShip = false;
  float shootCounter;
  float jumpCounter;
  static Random rand = new Random(13);
  static Paint linePaint;
  static {
    linePaint = new Paint();
    linePaint.setARGB(0xff, 0, 0, 0);
    shipImg = BitmapFactory.decodeResource(Game.app.getResources(),
        R.drawable.merkkari);
    sharkImg = BitmapFactory.decodeResource(Game.app.getResources(),
        R.drawable.hai);
    mineImg = BitmapFactory.decodeResource(Game.app.getResources(),
        R.drawable.miina);
  }
  {
    waterUp = true;
    if (Gameplay.current.storyMode) {
      if (Gameplay.current.counter < 36) {
        isMine = true;
      } else if (Gameplay.current.counter < 70) {
        isMine = rand.nextBoolean();
        isShark = !isMine;
      } else {
        isMine = rand.nextBoolean();
        isShark = isMine ? false : rand.nextInt(3) != 1;
      }
    } else {
      isMine = rand.nextBoolean();
      isShark = isMine ? false : rand.nextInt(3) != 1;
    }
    isShip = !isMine && !isShark;
    if (isMine)
      waterUp = false;
    vx = (float) -(Game.water.getWaveSpeed() * 0.5);
    enemy = true;
  }

  Bitmap getImage() {
    if (isMine)
      return mineImg;
    if (isShark)
      return sharkImg;
    return shipImg;
  }

  @Override
  public void tick() {
    if (isMine) {
      y = Game.water.getAt((int) x);
      x += vx * DELTA;
      Game.canvas.drawLine(x, y, x, 0, linePaint);
      Game.canvas.drawBitmap(mineImg, x - mineImg.getWidth() / 2, y - 7,
          null);
      return;
    }
    super.tick();

    shootCounter += DELTA;
    if (isShip) {
      if (shootCounter > 3.5) {
        shootCounter = 0;
        shoot();
      }
    }
    jumpCounter += DELTA;
    if (isShip || isShark) {
      if (jumpCounter > 4.5) {
        jumpCounter = 0;
        jump();
      }
    }
  }

  void shoot() {
    Bullet bullet = new Bullet();
    bullet.enemy = true;
    bullet.x = this.x;
    bullet.y = this.y + 15;
    int speed = 100;
    bullet.vx = -(float) (speed * 2);
    bullet.vy = (float) (speed * 1.5);
    Gameplay.current.objects.add(bullet);
  }

  boolean kill() {
    Gameplay.current.score += (isMine ? 20 : (isShip ? 30 : 20));
    return super.kill();
  }
}




Java Source Code List

com.ankit.funnyboat.Bullet.java
com.ankit.funnyboat.DeathBody.java
com.ankit.funnyboat.Enemy.java
com.ankit.funnyboat.GameModule.java
com.ankit.funnyboat.GameObject.java
com.ankit.funnyboat.Game.java
com.ankit.funnyboat.Gameplay.java
com.ankit.funnyboat.MainActivity.java
com.ankit.funnyboat.Menu.java
com.ankit.funnyboat.Player.java
com.ankit.funnyboat.Water.java