Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.b1sha_000.hw1;
- import android.graphics.Canvas;
- import android.graphics.Color;
- import android.graphics.Paint;
- import java.util.Random;
- /**
- * Created by Yuji on 4/15/2015.
- */
- public class Bubble {
- private final BubbleShooterView bsv;
- private final int mR;
- private final int mColor;
- private int mX;
- private int mY;
- private int mAlpha;
- private int mVelX;
- private int mVelY;
- public Bubble(BubbleShooterView bsv,int radius, int color, int yPos, int xPos, int alpha, int VelX, int VelY){
- this.bsv = bsv;
- this.mColor = color;
- this.mR = radius;
- this.mX = xPos;
- this.mY = yPos;
- this.mAlpha = alpha;
- this.mVelX = VelX;
- this.mVelY = VelY;
- }
- public void draw( Canvas c ) {
- Paint paint = new Paint();
- paint.setColor( mColor );
- c.drawCircle( this.getX(), this.getY(), this.getR(), paint );
- }
- public int getX() { return mX; }
- public int getY() { return mY; }
- public int getR() { return mR; }
- public int getColor() { return mColor; }
- public int getAlpha() { return mAlpha; }
- public int getVelX() { return mVelX; }
- public int getVelY() { return mVelY; }
- // The laws of physics: Restricted frictionless motion :)
- public void stepCoordinates() {
- int maxX = bsv.getWidth();
- int maxY = bsv.getHeight();
- mX += mVelX;
- mY += mVelY;
- if ( mX > ( maxX - mR) ) {
- mVelX = -mVelX;
- mX = maxX - mR;
- } else if ( mX < mR) {
- mVelX = -mVelX;
- mX = mR;
- }
- if ( mY > ( maxY - mR) ) {
- mVelY = -mVelY;
- mY = maxY - mR;
- } else if ( mY < mR) {
- mVelY = -mVelY;
- mY = mR;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement