From 4cb7cbd3734205bb923c65290e73fe47c85f86a4 Mon Sep 17 00:00:00 2001 From: Preston Pan Date: Mon, 6 Feb 2023 19:36:10 -0800 Subject: add block structure --- LICENSE | 1 + Makefile | 4 ++++ block.c | 13 +++++++++++++ block.h | 27 +++++++++++++++++++++++++++ config.h | 5 +++++ indent.sh | 10 ++++++++++ 6 files changed, 60 insertions(+) create mode 100644 Makefile create mode 100644 block.c create mode 100644 block.h create mode 100644 config.h create mode 100644 indent.sh 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 +#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 -- cgit v1.3.1