fix dangerous use of pointer as value keeper in Obst_MoveUpDown

This commit is contained in:
Sebastian Krzyszkowiak 2012-10-02 14:03:10 +02:00
parent ff2deb4dd7
commit 32207926f3
2 changed files with 5 additions and 4 deletions

View file

@ -149,7 +149,8 @@ bool GenerateObstacles(struct Game *game, struct TM_Action *action, enum TM_Acti
} else { } else {
obst->callback = &Obst_MoveUpDown; obst->callback = &Obst_MoveUpDown;
obst->bitmap = &(game->level.dodger.obst_bmps.screwball); obst->bitmap = &(game->level.dodger.obst_bmps.screwball);
obst->data = (void*)(rand()%2); // FIXME: not portable! obst->data = malloc(sizeof(bool));
*((bool*)obst->data) = rand()%2;
obst->rows = 4; obst->rows = 4;
obst->cols = 4; obst->cols = 4;
obst->speed = 1.1; obst->speed = 1.1;

View file

@ -23,15 +23,15 @@
#include "callbacks.h" #include "callbacks.h"
void Obst_MoveUpDown(struct Game *game, struct Obstacle *obstacle) { void Obst_MoveUpDown(struct Game *game, struct Obstacle *obstacle) {
if (obstacle->data) { if (*((bool*)obstacle->data)) {
obstacle->y -= 0.5; obstacle->y -= 0.5;
if (obstacle->y<=0) { if (obstacle->y<=0) {
obstacle->data=NULL; *((bool*)obstacle->data)=false;
} }
} else { } else {
obstacle->y += 0.5; obstacle->y += 0.5;
if (obstacle->y>=((game->viewportHeight-al_get_bitmap_height(*(obstacle->bitmap))/obstacle->rows)/(float)game->viewportHeight)*100) { if (obstacle->y>=((game->viewportHeight-al_get_bitmap_height(*(obstacle->bitmap))/obstacle->rows)/(float)game->viewportHeight)*100) {
obstacle->data++; *((bool*)obstacle->data)=true;
} }
} }
} }