-
Notifications
You must be signed in to change notification settings - Fork 0
/
platforms.c
38 lines (29 loc) · 856 Bytes
/
platforms.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "main.h"
#include "myLib.h"
#include "platforms.h"
#include <stdlib.h>
#include <stdio.h>
void handlePlatforms(PLATFORM * platforms){
for (int i = 0; i < NUMPLATFORMS; ++i){
if (platforms[i].active && platforms[i].type == MOVING){
platforms[i].col += platforms[i].cDel;
if (platforms[i].col < 3 || platforms[i].col + platforms[i].width - 3 > 240){
platforms[i].cDel = -(platforms[i].cDel);
}
}
if (platforms[i].row > 145){
platforms[i].col = random(0, SCREENWIDTH - platforms[i].width - 1);
platforms[i].row = 0;
if (rand() % 5 == 0){
platforms[i].type = NONE;
} else if (rand() % 5 == 1 || rand() % 5 == 2){
platforms[i].type = MOVING;
} else {
platforms[i].type = STATIONARY;
}
}
}
}
int random(int min, int max){
return min + rand() / (RAND_MAX / (max - min + 1) + 1);
}