jag

tetoris_c

public

Small block game in C

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