rnd-19980906
[rocksndiamonds.git] / src / events.c
index 1e8fcd1c37fc53a57a5c5553c3aea5d4ba118e8c..5f85101eb06ef4b6764c38034d140e0620b771f7 100644 (file)
 *               q99492@pbhrzx.uni-paderborn.de             *
 *----------------------------------------------------------*
 *  events.c                                                *
-*                                                          *
-*  Letzte Aenderung: 15.06.1995                            *
 ***********************************************************/
 
 #include "events.h"
+#include "init.h"
 #include "screens.h"
 #include "tools.h"
 #include "game.h"
 #include "editor.h"
+#include "misc.h"
+#include "tape.h"
+#include "joystick.h"
 
 void EventLoop(void)
 {
@@ -39,8 +41,6 @@ void EventLoop(void)
          SleepWhileUnmapped();
          break;
        case ButtonPress:
-         HandleButtonEvent((XButtonEvent *) &event);
-         break;
        case ButtonRelease:
          HandleButtonEvent((XButtonEvent *) &event);
          break;
@@ -48,16 +48,15 @@ void EventLoop(void)
          HandleMotionEvent((XMotionEvent *) &event);
          break;
        case KeyPress:
-         HandleKeyEvent((XKeyEvent *) &event);
-         break;
        case KeyRelease:
          HandleKeyEvent((XKeyEvent *) &event);
          break;
        case FocusIn:
-         HandleFocusEvent(FOCUS_IN);
-         break;
        case FocusOut:
-         HandleFocusEvent(FOCUS_OUT);
+         HandleFocusEvent((XFocusChangeEvent *) &event);
+         break;
+        case ClientMessage:
+         HandleClientMessageEvent((XClientMessageEvent *) &event);
          break;
        default:
          break;
@@ -66,11 +65,11 @@ void EventLoop(void)
     else                       /* got no event, but don't be lazy... */
     {
       HandleNoXEvent();
-
-      if (game_status!=PLAYING)
-       Delay(10000);           /* don't use all CPU time when idle */
+      Delay(1000);             /* don't use all CPU time when idle */
     }
 
+    XSync(display,FALSE);
+
     if (game_status==EXITGAME)
       return;
   }
@@ -96,13 +95,14 @@ void ClearEventQueue()
        button_status = MB_RELEASED;
        break;
       case KeyRelease:
-       key_status = KEY_RELEASED;
+       key_joystick_mapping = 0;
        break;
       case FocusIn:
-       HandleFocusEvent(FOCUS_IN);
-       break;
       case FocusOut:
-       HandleFocusEvent(FOCUS_OUT);
+       HandleFocusEvent((XFocusChangeEvent *) &event);
+       break;
+      case ClientMessage:
+       HandleClientMessageEvent((XClientMessageEvent *) &event);
        break;
       default:
        break;
@@ -131,11 +131,14 @@ void SleepWhileUnmapped()
        button_status = MB_RELEASED;
        break;
       case KeyRelease:
-       key_status = KEY_RELEASED;
+       key_joystick_mapping = 0;
        break;
       case MapNotify:
        window_unmapped = FALSE;
        break;
+      case ClientMessage:
+       HandleClientMessageEvent((XClientMessageEvent *) &event);
+       break;
       default:
        break;
     }
@@ -150,21 +153,30 @@ void HandleExposeEvent(XExposeEvent *event)
   int x = event->x, y = event->y;
   int width = event->width, height = event->height;
 
-  XCopyArea(display,drawto,window,gc, x,y, width,height, x,y);
-
   if (direct_draw_on && game_status==PLAYING)
   {
     int xx,yy;
     int x1 = (x-SX)/TILEX, y1 = (y-SY)/TILEY;
     int x2 = (x-SX+width)/TILEX, y2 = (y-SY+height)/TILEY;
 
+    SetDrawtoField(DRAW_BACKBUFFER);
+
     for(xx=0;xx<SCR_FIELDX;xx++)
       for(yy=0;yy<SCR_FIELDY;yy++)
        if (xx>=x1 && xx<=x2 && yy>=y1 && yy<=y2)
          DrawScreenField(xx,yy);
-    DrawLevelElement(JX,JY,EL_SPIELFIGUR);
+    DrawPlayerField();
+
+    SetDrawtoField(DRAW_DIRECT);
   }
 
