/+junk/c_sdl_joypad_ducktape

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/c_sdl_joypad_ducktape

« back to all changes in this revision

Viewing changes to src/GameObject.c

  • Committer: Gustav Hartvigsson
  • Date: 2014-09-02 20:15:48 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20140902201548-h1kss1wdocqhs8df
* Fixed Makefile
* Changed all void * to _pointer in DynamicArray.[h,c].
* Fixed GameObject to work with the new base-type.
* Made the Object stuffs...
* added string_new_printf utility function in utils.[h,c]

* Derp.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 * Author Gustav Hartvigsson <gustav.hartvigsson _at_ gmail.com> 2014
13
13
 */
14
14
 
 
15
void game_object_class_initialize (GameObjectClass *    klass,
 
16
                             NewFunc                    new_func,
 
17
                             FreeFunc                   free_func,
 
18
                             ToStringFunc               to_string_func,
 
19
                             GameObjectCallbackHandlerFunc
 
20
                                                          callback_handler_func,
 
21
                             GameObjectSetCallbackFunc  set_callback_func,
 
22
                             GameObjectMoveFunc         move_func,
 
23
                             GameObjectSetMovementDeltaFunc
 
24
                                                        set_movement_delta_func,
 
25
                             GameObjectGetBoundingBoxFunc
 
26
                                                        get_bounding_box_func,
 
27
                             GameObjectGetIsAliveFunc   get_is_alive_func,
 
28
                             GameObjectGetIsCollideFunc get_is_collide_func) {
 
29
  
 
30
  /* First things first, we need to initialise the Object base class. */
 
31
  ObjectClass * objkls = (ObjectClass *) klass;
 
32
  object_class_initialize (objkls,  new_func, free_func, to_string_func);
 
33
  
 
34
  /* Now we add the methods to the GameObjectClass */
 
35
  klass->callback_handler_func = callback_handler_func;
 
36
  klass->set_callback_func = set_callback_func;
 
37
  klass->move_func = move_func;
 
38
  klass->set_movement_delta_func = set_movement_delta_func;
 
39
  klass->get_bounding_box_func = get_bounding_box_func;
 
40
  klass->get_is_alive_func = get_is_alive_func;
 
41
  klass->get_is_collide_func = get_is_collide_func;
 
42
  
 
43
  /* We are done. */
 
44
}
 
45
 
15
46
void game_object_draw (GameObject * self, SDL_Renderer * renderer) {
16
 
  GameObjectDrawFunc draw_func = self->klass->draw_func;
 
47
  Object * obj = (Object *) self;
 
48
  GameObjectClass * klass = (GameObjectClass *) obj->klass;
 
49
  GameObjectDrawFunc draw_func = klass->draw_func;
17
50
  draw_func (self, renderer);
18
51
}
19
52
 
20
53
void game_object_set_movment_delta (GameObject * self, int delta_x,
21
54
                                    int delta_y, uint32_t delta_time) {
 
55
  Object * obj = (Object *) self;
 
56
  GameObjectClass * klass = (GameObjectClass *) obj->klass;
22
57
  GameObjectSetMovementDeltaFunc set_movement_delta_func
23
 
                                         = self->klass->set_movement_delta_func;
 
58
                                         = klass->set_movement_delta_func;
24
59
  set_movement_delta_func (self, delta_x, delta_y, delta_time);
25
60
}
26
61
 
27
62
bool game_object_get_is_alive (GameObject * self) {
28
 
  GameObjectGetIsAliveFunc is_alive = self->klass->get_is_alive_func;
 
63
  Object * obj = (Object *) self;
 
64
  GameObjectClass * klass = (GameObjectClass *) obj->klass;
 
65
  GameObjectGetIsAliveFunc is_alive = klass->get_is_alive_func;
29
66
  bool ret = is_alive (self);
30
67
  return ret;
31
68
}
32
69
 
33
70
void game_object_set_callback (GameObject * self, char * name,
34
71
                               GameObjectCallbackFunc callback_func,
35
 
                               void * data) {
36
 
  GameObjectSetCallbackFunc set_callback_func = self->klass->set_callback_func;
 
72
                               _pointer data) {
 
73
  Object * obj = (Object *) self;
 
74
  GameObjectClass * klass = (GameObjectClass *) obj->klass;
 
75
  GameObjectSetCallbackFunc set_callback_func = klass->set_callback_func;
37
76
  set_callback_func (self, name, callback_func, data);
38
77
}
39
78
 
