Class Structure

java.lang.Object
rekit.logic.level.Structure
Direct Known Subclasses:
BossStructure

public class Structure extends Object

Represents a collection if GameElements that can be build into a level.

It is created from a two dimensional integer array that symbolizes a two dimensional fraction of a possible level. Each number in the array will be mapped to another kind of GameElement upon building. The mapping is specified by the GameElementFactory.

To build an existing Structure, it supplies the method build(int levelX, boolean autoCoinSpawn) that will build itself into the level from the given position levelX (inclusively). Build structures will always begin at the very bottom of the level independently to the original arrays dimension.
Note: this behavior requires building enough floor in order to make a level beatable.
Optional coin spawning can be activated with the parameter autoCoinSpawn.
Internally, GameElementFactory is used to add Elements to a Scene, so it must be initialized with a Scene.

Author:
Angelo Aracri, Dominik Fuchss
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
    Whether to spawn Coins on empty positions or not.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Structure(LevelDefinition definition, String[][] lines)
    Create a new Structure by level definition and structure lines.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected String[]
    Get alias.
    int
    build(int levelX)
    Adds all GameElements specified in the Structures template structureArray relative to a given x position.
    int
    Returns the height of this Structures template in game units.
    int
    Return the width of this Structures template in game units.
    void
    setGap(int gapWidth)
    Specifies the width of plain floor in game units that will be generated to the right of the Structure upon calling build(int levelX, boolean autoCoinSpawn).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • autoCoinSpawn

      protected boolean autoCoinSpawn
      Whether to spawn Coins on empty positions or not.
  • Constructor Details

    • Structure

      public Structure(LevelDefinition definition, String[][] lines)
      Create a new Structure by level definition and structure lines.
      Parameters:
      definition - the definition
      lines - the lines for the structure
  • Method Details

    • build

      public int build(int levelX)

      Adds all GameElements specified in the Structures template structureArray relative to a given x position. Also, it generates plain floor to the structures right if specified via setGap(int gapWidth).
      Optional coin spawning can be activated with the parameter autoCoinSpawn.

      Additionally, the method returns the width of the build structure including the width of the (optional) gap.

      Internally, GameElementFactory is used to add Elements to a Scene, so it must be initialized with a Scene.

      via
      Parameters:
      levelX - the x position in the level where to build this Structure to (inclusively)
      Returns:
      the width of the build structure plus the gapWidth.
    • applyAlias

      protected String[] applyAlias(String src)
      Get alias.
      Parameters:
      src - the source string
      Returns:
      the splitted definition for GameElementFactory.generate(String, int, int, String...)
    • getHeight

      public int getHeight()
      Returns the height of this Structures template in game units.
      Returns:
      the height of the Structures template.
    • getWidth

      public int getWidth()
      Return the width of this Structures template in game units. However, this method does not take the gap into account that can be specified using setGap(int gapWidth) and that will be build right to the right of the Structure. To get the actual width of the generated Structure use the return value of build(int levelX, boolean autoCoinSpawn).
      Returns:
      the width of the Structures template.
    • setGap

      public void setGap(int gapWidth)
      Specifies the width of plain floor in game units that will be generated to the right of the Structure upon calling build(int levelX, boolean autoCoinSpawn).
      Parameters:
      gapWidth - the gap's width