View Javadoc
1   package com.jed.actor;
2   
3   import com.jed.util.BasicShapeRenderer;
4   import com.jed.util.Vector2f;
5   
6   /**
7    *
8    * Concrete implementation of {@link com.jed.actor.PhysicsEntity} that represents a "Ball" or circle. The
9    * circle has a color which is represented as its respective Red, Green, and Blue values.
10   * 
11   * @author jlinde, Peter Colapietro
12   * @since 0.1.0
13   *
14   */
15  public final class Ball extends PhysicsEntity {
16  
17      /**
18       * 
19       */
20      private final int segments;
21      
22      /**
23       * Ball color's Green value.
24       */
25      private final float g;
26  
27      /**
28       * Ball color's Red value.
29       */
30      private final float r;
31      
32      /**
33       * Ball color's Blue value.
34       */
35      private final float b;
36  
37      /**
38       * 
39       * @param displacement displacement.
40       * @param movement movement.
41       * @param bounds bounds.
42       * @param segments segments.
43       * @param r red.
44       * @param g green.
45       * @param b blue.
46       */
47      public Ball(Vector2f displacement, Vector2f movement, Boundary bounds, int segments, float r, float g, float b) {
48          super(displacement, movement, bounds);
49  
50          this.r = r;
51          this.g = g;
52          this.b = b;
53  
54          this.segments = segments;
55      }
56  
57      @Override
58      public double mass() {
59          return getRadius();
60      }
61  
62      /**
63       * 
64       * @return radius of ball.
65       */
66      public int getRadius() {
67          return ((CircleBoundary) getBounds()).radius;
68      }
69  
70      @Override
71      public void render() {
72          setPosition(getPosition().add(getMovement()));
73          BasicShapeRenderer.drawFilledCircle(
74                  getPosition().x,
75                  getPosition().y,
76                  getRadius(),
77                  segments,
78                  r, g, b);
79  
80      }
81  }