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 |
*/
|
|
5 |
||
4
by Gustav Hartvigsson
What I have done: |
6 |
#include "GameObject.h" |
7 |
||
7
by Gustav Hartvigsson
* Added licensing information to the files. |
8 |
/**
|
9 |
* This file, as the rest of the project is under MIT license.
|
|
10 |
* see http://opensource.org/licenses/MIT
|
|
11 |
*
|
|
8
by Gustav Hartvigsson
* added and changed little in the files Lincening information. |
12 |
* Author Gustav Hartvigsson <gustav.hartvigsson _at_ gmail.com> 2014
|
7
by Gustav Hartvigsson
* Added licensing information to the files. |
13 |
*/
|
14 |
||
32
by Gustav Hartvigsson
* Removed code that is not needed |
15 |
void _game_object_private_set_visible (GameObject * self , bool visible); |
16 |
bool _game_object_private_get_visible (GameObject * self); |
|
17 |
||
29
by Gustav Hartvigsson
* Fixed Makefile |
18 |
void game_object_class_initialize (GameObjectClass * klass, |
19 |
NewFunc new_func, |
|
20 |
FreeFunc free_func, |
|
21 |
ToStringFunc to_string_func, |
|
22 |
GameObjectCallbackHandlerFunc |
|
23 |
callback_handler_func, |
|
30
by Gustav Hartvigsson
* Woops, forgot to draw_func to the arguments... |
24 |
GameObjectDrawFunc draw_func, |
29
by Gustav Hartvigsson
* Fixed Makefile |
25 |
GameObjectSetCallbackFunc set_callback_func, |
26 |
GameObjectMoveFunc move_func, |
|
27 |
GameObjectSetMovementDeltaFunc |
|
28 |
set_movement_delta_func, |
|
29 |
GameObjectGetBoundingBoxFunc |
|
30 |
get_bounding_box_func, |
|
31 |
GameObjectGetIsAliveFunc get_is_alive_func, |
|
32
by Gustav Hartvigsson
* Removed code that is not needed |
32 |
GameObjectGetIsCollideFunc get_is_collide_func, |
33 |
GameObjectSetVisibleFunc set_visible_func, |
|
34 |
GameObjectGetVisibleFunc get_visible_func) { |
|
29
by Gustav Hartvigsson
* Fixed Makefile |
35 |
|
36 |
/* First things first, we need to initialise the Object base class. */ |
|
37 |
ObjectClass * objkls = (ObjectClass *) klass; |
|
38 |
object_class_initialize (objkls, new_func, free_func, to_string_func); |
|
39 |
|
|
40 |
/* Now we add the methods to the GameObjectClass */ |
|
41 |
klass->callback_handler_func = callback_handler_func; |
|
42 |
klass->set_callback_func = set_callback_func; |
|
30
by Gustav Hartvigsson
* Woops, forgot to draw_func to the arguments... |
43 |
klass->draw_func = draw_func; |
29
by Gustav Hartvigsson
* Fixed Makefile |
44 |
klass->move_func = move_func; |
45 |
klass->set_movement_delta_func = set_movement_delta_func; |
|
46 |
klass->get_bounding_box_func = get_bounding_box_func; |
|
47 |
klass->get_is_alive_func = get_is_alive_func; |
|
48 |
klass->get_is_collide_func = get_is_collide_func; |
|
49 |
|
|
32
by Gustav Hartvigsson
* Removed code that is not needed |
50 |
if (set_visible_func == NULL) { |
51 |
klass->set_visible_func = _game_object_private_set_visible; |
|
52 |
} else { |
|
53 |
klass->set_visible_func = set_visible_func; |
|
54 |
} |
|
55 |
|
|
56 |
if (get_visible_func == NULL) { |
|
57 |
klass->get_visible_func = _game_object_private_get_visible; |
|
58 |
} else { |
|
59 |
klass->get_visible_func = get_visible_func; |
|
60 |
} |
|
61 |
|
|
29
by Gustav Hartvigsson
* Fixed Makefile |
62 |
/* We are done. */ |
63 |
}
|
|
64 |
||
4
by Gustav Hartvigsson
What I have done: |
65 |
void game_object_draw (GameObject * self, SDL_Renderer * renderer) { |
29
by Gustav Hartvigsson
* Fixed Makefile |
66 |
Object * obj = (Object *) self; |
67 |
GameObjectClass * klass = (GameObjectClass *) obj->klass; |
|
68 |
GameObjectDrawFunc draw_func = klass->draw_func; |
|
4
by Gustav Hartvigsson
What I have done: |
69 |
draw_func (self, renderer); |
70 |
}
|
|
71 |
||
72 |
void game_object_set_movment_delta (GameObject * self, int delta_x, |
|
73 |
int delta_y, uint32_t delta_time) { |
|
29
by Gustav Hartvigsson
* Fixed Makefile |
74 |
Object * obj = (Object *) self; |
75 |
GameObjectClass * klass = (GameObjectClass *) obj->klass; |
|
4
by Gustav Hartvigsson
What I have done: |
76 |
GameObjectSetMovementDeltaFunc set_movement_delta_func |
29
by Gustav Hartvigsson
* Fixed Makefile |
77 |
= klass->set_movement_delta_func; |
4
by Gustav Hartvigsson
What I have done: |
78 |
set_movement_delta_func (self, delta_x, delta_y, delta_time); |
79 |
}
|
|
80 |
||
81 |
bool game_object_get_is_alive (GameObject * self) { |
|
29
by Gustav Hartvigsson
* Fixed Makefile |
82 |
Object * obj = (Object *) self; |
83 |
GameObjectClass * klass = (GameObjectClass *) obj->klass; |
|
84 |
GameObjectGetIsAliveFunc is_alive = klass->get_is_alive_func; |
|
4
by Gustav Hartvigsson
What I have done: |
85 |
bool ret = is_alive (self); |
86 |
return ret; |
|
87 |
}
|
|
88 |
||
89 |
void game_object_set_callback (GameObject * self, char * name, |
|
5
by Gustav Hartvigsson
fixed the callback stuff.. |
90 |
GameObjectCallbackFunc callback_func, |
29
by Gustav Hartvigsson
* Fixed Makefile |
91 |
_pointer data) { |
92 |
Object * obj = (Object *) self; |
|
93 |
GameObjectClass * klass = (GameObjectClass *) obj->klass; |
|
94 |
GameObjectSetCallbackFunc set_callback_func = klass->set_callback_func; |
|
5
by Gustav Hartvigsson
fixed the callback stuff.. |
95 |
set_callback_func (self, name, callback_func, data); |
4
by Gustav Hartvigsson
What I have done: |
96 |
}
|
97 |
||
98 |
void game_object_do_callback (GameObject * self, char * name) { |
|
29
by Gustav Hartvigsson
* Fixed Makefile |
99 |
Object * obj = (Object *) self; |
100 |
GameObjectClass * klass = (GameObjectClass *) obj->klass; |
|
101 |
GameObjectCallbackHandlerFunc do_callback_func = klass->callback_handler_func; |
|
4
by Gustav Hartvigsson
What I have done: |
102 |
do_callback_func (self, name); |
103 |
}
|
|
104 |
||
105 |
bool game_object_get_is_collide (GameObject * self, GameObject * other) { |
|
29
by Gustav Hartvigsson
* Fixed Makefile |
106 |
Object * obj = (Object *) self; |
107 |
GameObjectClass * klass = (GameObjectClass *) obj->klass; |
|
108 |
GameObjectGetIsCollideFunc s_is_collide = klass->get_is_collide_func; |
|
4
by Gustav Hartvigsson
What I have done: |
109 |
bool ret = s_is_collide (self, other); |
110 |
return ret; |
|
111 |
}
|
|
112 |
||
32
by Gustav Hartvigsson
* Removed code that is not needed |
113 |
void game_object_set_visible (GameObject * self, bool visible) { |
114 |
Object * obj = (Object *) self; |
|
115 |
GameObjectClass * klass = (GameObjectClass *) obj->klass; |
|
116 |
GameObjectSetVisibleFunc set_visible_func = klass->set_visible_func; |
|
117 |
set_visible_func (self, visible); |
|
118 |
}
|
|
119 |
||
120 |
bool game_object_get_visible (GameObject * self) { |
|
121 |
Object * obj = (Object *) self; |
|
122 |
GameObjectClass * klass = (GameObjectClass *) obj->klass; |
|
123 |
GameObjectGetVisibleFunc get_visible_func = klass->get_visible_func; |
|
124 |
return get_visible_func (self); |
|
125 |
}
|
|
126 |
||
127 |
#if 0
|
|
4
by Gustav Hartvigsson
What I have done: |
128 |
/******************************************************************************/
|
129 |
||
130 |
||
131 |
void game_object_set_draw_func (GameObject * self,
|
|
132 |
GameObjectDrawFunc draw_func) {
|
|
29
by Gustav Hartvigsson
* Fixed Makefile |
133 |
Object * obj = (Object *) self;
|
134 |
GameObjectClass * klass = (GameObjectClass *) obj->klass;
|
|
135 |
klass->draw_func = draw_func;
|
|
4
by Gustav Hartvigsson
What I have done: |
136 |
}
|
137 |
||
138 |
void game_object_set_callback_handler_func (GameObject * self,
|
|
6
by Gustav Hartvigsson
reverted a mistake and fixed the code in the .c file to match this |
139 |
GameObjectCallbackHandlerFunc callback_handler_func) {
|
29
by Gustav Hartvigsson
* Fixed Makefile |
140 |
Object * obj = (Object *) self;
|
141 |
GameObjectClass * klass = (GameObjectClass *) obj->klass;
|
|
142 |
klass->callback_handler_func = callback_handler_func;
|
|
6
by Gustav Hartvigsson
reverted a mistake and fixed the code in the .c file to match this |
143 |
}
|
4
by Gustav Hartvigsson
What I have done: |
144 |
|
145 |
void game_object_set_set_callback_func (GameObject * self,
|
|
146 |
GameObjectSetCallbackFunc set_callback_func) {
|
|
29
by Gustav Hartvigsson
* Fixed Makefile |
147 |
Object * obj = (Object *) self;
|
148 |
GameObjectClass * klass = (GameObjectClass *) obj->klass;
|
|
149 |
klass->set_callback_func = set_callback_func;
|
|
4
by Gustav Hartvigsson
What I have done: |
150 |
}
|
151 |
||
152 |
void game_object_set_move_func (GameObject * self,
|
|
153 |
GameObjectMoveFunc move_func) {
|
|
29
by Gustav Hartvigsson
* Fixed Makefile |
154 |
Object * obj = (Object *) self;
|
155 |
GameObjectClass * klass = (GameObjectClass *) obj->klass;
|
|
156 |
klass->move_func = move_func;
|
|
4
by Gustav Hartvigsson
What I have done: |
157 |
}
|
158 |
||
159 |
void game_object_set_set_move_delta_func (GameObject * self,
|
|
6
by Gustav Hartvigsson
reverted a mistake and fixed the code in the .c file to match this |
160 |
GameObjectSetMovementDeltaFunc set_movement_delta_func) {
|
29
by Gustav Hartvigsson
* Fixed Makefile |
161 |
Object * obj = (Object *) self;
|
162 |
GameObjectClass * klass = (GameObjectClass *) obj->klass;
|
|
163 |
klass->set_movement_delta_func = set_movement_delta_func;
|
|
4
by Gustav Hartvigsson
What I have done: |
164 |
}
|
165 |
||
166 |
void game_object_set_get_bounding_box_func (GameObject * self,
|
|
167 |
GameObjectGetBoundingBoxFunc get_bounding_box_func) {
|
|
29
by Gustav Hartvigsson
* Fixed Makefile |
168 |
Object * obj = (Object *) self;
|
169 |
GameObjectClass * klass = (GameObjectClass *) obj->klass;
|
|
170 |
klass->get_bounding_box_func = get_bounding_box_func;
|
|
4
by Gustav Hartvigsson
What I have done: |
171 |
}
|
172 |
||
173 |
void game_object_set_get_is_alive_func (GameObject * self,
|
|
174 |
GameObjectGetIsAliveFunc get_is_alive_func) {
|
|
29
by Gustav Hartvigsson
* Fixed Makefile |
175 |
Object * obj = (Object *) self;
|
176 |
GameObjectClass * klass = (GameObjectClass *) obj->klass;
|
|
177 |
klass->get_is_alive_func = get_is_alive_func;
|
|
4
by Gustav Hartvigsson
What I have done: |
178 |
}
|
179 |
||
180 |
void game_object_set_is_collide_func (GameObject * self,
|
|
181 |
GameObjectGetIsCollideFunc get_is_collide_func) {
|
|
29
by Gustav Hartvigsson
* Fixed Makefile |
182 |
Object * obj = (Object *) self;
|
183 |
GameObjectClass * klass = (GameObjectClass *) obj->klass;
|
|
184 |
klass->get_is_collide_func = get_is_collide_func;
|
|
4
by Gustav Hartvigsson
What I have done: |
185 |
}
|
32
by Gustav Hartvigsson
* Removed code that is not needed |
186 |
#endif
|
187 |
||
188 |
/* ****************************************************************************/
|
|
189 |
void _game_object_private_set_visible (GameObject * self , bool visible) { |
|
190 |
self->visible = visible; |
|
191 |
}
|
|
192 |
||
193 |
bool _game_object_private_get_visible (GameObject * self) { |
|
194 |
return self->visible; |
|
195 |
}
|
|
4
by Gustav Hartvigsson
What I have done: |
196 |
|
197 |
/** MOOOOO! **/
|