summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
Diffstat (limited to 'share')
-rw-r--r--share/hackvr/examples/dungen/Makefile10
-rw-r--r--share/hackvr/examples/dungen/dun2ascii.c46
-rw-r--r--share/hackvr/examples/dungen/dungen.c42
3 files changed, 58 insertions, 40 deletions
diff --git a/share/hackvr/examples/dungen/Makefile b/share/hackvr/examples/dungen/Makefile
index 4420649..20e1a90 100644
--- a/share/hackvr/examples/dungen/Makefile
+++ b/share/hackvr/examples/dungen/Makefile
@@ -1 +1,11 @@
+.PHONY: all clean
+
+all: dungen dun2ascii
+
+clean:
+ rm -f dungen
+ rm -f dun2ascii
+
dungen: dungen.c
+
+dun2ascii: dun2ascii.c
diff --git a/share/hackvr/examples/dungen/dun2ascii.c b/share/hackvr/examples/dungen/dun2ascii.c
new file mode 100644
index 0000000..d7a9996
--- /dev/null
+++ b/share/hackvr/examples/dungen/dun2ascii.c
@@ -0,0 +1,46 @@
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+//nsew
+char *a[16];
+
+char field[256];
+
+void print_field() {
+ int i;
+ fprintf(stderr,"\x1b[H");
+ for(i=0;i<(16*strlen(a[field[0]]))+1;i++) fprintf(stderr,"#");
+ for(i=0;i<256;i++) {
+ if(i%16 == 0) fprintf(stderr,"#\n#");
+ fprintf(stderr,"%s",a[field[i]]);
+ }
+ fprintf(stderr,"#\n");
+ for(i=0;i<(16*strlen(a[field[0]]))+2;i++) fprintf(stderr,"#");
+ fprintf(stderr,"\n");
+}
+
+int main(int argc,char *argv[]) {
+ int i;
+ fprintf(stderr,"\x1b[H\x1b[2J");
+ a[0x0]=" ";
+ a[0x1]="- ";
+ a[0x2]=" -";
+ a[0x3]="---";
+ a[0x4]=" . ";
+ a[0x5]="-. ";
+ a[0x6]=" .-";
+ a[0x7]="-.-";
+ a[0x8]=" ' ";
+ a[0x9]="-' ";
+ a[0xa]=" '-";
+ a[0xb]="-'-";
+ a[0xc]=" | ";
+ a[0xd]="-| ";
+ a[0xe]=" |-";
+ a[0xf]="-|-";
+ while(read(0,field,sizeof(field)) > 0) {
+ print_field();
+ sleep(1);
+ }
+}
diff --git a/share/hackvr/examples/dungen/dungen.c b/share/hackvr/examples/dungen/dungen.c
index 47a1f46..b38f076 100644
--- a/share/hackvr/examples/dungen/dungen.c
+++ b/share/hackvr/examples/dungen/dungen.c
@@ -6,25 +6,9 @@
#define ITERATIONS 16
-//nsew
-char *a[16];
-
char field[256];
char nfield[256];
-void print_field() {
- int i;
- fprintf(stderr,"\x1b[H");
- for(i=0;i<(16*strlen(a[field[0]]))+1;i++) fprintf(stderr,"#");
- for(i=0;i<256;i++) {
- if(i%16 == 0) fprintf(stderr,"#\n#");
- fprintf(stderr,"%s",a[field[i]]);
- }
- fprintf(stderr,"#\n");
- for(i=0;i<(16*strlen(a[field[0]]))+2;i++) fprintf(stderr,"#");
- fprintf(stderr,"\n");
-}
-
void prune() {//remove paths into wall
int i;
memcpy(nfield,field,256);//make a copy just for comparison
@@ -56,9 +40,7 @@ void grow() {
void dump() {
int i;
- for(i=0;i<256;i++) {
- printf("%c",field[i]);
- }
+ write(1,field,sizeof(field));
}
int main(int argc,char *argv[]) {
@@ -67,33 +49,13 @@ int main(int argc,char *argv[]) {
if(argc > 1) {
seed=atoi(argv[1]);
}
- fprintf(stderr,"\x1b[H\x1b[2J");
srandom(seed);
- a[0x0]=" ";
- a[0x1]="- ";
- a[0x2]=" -";
- a[0x3]="---";
- a[0x4]=" . ";
- a[0x5]="-. ";
- a[0x6]=" .-";
- a[0x7]="-.-";
- a[0x8]=" ' ";
- a[0x9]="-' ";
- a[0xa]=" '-";
- a[0xb]="-'-";
- a[0xc]=" | ";
- a[0xd]="-| ";
- a[0xe]=" |-";
- a[0xf]="-|-";
-
field[7+16] = 0x4;//center top
for(i=0;i<ITERATIONS;i++) {
- print_field();
-// sleep(1);
+ if(argc > 2) dump();
grow();
}
prune();
- print_field();
dump();
fprintf(stderr,"seed: %d\n",seed);
}