Android Open Source - endlessJourney Bot






From Project

Back to project page endlessJourney.

License

The source code is released under:

GNU General Public License

If you think the Android project endlessJourney 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.kambashi.endlessjourney.model;
/* w  ww  .  j  a  v a  2 s  . c  o m*/
import android.graphics.Bitmap;
import android.graphics.Canvas;

import com.kambashi.endlessjourney.model.components.Speed;

public class Bot {

  private Bitmap bitmap; // the actual bitmap
  private int x; // the X coordinate
  private int y; // the Y coordinate
  private boolean touched; // if droid is touched/picked up

  private Speed speed; // the speed with its directions

  public Bot(Bitmap bitmap, int x, int y) {
    this.bitmap = bitmap;
    this.x = x;
    this.y = y;
    this.speed = new Speed();
  }

  public Bitmap getBitmap() {
    return bitmap;
  }

  public void setBitmap(Bitmap bitmap) {
    this.bitmap = bitmap;
  }

  public int getX() {
    return x;
  }

  public void setX(int x) {
    this.x = x;
  }

  public int getY() {
    return y;
  }

  public void setY(int y) {
    this.y = y;
  }

  public boolean isTouched() {
    return touched;
  }

  public void setTouched(boolean touched) {
    this.touched = touched;
  }

  public Speed getSpeed() {
    return speed;
  }

  public void setSpeed(Speed speed) {
    this.speed = speed;
  }

  public void draw(Canvas canvas) {
    canvas.drawBitmap(bitmap, x - (bitmap.getWidth() / 2),
        y - (bitmap.getHeight() / 2), null);
  }

  public void handleActionDown(int eventX, int eventY) {
    if (eventX >= (x - bitmap.getWidth() / 2)
        && (eventX <= (x + bitmap.getWidth() / 2))) {
      if (eventY >= (y - bitmap.getHeight() / 2)
          && (y <= (y + bitmap.getHeight() / 2))) {
        // droid touched
        setTouched(true);
      } else {
        setTouched(false);
      }
    } else {
      setTouched(false);
    }
  }

  public void update() {
    if (!touched) {
      x += (speed.getXv() * speed.getxDirection());
      y += (speed.getYv() * speed.getyDirection());
    }
  }
}




Java Source Code List

com.kambashi.endlessjourney.EndlessActivity.java
com.kambashi.endlessjourney.MainGamePanel.java
com.kambashi.endlessjourney.MainThread.java
com.kambashi.endlessjourney.model.Bot.java
com.kambashi.endlessjourney.model.components.Speed.java