summaryrefslogtreecommitdiff
path: root/main.ha
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-11-13 01:11:53 +0000
committerubq323 <ubq323@ubq323.website>2023-11-13 01:11:53 +0000
commitd413e6b54d0c505a529ca6a9a90ddf73c07a8c42 (patch)
tree08c7bfd57d8735fad37d02cfcdef2dffa4e7e860 /main.ha
parent39d3a3c542bf2848abda61185c1fb5b68de31031 (diff)
add entities, sort of
Diffstat (limited to 'main.ha')
-rw-r--r--main.ha66
1 files changed, 49 insertions, 17 deletions
diff --git a/main.ha b/main.ha
index 41917c8..967e92c 100644
--- a/main.ha
+++ b/main.ha
@@ -2,10 +2,11 @@ use math::random;
use vt;
use io;
use os;
+use fmt;
type player = struct {
- x: int,
- y: int,
+ x: uint,
+ y: uint,
};
type wall = void;
@@ -29,6 +30,18 @@ fn set_tile_at(r: room, x: size, y: size, t: tile) void = {
r.tiles[ix] = t;
};
+fn draw_room(t: *vt::term, r: room) void = {
+ for (let y = 0z; y < r.h; y+=1) {
+ vt::move(t, (y+1):uint, 0)!;
+ for (let x = 0z; x < r.w; x+=1) {
+ fmt::fprint(t, match (tile_at(r,x,y)) {
+ case floor => yield '.';
+ case wall => yield '\u2588';
+ })!;
+ };
+ };
+};
+
fn get_key() u8 = {
let b = [0u8];
io::read(os::stdin_file, b)!;
@@ -36,7 +49,7 @@ fn get_key() u8 = {
};
def W = 50;
-def H = 90;
+def H = 40;
export fn main() void = {
@@ -69,26 +82,45 @@ export fn main() void = {
const playerpen = vt::newpen(vt::color::BLACK, vt::color::RED);
const playerstr = vt::tag(playerpen, "@");
+ let entities: []entity = [];
+ for (let i = 0u; i < 1; i += 1) {
+ append(entities, entity_new('g',vt::color::BLUE));
+ entities[i].x=i*2;
+ };
+
for (true) {
vt::clear(term)!;
- draw_room(room);
+ draw_room(term, room);
+ for (let i = 0z; i < len(entities); i +=1)
+ entity_draw(&entities[i], term);
+
vt::move(term, player.y:uint+1, player.x:uint+1)!;
vt::print(term, playerstr)!;
- const c = get_key(): rune;
- let nx = player.x;
- let ny = player.y;
- switch (c) {
- case 'h' => nx -= 1;
- case 'l' => nx += 1;
- case 'j' => ny += 1;
- case 'k' => ny -= 1;
- case 'q' => break;
- case => yield;
+
+
+ match (get_input(term)) {
+ case let m: move => {
+ let nx = player.x;
+ let ny = player.y;
+ switch (m) {
+ case move::UP => ny -= 1;
+ case move::DOWN => ny += 1;
+ case move::LEFT => nx -= 1;
+ case move::RIGHT => nx += 1;
+ };
+
+ if (tile_at(room, nx: size, ny: size) is floor) {
+ player.x = nx;
+ player.y = ny;
+ };
};
- if (tile_at(room, nx:size, ny:size) is floor) {
- player.x = nx;
- player.y = ny;
+ case quit => break;
+ case => yield;
};
+
+ for (let i = 0z; i < len(entities); i += 1)
+ entity_tick(&entities[i],&room);
+
};
};