123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- package com.darkdimension.ritle_run;
- import android.content.res.Resources;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.graphics.Canvas;
- import android.graphics.Paint;
- public class DiPoint
- {
- //Graphics
- protected static Bitmap[] image;
- public static boolean firstChar = true;
- //Load Graphics
- public static void loadGraphics(Resources resources, int...imageId)
- {
- //Load graphics
- image = new Bitmap[imageId.length];
- for (int iii = 0; iii < imageId.length; iii++)
- image[iii] = BitmapFactory.decodeResource(resources, imageId[iii]);
- }
- public static boolean isLoaded() {return image != null;}
- public static void changeCharacter(Resources resources)
- {
- if (firstChar)
- {
- firstChar = false;
- //Run Animation
- image[28] = BitmapFactory.decodeResource(resources, R.drawable.diment_run_0);
- image[29] = BitmapFactory.decodeResource(resources, R.drawable.diment_run_1);
- image[30] = BitmapFactory.decodeResource(resources, R.drawable.diment_run_2);
- image[31] = BitmapFactory.decodeResource(resources, R.drawable.diment_run_3);
- image[32] = BitmapFactory.decodeResource(resources, R.drawable.diment_run_4);
- image[33] = BitmapFactory.decodeResource(resources, R.drawable.diment_run_5);
- image[34] = BitmapFactory.decodeResource(resources, R.drawable.diment_run_6);
- image[35] = BitmapFactory.decodeResource(resources, R.drawable.diment_run_7);
- //Fall - Jump
- image[36] = BitmapFactory.decodeResource(resources, R.drawable.diment_fall);
- image[37] = BitmapFactory.decodeResource(resources, R.drawable.diment_jump);
- //Air Jump Platform
- image[40] = BitmapFactory.decodeResource(resources, R.drawable.air_jump_diment);
- }
- else
- {
- firstChar = true;
- //Run Animation
- image[28] = BitmapFactory.decodeResource(resources, R.drawable.darek_run_0);
- image[29] = BitmapFactory.decodeResource(resources, R.drawable.darek_run_1);
- image[30] = BitmapFactory.decodeResource(resources, R.drawable.darek_run_2);
- image[31] = BitmapFactory.decodeResource(resources, R.drawable.darek_run_3);
- image[32] = BitmapFactory.decodeResource(resources, R.drawable.darek_run_4);
- image[33] = BitmapFactory.decodeResource(resources, R.drawable.darek_run_5);
- image[34] = BitmapFactory.decodeResource(resources, R.drawable.darek_run_6);
- image[35] = BitmapFactory.decodeResource(resources, R.drawable.darek_run_7);
- //Fall - Jump
- image[36] = BitmapFactory.decodeResource(resources, R.drawable.darek_fall);
- image[37] = BitmapFactory.decodeResource(resources, R.drawable.darek_jump);
- //Air Jump Platform
- image[40] = BitmapFactory.decodeResource(resources, R.drawable.air_jump_darek);
- }
- }
- //Point
- protected int frame;
- protected int x = 0, y = 0;
- public DiPoint(int gFrame) {frame = gFrame;}
- //Touch
- public boolean isTouched(int touchX, int touchY)
- {
- //If touch
- if (touchX > x && touchX < x +image[frame].getWidth ()
- && touchY > y && touchY < y +image[frame].getHeight())
- return true;
- //Not touched
- return false;
- }
- //Draw
- public void draw(Canvas canvas) {
- canvas.drawBitmap(image[frame], x, y, null);}
- public void draw(Canvas canvas, Paint paint) {
- canvas.drawBitmap(image[frame], x, y, paint);}
- public void draw(Canvas canvas, int offsetX, int offsetY) {
- canvas.drawBitmap(image[frame], x +offsetX, y +offsetY, null);}
- public void draw(Canvas canvas, int offsetX, int offsetY, Paint paint) {
- canvas.drawBitmap(image[frame], x +offsetX, y +offsetY, paint);}
- //Actions
- public void changeX(int amount) {x += amount;}
- //public void changeY(int amount) {y += amount;}
- //Setters
- public void setFrame (int amount) {frame = amount;}
- public void setLeft (int amount) {x = amount;}
- public void setTop (int amount) {y = amount;}
- public void setRight (int amount) {x = amount -image[frame].getWidth ();}
- public void setBottom(int amount) {y = amount -image[frame].getHeight();}
- public void setCenterX(int amount) {x = amount -image[frame].getWidth ()/2;}
- public void setCenterY(int amount) {y = amount -image[frame].getHeight()/2;}
- //Getters
- public int getFrame() {return frame;}
- public int getLeft () {return x;}
- public int getTop () {return y;}
- public int getRight () {return x +image[frame].getWidth ();}
- public int getBottom() {return y +image[frame].getHeight();}
- public int getCenterX() {return x +image[frame].getWidth ()/2;}
- public int getCenterY() {return y +image[frame].getHeight()/2;}
- public int getWidth () {return image[frame].getWidth ();}
- public int getHeight() {return image[frame].getHeight();}
- public static int getWidth (int graphic) {return image[graphic].getWidth ();}
- public static int getHeight(int graphic) {return image[graphic].getHeight();}
- public int[] getSquare()
- {
- int[] returner = new int[4];
- returner[0] = x;
- returner[1] = y;
- returner[2] = x +image[frame].getWidth();
- returner[3] = y +image[frame].getHeight();
- return returner;
- }
- public int[] getSquare(int offsetX, int offsetY)
- {
- int[] returner = new int[4];
- returner[0] = x +offsetX;
- returner[1] = y +offsetY;
- returner[2] = x +image[frame].getWidth () +offsetX;
- returner[3] = y +image[frame].getHeight() +offsetY;
- return returner;
- }
- }
|