1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-98 Artsoft Entertainment *
8 * phone: ++49 +521 290471 *
9 * email: aeglos@valinor.owl.de *
10 *----------------------------------------------------------*
12 ***********************************************************/
22 #if defined(PLATFORM_MSDOS)
29 DrawWindow window = None;
30 GC gc, clip_gc[NUM_BITMAPS], tile_clip_gc;
31 Bitmap pix[NUM_BITMAPS];
32 Bitmap pix_masked[NUM_BITMAPS], tile_masked[NUM_TILES];
33 Pixmap clipmask[NUM_BITMAPS], tile_clipmask[NUM_TILES];
35 DrawBuffer drawto, drawto_field, backbuffer, fieldbuffer;
38 char *sound_device_name = SOUND_DEVICE;
40 int joystick_device = 0;
41 char *joystick_device_name[MAX_PLAYERS] =
49 char *program_name = NULL;
51 int game_status = MAINMENU;
52 boolean level_editor_test_game = FALSE;
53 boolean network_playing = FALSE;
54 int button_status = MB_NOT_PRESSED;
55 boolean motion_status = FALSE;
56 int key_joystick_mapping = 0;
57 int global_joystick_status = JOYSTICK_STATUS;
58 int joystick_status = JOYSTICK_STATUS;
59 boolean fullscreen_available = FULLSCREEN_STATUS;
60 boolean fullscreen_enabled = FALSE;
62 boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
63 int redraw_x1 = 0, redraw_y1 = 0;
67 short Feld[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
68 short Ur[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
69 short MovPos[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
70 short MovDir[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
71 short MovDelay[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
72 short Store[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
73 short Store2[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
74 short StorePlayer[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
75 short Frame[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
76 boolean Stop[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
77 short JustStopped[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
78 short AmoebaNr[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
79 short AmoebaCnt[MAX_NUM_AMOEBA], AmoebaCnt2[MAX_NUM_AMOEBA];
80 unsigned long Elementeigenschaften1[MAX_ELEMENTS];
81 unsigned long Elementeigenschaften2[MAX_ELEMENTS];
84 int lev_fieldx,lev_fieldy, scroll_x,scroll_y;
86 int FX = SX, FY = SY, ScrollStepSize;
87 int ScreenMovDir = MV_NO_MOVING, ScreenMovPos = 0;
89 int BorderElement = EL_BETON;
90 int GameFrameDelay = GAME_FRAME_DELAY;
91 int FfwdFrameDelay = FFWD_FRAME_DELAY;
92 int BX1 = 0, BY1 = 0, BX2 = SCR_FIELDX-1, BY2 = SCR_FIELDY-1;
93 int SBX_Left, SBX_Right;
94 int SBY_Upper, SBY_Lower;
95 int ZX,ZY, ExitX,ExitY;
97 int FrameCounter, TimeFrames, TimePlayed, TimeLeft;
99 boolean network_player_action_received = FALSE;
101 struct LevelDirInfo *leveldir_first = NULL, *leveldir_current = NULL;
102 struct LevelInfo level;
103 struct PlayerInfo stored_player[MAX_PLAYERS], *local_player = NULL;
104 struct HiScore highscore[MAX_SCORE_ENTRIES];
105 struct SampleInfo Sound[NUM_SOUNDS];
106 struct TapeInfo tape;
107 struct OptionInfo options;
108 struct SetupInfo setup;
109 struct GameInfo game;
110 struct SystemInfo sysinfo;
111 struct GlobalInfo global;
113 /* data needed for playing sounds */
114 char *sound_name[NUM_SOUNDS] =
180 /* background music */
181 int background_loop[] =
191 int num_bg_loops = sizeof(background_loop)/sizeof(int);
193 char *element_info[] =
195 "empty space", /* 0 */
205 "spaceship", /* 10 */
212 "quicksand with rock",
215 "magic wall", /* 20 */
225 "magic wheel", /* 30 */
235 "gray door (opened by red key)", /* 40 */
236 "gray door (opened by yellow key)",
237 "gray door (opened by green key)",
238 "gray door (opened by blue key)",
241 "invisible normal wall",
243 "ligh bulb (glowing)",
245 "wall with diamond", /* 50 */
246 "amoeba with content",
251 "diamond (BD style)",
253 "wall with BD style diamond",
254 "wall with yellow emerald",
255 "dark yam yam", /* 60 */
256 "magic wall (BD style)",
257 "invisible steel wall",
259 "increases number of bombs",
260 "increases explosion size",
261 "increases power of explosion",
263 "sokoban empty field",
264 "sokoban field with object",
265 "butterfly (starts moving right)", /* 70 */
266 "butterfly (starts moving up)",
267 "butterfly (starts moving left)",
268 "butterfly (starts moving down)",
269 "firefly (starts moving right)",
270 "firefly (starts moving up)",
271 "firefly (starts moving left)",
272 "firefly (starts moving down)",
275 "yellow player", /* 80 */
279 "bug (starts moving right)",
280 "bug (starts moving up)",
281 "bug (starts moving left)",
282 "bug (starts moving down)",
283 "spaceship (starts moving right)",
284 "spaceship (starts moving up)",
285 "spaceship (starts moving left)", /* 90 */
286 "spaceship (starts moving down)",
287 "pac man (starts moving right)",
288 "pac man (starts moving up)",
289 "pac man (starts moving left)",
290 "pac man (starts moving down)",
293 "wall with red emerald",
294 "wall with violet emerald",
300 "normal wall (BD style)",
313 "fire breathing dragon",
315 "letter ' '", /* 120 */
325 "letter '*'", /* 130 */
335 "letter '4'", /* 140 */
345 "letter '>'", /* 150 */
355 "letter 'H'", /* 160 */
365 "letter 'R'", /* 170 */
375 "letter 'Ö'", /* 180 */
385 "letter ''", /* 190 */
395 "growing wall (horizontal)", /* 200 */
396 "growing wall (vertical)",
397 "growing wall (all directions)",
405 "empty space", /* 210 */
414 "port (leading right)",
415 "port (leading down)", /* 220 */
416 "port (leading left)",
418 "port (leading right)",
419 "port (leading down)",
420 "port (leading left)",
425 "red disk", /* 230 */
428 "port (all directions)",
435 "hardware", /* 240 */
458 "white door", /* 260 */
459 "gray door (opened by white key)",
463 "switch gate (open)",
464 "switch gate (closed)",
465 "switch for switch gate",
466 "switch for switch gate",
469 "red conveyor belt (left)",
470 "red conveyor belt (middle)",
471 "red conveyor belt (right)",
472 "switch for red conveyor belt (left)",
473 "switch for red conveyor belt (middle)",
474 "switch for red conveyor belt (right)",
475 "yellow conveyor belt (left)",
476 "yellow conveyor belt (middle)",
477 "yellow conveyor belt (right)",
478 "switch for yellow conveyor belt (left)", /* 280 */
479 "switch for yellow conveyor belt (middle)",
480 "switch for yellow conveyor belt (right)",
481 "green conveyor belt (left)",
482 "green conveyor belt (middle)",
483 "green conveyor belt (right)",
484 "switch for green conveyor belt (left)",
485 "switch for green conveyor belt (middle)",
486 "switch for green conveyor belt (right)",
487 "blue conveyor belt (left)",
488 "blue conveyor belt (middle)", /* 290 */
489 "blue conveyor belt (right)",
490 "switch for blue conveyor belt (left)",
491 "switch for blue conveyor belt (middle)",
492 "switch for blue conveyor belt (right)",
495 "light switch (off)",
497 "sign (exclamation)",
498 "sign (radio activity)", /* 300 */
500 "sign (wheel chair)",
508 "sign (other)", /* 310 */
509 "mole (starts moving left)",
510 "mole (starts moving right)",
511 "mole (starts moving up)",
512 "mole (starts moving down)",
513 "steel wall (slanted)",
519 "shield (active, kills enemies)",
521 "time gate (closed)",
522 "switch for time gate",
523 "switch for time gate",
525 "send balloon to the left",
526 "send balloon to the right",
528 "send balloon down", /* 330 */
529 "send balloon in any direction",
538 "normal wall", /* 340 */
542 "tube (all directions)",
545 "tube (vertical & left)",
546 "tube (vertical & right)",
547 "tube (horizontal & up)",
548 "tube (horizontal & down)", /* 350 */
550 "tube (left & down)",
552 "tube (right & down)",
555 "stable bomb (DX style)",
559 "-------------------------------",
562 int num_element_info = sizeof(element_info)/sizeof(char *);
566 /* +-----------------------------------------------------------------------+ */
567 /* | SDL TEST STUFF | */
568 /* +-----------------------------------------------------------------------+ */
570 #if defined(TARGET_SDL)
572 SDL_Surface *sdl_screen, *sdl_image_tmp, *sdl_image, *sdl_image_masked;
573 SDL_Surface *sdl_image2_tmp, *sdl_image2, *sdl_image2_masked;
575 void TEST_SDL_BLIT_RECT(int x, int y)
577 SDL_Rect rect_src, rect_dst;
579 SDLCopyArea(pix_masked[PIX_HEROES], window,
580 8 * TILEX, 8 * TILEY, TILEX, TILEY, x, y);
583 rect_src.x = 8 * TILEX;
584 rect_src.y = 8 * TILEY;
593 SDL_BlitSurface(sdl_image2_masked, &rect_src, sdl_screen, &rect_dst);
594 SDL_UpdateRect(sdl_screen, x, y, TILEX, TILEY);
597 void TEST_SDL_INIT_DISPLAY()
599 SDL_Rect rect_src, rect_dst;
601 if (SDL_Init(SDL_INIT_VIDEO) < 0)
603 fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
607 /* automatically cleanup SDL stuff after exit() */
610 if ((sdl_screen = SDL_SetVideoMode(WIN_XSIZE, WIN_YSIZE, 16, SDL_HWSURFACE))
613 fprintf(stderr, "SDL_SetVideoMode() failed: %s\n", SDL_GetError());
617 SDL_WM_SetCaption(WINDOW_TITLE_STRING, WINDOW_TITLE_STRING);
619 if ((sdl_image_tmp = IMG_Load("graphics/RocksScreen.pcx")) == NULL)
621 fprintf(stderr, "IMG_Load() failed: %s\n", SDL_GetError());
625 sdl_image = SDL_DisplayFormat(sdl_image_tmp);
627 SDL_SetColorKey(sdl_image_tmp, SDL_SRCCOLORKEY,
628 SDL_MapRGB(sdl_image_tmp->format, 0x00, 0x00, 0x00));
629 sdl_image_masked = SDL_DisplayFormat(sdl_image_tmp);
631 SDL_FreeSurface(sdl_image_tmp);
633 if ((sdl_image2_tmp = IMG_Load("graphics/RocksHeroes.pcx")) == NULL)
635 fprintf(stderr, "IMG_Load() failed: %s\n", SDL_GetError());
639 sdl_image2 = SDL_DisplayFormat(sdl_image2_tmp);
640 SDL_FreeSurface(sdl_image2_tmp);
642 sdl_image2_masked = SDL_DisplayFormat(sdl_image2);
643 SDL_SetColorKey(sdl_image2_masked, SDL_SRCCOLORKEY,
644 SDL_MapRGB(sdl_image2_masked->format, 0x00, 0x00, 0x00));
648 rect_src.w = sdl_image->w;
649 rect_src.h = sdl_image->h;
653 rect_dst.w = sdl_image->w;
654 rect_dst.h = sdl_image->h;
656 SDL_BlitSurface(sdl_image, &rect_src, sdl_screen, &rect_dst);
659 SDL_UpdateRect(sdl_screen, 0, 0, WIN_XSIZE, WIN_YSIZE);
662 SDL_UpdateRect(sdl_screen, 0, 0, 0, 0);
664 SDL_Flip(sdl_screen);
671 void TEST_SDL_EVENT_LOOP()
675 SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
678 while (!quit_loop && SDL_WaitEvent(&event) >=0)
685 if (SDL_PollEvent(&event))
687 /* hier werden die Ereignisse behandelt */
696 case SDL_MOUSEBUTTONDOWN:
698 int x = event.button.x;
699 int y = event.button.y;
701 SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);
703 TEST_SDL_BLIT_RECT(x, y);
705 printf("SDL_MOUSEBUTTONDOWN(%d, %d)\n", x, y);
709 case SDL_MOUSEBUTTONUP:
711 int x = event.button.x;
712 int y = event.button.y;
714 SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
716 printf("SDL_MOUSEBUTTONUP(%d, %d)\n", x, y);
720 case SDL_MOUSEMOTION:
722 int x = event.motion.x;
723 int y = event.motion.y;
725 TEST_SDL_BLIT_RECT(x, y);
727 printf("SDL_MOUSEMOTION(%d, %d)\n", x, y);
736 if (!SDL_PollEvent(NULL)) /* delay only if no pending events */
738 printf("waiting...\n");
743 SDL_FreeSurface(sdl_image);
747 #define SCREEN_WIDTH 640
748 #define SCREEN_HEIGHT 480
750 void WatchJoysticks()
757 SDL_Rect axis_area[2];
759 SDL_Joystick *joystick = Get_SDL_Joystick(joystick_nr);
761 /* Set a video mode to display joystick axis position */
762 screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16, 0);
763 if ( screen == NULL ) {
764 fprintf(stderr, "Couldn't set video mode: %s\n",SDL_GetError());
768 /* Print info about the joysticks we are watching */
771 joystick = Get_SDL_Joystick(i);
773 name = SDL_JoystickName(i);
774 printf("Watching joystick %d: (%s)\n", i,
775 name ? name : "Unknown Joystick");
776 printf("Joystick has %d axes, %d hats, %d balls, and %d buttons\n",
777 SDL_JoystickNumAxes(joystick),
778 SDL_JoystickNumHats(joystick),
779 SDL_JoystickNumBalls(joystick),
780 SDL_JoystickNumButtons(joystick));
783 /* Initialize drawing rectangles */
784 memset(axis_area, 0, (sizeof axis_area));
787 /* Loop, getting joystick events! */
790 while ( SDL_PollEvent(&event) ) {
791 switch (event.type) {
792 case SDL_JOYAXISMOTION:
793 joystick_nr = event.jaxis.which;
794 printf("Joystick %d axis %d value: %d\n",
799 case SDL_JOYHATMOTION:
800 joystick_nr = event.jaxis.which;
801 printf("Joystick %d hat %d value:",
804 if ( event.jhat.value == SDL_HAT_CENTERED )
806 if ( event.jhat.value & SDL_HAT_UP )
808 if ( event.jhat.value & SDL_HAT_RIGHT )
810 if ( event.jhat.value & SDL_HAT_DOWN )
812 if ( event.jhat.value & SDL_HAT_LEFT )
816 case SDL_JOYBALLMOTION:
817 joystick_nr = event.jaxis.which;
818 printf("Joystick %d ball %d delta: (%d,%d)\n",
824 case SDL_JOYBUTTONDOWN:
825 joystick_nr = event.jaxis.which;
826 printf("Joystick %d button %d down\n",
828 event.jbutton.button);
830 case SDL_JOYBUTTONUP:
831 joystick_nr = event.jaxis.which;
832 printf("Joystick %d button %d up\n",
834 event.jbutton.button);
837 if ( event.key.keysym.sym != SDLK_ESCAPE ) {
840 /* Fall through to signal quit */
849 joystick = Get_SDL_Joystick(joystick_nr);
851 /* Update visual joystick state */
852 for ( i=0; i<SDL_JoystickNumButtons(joystick); ++i ) {
856 area.y = SCREEN_HEIGHT-34;
859 if (SDL_JoystickGetButton(joystick, i) == SDL_PRESSED) {
860 SDL_FillRect(screen, &area, 0xFFFF);
862 SDL_FillRect(screen, &area, 0x0000);
864 SDL_UpdateRects(screen, 1, &area);
867 /* Erase previous axes */
868 SDL_FillRect(screen, &axis_area[draw], 0x0000);
870 /* Draw the X/Y axis */
872 x = (((int)SDL_JoystickGetAxis(joystick, 0))+32768);
878 if ( x > (SCREEN_WIDTH-16) ) {
881 y = (((int)SDL_JoystickGetAxis(joystick, 1))+32768);
887 if ( y > (SCREEN_HEIGHT-16) ) {
888 y = SCREEN_HEIGHT-16;
890 axis_area[draw].x = (Sint16)x;
891 axis_area[draw].y = (Sint16)y;
892 axis_area[draw].w = 16;
893 axis_area[draw].h = 16;
894 SDL_FillRect(screen, &axis_area[draw], 0xFFFF);
896 SDL_UpdateRects(screen, 2, axis_area);
900 void TEST_SDL_JOYSTICK()
905 /* Initialize SDL (Note: video is required to start event loop) */
906 if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) < 0 )
908 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
912 /* Print information about the joysticks */
913 printf("There are %d joysticks attached\n", SDL_NumJoysticks());
914 for ( i=0; i<SDL_NumJoysticks(); ++i )
916 name = SDL_JoystickName(i);
917 printf("Joystick %d: %s\n",i,name ? name : "Unknown Joystick");
922 if (!Open_SDL_Joystick(i))
923 printf("Couldn't open joystick %d: %s\n", i, SDL_GetError());
929 Close_SDL_Joystick(i);
931 SDL_QuitSubSystem(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK);
934 #endif /* TARGET_SDL */
936 /* +-----------------------------------------------------------------------+ */
937 /* | SDL TEST STUFF | */
938 /* +-----------------------------------------------------------------------+ */
942 int main(int argc, char *argv[])
944 program_name = (strrchr(argv[0],'/') ? strrchr(argv[0],'/') + 1 : argv[0]);
946 #if defined(PLATFORM_MSDOS)
958 TEST_SDL_BLIT_RECT((WIN_XSIZE - TILEX)/2, (WIN_YSIZE - TILEY)/2);
959 TEST_SDL_EVENT_LOOP();
968 exit(0); /* to keep compilers happy */