Screen
trigscript/screen is a grid of pixels shown on the map as units, so the minimap shows
the picture: a game of Snake or Tetris played on the minimap, a score in big digits.
import { Screen, sprite } from "trigscript/screen";
const SHIP = sprite([".1.", "111", "1.1"]);
program(async () => {
const screen = new Screen(4, 4, 24, 16); // 24 × 16 pixels, its top left on tile (4, 4)
screen.reveal(P1);
let x = 10;
let score = 0;
while (true) {
if (keyHeld(P1, "Left")) x = Math.max(x - 1, 0);
if (keyHeld(P1, "Right")) x = Math.min(x + 1, 21);
screen.clear();
screen.rect(0, 15, 24, 1, 5); // the ground, in colour 5
screen.blit(SHIP, x, 12);
screen.number(score, 1, 1, 2); // digits 3 × 5 pixels, in colour 2
screen.present();
score += 1;
await nextFrame();
}
});
A pixel is 0 (empty) or a colour from 1 to 7. Drawing changes the grid, and present()
shows it: each pixel is a unit on the map, two tiles across, owned by the player whose
colour it is. Only the pixels that changed since the last present() are made or taken
away, so a still picture costs nothing to show. Draw through the methods; a pixel written
into the grid directly is not seen.
What the map needs.
- The players who own the pixels are, for colours 1 to 7, Players 3, 4, 5, 1, 6, 7 and 8. Give each the colour the screen should show (cyan, yellow, purple, green, red, blue, orange), and make none of them a computer, since a computer moves its own units.
- StarCraft: Remastered will not start a game without a computer, so make Player 2 a computer. It owns no pixel.
- A pixel is an Overlord unless the screen is made with
"solid". An Overlord flies, so the screen can be over any ground, Space included; the minimap draws each as a dot with a gap round it. A"solid"pixel is a Pylon, which the minimap draws as its whole two-tile footprint, so pixels side by side join into one block; a Pylon needs buildable ground and none of the map's own units in the way. - A player sees the pixels only where they have vision, so call
screen.reveal(player)once, before the firstpresent().
| Name | What it does |
|---|---|
new Screen(x, y, width, height, look?) |
A screen of width × height pixels (2 048 at most), its top left on tile (x, y). look is "dots" (the default) or "solid". |
clear(color?), set(x, y, color), get(x, y) |
Fill it, set one pixel, read one. |
rect(x, y, width, height, color), line(x0, y0, x1, y1, color) |
A filled rectangle; a line, both ends drawn. |
sprite(rows), blit(sprite, x, y) |
A picture from rows of text ("1" … "7", anything else see-through), and drawing it. |
number(n, x, y, color) |
A whole number's digits, 3 × 5 pixels each. |
reveal(player) |
Let a player see the screen. |
present() |
Show what was drawn. |
<ScreenView screen width height /> |
The same grid in a player's text area, a square a pixel, for a ui.lines view. |