40
79
void game_object_do_callback (GameObject * self, char * name) {
41
 
  GameObjectCallbackHandlerFunc do_callback_func
42
 
                                           = self->klass->callback_handler_func;
 
80
  Object * obj = (Object *) self;
 
81
  GameObjectClass * klass = (GameObjectClass *) obj->klass;
 
82
  GameObjectCallbackHandlerFunc do_callback_func = klass->callback_handler_func;
43
83
  do_callback_func (self, name);
44
84
}
45
85
 
46
86
bool game_object_get_is_collide (GameObject * self, GameObject * other) {
47
 
  GameObjectGetIsCollideFunc s_is_collide = self->klass->get_is_collide_func;
 
87
  Object * obj = (Object *) self;
 
88
  GameObjectClass * klass = (GameObjectClass *) obj->klass;
 
89
  GameObjectGetIsCollideFunc s_is_collide = klass->get_is_collide_func;
48
90
  bool ret = s_is_collide (self, other);
49
91
  return ret;
50
92
}
52
94
 
53
95
/******************************************************************************/
54
96
 
55
 
void game_object_set_free_func (GameObject * self,
56
 
                                GameObjectFreeFunc free_func) {
57
 
  self->klass->free_func = free_func;
58
 
}
59
 
 
60
97
 
61
98
void game_object_set_draw_func (GameObject * self,
62
99
                                GameObjectDrawFunc draw_func) {
63
 
  self->klass->draw_func = draw_func;
 
100
  Object * obj = (Object *) self;
 
101
  GameObjectClass * klass = (GameObjectClass *) obj->klass;
 
102
  klass->draw_func = draw_func;
64
103
}
65
104
 
66
105
void game_object_set_callback_handler_func (GameObject * self,
67
106
                          GameObjectCallbackHandlerFunc callback_handler_func) {
68
 
  self->klass->callback_handler_func = callback_handler_func;
 
107
  Object * obj = (Object *) self;
 
108
  GameObjectClass * klass = (GameObjectClass *) obj->klass;
 
109
  klass->callback_handler_func = callback_handler_func;
69
110
}
70
111
 
71
112
void game_object_set_set_callback_func (GameObject * self,
72
113
                                  GameObjectSetCallbackFunc set_callback_func) {
73
 
  self->klass->set_callback_func = set_callback_func;
 
114
  Object * obj = (Object *) self;
 
115
  GameObjectClass * klass = (GameObjectClass *) obj->klass;
 
116
  klass->set_callback_func = set_callback_func;
74
117
}
75
118
 
76
119
void game_object_set_move_func (GameObject * self,
77
120
                                GameObjectMoveFunc move_func) {
78
 
  self->klass->move_func = move_func;
 
121
  Object * obj = (Object *) self;
 
122
  GameObjectClass * klass = (GameObjectClass *) obj->klass;
 
123
  klass->move_func = move_func;
79
124
}
80
125
 
81
126
void game_object_set_set_move_delta_func (GameObject * self,
82
127
                       GameObjectSetMovementDeltaFunc set_movement_delta_func) {
83
 
  self->klass->set_movement_delta_func = set_movement_delta_func;
 
128
  Object * obj = (Object *) self;
 
129
  GameObjectClass * klass = (GameObjectClass *) obj->klass;
 
130
  klass->set_movement_delta_func = set_movement_delta_func;
84
131
}
85
132
 
86
133
void game_object_set_get_bounding_box_func (GameObject * self,
87
134
                           GameObjectGetBoundingBoxFunc get_bounding_box_func) {
88
 
  self->klass->get_bounding_box_func = get_bounding_box_func;
 
135
  Object * obj = (Object *) self;
 
136
  GameObjectClass * klass = (GameObjectClass *) obj->klass;
 
137
  klass->get_bounding_box_func = get_bounding_box_func;
89
138
}
90
139
 
91
140
void game_object_set_get_is_alive_func (GameObject * self,
92
141
                                   GameObjectGetIsAliveFunc get_is_alive_func) {
93
 
  self->klass->get_is_alive_func = get_is_alive_func;
 
142
  Object * obj = (Object *) self;
 
143
  GameObjectClass * klass = (GameObjectClass *) obj->klass;
 
144
  klass->get_is_alive_func = get_is_alive_func;
94
145
}
95
146
 
96
147
void game_object_set_is_collide_func (GameObject * self,
97
148
                               GameObjectGetIsCollideFunc get_is_collide_func) {
98
 
  self->klass->get_is_collide_func = get_is_collide_func;
 
149
  Object * obj = (Object *) self;
 
150
  GameObjectClass * klass = (GameObjectClass *) obj->klass;
 
151
  klass->get_is_collide_func = get_is_collide_func;
99
152
}
100
153
 
101
154
/**  MOOOOO!  **/