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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
/*
* xrick/scr_getname.c
*
* Copyright (C) 1998-2002 BigOrno (bigorno@bigorno.net).
* Copyright (C) 2008-2014 Pierluigi Vicinanza.
* All rights reserved.
*
* The use and distribution terms for this software are contained in the file
* named README, which can be found in the root of this distribution. By
* using this software in any fashion, you are agreeing to be bound by the
* terms of this license.
*
* You must not remove this notice, or any other, from this software.
*/
#include "xrick/screens.h"
#include "xrick/game.h"
#include "xrick/draw.h"
#include "xrick/control.h"
#include "xrick/data/pics.h"
#include "xrick/system/system.h"
/*
* local vars
*/
static U8 seq = 0;
static U8 x, y, p;
static U8 player_name[HISCORE_NAME_SIZE];
#define TILE_POINTER '\072'
#define TILE_CURSOR '\073'
#define TOPLEFT_X 116
#define TOPLEFT_Y 64
#define NAMEPOS_X 120
#define NAMEPOS_Y 160
#define AUTOREPEAT_TMOUT 100
/*
* prototypes
*/
static void pointer_show(bool);
static void name_update(void);
static void name_draw(void);
/*
* Get name
*
* return: 0 while running, 1 when finished.
*/
U8
screen_getname(void)
{
static U32 tm = 0;
U8 i, j;
if (seq == 0)
{
/* figure out if this is a high score */
if (game_score < screen_highScores[screen_nbr_hiscores - 1].score)
return SCREEN_DONE;
/* prepare */
draw_tilesBank = 0;
#ifdef GFXPC
draw_filter = 0xffff;
#endif
for (i = 0; i < HISCORE_NAME_SIZE; i++)
{
player_name[i] = '@';
}
x = 5, y = 4, p = 0;
game_rects = &draw_SCREENRECT;
seq = 1;
}
switch (seq)
{
case 1: /* prepare screen */
{
sysvid_clear();
#ifdef GFXPC
draw_setfb(32, 8);
draw_filter = 0xaaaa; /* red */
draw_tilesListImm(screen_congrats);
#endif
#ifdef GFXST
draw_pic(pic_congrats);
#endif
draw_setfb(72, 40);
#ifdef GFXPC
draw_filter = 0xffff; /* yellow */
#endif
draw_tilesListImm((U8 *)"PLEASE@ENTER@YOUR@NAME\376");
#ifdef GFXPC
draw_filter = 0x5555; /* green */
#endif
for (i = 0; i < 6; i++)
{
for (j = 0; j < 4; j++)
{
draw_setfb(TOPLEFT_X + i * 8 * 2, TOPLEFT_Y + j * 8 * 2);
draw_tile('A' + i + j * 6);
}
}
draw_setfb(TOPLEFT_X, TOPLEFT_Y + 64);
#ifdef GFXST
draw_tilesListImm((U8 *)"Y@Z@.@@@\074\373\374\375\376");
#endif
#ifdef GFXPC
draw_tilesListImm((U8 *)"Y@Z@.@@@\074@\075@\376");
#endif
name_draw();
pointer_show(true);
seq = 2;
break;
}
case 2: /* wait for key pressed */
{
if (control_test(Control_FIRE))
seq = 3;
if (control_test(Control_UP)) {
if (y > 0) {
pointer_show(false);
y--;
pointer_show(true);
tm = sys_gettime();
}
seq = 4;
}
if (control_test(Control_DOWN)) {
if (y < 4) {
pointer_show(false);
y++;
pointer_show(true);
tm = sys_gettime();
}
seq = 5;
}
if (control_test(Control_LEFT)) {
if (x > 0) {
pointer_show(false);
x--;
pointer_show(true);
tm = sys_gettime();
}
seq = 6;
}
if (control_test(Control_RIGHT)) {
if (x < 5) {
pointer_show(false);
x++;
pointer_show(true);
tm = sys_gettime();
}
seq = 7;
}
break;
}
case 3: /* wait for FIRE released */
{
if (!(control_test(Control_FIRE)))
{
if (x == 5 && y == 4)
{ /* end */
i = 0;
while (game_score < screen_highScores[i].score) i++;
j = 7;
while (j > i)
{
screen_highScores[j].score = screen_highScores[j - 1].score;
for (x = 0; x < HISCORE_NAME_SIZE; x++)
{
screen_highScores[j].name[x] = screen_highScores[j - 1].name[x];
}
j--;
}
screen_highScores[i].score = game_score;
for (x = 0; x < HISCORE_NAME_SIZE; x++)
{
screen_highScores[i].name[x] = player_name[x];
}
seq = 99;
}
else
{
name_update();
name_draw();
seq = 2;
}
}
break;
}
case 4: /* wait for UP released */
{
if (!(control_test(Control_UP)) ||
sys_gettime() - tm > AUTOREPEAT_TMOUT)
seq = 2;
break;
}
case 5: /* wait for DOWN released */
{
if (!(control_test(Control_DOWN)) ||
sys_gettime() - tm > AUTOREPEAT_TMOUT)
seq = 2;
break;
}
case 6: /* wait for LEFT released */
{
if (!(control_test(Control_LEFT)) ||
sys_gettime() - tm > AUTOREPEAT_TMOUT)
seq = 2;
break;
}
case 7: /* wait for RIGHT released */
{
if (!(control_test(Control_RIGHT)) ||
sys_gettime() - tm > AUTOREPEAT_TMOUT)
seq = 2;
break;
}
}
if (control_test(Control_EXIT)) /* check for exit request */
return SCREEN_EXIT;
if (seq == 99) { /* seq 99, we're done */
sysvid_clear();
seq = 0;
return SCREEN_DONE;
}
else
return SCREEN_RUNNING;
}
static void
pointer_show(bool show)
{
draw_setfb(TOPLEFT_X + x * 8 * 2, TOPLEFT_Y + y * 8 * 2 + 8);
#ifdef GFXPC
draw_filter = 0xaaaa; /* red */
#endif
draw_tile(show? TILE_POINTER:'@');
}
static void
name_update(void)
{
U8 i;
i = x + y * 6;
if (i < 26 && p < 10)
player_name[p++] = 'A' + i;
if (i == 26 && p < 10)
player_name[p++] = '.';
if (i == 27 && p < 10)
player_name[p++] = '@';
if (i == 28 && p > 0) {
p--;
}
}
static void
name_draw(void)
{
U8 i;
draw_setfb(NAMEPOS_X, NAMEPOS_Y);
#ifdef GFXPC
draw_filter = 0xaaaa; /* red */
#endif
for (i = 0; i < p; i++)
draw_tile(player_name[i]);
for (i = p; i < 10; i++)
draw_tile(TILE_CURSOR);
#ifdef GFXST
draw_setfb(NAMEPOS_X, NAMEPOS_Y + 8);
for (i = 0; i < 10; i++)
draw_tile('@');
draw_setfb(NAMEPOS_X + 8 * (p < 9 ? p : 9), NAMEPOS_Y + 8);
draw_tile(TILE_POINTER);
#endif
}
/* eof */
|