added support for suicide key for BD game engine
authorHolger Schemel <holger.schemel@virtion.de>
Tue, 3 Dec 2024 18:56:19 +0000 (19:56 +0100)
committerHolger Schemel <holger.schemel@virtion.de>
Tue, 3 Dec 2024 13:56:59 +0000 (14:56 +0100)
src/events.c
src/files.c
src/game_bd/bd_gameplay.c
src/game_bd/bd_gameplay.h
src/game_bd/main_bd.c
src/libgame/system.h

index 3117dc8837df9415977401a68c36e396b76a677f..80c15c2e16c089ed71101312bca42fe99813b4a0 100644 (file)
@@ -2191,6 +2191,10 @@ void HandleKey(Key key, int key_status)
            tape.property_bits |= TAPE_PROPERTY_TAS_KEYS;
          }
        }
+
+        // also handle suicide key for the first player only
+        if (key == setup.shortcut.suicide)
+          key_action |= KEY_SUICIDE;
       }
 
       if (key_status == KEY_PRESSED)
index 839d5fb5b3e5ba64fd1211453d0d570e8790c67b..f9eabd786cd95e66e8a184a2970a10cd3cb258aa 100644 (file)
@@ -12040,6 +12040,8 @@ static void setSetupInfoToDefaults(struct SetupInfo *si)
   si->shortcut.speed_fast      = DEFAULT_KEY_SPEED_FAST;
   si->shortcut.speed_slow      = DEFAULT_KEY_SPEED_SLOW;
 
+  si->shortcut.suicide         = DEFAULT_KEY_SUICIDE;
+
   for (i = 0; i < MAX_PLAYERS; i++)
   {
     si->input[i].use_joystick = FALSE;
index 94bdca2b6a2cf828b9c5a521cafeccf158e54277..260d6d4a553f7c8febc8ce7152edc2c6de99a076 100644 (file)
@@ -238,6 +238,8 @@ GdGame *gd_game_new(const int cave, const int level)
   game->player_move = GD_MV_STILL;
   game->player_move_stick = FALSE;
   game->player_fire = FALSE;
+  game->player_suicide = FALSE;
+  game->player_suicide_stick = FALSE;
 
   game->state_counter = GAME_INT_LOAD_CAVE;
 
@@ -253,10 +255,8 @@ boolean check_iteration_reached(GdGame *game)
   return (game->milliseconds_game + millisecs_elapsed >= game->cave->speed);
 }
 
-static void iterate_cave(GdGame *game, GdDirection player_move, boolean fire)
+static void iterate_cave(GdGame *game, GdDirection player_move, boolean fire, boolean suicide)
 {
-  boolean suicide = FALSE;
-
   // ANYTHING EXCEPT A TIMEOUT, WE ITERATE THE CAVE
   if (game->cave->player_state != GD_PL_TIMEOUT)
   {
@@ -270,6 +270,7 @@ static void iterate_cave(GdGame *game, GdDirection player_move, boolean fire)
 
        player_move = ((action_bd & GD_REPLAY_MOVE_MASK));
        fire        = ((action_bd & GD_REPLAY_FIRE_MASK)    != 0);
+       suicide     = ((action_bd & GD_REPLAY_SUICIDE_MASK) != 0);
       }
     }
 
