bzr branch
http://gegoxaren.bato24.eu/bzr/%2Bjunk/c_sdl_joypad_ducktape
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
1 |
#ifndef __H_GAME_OBJECT__
|
2 |
#define __H_GAME_OBJECT__
|
|
3 |
||
4 |
/**
|
|
7
by Gustav Hartvigsson
* Added licensing information to the files. |
5 |
* This file, as the rest of the project is under MIT license.
|
6 |
* see http://opensource.org/licenses/MIT
|
|
7 |
*
|
|
8 |
* Author Gustav Hartvigsson <gustav.hartvigsson _at_ gmail.com> 2014
|
|
8
by Gustav Hartvigsson
* added and changed little in the files Lincening information. |
9 |
*/
|
7
by Gustav Hartvigsson
* Added licensing information to the files. |
10 |
|
11 |
#include <SDL2/SDL.h> |
|
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
12 |
#include <stdbool.h> |
13 |
||
14 |
typedef struct GameObject GameObject; |
|
15
by Gustav Hartvigsson
* moved the files to ./src/ |
15 |
|
16 |
/******************************************************************************
|
|
17 |
* Function pointer declarations.
|
|
18 |
*****************************************************************************/
|
|
19 |
|
|
20 |
typedef void (* GameObjectCallbackFunc)(GameObject * self, void * data); |
|
21 |
||
22 |
typedef void (* GameObjectFreeFunc)(GameObject * self); |
|
23 |
||
24 |
typedef void (* GameObjectDrawFunc)(GameObject * self, SDL_Renderer * renderer); |
|
25 |
||
26 |
typedef void (* GameObjectCallbackHandlerFunc)(GameObject * self, char * name); |
|
27 |
||
28 |
typedef void (* GameObjectSetCallbackFunc)(GameObject * self, char * name,\ |
|
29 |
GameObjectCallbackFunc callback_func, |
|
30 |
void * data); |
|
31 |
||
32 |
typedef void (* GameObjectMoveFunc)(GameObject * self); |
|
33 |
||
34 |
typedef void (* GameObjectSetMovementDeltaFunc)(GameObject * self, int delta_x,\ |
|
35 |
int delta_y, Uint32 time_delta); |
|
36 |
||
37 |
typedef SDL_Rect (* GameObjectGetBoundingBoxFunc)(GameObject * self); |
|
38 |
||
39 |
typedef bool (* GameObjectGetIsAliveFunc)(GameObject * self); |
|
40 |
||
41 |
typedef bool (* GameObjectGetIsCollideFunc)(GameObject * self, |
|
42 |
GameObject * other); |
|
43 |
||
44 |
/******************************************************************************
|
|
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
45 |
* Object declaration.
|
46 |
*****************************************************************************/
|
|
47 |
||
48 |
typedef struct GameObjectClass { |
|
49 |
GameObjectFreeFunc free_func; |
|
50 |
GameObjectDrawFunc draw_func; |
|
51 |
GameObjectCallbackHandlerFunc callback_handler_func; |
|
52 |
GameObjectSetCallbackFunc set_callback_func; |
|
53 |
GameObjectMoveFunc move_func; |
|
54 |
GameObjectSetMovementDeltaFunc set_movement_delta_func; |
|
55 |
GameObjectGetBoundingBoxFunc get_bounding_box_func; |
|
56 |
GameObjectGetIsAliveFunc get_is_alive_func; |
|
57 |
GameObjectGetIsCollideFunc get_is_collide_func; |
|
58 |
} GameObjectClass; |
|
59 |
||
60 |
||
61 |
typedef struct GameObject { |
|
62 |
GameObjectClass * klass; /**< the class that holds all the virtual |
|
63 |
* functions. */
|
|
64 |
void * priv; /**< The private data. */ |
|
65 |
} GameObject; |
|
66 |
||
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
67 |
|
4
by Gustav Hartvigsson
What I have done: |
68 |
|
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
69 |
/******************************************************************************
|
70 |
* Game Object base functions.
|
|
71 |
*****************************************************************************/
|
|
72 |
void game_object_free (GameObject * self); |
|
73 |
||
74 |
GameObjectClass * game_object_get_class (GameObject * self); |
|
75 |
||
76 |
void game_object_set_class (GameObject * self, GameObjectClass * klass); |
|
77 |
||
78 |
void game_object_draw (GameObject * self, SDL_Renderer * renderer); |
|
79 |
||
80 |
void game_object_move (GameObject * self); |
|
81 |
||
82 |
void game_object_set_movement_delta (GameObject * self, int delta_x, |
|
4
by Gustav Hartvigsson
What I have done: |
83 |
int delta_y, uint32_t d_t); |
84 |
||
85 |
bool game_object_get_is_alive (GameObject * self); |
|
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
86 |
|
87 |
void game_object_set_callback (GameObject * self, char * name, |
|
4
by Gustav Hartvigsson
What I have done: |
88 |
GameObjectCallbackFunc callback_func, |
5
by Gustav Hartvigsson
fixed the callback stuff.. |
89 |
void * data); |
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
90 |
|
91 |
void game_object_do_callback (GameObject * self, char * name); |
|
4
by Gustav Hartvigsson
What I have done: |
92 |
|
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
93 |
|
94 |
/******************************************************************************
|
|
95 |
* Game Object set virtual function functions.
|
|
96 |
*****************************************************************************/
|
|
97 |
||
98 |
void game_object_set_free_func (GameObject * self, |
|
99 |
GameObjectFreeFunc free_func); |
|
100 |
||
101 |
void game_object_set_draw_func (GameObject * self, |
|
102 |
GameObjectDrawFunc draw_func); |
|
103 |
||
104 |
void game_object_set_callback_handler_func (GameObject * self, |
|
105 |
GameObjectCallbackHandlerFunc callback_handler_func); |
|
106 |
||
107 |
void game_object_set_add_callback_func (GameObject * self, |
|
108 |
GameObjectSetCallbackFunc add_callback_func); |
|
4
by Gustav Hartvigsson
What I have done: |
109 |
|
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
110 |
void game_object_set_move_func (GameObject * self, |
111 |
GameObjectMoveFunc move_func); |
|
112 |
||
113 |
void game_object_set_set_move_delta_func (GameObject * self, |
|
114 |
GameObjectSetMovementDeltaFunc set_movent_delta_func); |
|
115 |
||
116 |
void game_object_set_get_bounding_box_func (GameObject * self, |
|
117 |
GameObjectGetBoundingBoxFunc get_bounding_box_func); |
|
118 |
||
119 |
void game_object_set_movment_delta (GameObject * self, int delta_x, |
|
120 |
int delta_y, uint32_t delta_time); |
|
4
by Gustav Hartvigsson
What I have done: |
121 |
|
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
122 |
void game_object_set_get_is_alive_func (GameObject * self, |
123 |
GameObjectGetIsAliveFunc get_is_alive_func); |
|
124 |
||
125 |
void game_object_set_is_collide_func (GameObject * self, |
|
4
by Gustav Hartvigsson
What I have done: |
126 |
GameObjectGetIsCollideFunc is_collide_func); |
127 |
#endif /* __H_GAME_OBJECT__ */ |
|
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
128 |