jag

tetoris_c

public

Small block game in C

Star0
Watch0
b7c05d8620b059a69bf69dec38a8c71d5d8d608c
1
ssh://git@git.jaglekon.de:30/jag/tetoris_c.git
source/main.hC98 lines1.5 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 19
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 16742006
33
34
#define FALL 53
35
#define BLINK 12
36
#define SPIN 8
37
#define FALL_PROTECTION 50
38
#define KEY_PROTECTION 2
39
40
#define LINES_LEVEL 10
41
#define MAX_LEVEL 20
42
43
44
typedef enum {
45
  EMPTY, I_PIECE, J_PIECE, L_PIECE, O_PIECE, S_PIECE, T_PIECE, Z_PIECE, TETRIS
46
} tetromino;
47
48
typedef enum {
49
  TOP, RIGHT, BOTTOM, LEFT
50
} direction;
51
52
typedef struct {
53
  tetromino name;
54
  bool piece[4][4];
55
  int8_t x;
56
  int8_t y;
57
  uint8_t size;
58
  direction rotation;
59
  uint8_t positions;
60
} piece;
61
62
typedef struct {
63
  int8_t x;
64
  int8_t y;
65
} coord;
66
67
typedef struct {
68
  uint8_t r;
69
  uint8_t g;
70
  uint8_t b;
71
} color;
72
73
74
void init_field();
75
76
void draw_board(piece current_piece, piece next_piece, bool *blink, bool is_piece);
77
void draw_pause();
78
79
80
piece init_piece(tetromino new_piece);
81
82
coord find_direction(piece current_piece, uint8_t x, uint8_t y);
83
  
84
bool valid_position(piece current_piece);
85
86
uint8_t level_delay();
87
88
uint16_t line_points_add(uint8_t lines_cleared, uint8_t level);
89
90
91
extern tetromino playfield[FULL_HEIGHT][FULL_WIDTH];
92
93
extern uint8_t level;
94
extern uint16_t all_cleared_lines;
95
extern uint32_t score;
96
97
98
#endif