+  if (soft_scrolling_on && game_status==PLAYING)
+    XCopyArea(display,fieldbuffer,backbuffer,gc,
+             FX,FY, SXSIZE,SYSIZE,
+             SX,SY);
+
+  XCopyArea(display,drawto,window,gc, x,y, width,height, x,y);
+
   XFlush(display);
 }
 
@@ -189,34 +201,38 @@ void HandleMotionEvent(XMotionEvent *event)
 
 void HandleKeyEvent(XKeyEvent *event)
 {
-  static KeySym old_keycode = 0;
-  int new_keycode = event->keycode;
-  KeySym new_key = XLookupKeysym(event,event->state);
-  int new_key_status = (event->type==KeyPress ? KEY_PRESSED : KEY_RELEASED);
+  int key_status = (event->type == KeyPress ? KEY_PRESSED : KEY_RELEASED);
+  unsigned int event_state = (game_status != PLAYING ? event->state : 0);
+  KeySym key = XLookupKeysym(event, event_state);
 
-  if (game_status==PLAYING &&
-      (old_keycode!=new_keycode || key_status!=new_key_status))
+  HandleKey(key, key_status);
+}
+
+void HandleFocusEvent(XFocusChangeEvent *event)
+{
+  static int old_joystick_status = -1;
+
+  if (event->type == FocusOut)
   {
-    DigField(0,0,DF_NO_PUSH);
-    SnapField(0,0);
+    XAutoRepeatOn(display);
+    old_joystick_status = joystick_status;
+    joystick_status = JOYSTICK_OFF;
+    key_joystick_mapping = 0;
   }
-
-  if (event->type==KeyPress)
+  else if (event->type == FocusIn)
   {
-    key_status = KEY_PRESSED;
-    HandleKey(new_key);
-    old_keycode = new_keycode;
+    if (game_status == PLAYING)
+      XAutoRepeatOff(display);
+    if (old_joystick_status != -1)
+      joystick_status = old_joystick_status;
   }
-  else if (key_status==KEY_PRESSED && old_keycode==new_keycode)
-    key_status = KEY_RELEASED;
 }
 
-void HandleFocusEvent(int focus_status)
+void HandleClientMessageEvent(XClientMessageEvent *event)
 {
-  if (focus_status==FOCUS_OUT)
-    XAutoRepeatOn(display);
-  else if (game_status==PLAYING)
-    XAutoRepeatOff(display);
+  if ((event->window == window) &&
+      (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE)))
+    CloseAll();
 }
 
 void HandleButton(int mx, int my, int button)
@@ -262,41 +278,163 @@ void HandleButton(int mx, int my, int button)
       HandleSetupScreen(mx,my,0,0,button);
       break;
     case PLAYING:
-      if (!LevelSolved)
-      {
-       switch(GameActions(mx,my,button))
-       {
-         case ACT_GAME_OVER:
-           game_status = MAINMENU;
-           DrawMainMenu();
-           BackToFront();
-           break;
-         case ACT_NEW_GAME:
-           game_status = PLAYING;
-           InitGame();
-           break;
-         case ACT_GO_ON:
-           break;
-         default:
-           break;
-       }
-      }
-      BackToFront();
-      Delay(10000);
+      HandleGameActions();
       break;
     default:
       break;
   }
 }
 
