1
2 // the Map System
3 #include "nx.h"
4 #include "map_system.h"
5 #include "map_system.fdh"
6
7 #define MS_EXPANDING 0
8 #define MS_DISPLAYED 1
9 #define MS_CONTRACTING 2
10
11 // # of frames in the expand/contract animation
12 #define EXPAND_LENGTH 8
13
14 #define BANNER_TOP 7
15 #define BANNER_BTM 23
16
17 static struct
18 {
19 int x, y; // the position of the upper-left corner of the image
20 int w, h; // size of image
21
22 int expandframe; // for expand/contract effect
23 int current_row; // scan down effect
24
25 int px, py; // the position of the you-are-here dot
26 int timer; // for the flashing
27
28 int state; // expanding, displayed, contracting
29 int return_gm; // game mode to return to
30
31 const char *bannertext;
32 int textx, texty;
33
34 bool lastbuttondown;
35 } ms;
36
37
ms_init(int return_to_mode)38 bool ms_init(int return_to_mode)
39 {
40 memset(&ms, 0, sizeof(ms));
41 ms.return_gm = return_to_mode;
42 ms.lastbuttondown = true;
43 ms.w = map.xsize;
44 ms.h = map.ysize;
45
46 ms.x = (SCREEN_WIDTH / 2) - (ms.w / 2);
47 ms.y = (SCREEN_HEIGHT / 2) - (ms.h / 2);
48
49 // where will we put the dot?
50 ms.px = ms.x + ((player->x >> CSF) / TILE_W);
51 ms.py = ms.y + ((player->y >> CSF) / TILE_H);
52
53 ms.bannertext = stages[game.curmap].stagename;
54 ms.textx = (SCREEN_WIDTH / 2) - (GetFontWidth(ms.bannertext, 0) / 2);
55 ms.texty = BANNER_TOP+3;
56
57 return 0;
58 }
59
ms_close(void)60 void ms_close(void)
61 {
62 memset(inputs, 0, sizeof(inputs));
63 }
64
65
66 /*
67 void c------------------------------() {}
68 */
69
ms_tick(void)70 void ms_tick(void)
71 {
72 DrawScene();
73 draw_banner();
74
75 if (ms.state == MS_EXPANDING)
76 {
77 ms.expandframe++;
78
79 if (ms.expandframe > EXPAND_LENGTH)
80 ms.state = MS_DISPLAYED;
81 else
82 draw_expand();
83 }
84
85 if (ms.state == MS_DISPLAYED)
86 {
87
88 // draw map
89 DrawRect(ms.x - 1, ms.y - 1, ms.x + ms.w, ms.y + ms.h, DK_BLUE);
90
91 FillRect(ms.x - 1, ms.y - 1, ms.x + ms.w, ms.y + ms.h, DK_BLUE);
92 for (int y=0;y<ms.current_row;y++)
93 {
94 for(int x=0;x<map.xsize;x++)
95 {
96 int tc = tilecode[map.tiles[x][y]];
97
98 draw_sprite(ms.x+x, ms.y+y, SPR_MAP_PIXELS, get_color(tc));
99 }
100 }
101
102 if (ms.current_row < map.ysize)
103 ms.current_row++;
104 if (ms.current_row < map.ysize)
105 ms.current_row++;
106
107 // you-are-here dot
108 if (++ms.timer & 8)
109 draw_sprite(ms.px, ms.py, SPR_MAP_PIXELS, 4);
110
111 // dismissal
112 if (ms.lastbuttondown)
113 {
114 if (!buttondown())
115 ms.lastbuttondown = false;
116 }
117 else if (buttondown())
118 {
119 ms.state = MS_CONTRACTING;
120 }
121 }
122 else if (ms.state == MS_CONTRACTING)
123 {
124 ms.expandframe--;
125
126 if (ms.expandframe <= 0)
127 {
128 int param = (ms.return_gm == GM_INVENTORY) ? 1 : 0;
129 game.setmode(ms.return_gm, param);
130 }
131 else
132 {
133 draw_expand();
134 }
135 }
136 }
137
138
139
140 // expand/contract effect
draw_expand(void)141 static void draw_expand(void)
142 {
143 int x1, y1, x2, y2;
144
145 int wd = (map.xsize * ms.expandframe) / EXPAND_LENGTH;
146 int ht = (map.ysize * ms.expandframe) / EXPAND_LENGTH;
147
148 x1 = (SCREEN_WIDTH / 2) - (wd / 2);
149 y1 = (SCREEN_HEIGHT / 2) - (ht / 2);
150 x2 = (SCREEN_WIDTH / 2) + (wd / 2);
151 y2 = (SCREEN_HEIGHT / 2) + (ht / 2);
152
153 FillRect(x1, y1, x2, y2, DK_BLUE);
154 }
155
156
draw_banner(void)157 static void draw_banner(void)
158 {
159 FillRect(0, BANNER_TOP, SCREEN_WIDTH, BANNER_BTM, NXColor(0, 0, 0));
160 font_draw(ms.textx, ms.texty, ms.bannertext, 0);
161 }
162
163
164 /*
165 void c------------------------------() {}
166 */
167
168
get_color(int tilecode)169 static int get_color(int tilecode)
170 {
171 switch(tilecode)
172 {
173 case 0:
174 return 0;
175
176 case 0x01:
177 case 0x02:
178 case 0x40:
179 case 0x44:
180 case 0x51:
181 case 0x52:
182 case 0x55:
183 case 0x56:
184 case 0x60:
185 case 0x71:
186 case 0x72:
187 case 0x75:
188 case 0x76:
189 case 0x80:
190 case 0x81:
191 case 0x82:
192 case 0x83:
193 case 0xA0:
194 case 0xA1:
195 case 0xA2:
196 case 0xA3:
197 return 1;
198
199 case 0x43:
200 case 0x50:
201 case 0x53:
202 case 0x54:
203 case 0x57:
204 case 0x63:
205 case 0x70:
206 case 0x73:
207 case 0x74:
208 case 0x77:
209 return 2;
210
211 default:
212 return 3;
213 }
214 }
215
216
217