Package generators

Source Code of generators.DotsGenerator

package generators;

import squaresgame.ColourManager;
import framework.component.ComponentSystem;
import framework.component.ParentComponent;
import framework.rendering.SpriteComponent;
import framework.spacial.PositionComponent;

public class DotsGenerator {
  /**
   * Create the graphics for the grid of dots.
   * @param startingX x coordinate of the first point
   * @param startingY y coordinate of the first point
   * @param width the number of dots horizontally
   * @param height the number of dots vertically
   * @param spacing the space between dots
   */
  public static void createDots(int startingX,  int startingY, int width, int height, float spacing, ParentComponent gridParent){
    for(int i = 0; i < width; i+= 1){
      for(int j = 0; j < height; j+= 1) {
        createDot(startingX + i * spacing ,startingY + j* spacing, gridParent);
      }
    }
  }
 
  /**
   * Draw a dot on the screen at the given coordinates.
   * @param x The x coordinate (in pixels) of the dot on the screen.
   * @param y The y coordinate (in pixels) of the dot on the screen.
   */
  private static void createDot(float x, float y, ParentComponent gridParent){
    ParentComponent ballParent = new ParentComponent();
    gridParent.addComponent(ballParent);

    PositionComponent ballPos = new PositionComponent(x,y);
    ballParent.addComponent(ballPos);
    SpriteComponent ballSprite = new SpriteComponent(ColourManager.getDot(), 17, 17);
    ballParent.addComponent(ballSprite);
  }

}
TOP

Related Classes of generators.DotsGenerator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.