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 |
||
17
by Gustav Hartvigsson
* fixed a few Doxygen problems. |
7 |
/*
|
7
by Gustav Hartvigsson
* Added licensing information to the files. |
8 |
* This file, as the rest of the project is under MIT license.
|
9 |
* see http://opensource.org/licenses/MIT
|
|
10 |
*
|
|
8
by Gustav Hartvigsson
* added and changed little in the files Lincening information. |
11 |
* Author Gustav Hartvigsson <gustav.hartvigsson _at_ gmail.com> 2014
|
7
by Gustav Hartvigsson
* Added licensing information to the files. |
12 |
*/
|
13 |
||
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
14 |
#ifndef __H_GAME_OBJECT__
|
15 |
#define __H_GAME_OBJECT__
|
|
16 |
||
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
17 |
#include <SDL2/SDL.h> |
18 |
#include <stdbool.h> |
|
19 |
||
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
20 |
#include "defs.h" |
27
by Gustav Hartvigsson
* Started working on the an object baseclass to make things |
21 |
#include "Object.h" |
22 |
||
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
23 |
/** @file
|
24 |
* GameObject is the base class for game objects, it provides a set
|
|
25 |
* of methods that make it easy to handle drawing and moving of objects in
|
|
26 |
* the game.
|
|
27 |
*
|
|
28 |
* All game objects that require drawing to the screen should be a "subclass"
|
|
29 |
* of this.
|
|
30 |
*
|
|
31 |
* @warning A GameObject contains no data, only the primaries for handling
|
|
32 |
* game objects.
|
|
33 |
*/
|
|
34 |
||
35 |
BEGIN_DECLS
|
|
36 |
||
37 |
#ifndef DOXYGEN_SHOULD_SKIP_THIS
|
|
15
by Gustav Hartvigsson
* moved the files to ./src/ |
38 |
typedef struct GameObject GameObject; |
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
39 |
typedef struct GameObjectClass GameObjectClass; |
40 |
#endif /* DOXYGEN_SHOULD_SKIP_THIS */ |
|
15
by Gustav Hartvigsson
* moved the files to ./src/ |
41 |
|
42 |
/******************************************************************************
|
|
43 |
* Function pointer declarations.
|
|
44 |
*****************************************************************************/
|
|
45 |
|
|
29
by Gustav Hartvigsson
* Fixed Makefile |
46 |
typedef void (* GameObjectCallbackFunc)(GameObject * self, _pointer data); |
15
by Gustav Hartvigsson
* moved the files to ./src/ |
47 |
|
48 |
typedef void (* GameObjectDrawFunc)(GameObject * self, SDL_Renderer * renderer); |
|
49 |
||
50 |
typedef void (* GameObjectCallbackHandlerFunc)(GameObject * self, char * name); |
|
51 |
||
52 |
typedef void (* GameObjectSetCallbackFunc)(GameObject * self, char * name,\ |
|
53 |
GameObjectCallbackFunc callback_func, |
|
29
by Gustav Hartvigsson
* Fixed Makefile |
54 |
_pointer data); |
15
by Gustav Hartvigsson
* moved the files to ./src/ |
55 |
|
56 |
typedef void (* GameObjectMoveFunc)(GameObject * self); |
|
57 |
||
58 |
typedef void (* GameObjectSetMovementDeltaFunc)(GameObject * self, int delta_x,\ |
|
59 |
int delta_y, Uint32 time_delta); |
|
60 |
||
61 |
typedef SDL_Rect (* GameObjectGetBoundingBoxFunc)(GameObject * self); |
|
62 |
||
63 |
typedef bool (* GameObjectGetIsAliveFunc)(GameObject * self); |
|
64 |
||
65 |
typedef bool (* GameObjectGetIsCollideFunc)(GameObject * self, |
|
66 |
GameObject * other); |
|
67 |
||
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
68 |
/******************************************************************************
|
69 |
* Object declaration.
|
|
70 |
*****************************************************************************/
|
|
71 |
||
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
72 |
/**
|
73 |
* The class for the GameObject.
|
|
74 |
*/
|
|
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
75 |
typedef struct GameObjectClass { |
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
76 |
/** The Parent Class */ |
27
by Gustav Hartvigsson
* Started working on the an object baseclass to make things |
77 |
ObjectClass parent; |
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
78 |
/** The callback handler */ |
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
79 |
GameObjectCallbackHandlerFunc callback_handler_func; |
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
80 |
/** Method used to set a callback on a GameObject */ |
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
81 |
GameObjectSetCallbackFunc set_callback_func; |
29
by Gustav Hartvigsson
* Fixed Makefile |
82 |
/** The method that is used to draw a GameObject */ |
83 |
GameObjectDrawFunc draw_func; |
|
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
84 |
/** The method to be run when <tt>game_object_move ()</tt> is run. */ |
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
85 |
GameObjectMoveFunc move_func; |
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
86 |
/** The method that handles how objects move over time */ |
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
87 |
GameObjectSetMovementDeltaFunc set_movement_delta_func; |
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
88 |
/** The method that returns the bounding box of an object, if available. */ |
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
89 |
GameObjectGetBoundingBoxFunc get_bounding_box_func; |
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
90 |
/** Gets weather a game object is "alive" or "dead" */ |
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
91 |
GameObjectGetIsAliveFunc get_is_alive_func; |
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
92 |
/** The method that determines if a Game Object is colliding with an other |
93 |
* game object or not.
|
|
94 |
*/
|
|
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
95 |
GameObjectGetIsCollideFunc get_is_collide_func; |
96 |
} GameObjectClass; |
|
97 |
||
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
98 |
/**
|
99 |
* Instance of a GameObject.
|
|
100 |
*/
|
|
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
101 |
typedef struct GameObject { |
27
by Gustav Hartvigsson
* Started working on the an object baseclass to make things |
102 |
Object parent; |
12
by Gustav Hartvigsson
* reorganising code to be remove extra typedefs. |
103 |
} GameObject; |
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
104 |
|
4
by Gustav Hartvigsson
What I have done: |
105 |
|
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
106 |
|
107 |
/******************************************************************************
|
|
108 |
* Game Object base functions.
|
|
109 |
*****************************************************************************/
|
|
110 |
||
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
111 |
/**
|
29
by Gustav Hartvigsson
* Fixed Makefile |
112 |
* Initialises a GameObject
|
113 |
*
|
|
114 |
* This function should be run on every "sub instance" of a GameObject.
|
|
115 |
*
|
|
116 |
* @warning It is important to note that like object_initialize, this one does
|
|
117 |
* not allocate any memory. This is left up to the caller.
|
|
118 |
*/
|
|
119 |
void game_object_initialize (GameObject * self, char * name, _pointer klass); |
|
120 |
||
121 |
/**
|
|
122 |
* Initialises a GameObjectClass.
|
|
123 |
*
|
|
124 |
* 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". |
125 |
* sub instance has its own methods and data set.
|
29
by Gustav Hartvigsson
* Fixed Makefile |
126 |
*
|
127 |
* @warning Like <tt>object_class_initialize</tt> this does not allocate any
|
|
128 |
* memory for the objects, that is left to the caller.
|
|
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
129 |
*/
|
29
by Gustav Hartvigsson
* Fixed Makefile |
130 |
void game_object_class_initialize (GameObjectClass * klass, |
131 |
NewFunc new_func, |
|
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
132 |
FreeFunc free_func, |
133 |
ToStringFunc to_string_func, |
|
29
by Gustav Hartvigsson
* Fixed Makefile |
134 |
GameObjectCallbackHandlerFunc |
135 |
callback_handler_func, |
|
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
136 |
GameObjectSetCallbackFunc set_callback_func, |
137 |
GameObjectMoveFunc move_func, |
|
138 |
GameObjectSetMovementDeltaFunc |
|
139 |
set_movement_delta_func, |
|
140 |
GameObjectGetBoundingBoxFunc |
|
141 |
get_bounding_box_func, |
|
142 |
GameObjectGetIsAliveFunc get_is_alive_func, |
|
143 |
GameObjectGetIsCollideFunc get_is_collide_func |
|
144 |
); |
|
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
145 |
|
146 |
void game_object_draw (GameObject * self, SDL_Renderer * renderer); |
|
147 |
||
148 |
void game_object_move (GameObject * self); |
|
149 |
||
4
by Gustav Hartvigsson
What I have done: |
150 |
void game_object_set_movement_delta (GameObject * self, int delta_x, |
151 |
int delta_y, uint32_t d_t); |
|
152 |
||
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
153 |
bool game_object_get_is_alive (GameObject * self); |
154 |
||
4
by Gustav Hartvigsson
What I have done: |
155 |
void game_object_set_callback (GameObject * self, char * name, |
5
by Gustav Hartvigsson
fixed the callback stuff.. |
156 |
GameObjectCallbackFunc callback_func, |
29
by Gustav Hartvigsson
* Fixed Makefile |
157 |
_pointer data); |
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
158 |
|
4
by Gustav Hartvigsson
What I have done: |
159 |
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 |
160 |
|
161 |
||
162 |
/******************************************************************************
|
|
163 |
* Game Object set virtual function functions.
|
|
164 |
*****************************************************************************/
|
|
165 |
||
166 |
void game_object_set_callback_handler_func (GameObject * self, |
|
167 |
GameObjectCallbackHandlerFunc callback_handler_func); |
|
168 |
||
169 |
void game_object_set_add_callback_func (GameObject * self, |
|
4
by Gustav Hartvigsson
What I have done: |
170 |
GameObjectSetCallbackFunc add_callback_func); |
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
171 |
|
172 |
void game_object_set_move_func (GameObject * self, |
|
173 |
GameObjectMoveFunc move_func); |
|
174 |
||
175 |
void game_object_set_set_move_delta_func (GameObject * self, |
|
176 |
GameObjectSetMovementDeltaFunc set_movent_delta_func); |
|
177 |
||
178 |
void game_object_set_get_bounding_box_func (GameObject * self, |
|
179 |
GameObjectGetBoundingBoxFunc get_bounding_box_func); |
|
180 |
||
181 |
void game_object_set_movment_delta (GameObject * self, int delta_x, |
|
4
by Gustav Hartvigsson
What I have done: |
182 |
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 |
183 |
|
184 |
void game_object_set_get_is_alive_func (GameObject * self, |
|
185 |
GameObjectGetIsAliveFunc get_is_alive_func); |
|
186 |
||
4
by Gustav Hartvigsson
What I have done: |
187 |
void game_object_set_is_collide_func (GameObject * self, |
188 |
GameObjectGetIsCollideFunc is_collide_func); |
|
28
by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class". |
189 |
|
190 |
END_DECLS
|
|
191 |
||
3
by Gustav Hartvigsson
Added the skeliton for game objects that. They can be used as a basis for a |
192 |
#endif /* __H_GAME_OBJECT__ */ |