jag

tetoris_c

public

Small block game in C

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