bzr branch
http://gegoxaren.bato24.eu/bzr/%2Bjunk/c_sdl_joypad_ducktape
21
by Gustav Hatvigsson
* added Modeline to (almost) all files. |
1 |
/* c-basic-offset: 2; tab-width: 2; indent-tabs-mode: nil
|
2 |
* vi: set shiftwidth=2 tabstop=2 expandtab:
|
|
3 |
* :indentSize=2:tabSize=2:noTabs=true:
|
|
4 |
*/
|
|
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
5 |
|
6 |
||
33
by Gustav Hartvigsson
* Fixed a problem with Doxygen. |
7 |
/* This file, as the rest of the project is under MIT license.
|
7
by Gustav Hartvigsson
* Added licensing information to the files. |
8 |
* see http://opensource.org/licenses/MIT
|
9 |
*
|
|
8
by Gustav Hartvigsson
* added and changed little in the files Lincening information. |
10 |
* Author Gustav Hartvigsson <gustav.hartvigsson _at_ gmail.com> 2014
|
7
by Gustav Hartvigsson
* Added licensing information to the files. |
11 |
*/
|
12 |
||
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
13 |
#ifndef __H_GAME_OBJECT__
|
14 |
#define __H_GAME_OBJECT__
|
|
15 |
||
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
16 |
#include <SDL2/SDL.h> |
17 |
#include <stdbool.h> |
|
18 |
||
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
19 |
#include "defs.h" |
27
by Gustav Hartvigsson
* Started working on the an object baseclass to make things |
20 |
#include "Object.h" |
21 |
||
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
22 |
/** @file
|
23 |
* GameObject is the base class for game objects, it provides a set
|
|
24 |
* of methods that make it easy to handle drawing and moving of objects in
|
|
25 |
* the game.
|
|
26 |
*
|
|
27 |
* All game objects that require drawing to the screen should be a "subclass"
|
|
28 |
* of this.
|
|
29 |
*
|
|
30 |
* @warning A GameObject contains no data, only the primaries for handling
|
|
31 |
* game objects.
|
|
32 |
*/
|
|
33 |
||
34 |
BEGIN_DECLS
|
|
35 |
||
36 |
#ifndef DOXYGEN_SHOULD_SKIP_THIS
|
|
15
by Gustav Hartvigsson
* moved the files to ./src/ |
37 |
typedef struct GameObject GameObject; |
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
38 |
typedef struct GameObjectClass GameObjectClass; |
39 |
#endif /* DOXYGEN_SHOULD_SKIP_THIS */ |
|
15
by Gustav Hartvigsson
* moved the files to ./src/ |
40 |
|
41 |
/******************************************************************************
|
|
42 |
* Function pointer declarations.
|
|
43 |
*****************************************************************************/
|
|
44 |
|
|
29
by Gustav Hartvigsson
* Fixed Makefile |
45 |
typedef void (* GameObjectCallbackFunc)(GameObject * self, _pointer data); |
15
by Gustav Hartvigsson
* moved the files to ./src/ |
46 |
|
47 |
typedef void (* GameObjectDrawFunc)(GameObject * self, SDL_Renderer * renderer); |
|
48 |
||
49 |
typedef void (* GameObjectCallbackHandlerFunc)(GameObject * self, char * name); |
|
50 |
||
51 |
typedef void (* GameObjectSetCallbackFunc)(GameObject * self, char * name,\ |
|
52 |
GameObjectCallbackFunc callback_func, |
|
29
by Gustav Hartvigsson
* Fixed Makefile |
53 |
_pointer data); |
15
by Gustav Hartvigsson
* moved the files to ./src/ |
54 |
|
55 |
typedef void (* GameObjectMoveFunc)(GameObject * self); |
|
56 |
||
57 |
typedef void (* GameObjectSetMovementDeltaFunc)(GameObject * self, int delta_x,\ |
|
58 |
int delta_y, Uint32 time_delta); |
|
59 |
||
60 |
typedef SDL_Rect (* GameObjectGetBoundingBoxFunc)(GameObject * self); |
|
61 |
||
62 |
typedef bool (* GameObjectGetIsAliveFunc)(GameObject * self); |
|
63 |
||
64 |
typedef bool (* GameObjectGetIsCollideFunc)(GameObject * self, |
|
65 |
GameObject * other); |
|
66 |
||
32
by Gustav Hartvigsson
* Removed code that is not needed |
67 |
typedef void (* GameObjectSetVisibleFunc)(GameObject * self, bool visible); |
68 |
||
69 |
typedef bool (* GameObjectGetVisibleFunc)(GameObject * self); |
|
70 |
||
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
71 |
/******************************************************************************
|
72 |
* Object declaration.
|
|
73 |
*****************************************************************************/
|
|
74 |
||
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
75 |
/**
|
76 |
* The class for the GameObject.
|
|
77 |
*/
|
|
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
78 |
typedef struct GameObjectClass { |
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
79 |
/** The Parent Class */ |
27
by Gustav Hartvigsson
* Started working on the an object baseclass to make things |
80 |
ObjectClass parent; |
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
81 |
/** The callback handler */ |
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
82 |
GameObjectCallbackHandlerFunc callback_handler_func; |
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
83 |
/** Method used to set a callback on a GameObject */ |
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
84 |
GameObjectSetCallbackFunc set_callback_func; |
29
by Gustav Hartvigsson
* Fixed Makefile |
85 |
/** The method that is used to draw a GameObject */ |
86 |
GameObjectDrawFunc draw_func; |
|
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
87 |
/** The method to be run when <tt>game_object_move ()</tt> is run. */ |
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
88 |
GameObjectMoveFunc move_func; |
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
89 |
/** The method that handles how objects move over time */ |
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
90 |
GameObjectSetMovementDeltaFunc set_movement_delta_func; |
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
91 |
/** The method that returns the bounding box of an object, if available. */ |
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
92 |
GameObjectGetBoundingBoxFunc get_bounding_box_func; |
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
93 |
/** Gets weather a game object is "alive" or "dead" */ |
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
94 |
GameObjectGetIsAliveFunc get_is_alive_func; |
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
95 |
/** The method that determines if a Game Object is colliding with an other |
96 |
* game object or not.
|
|
97 |
*/
|
|
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
98 |
GameObjectGetIsCollideFunc get_is_collide_func; |
32
by Gustav Hartvigsson
* Removed code that is not needed |
99 |
/** This method sets the visiblillity of the GameObject */ |
100 |
GameObjectSetVisibleFunc set_visible_func; |
|
101 |
/** This method is used to get the visiblillity of an object. */ |
|
102 |
GameObjectGetVisibleFunc get_visible_func; |
|
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
103 |
} GameObjectClass; |
104 |
||
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
105 |
/**
|
106 |
* Instance of a GameObject.
|
|
107 |
*/
|
|
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
108 |
typedef struct GameObject { |
27
by Gustav Hartvigsson
* Started working on the an object baseclass to make things |
109 |
Object parent; |
32
by Gustav Hartvigsson
* Removed code that is not needed |
110 |
/** Is the object visible? */ |
111 |
bool visible; |
|
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
112 |
} GameObject; |
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
113 |
|
4
by Gustav Hartvigsson
What I have done: |
114 |
|
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
115 |
|
116 |
/******************************************************************************
|
|
117 |
* Game Object base functions.
|
|
118 |
*****************************************************************************/
|
|
119 |
||
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
120 |
/**
|
29
by Gustav Hartvigsson
* Fixed Makefile |
121 |
* Initialises a GameObject
|
122 |
*
|
|
123 |
* This function should be run on every "sub instance" of a GameObject.
|
|
124 |
*
|
|
125 |
* @warning It is important to note that like object_initialize, this one does
|
|
126 |
* not allocate any memory. This is left up to the caller.
|
|
127 |
*/
|
|
128 |
void game_object_initialize (GameObject * self, char * name, _pointer klass); |
|
129 |
||
130 |
/**
|
|
131 |
* Initialises a GameObjectClass.
|
|
132 |
*
|
|
133 |
* This should be run on every "sub class" of a GameObjectClass before the
|
|
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
134 |
* sub instance has its own methods and data set.
|
29
by Gustav Hartvigsson
* Fixed Makefile |
135 |
*
|
136 |
* @warning Like <tt>object_class_initialize</tt> this does not allocate any
|
|
137 |
* memory for the objects, that is left to the caller.
|
|
35
by Gustav Hartvigsson
* added more documentation on game_object_class_initialize. |
138 |
*
|
139 |
* Also see Object for more information.
|
|
140 |
*
|
|
141 |
* @param klass The class to industrialise.
|
|
142 |
* @param callback_handler_func The method used to do callbacks.
|
|
143 |
* @param draw_func The Method used to draw a GameObject.
|
|
144 |
* @param set_callback_func The method used to hook up callbacks.
|
|
145 |
* @param move_func The method used to move an object. It takes no parameters.
|
|
146 |
* @param set_movement_delta_func The method used to set how a object should
|
|
147 |
* move.
|
|
148 |
* @param get_bounding_box_func The method used for getting the bounding box of
|
|
149 |
* a GameObject.
|
|
150 |
* @param get_is_alive_func The method used to determin if an obejct is alive or
|
|
151 |
* not.
|
|
152 |
* @param get_is_collide_func The method used to determin if an GameObject has
|
|
153 |
* collided with an other GameObject.
|
|
154 |
* @param set_visible_func The method used to set the visiblillity of a
|
|
155 |
GameObject. If NULL it will use a standard method.
|
|
36
by Gustav Hartvigsson
* Updated Duktape to 0.11.0 |
156 |
* @param get_visible_func The method used to check if a GameObject is visible
|
35
by Gustav Hartvigsson
* added more documentation on game_object_class_initialize. |
157 |
* or not. If NULL it will use standard method.
|
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
158 |
*/
|
29
by Gustav Hartvigsson
* Fixed Makefile |
159 |
void game_object_class_initialize (GameObjectClass * klass, |
160 |
NewFunc new_func, |
|
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
161 |
FreeFunc free_func, |
162 |
ToStringFunc to_string_func, |
|
29
by Gustav Hartvigsson
* Fixed Makefile |
163 |
GameObjectCallbackHandlerFunc |
164 |
callback_handler_func, |
|
31
by Gustav Hartvigsson
* Woops! |
165 |
GameObjectDrawFunc draw_func, |
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
166 |
GameObjectSetCallbackFunc set_callback_func, |
167 |
GameObjectMoveFunc move_func, |
|
168 |
GameObjectSetMovementDeltaFunc |
|
169 |
set_movement_delta_func, |
|
170 |
GameObjectGetBoundingBoxFunc |
|
171 |
get_bounding_box_func, |
|
172 |
GameObjectGetIsAliveFunc get_is_alive_func, |
|
32
by Gustav Hartvigsson
* Removed code that is not needed |
173 |
GameObjectGetIsCollideFunc get_is_collide_func, |
174 |
GameObjectSetVisibleFunc set_visible_func, |
|
175 |
GameObjectGetVisibleFunc get_visible_func |
|
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
176 |
); |
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
177 |
|
178 |
void game_object_draw (GameObject * self, SDL_Renderer * renderer); |
|
179 |
||
180 |
void game_object_move (GameObject * self); |
|
181 |
||
4
by Gustav Hartvigsson
What I have done: |
182 |
void game_object_set_movement_delta (GameObject * self, int delta_x, |
183 |
int delta_y, uint32_t d_t); |
|
184 |
||
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
185 |
bool game_object_get_is_alive (GameObject * self); |
186 |
||
4
by Gustav Hartvigsson
What I have done: |
187 |
void game_object_set_callback (GameObject * self, char * name, |
5
by Gustav Hartvigsson
fixed the callback stuff.. |
188 |
GameObjectCallbackFunc callback_func, |
29
by Gustav Hartvigsson
* Fixed Makefile |
189 |
_pointer data); |
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
190 |
|
4
by Gustav Hartvigsson
What I have done: |
191 |
void game_object_do_callback (GameObject * self, char * name); |
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
192 |
|
32
by Gustav Hartvigsson
* Removed code that is not needed |
193 |
void game_object_set_visible (GameObject * self, bool visible); |
194 |
||
195 |
bool game_object_get_visible (GameObject * self); |
|
196 |
||
197 |
#if 0
|
|
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
198 |
/******************************************************************************
|
199 |
* Game Object set virtual function functions.
|
|
200 |
*****************************************************************************/
|
|
201 |
||
202 |
void game_object_set_callback_handler_func (GameObject * self,
|
|
203 |
GameObjectCallbackHandlerFunc callback_handler_func);
|
|
204 |
||
205 |
void game_object_set_add_callback_func (GameObject * self,
|
|
4
by Gustav Hartvigsson
What I have done: |
206 |
GameObjectSetCallbackFunc add_callback_func);
|
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
207 |
|
208 |
void game_object_set_move_func (GameObject * self,
|
|
209 |
GameObjectMoveFunc move_func);
|
|
210 |
||
211 |
void game_object_set_set_move_delta_func (GameObject * self,
|
|
212 |
GameObjectSetMovementDeltaFunc set_movent_delta_func);
|
|
213 |
||
214 |
void game_object_set_get_bounding_box_func (GameObject * self,
|
|
215 |
GameObjectGetBoundingBoxFunc get_bounding_box_func);
|
|
216 |
||
217 |
void game_object_set_movment_delta (GameObject * self, int delta_x,
|
|
4
by Gustav Hartvigsson
What I have done: |
218 |
int delta_y, uint32_t delta_time);
|
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
219 |
|
220 |
void game_object_set_get_is_alive_func (GameObject * self,
|
|
221 |
GameObjectGetIsAliveFunc get_is_alive_func);
|
|
222 |
||
4
by Gustav Hartvigsson
What I have done: |
223 |
void game_object_set_is_collide_func (GameObject * self,
|
224 |
GameObjectGetIsCollideFunc is_collide_func);
|
|
32
by Gustav Hartvigsson
* Removed code that is not needed |
225 |
#endif
|
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
226 |
|
227 |
END_DECLS
|
|
228 |
||
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
229 |
#endif /* __H_GAME_OBJECT__ */ |