Advertisement
kanzeparov

Eighth_endGame_EnemyCircle

Nov 18th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.97 KB | None | 0 0
  1. class EnemyCircle extends SimpleCircle {
  2.  
  3.       static int FROM_RADIUS = 10;
  4.       static final int TO_RADIUS = 110;
  5.       static int ENEMY_COLOR = Color.RED;
  6.       static int FOOD_COLOR = Color.rgb(0, 200, 0);
  7.       static int RANDOM_SPEED = 10;
  8.       int dx;
  9.       int dy;
  10.  
  11.       EnemyCircle(int x, int y, int radius, int dxFromConstructor, int dyFromConstructor) {
  12.                 super(x, y, radius);
  13.                 dx = dxFromConstructor;
  14.                 dy = dyFromConstructor;
  15.             }
  16.  
  17.     void setEnemyOrFoodColorDependsOn(MainCircle mainCircle) {
  18.         Log.d("mylog", mainCircle.radius  + "setEn" + radius);
  19.                 if (isSmallerThan(mainCircle)) {
  20.                         setColor(FOOD_COLOR);
  21.                     } else {
  22.                         setColor(ENEMY_COLOR);
  23.                     }
  24.             }
  25.  
  26.     public void moveOneStep() {
  27.                 x += dx;
  28.                 y += dy;
  29.         checkBounds();
  30.             }
  31.  
  32.  
  33.     private void checkBounds() {
  34.                if (x > CanvasView.width || x < 0) {
  35.                         dx = -dx;
  36.                     }
  37.                if (y > CanvasView.height || y < 0) {
  38.                         dy = -dy;
  39.                     }
  40.             }
  41.  
  42.      boolean isSmallerThan(SimpleCircle circle) {
  43.                 if (radius < circle.radius) {
  44.                         return true;
  45.                     }
  46.                 return false;
  47.             }
  48.  
  49.     static EnemyCircle getRandomCircle() {
  50.                 Random random = new Random();
  51.                 int x = random.nextInt(CanvasView.width);
  52.                 int y = random.nextInt(CanvasView.height);
  53.                 int dx = 1 + random.nextInt(RANDOM_SPEED);
  54.                 int dy = 1 + random.nextInt(RANDOM_SPEED);
  55.                 int radius = FROM_RADIUS + random.nextInt(TO_RADIUS - FROM_RADIUS);
  56.                 EnemyCircle enemyCircle = new EnemyCircle(x, y, radius, dx, dy);
  57.                 return enemyCircle;
  58.     }
  59.  
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement