-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevels.c
178 lines (137 loc) · 4.61 KB
/
levels.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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include "myLib.h"
#include "levels.h"
#include "images/Level1.h"
int MAP_WIDTH = 32*8;
void loadLevel(int level) {
voff = 0;
hoff = 0;
showLevel(level);
}
void showLevel(int level) {
int i;
/*****************************************************************
*
* Step 1 -- Tile Images
*
* This data tells us what each different tile will look like
* It will be copied into a character block
*
****************************************************************/
/*****************************************************************
*
* Step 2 -- Screen Image (map)
*
* The numbers in this array tell us which tile we want in each
* tile location on the screen. We will copy this data into a
* screen block
*
****************************************************************/
/*****************************************************************
*
* Step 3 -- Palette
*
****************************************************************/
/*****************************************************************
*
* Step 4 -- Store Tile Images
*
****************************************************************/
int nTiles = 256;
int total = nTiles*64/2;
switch(level) {
case 1:
for(i=0; i < total; i++) { // There are 10 tiles. Each tile is described by 64 chars
// but we are storing them two to a short so we are
// storing data in 64/2 shorts per tile
//CHARBLOCKBASE[0].tileimg[i] = myTileImages[i*2] | (myTileImages[i*2+1]<<8);
CHARBLOCKBASE[0].tileimg[i] = Level1Tiles[i*2] | (Level1Tiles[i*2+1]<<8);
}
break;
}
/*****************************************************************
*
* Step 5 -- Store map
*
****************************************************************/
int totalMap;
switch(level) {
case 1:
totalMap = 32*32; //1024
loadMapBlock(0, Level1Map);
for(i=0; i < totalMap; i++) {
//SCREENBLOCKBASE[31].tilemap[i] = Level1Map[i];
//SCREENBLOCKBASE[30].tilemap[i] = myScreenMap[i];
SCREENBLOCKBASE[28].tilemap[i] = myBackgroundMap[i];
}
break;
}
/*****************************************************************
*
* Step 6 -- Store palette
*
****************************************************************/
switch(level) {
case 1:
//loadPalette(myPalette);
loadPalette(Level1Pal);
break;
}
/*****************************************************************
*
* Step 7 -- Set image controls
*
****************************************************************/
//REG_DISPCTL = MODE0 | BG0_ENABLE | BG1_ENABLE | BG2_ENABLE;
//SETMODE(MODE0 | BG0_ENABLE | BG1_ENABLE | BG2_ENABLE | SPRITE_ENABLE);
SETMODE(MODE0 | BG0_ENABLE | /*BG1_ENABLE |*/ BG2_ENABLE | SPRITE_ENABLE);
REG_BG0HOFS = 0;
REG_BG0VOFS = 0;
// MyGUI: Texts,... Comment out this line to turn off BG0
//REG_BG0CNT = BG_SIZE0 | SBB(31) | COLOR256 | CBB(0);
// Game
REG_BG0CNT = BG_SIZE0 | SBB(30) | COLOR256 | CBB(0);
// Background
REG_BG2CNT = BG_SIZE0 | SBB(28) | COLOR256 | CBB(0);
// DeuXieme part ;) // 30
//REG_BG1CNT = BG_SIZE0 | SBB(31) | COLOR256 | CBB(0);
}
void loadMapBlock(int bb, unsigned short levelMap[]) {
int loadRows = 32;
int loadCols = 32;
//bb = 1;
int i = 0;
int r, c;
int cIni = bb*32; //32;
int cLast = cIni+loadCols;
//for(i = 0; i < totalMap; i++) {
for (r = 0; r < loadRows; r++) {
for (c = cIni; c < cLast; c++) {
SCREENBLOCKBASE[30].tilemap[i] = levelMap[r*MAP_WIDTH+c];
i++;
}
}
//}
}
void loadMapBlockCol(int col, unsigned short levelMap[]) {
int loadRows = 32;
int loadCols = 32;
int i = 0;
int r, c;
int cLast = col+loadCols;
//for(i = 0; i < totalMap; i++) {
for (r = 0; r < loadRows; r++) {
for (c = col; c < cLast; c++) {
SCREENBLOCKBASE[30].tilemap[i] = levelMap[r*MAP_WIDTH+c];
i++;
}
}
//}
}
// Find the Value of a tile inside a Map
int loadTile(int row, int col, unsigned short levelMap[]) {
int theTile = levelMap[row*MAP_WIDTH + col];
return theTile;
}
int levelWidth() {
return MAP_WIDTH * 8;
}