-
Notifications
You must be signed in to change notification settings - Fork 1
Map Generation
Almost all other feature teams are dependent on map generation. It is crucial in creating map content (such as obstacles and power ups) and coding enemies and player movement into the game. Thereby, map generation is one of the most important components of Ragnarok Racers.
This feature will see the development of the Bifrost. This is the vibrant rainbow bridge in which the main character of the game races across. This feature will also create the starry backdrop of the Bifrost. This will be achieved by creating textures for the map in Photoshop and creating various methods to replicate the map design in Java code.
Furthermore, this feature will introduce several new classes. Namely, it will introduce Bridge and Lane classes. These will segment the map into smaller chunks, allowing for more complex functionalities to be built into the game. For example, these classes will be vital in establishing bounds for player movement and creating methods which allow users to move between lanes.
You can access the rainbow bridge directly under
source/core/src/main/com/deco2800/game/screens/RagnorakRacer.java
public class RagnorakRacer extends ScreenAdapter {
private final GdxGame game;
private final Renderer renderer;
/** The Bridge instance is available here under Ragnorak Racer */
private Bridge rainbowBridge;
private static final Vector2 CAMERA_POSITION = new Vector2(7.5f, 7.5f);
public RagnorakRacer(GdxGame game) {
this.game = game;
ServiceLocator.registerInputService(new InputService());
ServiceLocator.registerResourceService(new ResourceService());
ServiceLocator.registerEntityService(new EntityService());
ServiceLocator.registerRenderService(new RenderService());
this.renderer = RenderFactory.createRenderer();
this.renderer.getCamera().getEntity().setPosition(CAMERA_POSITION);
createUI();
TerrainFactory terrainFactory = new TerrainFactory(renderer.getCamera());
RainbowBridge rainbowBridge = new RainbowBridge(terrainFactory);
rainbowBridge.create();
/** The rainbowBridge attribute is initialized once the terrain is created */
this.rainbowBridge = rainbowBridge.getRainbowBridge();
}
...
A Bridge class holds several Lane classes, which can be accessed from a List<bridge>
The bridge is created as a component and can be found under source\core\src\main\com\deco2800\game\components\bridge
The javadoc in Bridge.java & Lane.java explains exactly how the two work together to create the rainbow bridge
source/core/src/main/com/deco2800/game/components/bridge/Bridge.java
public class Bridge {
/**
* Offsets the location of the bridge to be
* Used to change where the bridge is drawn on-screen
* */
private int offset;
private int width;
/** A list of lanes on a bridge */
private List<Lane> lanes;
...
...
/**
* Returns all lanes on the bridge
* @return lanes
*/
public List<Lane> getLanes() {
return this.lanes;
}
...
...
/**
* Returns a map of the top and bottom bounds (Integer)
* @return a Map with a top and bottom y-coordinate
*/
public Map<String, Integer> getBounds() {
if (this.lanes.size() == 0) {
throw new IllegalCallerException("Unable to get bridge bounds from a bridge with no lanes");
} else {
Map<String, Integer> bounds = new HashMap<>();
bounds.put("top", this.getLastLane().getTop());
bounds.put("bot", this.lanes.get(0).getBot());
return bounds;
}
}
...
source/core/src/main/com/deco2800/game/components/bridge/Bridge.java
public class Lane {
private int y1;
private int y2;
private int mid;
/**
* Set 2 y-coordinate that defines the bounds of a lane
* @param top top y coordinate
* @param bot bottom y coordinate
*/
public Lane(int top, int bot) {
if (top >= bot) {
throw new IllegalArgumentException("top y-coordinate cannot be bigger or equal to bottom y-coordinate");
} else {
this.y1 = top;
this.y2 = bot;
this.mid = (top + bot) / 2;
}
}
...
/**
* returns the center y-coordinate of the lane
* @return a y-coordinate
*/
public int getMid() {
return this.mid;
}
/**
* Returns the top of the bridge from the user's perspective
* TerrainFactory fills tiles from the bottom up
* @return
*/
public int getTop() {
return this.y2;
}
/**
* Returns the bottom of the bridge from the user's perspective
* TerrainFactory fills tiles from the bottom up
* @return
*/
public int getBot() {
return this.y1;
}
...