Skip to content
sirrandalot edited this page Aug 19, 2018 · 20 revisions

Screen is a class which extends JPanel and overrides its PaintComponent method in order to draw a scaled BufferedImage. (The BufferedImages used are private, so you only have to worry about placing "Tiles").

When setting the colours, the indices of what colour in the palette you want is used and although there's no real transparency (everything is strictly RGB), a transparent-like behaviour can be achieved by calling the useSameBackground(boolean) and useSameForeground(boolean) functions or giving an index value of -1 when setting the foreground or background colours. This will tell the screen whether or not to draw tiles using the foreground/background colours which were most recently used in a given position. The effect is independent between foreground and background and active as long as the current foreground or background colour index is not changed to anything other than -1.


Attributes:

final int imageScale

  • How much the image is scaled in order to display it

final int numTilesX

  • The horizontal number of tiles on the screen.

final int numTilesY

  • The vertical number of tiles on the screen.

Tileset tileset

  • The Tileset to use.

Palette palette

  • The palette to use.

Constructor:

Screen(int numTx, int numTy, int scale, Tileset t, Palette p)

  • Takes the horizontal and vertical number of tiles, the image scale, a Tileset and a Palette.

Methods:

void clearScreen()

  • Colours the entire screen with the background colour.

boolean setForegroundColour(int index)

  • Sets the foreground colour.
  • An index value of -1 is equivalent to calling useSameForeground(true)
  • Returns true if the colour was set successfully, false otherwise

boolean setBackgroundColour(int index)

  • Sets the background colour.
  • An index value of -1 is equivalent to calling useSameBackground(true)
  • Returns true if the colour was set successfully, false otherwise

void useSameBackground(boolean use)

  • Sets whether or not to use the most recently used background colour for a tile position when drawing a tile instead of the currently defined one.

void useSameForeground(boolean use)

  • Sets whether or not to use the most recently used foreground colour for a tile position when drawing a tile instead of the currently defined one.

boolean[2] setColour(int indexBackground, int indexForeground)

  • Sets the foreground and background colour.
  • Returns true if the colour was set successfully, false otherwise (for both colours)

boolean drawTile(int x, int y, int tile)

  • Draws a tile at a position. A char can be provided in the place of a tile int without any problem and with a standard ASCII tileset loaded, drawTile(x, y, 'f') for example will draw an actual "f" on the screen.
  • Returns true if the tile was drawn, false if it was out of bounds.

boolean drawTile(int x, int y, int tile, boolean flipX, boolean flipY)

  • Draws a tile at a position. If flipX is true, the tile will be flipped horizontally, if flipY is true, the tile will be flipped vertically.
  • Returns true if the tile was drawn, false if it was out of bounds.

boolean drawRandomTile(int x, int y, long seed)

  • Draws a (seeded) random tile at a position.
  • Returns true if the tile was drawn, false if it was out of bounds.

boolean drawGarbageTile(int x, int y, long seed)

  • Draws a (seeded) garbage tile at a position by randomly mixing several tiles together.
  • Returns true if the tile was drawn, false if it was out of bounds.

void drawString(int x, int y, String s, boolean wrapX, boolean wrapOnSpace)

  • Draws a string starting at a given position. The string will be "correct" as long as the Tileset being used holds standard ASCII values.
  • wrapX wraps the string horizontally and wrapOnSpace will attempt to wrap the string on spaces (' ')

void drawTileImage(int x, int y, TileImage t)

  • Draws a TileImage starting at the specified x and y positions on the screen.

void drawTileImage(int x, int y, TileImage t, boolean flipX, boolean flipY)

  • Draws a TileImage (flipped either horizontally, vertically or both) starting at the specified x and y positions on the screen.

void drawTileset(boolean flat)

  • Draws the current Tileset.
  • If flat is true, it wraps at the screen width, otherwise it wraps at 16.

void drawPalette(boolean flat)

  • Draws the current Palette.
  • If flat is true, it wraps at the screen width, otherwise it wraps at 16.