jag

tetoris_c

public

Small block game in C

Star0
Watch0
6642d1d9ca12fe4a7b7732a94430c68fb49956ce
1
ssh://git@git.jaglekon.de:30/jag/tetoris_c.git
main.hC69 lines1.1 KB
1
#ifndef MAIN_C
2
3
#define MAIN_C
4
5
#include <stdio.h>
6
#include <stdint.h>
7
#include <stdbool.h>
8
#include <stdlib.h>
9
10
#include <termios.h>
11
#include <sys/ioctl.h>
12
#include <sys/stat.h>
13
14
#include <time.h>
15
#include <unistd.h>
16
17
#include <errno.h>
18
19
20
#define FIELD_WIDTH 10
21
#define FIELD_HEIGHT 21
22
23
#define BORDER_WIDTH 2
24
#define TOP_GAP 1
25
26
#define FULL_WIDTH (FIELD_WIDTH + BORDER_WIDTH * 2)
27
#define FULL_HEIGHT (FIELD_HEIGHT + BORDER_WIDTH)
28
29
typedef enum {
30
  EMPTY, I_PIECE, J_PIECE, L_PIECE, O_PIECE, S_PIECE, T_PIECE, Z_PIECE, TETRIS
31
} tetromino;
32
33
typedef enum {
34
  TOP, RIGHT, BOTTOM, LEFT
35
} direction;
36
37
typedef struct {
38
  tetromino name;
39
  bool piece[4][4];
40
  int8_t x;
41
  int8_t y;
42
  uint8_t size;
43
  direction rotation;
44
  uint8_t positions;
45
} piece;
46
47
typedef struct {
48
  int8_t x;
49
  int8_t y;
50
} coord;
51
52
53
54
void init_field();
55
56
void draw_board(piece current_piece, bool *blink, bool is_piece);
57
58
piece init_piece(tetromino new_piece);
59
60
coord find_direction(piece current_piece, uint8_t x, uint8_t y);
61
  
62
bool valid_position(piece current_piece);
63
64
65
66
extern tetromino playfield[FULL_HEIGHT][FULL_WIDTH];
67
68
69
#endif