-void HandleKey(KeySym key)
+int GameSpeed = 2;
+int MoveSpeed = 8;
+
+void HandleKey(KeySym key, int key_status)
 {
-  static KeySym old_key = 0;
+  int joy = 0;
 
-  if (!key)
-    key = old_key;
-  else
-    old_key = key;
+  /* Map cursor keys to joystick directions */
+
+  switch(key)
+  {
+    case XK_Left:              /* normale Richtungen */
+#ifdef XK_KP_Left
+    case XK_KP_Left:
+#endif
+    case XK_KP_4:
+#ifndef MSDOS
+    case XK_J:
+#endif
+    case XK_j:
+      joy |= JOY_LEFT;
+      break;
+    case XK_Right:
+#ifdef XK_KP_Right
+    case XK_KP_Right:
+#endif
+    case XK_KP_6:
+#ifndef MSDOS
+    case XK_K:
+#endif
+    case XK_k:
+      joy |= JOY_RIGHT;
+      break;
+    case XK_Up:
+#ifdef XK_KP_Up
+    case XK_KP_Up:
+#endif
+    case XK_KP_8:
+#ifndef MSDOS
+    case XK_I:
+#endif
+    case XK_i:
+      joy |= JOY_UP;
+      break;
+    case XK_Down:
+#ifdef XK_KP_Down
+    case XK_KP_Down:
+#endif
+    case XK_KP_2:
+#ifndef MSDOS
+    case XK_M:
+#endif
+    case XK_m:
+      joy |= JOY_DOWN;
+      break;
+#ifdef XK_KP_Home
+    case XK_KP_Home:           /* Diagonalrichtungen */
+#endif
+    case XK_KP_7:
+      joy |= JOY_UP | JOY_LEFT;
+      break;
+#ifdef XK_KP_Page_Up
+    case XK_KP_Page_Up:
+#endif
+    case XK_KP_9:
+      joy = JOY_UP | JOY_RIGHT;
+      break;
+#ifdef XK_KP_End
+    case XK_KP_End:
+#endif
+    case XK_KP_1:
+      joy |= JOY_DOWN | JOY_LEFT;
+      break;
+#ifdef XK_KP_Page_Down
+    case XK_KP_Page_Down:
+#endif
+    case XK_KP_3:
+      joy |= JOY_DOWN | JOY_RIGHT;
+      break;
+#ifndef MSDOS
+    case XK_S:                 /* Feld entfernen */
+#endif
+    case XK_s:
+      joy |= JOY_BUTTON_1 | JOY_LEFT;
+      break;
+#ifndef MSDOS
+    case XK_D:
+#endif
+    case XK_d:
+      joy |= JOY_BUTTON_1 | JOY_RIGHT;
+      break;
+#ifndef MSDOS
+    case XK_E:
+#endif
+    case XK_e:
+      joy |= JOY_BUTTON_1 | JOY_UP;
+      break;
+#ifndef MSDOS
+    case XK_X:
+#endif
+    case XK_x:
+      joy |= JOY_BUTTON_1 | JOY_DOWN;
+      break;
+    case XK_Shift_L:           /* Linker Feuerknopf */
+#ifndef MSDOS
+    case XK_Control_L:
+    case XK_Alt_L:
+    case XK_Meta_L:
+#endif
+      joy |= JOY_BUTTON_1;
+      break;
+    case XK_Shift_R:           /* Rechter Feuerknopf */
+#ifndef MSDOS
+    case XK_Control_R:
+    case XK_Alt_R:
+    case XK_Meta_R:
+    case XK_Mode_switch:
+    case XK_Multi_key:
+    case XK_B:                 /* (Bombe legen) */
+#endif
+    case XK_b:
+      joy |= JOY_BUTTON_2;
+      break;
+    default:
+      break;
+  }
+
+  if (joy)
+  {
+    if (key_status == KEY_PRESSED)
+      key_joystick_mapping |= joy;
+    else
+      key_joystick_mapping &= ~joy;
+
+    HandleJoystick();
+  }
+
+  if (game_status != PLAYING)
+    key_joystick_mapping = 0;
+
+  if (key_status == KEY_RELEASED)
+    return;
+
+  if (key==XK_Return && game_status==PLAYING && GameOver)
+  {
+    CloseDoor(DOOR_CLOSE_1);
+    game_status = MAINMENU;
+    DrawMainMenu();
+    return;
+  }
 
   if (key==XK_Escape && game_status!=MAINMENU) /* quick quit to MAINMENU */
   {
@@ -318,8 +456,6 @@ void HandleKey(KeySym key)
     case CHOOSELEVEL:
     case SETUP:
     {
-      int dx = 0, dy = 0;
-
       switch(key)
       {
        case XK_Return:
@@ -330,55 +466,9 @@ void HandleKey(KeySym key)
          else if (game_status==SETUP)
            HandleSetupScreen(0,0,0,0,MB_MENU_CHOICE);
          break;
-       case XK_Left:
-#ifdef XK_KP_Left
-       case XK_KP_Left:
-#endif
-       case XK_KP_4:
-       case XK_J:
-       case XK_j:
-         dx = -1;
-         break;
-       case XK_Right:
-#ifdef XK_KP_Right
-       case XK_KP_Right:
-#endif
-       case XK_KP_6:
-       case XK_K:
-       case XK_k:
-         dx = 1;
-         break;
-       case XK_Up:
-#ifdef XK_KP_Up
-       case XK_KP_Up:
-#endif
-       case XK_KP_8:
-       case XK_I:
-       case XK_i:
-         dy = -1;
-         break;
-       case XK_Down:
-#ifdef XK_KP_Down
-       case XK_KP_Down:
-#endif
-       case XK_KP_2:
-       case XK_M:
-       case XK_m:
-         dy = 1;
-         break;
        default:
          break;
       }
-
-      if (dx || dy)
-      {
-       if (game_status==MAINMENU)
-         HandleMainMenu(0,0,dx,dy,MB_MENU_MARK);
-        else if (game_status==CHOOSELEVEL)
-          HandleChooseLevel(0,0,dx,dy,MB_MENU_MARK);
-       else if (game_status==SETUP)
-         HandleSetupScreen(0,0,dx,dy,MB_MENU_MARK);
-      }
       break;
     }
     case HELPSCREEN:
@@ -401,128 +491,133 @@ void HandleKey(KeySym key)
       break;
     case PLAYING:
     {
-      int mvx = 0, mvy = 0;
-      int sbx = 0, sby = 0;
-      int joy = 0;
-      BOOL bomb = FALSE;
-      BOOL moved = FALSE, snapped = FALSE, bombed = FALSE;
-
       switch(key)
       {
-       case XK_Left:           /* normale Richtungen */
-#ifdef XK_KP_Left
-       case XK_KP_Left:
-#endif
-       case XK_KP_4:
-       case XK_J:
-       case XK_j:
-         mvx = -1;
-         joy = JOY_LEFT;
-         break;
-       case XK_Right:
-#ifdef XK_KP_Right
-       case XK_KP_Right:
-#endif
-       case XK_KP_6:
-       case XK_K:
-       case XK_k:
-         mvx = 1;
-         joy = JOY_RIGHT;
-         break;
-       case XK_Up:
-#ifdef XK_KP_Up
-       case XK_KP_Up:
-#endif
-       case XK_KP_8:
-       case XK_I:
-       case XK_i:
-         mvy = -1;
-         joy = JOY_UP;
-         break;
-       case XK_Down:
-#ifdef XK_KP_Down
-       case XK_KP_Down:
-#endif
-       case XK_KP_2:
-       case XK_M:
-       case XK_m:
-         mvy = 1;
-         joy = JOY_DOWN;
-         break;
-#ifdef XK_KP_Home
-       case XK_KP_Home:        /* Diagonalrichtungen */
-#endif
-       case XK_KP_7:
-         mvx = -1;
-         mvy = -1;
-         joy = JOY_UP | JOY_LEFT;
-         break;
-#ifdef XK_KP_Page_Up
-       case XK_KP_Page_Up:
-#endif
-       case XK_KP_9:
-         mvx = 1;
-         mvy = -1;
-         joy = JOY_UP | JOY_RIGHT;
-         break;
-#ifdef XK_KP_End
-       case XK_KP_End:
-#endif
-       case XK_KP_1:
-         mvx = -1;
-         mvy = 1;
-         joy = JOY_DOWN | JOY_LEFT;
-         break;
-#ifdef XK_KP_Page_Down
-       case XK_KP_Page_Down:
+
+#ifdef DEBUG
+       case XK_0:
+       case XK_1:
+       case XK_2:
+       case XK_3:
+       case XK_4:
+       case XK_5:
+       case XK_6:
+       case XK_7:
+       case XK_8:
+       case XK_9:
+         if (key == XK_0)
+           GameSpeed = 50;
+         else
+           GameSpeed = key - XK_0;
+         printf("GameSpeed == %d\n", GameSpeed);
+         break;
+
+       case XK_a:
+         if (ScrollStepSize == TILEX/8)
+           ScrollStepSize = TILEX/4;
+         else
+           ScrollStepSize = TILEX/8;
+         printf("ScrollStepSize == %d\n", ScrollStepSize);
+         break;
+
+       case XK_f:
+         ScrollStepSize = TILEX/8;
+         printf("ScrollStepSize == %d (1/8)\n", ScrollStepSize);
+         break;
+       case XK_g:
+         ScrollStepSize = TILEX/4;
+         printf("ScrollStepSize == %d (1/4)\n", ScrollStepSize);
+         break;
+       case XK_h:
+         ScrollStepSize = TILEX/2;
+         printf("ScrollStepSize == %d (1/2)\n", ScrollStepSize);
+         break;
+       case XK_l:
+         ScrollStepSize = TILEX;
+         printf("ScrollStepSize == %d (1/1)\n", ScrollStepSize);
+         break;
+
+#ifndef MSDOS
+       case XK_Q:
 #endif
-       case XK_KP_3:
-         mvx = 1;
-         mvy = 1;
-         joy = JOY_DOWN | JOY_RIGHT;
-         break;
-       case XK_S:              /* Feld entfernen */
-       case XK_s:
-         sbx = -1;
-         joy = JOY_BUTTON_1 | JOY_LEFT;
-         break;
-       case XK_D:
-       case XK_d:
-         sbx = 1;
-         joy = JOY_BUTTON_1 | JOY_RIGHT;
-         break;
-       case XK_E:
-       case XK_e:
-         sby = -1;
-         joy = JOY_BUTTON_1 | JOY_UP;
+       case XK_q:
+         Dynamite = 1000;
          break;
-       case XK_X:
+
        case XK_x:
-         sby = 1;
-         joy = JOY_BUTTON_1 | JOY_DOWN;
-         break;
-       case XK_B:              /* Bombe legen */
-       case XK_b:
-         bomb = TRUE;
-         joy = JOY_BUTTON_2;
-         break;
-       case XK_Q:
-         Dynamite = 1000;
+
+         {
+           int i,j,k, num_steps = 8, step_size = TILEX / num_steps;
+           static long scroll_delay=0;
+           long scroll_delay_value = 4*4 / num_steps;
+
+           printf("Scroll test\n");
+
+           for(i=0;i<3;i++)
+           {
+             for(j=0;j<SCR_FIELDX;j++)
+             {
+               for(k=0;k<num_steps;k++)
+               {
+                 int xxx = j*TILEX+k*step_size;
+                 int done = 0;
+
+                 while(!done)
+                 {
+                   if (DelayReached(&scroll_delay, scroll_delay_value))
+                   {
+                     XCopyArea(display,fieldbuffer,window,gc,
+                               SX+xxx,SY,
+                               SXSIZE-xxx,SYSIZE,
+                               SX,SY);
+                     XCopyArea(display,fieldbuffer,window,gc,
+                               SX,SY,
+                               xxx,SYSIZE,
+                               SX+SXSIZE-xxx,SY);
+  
+                     XFlush(display);
+                     XSync(display,FALSE);
+
+                     done = 1;
+                   }
+                   else
+                   {
+                     Delay(1000);
+                   }
+                 }
+  
+                 /*
+                 Delay(160000 / num_steps);
+                 */
+                 /*
+                 Delay(120000 / num_steps);
+                 */
+               }
+             }
+           }
+         }
+
+         break;
+
+       case XK_y:
+         {
+           printf("FX = %d, FY = %d\n", FX,FY);
+
+           XCopyArea(display,fieldbuffer,window,gc,
+                     0,0,
+                     MIN(WIN_XSIZE,FXSIZE),MIN(WIN_YSIZE,FYSIZE),
+                     0,0);
+           XFlush(display);
+           XSync(display,FALSE);
+           Delay(1000000);
+         }
+
          break;
+#endif
+
        default:
          break;
       }
-
-      if (mvx || mvy)
-       moved = MoveFigure(mvx,mvy);
-      else if (sbx || sby)
-       snapped = SnapField(sbx,sby);
-      else if (bomb)
-       bombed = PlaceBomb();
-
-      if (tape.recording && (moved || snapped || bombed))
-       TapeRecordAction(joy);
-
       break;
     }
     default:
@@ -532,7 +627,7 @@ void HandleKey(KeySym key)
 
 void HandleNoXEvent()
 {
-  if (button_status)
+  if (button_status && game_status != PLAYING)
   {
     HandleButton(-1,-1,button_status);
     return;
@@ -549,33 +644,7 @@ void HandleNoXEvent()
       break;
     case PLAYING:
       HandleJoystick();
-      if (key_status)
-       HandleKey(0);
-      if (game_status!=PLAYING)
-       break;
-
-      if (!LevelSolved)
-      {
-       switch(GameActions(0,0,MB_NOT_PRESSED))
-       {
-         case ACT_GAME_OVER:
-           game_status = MAINMENU;
-           DrawMainMenu();
-           BackToFront();
-           break;
-         case ACT_NEW_GAME:
-           game_status = PLAYING;
-           InitGame();
-           break;
-         case ACT_GO_ON:
-           break;
-         default:
-           break;
-       }
-      }
-
-      Delay(10000);
-
+      HandleGameActions();
       break;
     default:
       break;
@@ -584,7 +653,9 @@ void HandleNoXEvent()
 
 void HandleJoystick()
 {
-  int joy      = Joystick();
+  int joystick = Joystick();
+  int keyboard = key_joystick_mapping;
+  int joy      = (tape.playing ? TapePlayAction() : (joystick | keyboard));
   int left     = joy & JOY_LEFT;
   int right    = joy & JOY_RIGHT;
   int up       = joy & JOY_UP;
@@ -592,10 +663,12 @@ void HandleJoystick()
   int button   = joy & JOY_BUTTON;
   int button1  = joy & JOY_BUTTON_1;
   int button2  = joy & JOY_BUTTON_2;
-  int newbutton        = (JoystickButton()==JOY_BUTTON_NEW_PRESSED);
+  int newbutton        = (JoystickButton() == JOY_BUTTON_NEW_PRESSED);
+  int dx       = (left ? -1    : right ? 1     : 0);
+  int dy       = (up   ? -1    : down  ? 1     : 0);
 
-  if (button_status || key_status)
-    return;
+  if (game_status==PLAYING && (tape.playing || keyboard))
+    newbutton = ((joy & JOY_BUTTON) != 0);
 
   switch(game_status)
   {
@@ -603,20 +676,10 @@ void HandleJoystick()
     case CHOOSELEVEL:
     case SETUP:
     {
-      int dx = 0, dy = 0;
       static long joystickmove_delay = 0;
 
-      if (DelayReached(&joystickmove_delay,15) || button)
-      {
-       if (left)
-         dx = -1;
-       else if (right)
-         dx = 1;
-       if (up)
-         dy = -1;
-       else if (down)
-         dy = 1;
-      }
+      if (joystick && !button && !DelayReached(&joystickmove_delay,15))
+       newbutton = dx = dy = 0;
 
       if (game_status==MAINMENU)
        HandleMainMenu(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
@@ -634,31 +697,9 @@ void HandleJoystick()
       break;
     case PLAYING:
     {
-      int mvx = 0, mvy = 0;
       BOOL moved = FALSE, snapped = FALSE, bombed = FALSE;
 
-      if (tape.playing)
-      {
-       joy     = TapePlayAction();
-
-       left    = joy & JOY_LEFT;
-       right   = joy & JOY_RIGHT;
-       up      = joy & JOY_UP;
-       down    = joy & JOY_DOWN;
-       button  = joy & JOY_BUTTON;
-       button1 = joy & JOY_BUTTON_1;
-       button2 = joy & JOY_BUTTON_2;
-      }
-      else if (tape.pausing)
-       joy = 0;
-
-      if (!joy)
-      {
-       DigField(0,0,DF_NO_PUSH);
-       break;
-      }
-
-      if ((GameOver || LevelSolved) && newbutton)
+      if (GameOver && newbutton)
       {
        CloseDoor(DOOR_CLOSE_1);
        game_status = MAINMENU;
@@ -666,33 +707,59 @@ void HandleJoystick()
        return;
       }
 
-      if (left)
-       mvx = -1;
-      else if (right)
-       mvx = 1;
-      if (up)
-       mvy = -1;
-      else if (down)
-       mvy = 1;
-
-      if (button1)
-       snapped = SnapField(mvx,mvy);
+      if (tape.pausing || PlayerGone)
+       joy = 0;
+
+      if (joy)
+      {
+       if (button1)
+         snapped = SnapField(dx,dy);
+       else
+       {
+         if (button2)
+           bombed = PlaceBomb();
+         moved = MoveFigure(dx,dy);
+       }
+
+       if (tape.recording && (moved || snapped || bombed))
+       {
+         if (bombed && !moved)
+           joy &= JOY_BUTTON;
+         TapeRecordAction(joy);
+       }
+       else if (tape.playing && snapped)
+         SnapField(0,0);                       /* stop snapping */
+      }
       else
       {
-       if (button2)
-         bombed = PlaceBomb();
-       moved = MoveFigure(mvx,mvy);
+       DigField(0,0,0,0,DF_NO_PUSH);
+       SnapField(0,0);
+       PlayerFrame = 0;
       }
 
-      if (tape.recording && (moved || snapped || bombed))
+      if (tape.playing && !tape.pausing && !joy && tape.counter<tape.length)
       {
-       if (bombed && !moved)
-         joy &= JOY_BUTTON;
-       TapeRecordAction(joy);
-      }
-      else if (tape.playing && snapped)
-       SnapField(0,0);
+       int next_joy =
+         tape.pos[tape.counter].joystickdata & (JOY_LEFT|JOY_RIGHT);
 
+       if (next_joy == JOY_LEFT || next_joy == JOY_RIGHT)
+       {
+         int dx = (next_joy == JOY_LEFT ? -1 : +1);
+
+         if (IN_LEV_FIELD(JX+dx,JY) && IS_PUSHABLE(Feld[JX+dx][JY]))
+         {
+           int el = Feld[JX+dx][JY];
+           int push_delay = (IS_SB_ELEMENT(el) || el==EL_SONDE ? 2 : 10);
+
+           if (tape.delay_played + push_delay >= tape.pos[tape.counter].delay)
+           {
+             PlayerMovDir = next_joy;
+             PlayerFrame = FrameCounter % 4;
+             PlayerPushing = TRUE;
+           }
+         }
+       }
+      }
       break;
     }
     default: