dartterm/lib/game.dart

114 lines
2.8 KiB
Dart
Raw Permalink Normal View History

import 'dart:math' as math;
2023-09-20 02:19:26 +00:00
import 'package:dartterm/assets.dart';
import 'package:dartterm/algorithms/geometry.dart' as geo;
2023-09-22 02:29:34 +00:00
import 'package:dartterm/colors.dart';
import 'package:dartterm/gen/generator.dart';
2023-09-21 03:56:30 +00:00
import 'package:dartterm/input.dart';
import 'package:dartterm/skreek.dart';
2023-09-10 01:40:56 +00:00
import 'package:dartterm/terminal.dart';
2023-09-23 00:55:29 +00:00
import 'package:dartterm/world/level.dart';
2023-09-10 01:40:56 +00:00
2023-09-20 02:19:26 +00:00
void main() async {
Vaults vaults;
2023-09-20 02:19:26 +00:00
while (true) {
2023-09-21 03:56:30 +00:00
skreek("about to load template");
2023-09-20 02:19:26 +00:00
at(0, 0).clear();
at(0, 0).puts("Loading template!");
Vaults? maybeVaults =
2023-09-21 03:56:30 +00:00
getVaultsIfAvailable("assets/images/vaults/house1.png");
2023-09-20 02:19:26 +00:00
if (maybeVaults != null) {
2023-09-21 03:56:30 +00:00
skreek("wasn't null!");
vaults = maybeVaults;
2023-09-20 02:19:26 +00:00
break;
}
await zzz(0.1);
}
at(0, 0).clear();
at(0, 0).puts("Loaded! $vaults");
2023-09-20 02:19:26 +00:00
int seed = 0;
while (true) {
2023-09-21 05:00:45 +00:00
clear();
2023-09-23 00:55:29 +00:00
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)) {
2023-09-23 00:55:29 +00:00
case LevelTile.floor:
case LevelTile.openDoor:
2023-09-22 02:29:34 +00:00
cursor.puts(" ");
2023-09-23 00:55:29 +00:00
case LevelTile.closedDoor:
cursor.fg(Palette.demoDoor).puts("+");
case LevelTile.exit:
cursor.fg(Palette.demoExit).puts("X");
case LevelTile.wall:
cursor.puts("#");
2023-09-21 23:11:34 +00:00
case null:
cursor.puts("?");
}
2023-09-20 02:19:26 +00:00
}
}
2023-09-21 03:56:30 +00:00
inpLoop:
await for (var inp in rawInput()) {
2023-09-22 02:29:34 +00:00
skreek("$inp $seed");
2023-09-21 03:56:30 +00:00
switch (inp) {
case Keystroke(text: "a"):
seed -= 1;
break inpLoop;
case Keystroke(text: "d"):
seed += 1;
break inpLoop;
default:
}
}
2023-09-20 02:19:26 +00:00
}
}
/*
2023-09-10 01:40:56 +00:00
void main() async {
2023-09-11 02:00:06 +00:00
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");
2023-09-10 22:29:51 +00:00
2023-09-11 02:00:06 +00:00
at(4, 8).normal().puts("A $descriptor bat!");
2023-09-10 22:29:51 +00:00
2023-09-11 02:00:06 +00:00
// await zzz(1.0);
await waitMenu();
}
2023-09-10 01:40:56 +00:00
}
2023-09-20 02:19:26 +00:00
*/