Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.fhflensburg.manichja.barrier51;
- import android.content.Context;
- import android.content.res.ColorStateList;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.graphics.Canvas;
- import android.graphics.Color;
- import android.graphics.Paint;
- import android.graphics.Point;
- import android.graphics.drawable.Drawable;
- import android.util.Log;
- import android.view.View;
- import android.widget.ImageView;
- import android.util.Size;
- /**
- * Created by Niklas on 22.10.2015.
- */
- public class GameObject {
- private Size size; // A color as stated as a resource in the XML file (thus, it is an int)
- private Point position; // A color as stated as a resource in the XML file (thus, it is an int)
- private int fillColor; // A color as stated as a resource in the XML file (thus, it is an int)
- private int strokeColor;// A color as stated as a resource in the XML file (thus, it is an int)
- private int sprite;// A color as stated as a resource in the XML file (thus, it is an int)
- private Bitmap ourSprite;
- private Context conny;
- public GameObject(Context context)
- {
- this.conny = context;
- /*Paint myPaint = new Paint();
- myPaint.setColor(Color.rgb(0, 0, 0));
- myPaint.setStrokeWidth(10);
- c.drawRect(100, 100, 200, 200, myPaint);*/
- }
- /**
- * Sets the position of the GameObject on the screen.
- * @param position A Point instance with x and y
- */
- public void setPosition(Point position)
- {
- this.position = position;
- }
- /**
- * Sets the fill color of the game object. If it has a Sprite image, the assigned color will be ignored.
- * @param color A color resource, defined in the XML file (e.g. R.color.limegreen)
- */
- public void setFillColor(int color)
- {
- this.fillColor = color;
- }
- /**
- * Sets the stroke color of the game object. If it has a Sprite image, the assigned color will be ignored.
- * @param color A color resource, defined in the XML file (e.g. R.color.limegreen)
- */
- public void setStrokeColor(int color)
- {
- this.strokeColor = color;
- }
- /**
- * @return Delivers the current size of the GameObject
- */
- public Size getSize()
- {
- return size;
- }
- /**
- * @return Delivers the current position of the GameObject
- */
- public Point getPosition()
- {
- return position;
- }
- /**
- * @return Delivers the current position of the GameObject as stated in the XML file.
- */
- public int getFillColor()
- {
- return fillColor;
- }
- /**
- * @return Delivers the current stroke color of the GameObject as stated in the XML file.
- */
- public int getStrokeColor()
- {
- return strokeColor;
- }
- /**
- * Checks for a collision of this object with another instance of a GameObject.
- * @param obj The object to be checked for collision
- * @return Returns true if the objects' coordinates overlap at any pixel.
- */
- public boolean overlaps(GameObject obj)
- {
- if (getPosition().x < obj.getPosition().x + obj.getSize().getWidth() &&
- getPosition().x + getSize().getWidth() > obj.getPosition().x &&
- getPosition().y < obj.getPosition().y + obj.getSize().getHeight() &&
- getSize().getHeight() + getPosition().y > obj.getPosition().y)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- /**
- * Sets the sprite image of the GameObject.
- * @param sprite A bitmap resource as defined in the XML file.
- */
- public void setSprite(int sprite) {
- Log.i("Peter", "Inigame get started"+sprite);
- this.sprite = sprite;
- ourSprite = BitmapFactory.decodeResource(this.conny.getResources(),R.drawable.menu_background);
- }
- /**
- * @return Delivers the sprite resource id as an Integer.
- */
- public Bitmap getSprite() {
- return ourSprite;
- }
- /**
- * Renders the object with the current attributes on the screen.
- */
- public void render(Canvas c,Paint paint)
- {
- c.drawRect(0,0,120,120,paint);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement