equal
deleted
inserted
replaced
|
1 #include <stdio.h> |
|
2 #include "common.h" |
|
3 #include <SDL2/SDL.h> |
|
4 |
|
5 typedef struct |
|
6 { |
|
7 |
|
8 } |
|
9 Image; |
|
10 |
|
11 void loadLevelFromFile() |
|
12 { |
|
13 Image img; |
|
14 FILE* imageFile; |
|
15 |
|
16 imageFile = fopen("img/nhhs.ppm", "rb"); |
|
17 |
|
18 int whiteSpaces = 0; |
|
19 int lineCount = 0; |
|
20 int pixelCount = 0; |
|
21 if(imageFile) |
|
22 { |
|
23 unsigned char byte; |
|
24 SDL_Color color = {0, 0, 0, 255}; |
|
25 |
|
26 while(fread(&byte, 1, 1, imageFile)) |
|
27 { |
|
28 if(whiteSpaces == 4) |
|
29 { |
|
30 if(lineCount == 0) color.r = byte; |
|
31 if(lineCount == 1) color.g = byte; |
|
32 if(lineCount == 2) color.b = byte; |
|
33 lineCount ++; |
|
34 if(lineCount >= 3) |
|
35 { |
|
36 lineCount = 0; |
|
37 levelTiles[pixelCount] = (color.g == 255) ? (color.r == 0 ? 'G' : ' ') : (color.r == 255) ? ' ' : (color.r == 85) ? 'A' : (color.b == 191) ? 'S' : '#'; |
|
38 pixelCount ++; |
|
39 /*printf("Color: %02x, %02x, %02x\n", color.r, color.g, color.b);*/ |
|
40 } |
|
41 } |
|
42 |
|
43 if(byte == 10) whiteSpaces ++; |
|
44 } |
|
45 |
|
46 |
|
47 putchar('\n'); |
|
48 |
|
49 } |
|
50 |
|
51 fclose(imageFile); |
|
52 } |