Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package biz.hireholly.tutorial.models;
- import android.graphics.Bitmap;
- import android.graphics.Canvas;
- public class Orb {
- private Bitmap bitmap; //image
- private int x; //x coord
- private int y; //y coord
- private boolean touched; //if orb is touched/picked up
- //just to make things simpler to read
- int halfBmpX = bitmap.getWidth() /2;
- int halfBmpY = bitmap.getHeight() /2;
- public Orb(Bitmap bmp, int x, int y){
- this.bitmap = bmp;
- this.x = x;
- this.y = y;
- }
- public Bitmap getBitmap(){
- return bitmap;
- }
- public void setBitmap(Bitmap bmp){
- this.bitmap = bmp;
- }
- public int getX(){
- return x;
- }
- public int getY(){
- return y;
- }
- public void setX(int x){
- this.x = x;
- }
- public void setY(int y){
- this.y = y;
- }
- public boolean isTouched(){
- return touched;
- }
- public void setTouched(boolean touched){
- this.touched = true;
- }
- /**
- * takes the bitmap it was instantiated with.
- * Draws it to the canvas at the coordinates the orb is at in that moment.
- * @param canvas
- */
- public void draw(Canvas canvas){
- canvas.drawBitmap(bitmap, x-halfBmpX, y-halfBmpY, null );
- }
- /**
- * check if the events coordinates are inside the orb's bitmap.
- * Used when the user presses down to see if they touched the orb
- * @param eX
- * @param eY
- */
- public void handleActionDown(int eX, int eY){
- if(eX >= (x - halfBmpX) && (eX <= (x + halfBmpX))){ //checks if within width
- if (eY >= (y - halfBmpY) && (eY <= (y + halfBmpY))){ //checks if within height
- //orb touched
- setTouched(true);
- }
- else{
- setTouched(false);
- }
- }
- else{
- setTouched(false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement