dartterm/lib/game.dart
2023-09-22 17:55:29 -07:00

114 lines
2.8 KiB
Dart

import 'dart:math' as math;
import 'package:dartterm/assets.dart';
import 'package:dartterm/algorithms/geometry.dart' as geo;
import 'package:dartterm/colors.dart';
import 'package:dartterm/gen/generator.dart';
import 'package:dartterm/input.dart';
import 'package:dartterm/skreek.dart';
import 'package:dartterm/terminal.dart';
import 'package:dartterm/world/level.dart';
void main() async {
Vaults vaults;
while (true) {
skreek("about to load template");
at(0, 0).clear();
at(0, 0).puts("Loading template!");
Vaults? maybeVaults =
getVaultsIfAvailable("assets/images/vaults/house1.png");
if (maybeVaults != null) {
skreek("wasn't null!");
vaults = maybeVaults;
break;
}
await zzz(0.1);
}
at(0, 0).clear();
at(0, 0).puts("Loaded! $vaults");
int seed = 0;
while (true) {
clear();
Level output =
Generator(math.Random(seed), vaults).generateLevel(Requirement(
16,
32,
16,
18,
DirectionSet({
Direction.up,
Direction.down,
Direction.left,
Direction.right,
})));
var geo.Size(dx: w, dy: h) = output.size;
for (var y = 0; y < h; y++) {
for (var x = 0; x < w; x++) {
var cursor = at(x * 2, y * 2).big();
switch (output.tiles.get(x, y)) {
case LevelTile.floor:
case LevelTile.openDoor:
cursor.puts(" ");
case LevelTile.closedDoor:
cursor.fg(Palette.demoDoor).puts("+");
case LevelTile.exit:
cursor.fg(Palette.demoExit).puts("X");
case LevelTile.wall:
cursor.puts("#");
case null:
cursor.puts("?");
}
}
}
inpLoop:
await for (var inp in rawInput()) {
skreek("$inp $seed");
switch (inp) {
case Keystroke(text: "a"):
seed -= 1;
break inpLoop;
case Keystroke(text: "d"):
seed += 1;
break inpLoop;
default:
}
}
}
}
/*
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();
}
}
*/