dartterm/lib/game.dart

91 lines
2.1 KiB
Dart

import 'dart:developer';
import 'dart:math' as math;
import 'package:dartterm/assets.dart';
import 'package:dartterm/colors.dart';
import 'package:dartterm/gen/generator.dart';
import 'package:dartterm/terminal.dart';
import 'package:dartterm/world/level.dart';
void main() async {
Vaults vaults;
while (true) {
log("about to load template");
at(0, 0).clear();
at(0, 0).puts("Loading template!");
Vaults? maybeVaults =
getVaultsIfAvailable("assets/images/wfc/bighouse2.png");
if (maybeVaults != null) {
log("wasn't null!");
vaults = maybeVaults;
break;
}
await zzz(0.1);
}
at(0, 0).clear();
at(0, 0).puts("Loaded! $vaults");
Vault output = vaults.generateBoxed(
math.Random(2),
Requirement(
16,
16,
DirectionSet({
Direction.up,
Direction.left,
Direction.right,
Direction.down
})));
var w = output.vx;
var h = output.vy;
for (var y = 0; y < w; y++) {
for (var x = 0; x < h; x++) {
var cursor = at(x * 2, y * 2).big();
switch (output.tiles[x + y * w]) {
case LevelTile.floor:
cursor.puts(" ");
case LevelTile.door:
cursor.puts("d");
case LevelTile.wall:
cursor.puts("#");
case LevelTile.exit:
cursor.puts("X");
}
}
}
}
/*
void main() async {
var descriptor = "generic";
while (true) {
at(0, 0).clear();
at(0, 0).puts("Hello, bats!");
at(0, 2).fg(Palette.subtitle).small().puts("Beware of the bat!");
at(4, 4)
.bg(Palette.subtitle)
.fg(Palette.defaultBg)
.big()
.highlight()
.act(Act(
isDefault: true,
label: "Strong!",
callback: () async {
log("strong!");
descriptor = "strong";
}))
.act(Act(
label: "Nocturnal!",
callback: () async {
log("nocturnal!");
descriptor = "nocturnal";
}))
.puts("ALTER BAT");
at(4, 8).normal().puts("A $descriptor bat!");
// await zzz(1.0);
await waitMenu();
}
}
*/