Advertisement
ydornberg

Bubble

Apr 19th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.98 KB | None | 0 0
  1. package com.example.b1sha_000.hw1;
  2.  
  3. import android.graphics.Canvas;
  4. import android.graphics.Color;
  5. import android.graphics.Paint;
  6.  
  7. import java.util.Random;
  8. /**
  9.  * Created by Yuji on 4/15/2015.
  10.  */
  11. public class Bubble {
  12.  
  13.     private final BubbleShooterView  bsv;
  14.     private final int              mR;
  15.     private final int              mColor;
  16.     private       int              mX;
  17.     private       int              mY;
  18.     private       int              mAlpha;
  19.     private       int              mVelX;
  20.     private       int              mVelY;
  21.  
  22.     public Bubble(BubbleShooterView bsv,int radius, int color, int yPos, int xPos, int alpha, int VelX, int VelY){
  23.  
  24.         this.bsv    = bsv;
  25.         this.mColor = color;
  26.         this.mR     = radius;
  27.         this.mX     = xPos;
  28.         this.mY     = yPos;
  29.         this.mAlpha = alpha;
  30.         this.mVelX  = VelX;
  31.         this.mVelY  = VelY;
  32.  
  33.  
  34.     }
  35.     public void draw( Canvas c ) {
  36.         Paint paint = new Paint();
  37.         paint.setColor( mColor );
  38.         c.drawCircle( this.getX(), this.getY(), this.getR(), paint );
  39.     }
  40.  
  41.     public int getX() { return mX; }
  42.     public int getY() { return mY; }
  43.     public int getR() { return mR; }
  44.     public int getColor() { return mColor; }
  45.     public int getAlpha() { return mAlpha; }
  46.     public int getVelX() { return mVelX; }
  47.     public int getVelY() { return mVelY; }
  48.  
  49.     //    The laws of physics: Restricted frictionless motion :)
  50.     public void stepCoordinates() {
  51.         int maxX = bsv.getWidth();
  52.         int maxY = bsv.getHeight();
  53.  
  54.         mX += mVelX;
  55.         mY += mVelY;
  56.  
  57.         if ( mX > ( maxX - mR) ) {
  58.             mVelX = -mVelX;
  59.             mX = maxX - mR;
  60.         } else if ( mX < mR) {
  61.             mVelX = -mVelX;
  62.             mX = mR;
  63.         }
  64.         if ( mY > ( maxY - mR) ) {
  65.             mVelY = -mVelY;
  66.             mY = maxY - mR;
  67.         } else if ( mY < mR) {
  68.             mVelY = -mVelY;
  69.             mY = mR;
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement