Subversion Repositories Games.Rick Dangerous

Rev

Rev 9 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 pmbaty 1
/*
2
 * src/scr_getname.c
3
 *
4
 * Copyright (C) 1998-2002 BigOrno (bigorno@bigorno.net). All rights reserved.
5
 *
6
 * The use and distribution terms for this software are contained in the file
7
 * named README, which can be found in the root of this distribution. By
8
 * using this software in any fashion, you are agreeing to be bound by the
9
 * terms of this license.
10
 *
11
 * You must not remove this notice, or any other, from this software.
12
 */
13
 
14
#include "system.h"
15
#include "game.h"
16
#include "screens.h"
17
 
18
#include "draw.h"
19
#include "control.h"
20
 
21
/*
22
 * local vars
23
 */
24
static U8 seq = 0;
25
static U8 x, y, p;
26
static U8 name[10];
27
 
28
#define TILE_POINTER '\072'
29
#define TILE_CURSOR '\073'
30
#define TOPLEFT_X 116
31
#define TOPLEFT_Y 64
32
#define NAMEPOS_X 120
33
#define NAMEPOS_Y 160
34
#define AUTOREPEAT_TMOUT 100
35
 
36
 
37
/*
38
 * prototypes
39
 */
40
static void pointer_show (U8);
41
static void name_update (void);
42
static void name_draw (void);
43
 
44
 
45
/*
46
 * Get name
47
 *
48
 * return: 0 while running, 1 when finished.
49
 */
50
U8 screen_getname (void)
51
{
52
   static U32 tm = 0;
53
   U8 i, j;
54
 
55
   if (seq == 0)
56
   {
57
      /* figure out if this is a high score */
58
      if (game_score < game_hscores[7].score)
59
         return SCREEN_DONE;
60
 
61
      /* prepare */
62
      draw_tilesBank = 0;
63
 
64
      for (i = 0; i < 10; i++)
65
         name[i] = '@';
66
 
67
      x = y = p = 0;
68
      game_rects = &draw_SCREENRECT;
69
      seq = 1;
70
   }
71
 
72
   switch (seq)
73
   {
74
   case 1:   /* prepare screen */
75
      sysvid_clear ();
76
      draw_setfb (76, 40);
77
      draw_tilesListImm ((U8 *) "PLEASE@ENTER@YOUR@NAME\376");
78
 
79
      for (i = 0; i < 6; i++)
80
         for (j = 0; j < 4; j++)
81
         {
82
            draw_setfb (TOPLEFT_X + i * 8 * 2, TOPLEFT_Y + j * 8 * 2);
83
            draw_tile ((U8) ('A' + i + j * 6));
84
         }
85
 
86
      draw_setfb (TOPLEFT_X, TOPLEFT_Y + 64);
87
      draw_tilesListImm ((U8 *) "Y@Z@.@@@\074\373\374\375\376");
88
      name_draw ();
89
      pointer_show (TRUE);
90
      seq = 2;
91
 
92
      break;
93
 
94
   case 2:   /* wait for key pressed */
95
      if (control_status & CONTROL_FIRE)
96
         seq = 3;
97
 
98
      if (control_status & CONTROL_UP)
99
      {
100
         if (y > 0)
101
         {
102
            pointer_show (FALSE);
103
            y--;
104
            pointer_show (TRUE);
105
            tm = sys_gettime ();
106
         }
107
         seq = 4;
108
      }
109
 
110
      if (control_status & CONTROL_DOWN)
111
      {
112
         if (y < 4)
113
         {
114
            pointer_show (FALSE);
115
            y++;
116
            pointer_show (TRUE);
117
            tm = sys_gettime ();
118
         }
119
         seq = 5;
120
      }
121
 
122
      if (control_status & CONTROL_LEFT)
123
      {
124
         if (x > 0)
125
         {
126
            pointer_show (FALSE);
127
            x--;
128
            pointer_show (TRUE);
129
            tm = sys_gettime ();
130
         }
131
         seq = 6;
132
      }
133
 
134
      if (control_status & CONTROL_RIGHT)
135
      {
136
         if (x < 5)
137
         {
138
            pointer_show (FALSE);
139
            x++;
140
            pointer_show (TRUE);
141
            tm = sys_gettime ();
142
         }
143
         seq = 7;
144
      }
145
 
146
      if (seq == 2)
147
         sys_sleep (50);
148
 
149
      break;
150
 
151
   case 3:   /* wait for FIRE released */
152
      if (!(control_status & CONTROL_FIRE))
153
      {
154
         if (x == 5 && y == 4)
155
         {
156
            /* end */
157
            i = 0;
158
 
159
            while (game_score < game_hscores[i].score)
160
               i++;
161
 
162
            j = 7;
163
 
164
            while (j > i)
165
            {
166
               game_hscores[j].score = game_hscores[j - 1].score;
167
 
168
               for (x = 0; x < 10; x++)
169
                  game_hscores[j].name[x] = game_hscores[j - 1].name[x];
170
 
171
               j--;
172
            }
173
 
174
            game_hscores[i].score = game_score;
175
 
176
            for (x = 0; x < 10; x++)
177
               game_hscores[i].name[x] = name[x];
178
 
179
            seq = 99;
180
         }
181
         else
182
         {
183
            name_update ();
184
            name_draw ();
185
            seq = 2;
186
         }
187
      }
188
      else
189
         sys_sleep (50);
190
 
191
      break;
192
 
193
   case 4:   /* wait for UP released */
194
      if (!(control_status & CONTROL_UP) || sys_gettime () - tm > AUTOREPEAT_TMOUT)
195
         seq = 2;
196
      else
197
         sys_sleep (50);
198
 
199
      break;
200
 
201
   case 5:   /* wait for DOWN released */
202
      if (!(control_status & CONTROL_DOWN) || sys_gettime () - tm > AUTOREPEAT_TMOUT)
203
         seq = 2;
204
      else
205
         sys_sleep (50);
206
 
207
      break;
208
 
209
   case 6:   /* wait for LEFT released */
210
      if (!(control_status & CONTROL_LEFT) || sys_gettime () - tm > AUTOREPEAT_TMOUT)
211
         seq = 2;
212
      else
213
         sys_sleep (50);
214
 
215
      break;
216
 
217
   case 7:   /* wait for RIGHT released */
218
      if (!(control_status & CONTROL_RIGHT) || sys_gettime () - tm > AUTOREPEAT_TMOUT)
219
         seq = 2;
220
      else
221
         sys_sleep (50);
222
 
223
      break;
224
 
225
   }
226
 
227
   if (control_status & CONTROL_EXIT)   /* check for exit request */
228
      return SCREEN_EXIT;
229
 
230
   if (seq == 99)
231
   {   /* seq 99, we're done */
232
      sysvid_clear ();
233
      seq = 0;
234
      return SCREEN_DONE;
235
   }
236
   else
237
      return SCREEN_RUNNING;
238
}
239
 
240
 
241
static void pointer_show (U8 show)
242
{
243
   draw_setfb (TOPLEFT_X + x * 8 * 2, TOPLEFT_Y + y * 8 * 2 + 8);
244
   draw_tile ((U8) ((show == TRUE) ? TILE_POINTER : '@'));
245
}
246
 
247
 
248
static void name_update (void)
249
{
250
   U8 i;
251
 
252
   i = x + y * 6;
253
 
254
   if (i < 26 && p < 10)
255
      name[p++] = 'A' + i;
256
   if (i == 26 && p < 10)
257
      name[p++] = '.';
258
   if (i == 27 && p < 10)
259
      name[p++] = '@';
260
   if (i == 28 && p > 0)
261
      p--;
262
}
263
 
264
 
265
static void name_draw (void)
266
{
267
   U8 i;
268
 
269
   draw_setfb (NAMEPOS_X, NAMEPOS_Y);
270
   for (i = 0; i < p; i++)
271
      draw_tile (name[i]);
272
   for (i = p; i < 10; i++)
273
      draw_tile (TILE_CURSOR);
274
 
275
   draw_setfb (NAMEPOS_X, NAMEPOS_Y + 8);
276
   for (i = 0; i < 10; i++)
277
      draw_tile ('@');
278
   draw_setfb (NAMEPOS_X + 8 * (p < 9 ? p : 9), NAMEPOS_Y + 8);
279
   draw_tile (TILE_POINTER);
280
}