Single immutable character pixel.
Character-pixel is a fundamental graphics unit in ASCII-based games. Just like the raster pixel on a graphics screen it represents the smallest area that can be rendered on the screen.
CosPlay pixel is immutable and consists of a character from the ASCII character set, a foreground color, an optional background color and an optional tag. Note that pixel itself does not have a Z-index as it can be rendered at any Z-index.
Pixel creation and manipulation is used extensively throughout a CosPlay game. There are several ways you can create a pixel:
import org.cosplay.*
import org.cosplay.CPColor.*
import org.cosplay.CPPixel.*
// Canonical black 'x' on white background.
new CPPixel('x', C_BLACK, Some(C_WHITE), 0)
// Few companion object shortcuts for often used cases...
CPPixel('x', C_BLACK, C_WHITE) // Avoiding 'Some'.
CPPixel('x', C_BLACK) // Skipping background all together.
CPPixel('x', C_BLACK, 2) // Skipping background & setting a '2' ag.
CPPixel('x', C_BLACK, C_WHITE, 2) // Setting up a '2' tag.
You can also use a convenient syntactic sugar '&'
and '&&'
based on given conversion and extension of Char
type. The following unit test demonstrates that usage. Note that usage of '&'
extension operators is the recommended way and that is what is used internally by CosPlay:
import org.cosplay.*
import org.cosplay.CPColor.*
import org.cosplay.CPPixel.*
val p1 = 'x'&C_BLACK // Recommended way.
val p4 = CPPixel('x', C_BLACK)
val p5 = new CPPixel('x', C_BLACK, None, 0)
assertTrue(p1 == p4)
assertTrue(p4 == p5)
val p6 = 'x'&&(C_BLACK, C_WHITE) // Recommended way.
val p7 = new CPPixel('x', C_BLACK, C_WHITE.?, 0)
assertTrue(p6 == p7)
Value parameters
- bg
-
Background color. If not provided, the background color of this pixel will not be set when rendering on the screen.
- char
-
Pixel character.
- fg
-
Pixel foreground color.
- tag
-
Pixel tag. Tag can be used to tag a pixel, for example, during a fill in algorithm to mark the pixel as touched.
Attributes
- See also
- Companion
- object
- Source
- CPPixel.scala
- Graph
-
- Supertypes
-
trait Producttrait Equalstrait Serializableclass Objecttrait Matchableclass Any