jag

tetoris_c

public

Small block game in C

Star0
Watch0
c4f522359c37651c399337b11c82eea1ea8689a5
1
ssh://git@git.jaglekon.de:30/jag/tetoris_c.git
source/main.hC87 lines1.3 KB
1
#ifndef MAIN_H
2
3
#define MAIN_H
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
#include <poll.h>
17
18
#include <ctype.h>
19
20
#include <errno.h>
21
22
23
#define FIELD_WIDTH 10
24
#define FIELD_HEIGHT 21
25
26
#define BORDER_WIDTH 2
27
#define TOP_GAP 1
28
29
#define FULL_WIDTH (FIELD_WIDTH + BORDER_WIDTH * 2)
30
#define FULL_HEIGHT (FIELD_HEIGHT + BORDER_WIDTH)
31
32
#define FRAME 17000000
33
34
#define FALL 58
35
#define BLINK 12
36
#define SPIN 5
37
38
39
typedef enum {
40
  EMPTY, I_PIECE, J_PIECE, L_PIECE, O_PIECE, S_PIECE, T_PIECE, Z_PIECE, TETRIS
41
} tetromino;
42
43
typedef enum {
44
  TOP, RIGHT, BOTTOM, LEFT
45
} direction;
46
47
typedef struct {
48
  tetromino name;
49
  bool piece[4][4];
50
  int8_t x;
51
  int8_t y;
52
  uint8_t size;
53
  direction rotation;
54
  uint8_t positions;
55
} piece;
56
57
typedef struct {
58
  int8_t x;
59
  int8_t y;
60
} coord;
61
62
typedef struct {
63
  uint8_t r;
64
  uint8_t g;
65
  uint8_t b;
66
} color;
67
68
69
void init_field();
70
71
void draw_board(piece current_piece, piece next_piece, bool *blink, bool is_piece);
72
void draw_pause();
73
74
75
piece init_piece(tetromino new_piece);
76
77
coord find_direction(piece current_piece, uint8_t x, uint8_t y);
78
  
79
bool valid_position(piece current_piece);
80
81
82
83
extern tetromino playfield[FULL_HEIGHT][FULL_WIDTH];
84
extern uint8_t graying[FULL_HEIGHT][FULL_WIDTH];
85
86
87
#endif