summaryrefslogtreecommitdiffstats
path: root/src/char/char.h
blob: dc79cf60904a167d83a8db6cee30951266291d19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * Copyright (C) 2021  P. J. McDermott
 *
 * This file is part of Maze Fight
 *
 * Maze Fight is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Maze Fight is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Maze Fight.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef MF_CHAR_CHAR_H
#define MF_CHAR_CHAR_H

enum _mf_char_dir {
	MF_CHAR_DIR_N_,
	MF_CHAR_DIR_U_,
	MF_CHAR_DIR_D_,
	MF_CHAR_DIR_L_,
	MF_CHAR_DIR_R_
};

struct mf_char {
	struct mf_maze     *maze;
	int                 cell_width;
	int                 speed;
	enum _mf_char_dir   cur_dir;
	enum _mf_char_dir   new_dir;
	enum _mf_char_dir   old_dir;
	int                 turning;
	int                 turn_time;
	int                 cur_x;
	int                 cur_y;
	int                 new_x;
	int                 new_y;
	int                 travel;
	int                 padding;
	double              smile_y;
	double              smile_r;
	double              eye_x;
	double              eye_y;
	double              eye_r;
	SDL_Color           head_color;
	SDL_Color           smil_color;
	SDL_Color           eyes_color;
	int               (*update)(struct mf_char *);
	int               (*step)(struct mf_char *);
	int               (*turn)(struct mf_char *);
	int               (*render)(struct mf_char *, SDL_Renderer *);
	void              (*destroy)(struct mf_char *);
};

struct mf_char *
mf_char_new(size_t size) __attribute__((__malloc__));

#define mf_char_init(c, t_c, name) \
	do { \
		c = mf_char_new(sizeof(struct mf_##name)); \
		if (c == NULL) { \
			return NULL; \
		}; \
		c->update  = &_mf_##name##_update; \
		c->step    = &_mf_##name##_step; \
		c->turn    = &_mf_##name##_turn; \
		c->render  = &_mf_##name##_render; \
		c->destroy = &_mf_##name##_destroy; \
		t_c = (struct mf_##name *) c; \
	} while (0)

#endif  /* MF_CHAR_CHAR_H */