Subversion Repositories Games.Rick Dangerous

Rev

Rev 10 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 10 Rev 11
Line 9... Line 9...
9
 * terms of this license.
9
 * terms of this license.
10
 *
10
 *
11
 * You must not remove this notice, or any other, from this software.
11
 * You must not remove this notice, or any other, from this software.
12
 */
12
 */
13
 
13
 
14
#include <SDL.h>
14
#include <SDL2/SDL.h>
-
 
15
#include <string.h>
-
 
16
#include <ctype.h>
15
 
17
 
16
#include "system.h"
18
#include "system.h"
17
#include "game.h"
19
#include "game.h"
18
 
20
 
19
#include "control.h"
21
#include "control.h"
20
#include "draw.h"
22
#include "draw.h"
21
 
23
 
22
#define SYSJOY_RANGE 3280
24
#define SYSJOY_RANGE 3280
-
 
25
 
-
 
26
static char character_ringbuffer[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
-
 
27
static int character_ringbuffer_index = 0;
-
 
28
extern U8 want_infinitelives;
-
 
29
extern U8 want_infiniteammo;
23
 
30
 
24
static SDL_Event event;
31
static SDL_Event event;
25
extern U8 want_filter;
32
extern U8 want_filter;
26
extern U8 want_fullscreen;
33
extern U8 want_fullscreen;
27
extern U8 enable_endkey;
34
extern U8 enable_endkey;
28
extern U8 recreate_screen;
35
extern U8 recreate_screen;
-
 
36
 
-
 
37
 
-
 
38
static U8 has_accumulated (const char *str)
-
 
39
{
-
 
40
   int len = (int) strlen (str);
-
 
41
   for (int i = 0; i < len; i++)
-
 
42
      if (character_ringbuffer[(sizeof (character_ringbuffer) + character_ringbuffer_index - len + i) % 16] != str[i])
-
 
43
         return 0;
-
 
44
   return 1;
-
 
45
}
29
 
46
 
30
 
47
 
31
/*
48
/*
32
 * Process an event
49
 * Process an event
33
 */
50
 */
Line 50... Line 67...
50
      else if (alt_pressed && key == SDL_SCANCODE_F4)
67
      else if (alt_pressed && key == SDL_SCANCODE_F4)
51
      {
68
      {
52
         control_status |= CONTROL_EXIT;
69
         control_status |= CONTROL_EXIT;
53
         control_last = CONTROL_EXIT;
70
         control_last = CONTROL_EXIT;
54
      }
71
      }
55
      else if (key == SDL_SCANCODE_O || key == SDL_SCANCODE_UP)
72
      else if ((key == SDL_SCANCODE_O || key == SDL_SCANCODE_UP) && !has_accumulated ("MAT") && !has_accumulated ("MATOSGRAT") && !has_accumulated (";QT") && !has_accumulated (";QTOSGRQT"))
56
      {
73
      {
57
         control_status |= CONTROL_UP;
74
         control_status |= CONTROL_UP;
58
         control_last = CONTROL_UP;
75
         control_last = CONTROL_UP;
59
      }
76
      }
60
      else if (key == SDL_SCANCODE_K || key == SDL_SCANCODE_DOWN)
77
      else if (key == SDL_SCANCODE_K || key == SDL_SCANCODE_DOWN)
Line 70... Line 87...
70
      else if (key == SDL_SCANCODE_X || key == SDL_SCANCODE_RIGHT)
87
      else if (key == SDL_SCANCODE_X || key == SDL_SCANCODE_RIGHT)
71
      {
88
      {
72
         control_status |= CONTROL_RIGHT;
89
         control_status |= CONTROL_RIGHT;
73
         control_last = CONTROL_RIGHT;
90
         control_last = CONTROL_RIGHT;
74
      }
91
      }
75
      else if ((key == SDL_SCANCODE_PAUSE) || (key == SDL_SCANCODE_P))
92
      else if (((key == SDL_SCANCODE_PAUSE) || (key == SDL_SCANCODE_P)) && !has_accumulated ("MEME") && !has_accumulated (";E;E"))
76
      {
93
      {
77
         control_status |= CONTROL_PAUSE;
94
         control_status |= CONTROL_PAUSE;
78
         control_last = CONTROL_PAUSE;
95
         control_last = CONTROL_PAUSE;
79
      }
96
      }
80
      else if ((key == SDL_SCANCODE_END) && enable_endkey)
97
      else if ((key == SDL_SCANCODE_END) && enable_endkey)
Line 146... Line 163...
146
      }
163
      }
147
      else if (key == SDL_SCANCODE_SPACE)
164
      else if (key == SDL_SCANCODE_SPACE)
148
      {
165
      {
149
         control_status &= ~CONTROL_FIRE;
166
         control_status &= ~CONTROL_FIRE;
150
         control_last = CONTROL_FIRE;
167
         control_last = CONTROL_FIRE;
-
 
168
      }
-
 
169
      // cheat codes:
-
 
170
      // 'MEMEPASMAL' -> infinite lives
-
 
171
      // 'MATOSGRATOS' -> infinite ammo
-
 
172
      {
-
 
173
         const char *keyname = SDL_GetScancodeName (key);
-
 
174
         character_ringbuffer[character_ringbuffer_index] = toupper (keyname[0]);
-
 
175
         character_ringbuffer_index = (character_ringbuffer_index + 1) % 16;
-
 
176
         if (has_accumulated ("MEMEPASMAL") || has_accumulated (";E;EPQS;QL"))
-
 
177
         {
-
 
178
            want_infinitelives = TRUE;
-
 
179
            game_lives = 6;
-
 
180
            syssnd_play (WAV_DIE, 1);
-
 
181
         }
-
 
182
         else if (has_accumulated ("MATOSGRATOS") || has_accumulated (";QTOSGRQTOS"))
-
 
183
         {
-
 
184
            want_infiniteammo = TRUE;
-
 
185
            game_bullets = 6;
-
 
186
            game_bombs = 6;
-
 
187
            syssnd_play (WAV_DIE, 1);
-
 
188
         }
151
      }
189
      }
152
      break;
190
      break;
153
   case SDL_QUIT:
191
   case SDL_QUIT:
154
      /* player tries to close the window -- this is the same as pressing ESC */
192
      /* player tries to close the window -- this is the same as pressing ESC */
155
      control_status |= CONTROL_EXIT;
193
      control_status |= CONTROL_EXIT;