-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc.cpp
51 lines (40 loc) · 1.29 KB
/
calc.cpp
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
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "main.h"
#include "config.h"
#include <cstdlib>
char * StepWorld(char * world) {
char * worldstepped = (char *) calloc(WINDOW_WIDTH * WINDOW_HEIGHT, sizeof(char));
for (int i = 1; i < WINDOW_HEIGHT - 1; i++) {
for (int j = 1; j < WINDOW_WIDTH - 1; j++) {
int accesscoord = i * WINDOW_WIDTH + j;
for (int m = 0; m < masksize / 2; m++) {
short xmask = mask[2 * m + 0];
short ymask = mask[2 * m + 1] * WINDOW_WIDTH;
if (accesscoord + xmask + ymask < 0 || accesscoord + xmask + ymask >= WINDOW_LENGTH) {
continue;
}
if (world[accesscoord + xmask + ymask] > 0) {
worldstepped[accesscoord] += 1;
}
}
worldstepped[accesscoord] = rule[worldstepped[accesscoord] * 2 + world[accesscoord]];
}
}
free(world);
return worldstepped;
}
char * GenWorld() {
return (char *)calloc(WINDOW_WIDTH * WINDOW_HEIGHT, sizeof(char));
}
char * Draw(char * world, double xpos, double ypos, int xsize, int ysize, char state) {
xpos = xpos / SCALE;
ypos = ypos / SCALE;
ypos = WINDOW_HEIGHT - ypos;
for (int i = ypos - ysize / 2; i < ypos + ysize / 2; i++) {
for (int j = xpos - xsize / 2; j < xpos + xsize / 2; j++) {
if (i * WINDOW_WIDTH + j >= 0 && i * WINDOW_WIDTH + j < WINDOW_LENGTH) {
world[i * WINDOW_WIDTH + j] = state;
}
}
}
return world;
}