@@ -470,7 +471,7 @@ static GdGameState gd_game_main_int(GdGame *game, boolean allow_iterate, boolean
       // reset cycle frame counter for the next cave iteration
       game->itercycle = 0;
 
-      iterate_cave(game, game->player_move, game->player_fire);
+      iterate_cave(game, game->player_move, game->player_fire, game->player_suicide);
 
       game->cycle_counter++;
 
@@ -484,6 +485,16 @@ static GdGameState gd_game_main_int(GdGame *game, boolean allow_iterate, boolean
        game->player_move = GD_MV_STILL;
       }
 
+      if (game->player_suicide == FALSE)
+      {
+       game->player_suicide_stick = FALSE;
+      }
+      else
+      {
+       game->player_suicide_stick = TRUE;
+       game->player_suicide = FALSE;
+      }
+
       // as we iterated, the score and the like could have been changed.
       return_state = GD_GAME_LABELS_CHANGED;
 
@@ -660,6 +671,7 @@ void play_game_func(GdGame *game, int action)
   boolean move_left  = ((action & JOY_LEFT)    != 0);
   boolean move_right = ((action & JOY_RIGHT)   != 0);
   boolean fire       = ((action & JOY_BUTTON)  != 0);
+  boolean suicide    = ((action & KEY_SUICIDE) != 0);
 
   if (game->player_move_stick || move_up || move_down || move_left || move_right) // no "fire"!
   {
@@ -675,6 +687,9 @@ void play_game_func(GdGame *game, int action)
   if (game->player_move == GD_MV_STILL)
     game->player_fire = fire;
 
+  if (game->player_suicide_stick || suicide)
+    game->player_suicide = suicide;
+
   // tell the interrupt "20ms has passed"
   state = gd_game_main_int(game, !game->out_of_window, FALSE);
 
index 490ffa7e253ae6157714cd5893ebf869899f055f..adbb37a32585f20a516353fb0ca904f60d785975 100644 (file)
@@ -62,6 +62,8 @@ typedef struct _gd_game
   GdDirection player_move;
   boolean player_move_stick;
   boolean player_fire;
+  boolean player_suicide;
+  boolean player_suicide_stick;
 
   GdCave *cave;                 // Copy of the cave. This is the iterated, changed (ruined...) one
   GdCave *original_cave;        // original cave from caveset. used to record highscore
index fdf7afafc9579916994eab8bae9c744e964798a0..488837b85ad28aa580467dcd0dd1d60b5eb69474 100644 (file)
@@ -203,14 +203,16 @@ int map_action_RND_to_BD(int action)
                                                       action & JOY_LEFT,
                                                       action & JOY_RIGHT);
   int player_fire    = ((action & JOY_BUTTON)  != 0 ? GD_REPLAY_FIRE_MASK    : 0);
+  int player_suicide = ((action & KEY_SUICIDE) != 0 ? GD_REPLAY_SUICIDE_MASK : 0);
 
-  return (player_move | player_fire);
+  return (player_move | player_fire | player_suicide);
 }
 
 int map_action_BD_to_RND(int action)
 {
   GdDirection player_move    = ((action & GD_REPLAY_MOVE_MASK));
   boolean     player_fire    = ((action & GD_REPLAY_FIRE_MASK)    != 0);
+  boolean     player_suicide = ((action & GD_REPLAY_SUICIDE_MASK) != 0);
 
   int action_move = (player_move == GD_MV_UP           ? JOY_UP                :
                     player_move == GD_MV_UP_RIGHT      ? JOY_UP   | JOY_RIGHT  :
@@ -221,8 +223,9 @@ int map_action_BD_to_RND(int action)
                     player_move == GD_MV_LEFT          ?            JOY_LEFT   :
                     player_move == GD_MV_UP_LEFT       ? JOY_UP   | JOY_LEFT   : JOY_NO_ACTION);
   int action_fire    = (player_fire    ? JOY_BUTTON_1 : JOY_NO_ACTION);
+  int action_suicide = (player_suicide ? KEY_SUICIDE  : JOY_NO_ACTION);
 
-  return (action_move | action_fire);
+  return (action_move | action_fire | action_suicide);
 }
 
 boolean checkGameRunning_BD(void)
index a903ad099802e8ed5c340890d105ec713d42c329..a74ed1550d434acacb80210a3f87e3c4bdaf8652 100644 (file)
 #define DEFAULT_KEY_SNAP_DOWN          KSYM_UNDEFINED
 #define DEFAULT_KEY_SPEED_FAST         KSYM_f
 #define DEFAULT_KEY_SPEED_SLOW         KSYM_s
+#define DEFAULT_KEY_SUICIDE            KSYM_F12
 
 // default debug setup keys and values
 #define DEFAULT_FRAME_DELAY_0          20              // 100 % speed
 
 #define NUM_PLAYER_ACTIONS             6
 
-// values for special "focus player" bitmasks
+// values for special "focus player" and "suicide" bitmasks
 #define BIT_SET_FOCUS                  6
+#define BIT_SUICIDE                    7
 
 // values for drawing stages for global animations
 #define DRAW_GLOBAL_ANIM_STAGE_1       1
 #define KEY_ACTION                     (KEY_MOTION | KEY_BUTTON)
 
 #define KEY_SET_FOCUS                  (1 << BIT_SET_FOCUS)
+#define KEY_SUICIDE                    (1 << BIT_SUICIDE)
 
 #define MV_DIR_FROM_BIT(x)             ((x) < NUM_DIRECTIONS ? 1 << (x) :        \
                                         (x) == MV_BIT_UPLEFT    ? MV_UPLEFT    : \
@@ -1435,6 +1438,8 @@ struct SetupShortcutInfo
 
   Key speed_fast;
   Key speed_slow;
+
+  Key suicide;
 };
 
 struct SetupSystemInfo