jag

tetoris_c

public

Small block game in C

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