00001
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _ALLEGRO5_
00014 #define _ALLEGRO5_
00015 #include <allegro5/allegro5.h>
00016 #endif // _ALLEGRO5_
00017
00018 #ifndef _CHIPMUNK_
00019 #define _CHIPMUNK_
00020 #include "chipmunk.h"
00021 #endif // _CHIPMUNK_
00022
00023 #ifndef _SPRITES_
00024 #define _SPRITES_
00025 #include "../include/sprites.h"
00026 #endif // _SPRITES_
00027
00028 #ifndef _ENEMYSTORE_
00029 #define _ENEMYSTORE_
00030 #include "../include/enemystore.h"
00031 #endif // _ENEMYSTORE_
00032
00033 #ifndef _MAINGAME_
00034 #define _MAINGAME_
00035 #include "../include/maingame.h"
00036 #endif // _MAINGAME_
00037
00038 #ifndef _PHYSCOL_
00039 #define _PHYSCOL_
00040 #include "../include/physcol.h"
00041 #endif // _PHYSCOL_
00042
00043
00044
00045 static cpSpace *space = NULL;
00046
00047
00048
00049 cpSpace* set_global_cpSpace(cpSpace *newspace)
00050 {
00051 space = newspace;
00052 return space;
00053 }
00054
00055
00056
00057 cpSpace* get_global_cpSpace(void)
00058 {
00059 return space;
00060 }
00061
00062
00063
00064 cpBody* create_new_body(SPRITESPTR sprite, float weight)
00065 {
00066 float width = sprite->sdata.currentimg->width;
00067 float height = sprite->sdata.currentimg->height;
00068 cpBody *spriteBody = cpBodyNew(weight, INFINITY);;
00069 spriteBody->p = cpv(sprite->sdata.x+width/2, sprite->sdata.y+height/2);
00070 cpSpaceAddBody(space, spriteBody);
00071 return spriteBody;
00072 }
00073
00074
00075
00076 cpShape* create_new_shape(SPRITESPTR sprite, cpBody *spriteBody, float e, float u, int coltype, void *data)
00077 {
00078 float width = sprite->sdata.currentimg->width;
00079 float height = sprite->sdata.currentimg->height;
00080 cpVect vects[4] = {cpv(0-width/2, 0-height/2),
00081 cpv(0-width/2, 0+height/2),
00082 cpv(0+width/2, 0+height/2),
00083 cpv(0+width/2, 0-height/2)};
00084 cpShape *spriteShape = cpPolyShapeNew(spriteBody, 4, vects, cpvzero);
00085 spriteShape->e = e;
00086 spriteShape->u = u;
00087 spriteShape->collision_type = coltype;
00088 spriteShape->data = data;
00089 sprite->shape = spriteShape;
00090 cpSpaceAddShape(space, spriteShape);
00091 return spriteShape;
00092 }
00093
00094
00095
00096 cpShape* create_physics_object(SPRITESPTR sprite, float w, float e, float u, int coltype, void *data)
00097 {
00098 cpBody *spriteBody = create_new_body(sprite, w);
00099 cpShape *spriteShape = create_new_shape(sprite, spriteBody, e, u, coltype, data);
00100 return spriteShape;
00101 }
00102
00103
00104
00105 void remove_physics_object(SPRITESPTR sprite)
00106 {
00107 cpSpaceRemoveBody(space, sprite->shape->body);
00108 cpBodyFree(sprite->shape->body);
00109 cpSpaceRemoveShape(space, sprite->shape);
00110 cpShapeFree(sprite->shape);
00111 }
00112
00113
00114
00115 int collision_begin(cpArbiter *arb, cpSpace *Space, void *data)
00116 {
00117 cpShape *a, *b;
00118 cpArbiterGetShapes(arb, &a, &b);
00119 SPRITESPTR stman = search_sprite_list_for_element((char*)a->data);
00120 SPRITESPTR sprite = (SPRITESPTR)b->data;
00121 if((stman->sdata.animflags & MRECOVER))
00122 {
00123 return 0;
00124 }
00125 else
00126 {
00127 if(strcmp(sprite->slabel, "BRICK_WALL") == 0)
00128 {
00129 if(sprite->sdata.y < 405)
00130 {
00131 if((stman->sdata.animflags & MDOWN))
00132 return 0;
00133 else
00134 cpSpaceAddPostStepCallback(Space, collision_end_lose, b, NULL);
00135 }
00136 else if(stman->sdata.y+stman->sdata.currentimg->height > sprite->sdata.y)
00137 cpSpaceAddPostStepCallback(Space, collision_end_lose, b, NULL);
00138 return 1;
00139 }
00140 else if(strcmp(sprite->slabel, "CLAMP") == 0)
00141 {
00142 if((stman->sdata.animflags & MDOWN))
00143 return 0;
00144 else
00145 {
00146 set_anim_flags_on_sprite(sprite, MATTACK);
00147 cpSpaceAddPostStepCallback(Space, collision_end_lose, b, NULL);
00148 return 1;
00149 }
00150 }
00151 else if(strcmp(sprite->slabel, "STEEL_WALL") == 0)
00152 {
00153 if(sprite->sdata.y < 385)
00154 {
00155 if((stman->sdata.animflags & MDOWN))
00156 return 0;
00157 else
00158 cpSpaceAddPostStepCallback(Space, collision_end_lose, b, NULL);
00159 }
00160 else if(stman->sdata.y+stman->sdata.currentimg->height > sprite->sdata.y)
00161 cpSpaceAddPostStepCallback(Space, collision_end_lose, b, NULL);
00162 return 1;
00163 }
00164 else if(strcmp(sprite->slabel, "FLYING_FIST") == 0)
00165 {
00166 if(!(stman->sdata.animflags & MDOWN))
00167 cpSpaceAddPostStepCallback(Space, collision_end_lose, b, NULL);
00168 return 1;
00169 }
00170 else if(strcmp(sprite->slabel, "SPIKES") == 0)
00171 {
00172 cpSpaceAddPostStepCallback(Space, collision_end_lose, b, NULL);
00173 return 1;
00174 }
00175 else if((stman->sdata.animflags & MATTACK))
00176 cpSpaceAddPostStepCallback(Space, collision_end_win, b, NULL);
00177 else
00178 cpSpaceAddPostStepCallback(Space, collision_end_lose, b, NULL);
00179 }
00180 return 1;
00181 }
00182
00183
00184
00185 int collision_pre_solve(cpArbiter *arb, cpSpace *Space, void *data)
00186 {
00187 return 1;
00188 }
00189
00190
00191
00192 void collision_post_solve(cpArbiter *arb, cpSpace *Space, void *data)
00193 {
00194
00195 }
00196
00197
00198
00199 void collision_separate(cpArbiter *arb, cpSpace *Space, void *data)
00200 {
00201 }
00202
00203
00204
00205 int collision_static_begin(cpArbiter *arb, cpSpace *Space, void *data)
00206 {
00207 cpShape *a, *b;
00208 cpArbiterGetShapes(arb, &a, &b);
00209
00210 if(b->collision_type == 1 && strcmp((char*)a->data, "LEFTSHAPE") == 0)
00211 {
00212 SPRITESPTR stman = search_sprite_list_for_element((char*)b->data);
00213 if((stman->sdata.animflags & MDAMAGED))
00214 return 0;
00215 else
00216 return 1;
00217 }
00218 else if(strcmp((char*)a->data, "FLOORSHAPE") == 0)
00219 return 1;
00220 else if(strcmp((char*)a->data, "TOPSHAPE") == 0)
00221 return 1;
00222 else
00223 return 0;
00224 }
00225
00226
00227
00228 int collision_static_pre_solve(cpArbiter *arb, cpSpace *Space, void *data)
00229 {
00230 return 1;
00231 }
00232
00233
00234
00235 void collision_static_post_solve(cpArbiter *arb, cpSpace *Space, void *data)
00236 {
00237
00238 }
00239
00240
00241
00242 void collision_static_separate(cpArbiter *arb, cpSpace *Space, void *data)
00243 {
00244
00245 }
00246
00247
00248
00249 void collision_static_end(cpSpace *Space, void *obj, void *unused)
00250 {
00251
00252 }
00253
00254
00255
00256
00257
00258