***********************************************************/
#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)
{
SleepWhileUnmapped();
break;
case ButtonPress:
- HandleButtonEvent((XButtonEvent *) &event);
- break;
case ButtonRelease:
HandleButtonEvent((XButtonEvent *) &event);
break;
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;
else /* got no event, but don't be lazy... */
{
HandleNoXEvent();
- Delay(10000); /* don't use all CPU time when idle */
- }
- XSync(display,FALSE);
+ /* don't use all CPU time when idle; the main loop while playing
+ has its own synchronization and is CPU friendly, too */
- if (game_status==EXITGAME)
+ if (game_status != PLAYING)
+ {
+ XSync(display, FALSE);
+ Delay(10);
+ }
+ }
+
+ if (game_status == EXITGAME)
return;
}
}
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;
case MapNotify:
window_unmapped = FALSE;
break;
+ case ClientMessage:
+ HandleClientMessageEvent((XClientMessageEvent *) &event);
+ break;
default:
break;
}
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;
- for(xx=0;xx<SCR_FIELDX;xx++)
- for(yy=0;yy<SCR_FIELDY;yy++)
+ 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);
+ DrawAllPlayers();
+
+ SetDrawtoField(DRAW_DIRECT);
+ }
+
+ if (soft_scrolling_on && game_status == PLAYING)
+ {
+ int fx = FX, fy = FY;
+
+ fx += (local_player->MovDir & (MV_LEFT|MV_RIGHT) ? ScreenMovPos : 0);
+ fy += (local_player->MovDir & (MV_UP|MV_DOWN) ? ScreenMovPos : 0);
+
+ XCopyArea(display,fieldbuffer,backbuffer,gc,
+ fx,fy, SXSIZE,SYSIZE,
+ SX,SY);
}
+ XCopyArea(display,drawto,window,gc, x,y, width,height, x,y);
+
XFlush(display);
}
HandleKey(key, key_status);
}
-void HandleFocusEvent(int focus_status)
+void HandleFocusEvent(XFocusChangeEvent *event)
{
static int old_joystick_status = -1;
- if (focus_status==FOCUS_OUT)
+ if (event->type == FocusOut)
{
XAutoRepeatOn(display);
old_joystick_status = joystick_status;
joystick_status = JOYSTICK_OFF;
+ key_joystick_mapping = 0;
}
- else
+ else if (event->type == FocusIn)
{
if (game_status == PLAYING)
XAutoRepeatOff(display);
}
}
+void HandleClientMessageEvent(XClientMessageEvent *event)
+{
+ if ((event->window == window) &&
+ (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE)))
+ CloseAll();
+}
+
void HandleButton(int mx, int my, int button)
{
static int old_mx = 0, old_my = 0;
HandleGameButtons(mx,my,button);
}
+#ifdef DEBUG
+ if (game_status == PLAYING && !button)
+ {
+ int sx = (mx - SX) / TILEX;
+ int sy = (my - SY) / TILEY;
+
+ if (IN_SCR_FIELD(sx,sy))
+ {
+ int x = LEVELX(sx);
+ int y = LEVELY(sy);
+
+ printf("INFO: Feld[%d][%d] == %d\n", x,y, Feld[x][y]);
+ printf(" Store[%d][%d] == %d\n", x,y, Store[x][y]);
+ printf(" Store2[%d][%d] == %d\n", x,y, Store2[x][y]);
+ printf(" StorePlayer[%d][%d] == %d\n", x,y, StorePlayer[x][y]);
+ printf(" MovPos[%d][%d] == %d\n", x,y, MovPos[x][y]);
+ printf(" MovDir[%d][%d] == %d\n", x,y, MovDir[x][y]);
+ printf(" MovDelay[%d][%d] == %d\n", x,y, MovDelay[x][y]);
+ printf("\n");
+ }
+ }
+#endif
+
switch(game_status)
{
case MAINMENU:
HandleSetupScreen(mx,my,0,0,button);
break;
case PLAYING:
- HandleGameActions();
+ HandleGameActions(0);
break;
default:
break;
}
}
-int Gamespeed = 4;
-int Movemethod = 0;
-int Movespeed[2] = { 10, 3 };
-
void HandleKey(KeySym key, int key_status)
{
int joy = 0;
case XK_KP_Left:
#endif
case XK_KP_4:
+#ifndef MSDOS
case XK_J:
+#endif
case XK_j:
joy |= JOY_LEFT;
break;
case XK_KP_Right:
#endif
case XK_KP_6:
+#ifndef MSDOS
case XK_K:
+#endif
case XK_k:
joy |= JOY_RIGHT;
break;
case XK_KP_Up:
#endif
case XK_KP_8:
+#ifndef MSDOS
case XK_I:
+#endif
case XK_i:
joy |= JOY_UP;
break;
case XK_KP_Down:
#endif
case XK_KP_2:
+#ifndef MSDOS
case XK_M:
+#endif
case XK_m:
joy |= JOY_DOWN;
break;
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;
key_joystick_mapping &= ~joy;
HandleJoystick();
-
- if (game_status != PLAYING)
- key_joystick_mapping = 0;
}
+ if (game_status != PLAYING)
+ key_joystick_mapping = 0;
+
if (key_status == KEY_RELEASED)
return;
+ if (key==XK_Return && game_status==PLAYING && AllPlayersGone)
+ {
+ CloseDoor(DOOR_CLOSE_1);
+ game_status = MAINMENU;
+ DrawMainMenu();
+ return;
+ }
+
if (key==XK_Escape && game_status!=MAINMENU) /* quick quit to MAINMENU */
{
CloseDoor(DOOR_CLOSE_1 | DOOR_NO_DELAY);
case XK_7:
case XK_8:
case XK_9:
- Movespeed[Movemethod] = (Movemethod == 0 ? 4 : 0) + (key - XK_0);
- printf("method == %d, speed == %d\n",
- Movemethod, Movespeed[Movemethod]);
+ if (key == XK_0)
+ GameFrameDelay = 500;
+ else
+ GameFrameDelay = (key - XK_0) * 10;
+ printf("Game speed == %d%% (%d ms delay between two frames)\n",
+ GAME_FRAME_DELAY * 100 / GameFrameDelay, GameFrameDelay);
break;
case XK_a:
- Movemethod = !Movemethod;
- printf("method == %d, speed == %d\n",
- Movemethod, Movespeed[Movemethod]);
+ if (ScrollStepSize == TILEX/8)
+ ScrollStepSize = TILEX/4;
+ else
+ ScrollStepSize = TILEX/8;
+ printf("ScrollStepSize == %d\n", ScrollStepSize);
break;
case XK_f:
- Gamespeed = 2;
- printf("gamespeed == %d\n", Gamespeed);
+ ScrollStepSize = TILEX/8;
+ printf("ScrollStepSize == %d (1/8)\n", ScrollStepSize);
break;
case XK_g:
- Gamespeed = 3;
- printf("gamespeed == %d\n", Gamespeed);
+ ScrollStepSize = TILEX/4;
+ printf("ScrollStepSize == %d (1/4)\n", ScrollStepSize);
break;
case XK_h:
- Gamespeed = 4;
- printf("gamespeed == %d\n", Gamespeed);
+ ScrollStepSize = TILEX/2;
+ printf("ScrollStepSize == %d (1/2)\n", ScrollStepSize);
break;
case XK_l:
- Gamespeed = 10;
- printf("gamespeed == %d\n", Gamespeed);
+ ScrollStepSize = TILEX;
+ printf("ScrollStepSize == %d (1/1)\n", ScrollStepSize);
break;
+#ifndef MSDOS
case XK_Q:
+#endif
case XK_q:
- Dynamite = 1000;
+ local_player->dynamite = 1000;
break;
-#endif
case XK_x:
- /*
+
{
- int i,j,k, num_steps = 4, step_size = TILEX / num_steps;
+ 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;
- for(i=0;i<10;i++)
+ 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;
-
- XCopyArea(display,backbuffer,window,gc,
- REAL_SX+xxx,REAL_SY,
- FULL_SXSIZE-xxx,FULL_SYSIZE,
- REAL_SX,REAL_SY);
- XCopyArea(display,backbuffer,window,gc,
- REAL_SX,REAL_SY,
- xxx,FULL_SYSIZE,
- REAL_SX+FULL_SXSIZE-xxx,REAL_SY);
-
- XFlush(display);
- XSync(display,FALSE);
- Delay(120000 / num_steps);
+ 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(1);
+ }
+ }
+
+ /*
+ Delay(160 / num_steps);
+ */
+ /*
+ Delay(120 / 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(1000);
+ }
*/
+
+ printf("direct_draw_on == %d\n", direct_draw_on);
+
+ break;
+
+ case XK_z:
+ {
+ int i;
+
+ for(i=0; i<MAX_PLAYERS; i++)
+ {
+ printf("Player %d:\n", i);
+ printf(" jx == %d, jy == %d\n",
+ stored_player[i].jx, stored_player[i].jy);
+ printf(" last_jx == %d, last_jy == %d\n",
+ stored_player[i].last_jx, stored_player[i].last_jy);
+ }
+ printf("\n");
+ }
+
break;
+#endif
default:
break;
void HandleNoXEvent()
{
- if (button_status && game_status!=PLAYING)
+ if (button_status && game_status != PLAYING)
{
HandleButton(-1,-1,button_status);
return;
break;
case PLAYING:
HandleJoystick();
- HandleGameActions();
+
+ /*
+ HandleGameActions(0);
+ */
+
break;
default:
break;
int up = joy & JOY_UP;
int down = joy & JOY_DOWN;
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 dx = (left ? -1 : right ? 1 : 0);
int dy = (up ? -1 : down ? 1 : 0);
static long joystickmove_delay = 0;
if (joystick && !button && !DelayReached(&joystickmove_delay,15))
- break;
+ newbutton = dx = dy = 0;
if (game_status==MAINMENU)
HandleMainMenu(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
HandleSetupScreen(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
break;
}
+
case HALLOFFAME:
HandleHallOfFame(!newbutton);
break;
+
case HELPSCREEN:
HandleHelpScreen(!newbutton);
break;
- case PLAYING:
- {
- BOOL moved = FALSE, snapped = FALSE, bombed = FALSE;
-
- if (tape.pausing)
- joy = 0;
- if (!joy)
- {
- DigField(0,0,0,0,DF_NO_PUSH);
- SnapField(0,0);
- break;
- }
+ case PLAYING:
+ if (tape.playing || keyboard)
+ newbutton = ((joy & JOY_BUTTON) != 0);
- if (GameOver && newbutton)
+ if (AllPlayersGone && newbutton)
{
CloseDoor(DOOR_CLOSE_1);
game_status = MAINMENU;
return;
}
- 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 */
+ if (tape.pausing || AllPlayersGone)
+ joy = 0;
+ HandleGameActions(joy);
break;
- }
+
default:
break;
}