summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPreston Pan <preston@nullring.xyz>2023-02-06 19:36:10 -0800
committerPreston Pan <preston@nullring.xyz>2023-02-06 19:36:10 -0800
commit4cb7cbd3734205bb923c65290e73fe47c85f86a4 (patch)
tree6aed241a7dd7f57b7f52e79b38d1eb77742034bb
parent1a4999aa71a2369e86e996e11095e9c2d92e5d84 (diff)
add block structure
-rw-r--r--LICENSE1
-rw-r--r--Makefile4
-rw-r--r--block.c13
-rw-r--r--block.h27
-rw-r--r--config.h5
-rw-r--r--indent.sh10
6 files changed, 60 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
index 95c9586..d8832a3 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,5 +1,6 @@
Copyright 2023 Kai Stevenson
Copyright 2023 Preston Pan
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..d61e82d
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,4 @@
+clean:
+ -rm tetris3
+indent:
+ sh indent.sh
diff --git a/block.c b/block.c
new file mode 100644
index 0000000..2f4d36c
--- /dev/null
+++ b/block.c
@@ -0,0 +1,13 @@
+#include <stdlib.h>
+#include "block.h"
+#include "config.h"
+
+block_t *init_block(int type)
+{
+ block_t *block = malloc(sizeof(block_t));
+ block->type = type;
+ block->rotation = BLOCK_0;
+ block->x = width / 2;
+ block->y = 0;
+ return block;
+}
diff --git a/block.h b/block.h
new file mode 100644
index 0000000..1f12a72
--- /dev/null
+++ b/block.h
@@ -0,0 +1,27 @@
+#ifndef BLOCK_H
+#define BLOCK_H
+typedef struct {
+ enum {
+ BLOCK_T,
+ BLOCK_RL, /* L block with the bottom part facing
+ right */
+ BLOCK_LL, /* L block with the bottom part facing
+ left */
+ BLOCK_I,
+ BLOCK_RS,
+ BLOCK_LS,
+ } type;
+
+ enum {
+ BLOCK_0,
+ BLOCK_90,
+ BLOCK_180,
+ BLOCK_270,
+ } rotation;
+
+ int x;
+ int y;
+} block_t;
+
+block_t *init_block(int type);
+#endif
diff --git a/config.h b/config.h
new file mode 100644
index 0000000..05c0cc7
--- /dev/null
+++ b/config.h
@@ -0,0 +1,5 @@
+#ifndef CONFIG_H
+#define CONFIG_H
+int width = 20;
+int height = 40;
+#endif
diff --git a/indent.sh b/indent.sh
new file mode 100644
index 0000000..3a70d7f
--- /dev/null
+++ b/indent.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+for f in *.c; do
+ indent "$f"
+done
+
+for f in *.h; do
+ indent "$f"
+done
+rm *.BAK