mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2024-12-12 20:18:00 +01:00
fix dangerous use of pointer as value keeper in Obst_MoveUpDown
This commit is contained in:
parent
ff2deb4dd7
commit
32207926f3
2 changed files with 5 additions and 4 deletions
|
@ -149,7 +149,8 @@ bool GenerateObstacles(struct Game *game, struct TM_Action *action, enum TM_Acti
|
|||
} else {
|
||||
obst->callback = &Obst_MoveUpDown;
|
||||
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->cols = 4;
|
||||
obst->speed = 1.1;
|
||||
|
|
|
@ -23,15 +23,15 @@
|
|||
#include "callbacks.h"
|
||||
|
||||
void Obst_MoveUpDown(struct Game *game, struct Obstacle *obstacle) {
|
||||
if (obstacle->data) {
|
||||
if (*((bool*)obstacle->data)) {
|
||||
obstacle->y -= 0.5;
|
||||
if (obstacle->y<=0) {
|
||||
obstacle->data=NULL;
|
||||
*((bool*)obstacle->data)=false;
|
||||
}
|
||||
} else {
|
||||
obstacle->y += 0.5;
|
||||
if (obstacle->y>=((game->viewportHeight-al_get_bitmap_height(*(obstacle->bitmap))/obstacle->rows)/(float)game->viewportHeight)*100) {
|
||||
obstacle->data++;
|
||||
*((bool*)obstacle->data)=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue