jag

tetoris_c

public

Small block game in C

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