-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapmaker.cpp
More file actions
127 lines (106 loc) · 2.17 KB
/
mapmaker.cpp
File metadata and controls
127 lines (106 loc) · 2.17 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <iostream>
using namespace std;
SDL_Rect tilePicker(int tile);
SDL_Surface map()
{
SDL_Surface *mapSurface;
int mapArray[8][8] =
{
{3, 5, 5, 5, 5, 5, 5, 13},
{2, 3, 5, 5, 5, 5, 13, 2},
{2, 2, 100, 100, 100, 100, 2, 2},
{2, 2, 100, 1, 100, 100, 2, 2},
{2, 2, 100, 100, 1, 100, 2, 2},
{2, 2, 100, 100, 100, 100, 2, 2},
{2, 4, 5, 13, 3, 5, 14, 2},
{4, 5, 5, 14, 4, 5, 5, 14}
};
int blockx = 0, blocky = 0;
Object crate;
crate.x(blockx);
crate.y(blocky);
crate.boxsize(100);
crate.load("spritemap.png");
Uint8 r = 0, g = 0, b = 0, a = 0;
SDL_PixelFormat *fmt;
mapSurface = SDL_CreateRGBSurface(SDL_SWSURFACE,800,800,32,0, 0, 0, 0);
fmt=mapSurface->format;
Uint32 color = SDL_MapRGBA(fmt, r, g, b,a);
// Uint32 color;
SDL_Rect fill;
fill.x=800;
fill.y=800;
fill.w=0;
fill.h=0;
SDL_FillRect(mapSurface, &fill, color);
SDL_SetAlpha(mapSurface,SDL_SRCALPHA, 0);
for (int x =0; x <8; x++)
{
// iterates through each row
for (int y =0; y <8; y++)
{
// return mapArray[x][y]
int tilez = mapArray[x][y];
SDL_Rect wat = tilePicker(tilez);
SDL_Rect wtf = crate.rect();
// cout << "Tile: " << mapArray[x][y] << " Source: (" << wat.x << "," << wat.y << ") Dest: (" << wtf.x << "," << wtf.y << ") ";
SDL_BlitSurface(&crate.image(), &wat, mapSurface, &wtf);
blockx+=100;
crate.x(blockx);
};
//cout << "\n";
blocky+=100;
crate.y(blocky);
blockx=0;
crate.x(blockx);
};
SDL_SetAlpha(mapSurface,0 ,128);
return *mapSurface;
}
SDL_Rect tilePicker(int tile)
{
SDL_Rect selection;
selection.h=100;
selection.w=100;
switch(tile)
{
case 1:
selection.x=0;
selection.y=0;
break;
case 2:
selection.x=0;
selection.y=100;
break;
case 3:
selection.x=0;
selection.y=200;
break;
case 4:
selection.x=0;
selection.y=300;
break;
case 5:
selection.x=0;
selection.y=400;
break;
case 13:
selection.x=100;
selection.y=200;
break;
case 14:
selection.x=100;
selection.y=300;
break;
case 100:
selection.x=900;
selection.y=900;
break;
default:
// returns blank tile
selection.x=900;
selection.y=900;
break;
}
return selection;
}