rnd-20100313-1-src
[rocksndiamonds.git] / src / game_sp / main.c
1
2 #include "main_sp.h"
3 #include "global.h"
4
5
6 struct GameInfo_SP game_sp;
7 struct LevelInfo_SP native_sp_level;
8
9
10 int GfxElementLast[SP_MAX_PLAYFIELD_WIDTH][SP_MAX_PLAYFIELD_HEIGHT];
11 int GfxGraphicLast[SP_MAX_PLAYFIELD_WIDTH][SP_MAX_PLAYFIELD_HEIGHT];
12 int GfxGraphic[SP_MAX_PLAYFIELD_WIDTH][SP_MAX_PLAYFIELD_HEIGHT];
13 int GfxFrame[SP_MAX_PLAYFIELD_WIDTH][SP_MAX_PLAYFIELD_HEIGHT];
14
15
16 void InitGameEngine_SP()
17 {
18   int x, y;
19
20   gfx.anim_random_frame = -1;   // (use simple, ad-hoc random numbers)
21
22   game_sp.LevelSolved = FALSE;
23   game_sp.GameOver = FALSE;
24
25   game_sp.time_played = 0;
26   game_sp.infotrons_still_needed = native_sp_level.header.InfotronsNeeded;
27   game_sp.red_disk_count = 0;
28   game_sp.score = 0;
29
30   menBorder.Checked = setup.sp_show_border_elements;
31
32   for (x = 0; x < SP_MAX_PLAYFIELD_WIDTH; x++)
33   {
34     for (y = 0; y < SP_MAX_PLAYFIELD_HEIGHT; y++)
35     {
36       GfxElementLast[x][y] = -1;
37       GfxGraphicLast[x][y] = -1;
38       GfxGraphic[x][y] = -1;
39       GfxFrame[x][y] = 0;
40     }
41   }
42
43   InitScrollPlayfield();
44
45 #if 0
46   printf(":A: %d, %d [%d, %d]\n",
47          mScrollX, mScrollY, mScrollX_last, mScrollY_last);
48 #endif
49
50 #if 1
51   menPlay_Click();
52 #else
53   menPlayDemo_Click();
54 #endif
55
56 #if 0
57   printf(":B: %d, %d [%d, %d]\n",
58          mScrollX, mScrollY, mScrollX_last, mScrollY_last);
59 #endif
60 }
61
62 #if 0
63 void BlitScreenToBitmap_SP(Bitmap *target_bitmap)
64 {
65   DDScrollBuffer_Blt_Ext(target_bitmap);
66 }
67 #endif
68
69 void RedrawPlayfield_SP(boolean force_redraw)
70 {
71   // subDisplayLevel();
72
73   if (force_redraw)
74     RestorePlayfield();
75
76   UpdatePlayfield(force_redraw);
77
78   BackToFront_SP();
79 }
80
81 void DrawGameDoorValues_SP()
82 {
83 #if 1
84
85   game_sp.time_played = TimerVar / setup.game_frame_delay;
86   game_sp.infotrons_still_needed = InfotronsNeeded;
87   game_sp.red_disk_count = RedDiskCount;
88   game_sp.score = 0;            // (currently no score in Supaplex engine)
89
90 #else
91
92   int infotrons_still_needed = InfotronsNeeded;
93   int red_disks = RedDiskCount;
94   int no_score_in_supaplex = 0;
95 #if 1
96   int level_time_played = TimerVar / setup.game_frame_delay;
97 #else
98   int level_time_played = TimerVar / 35;        /* !!! CHECK THIS !!! */
99 #endif
100   int no_keys_in_supaplex = 0;
101
102   DrawAllGameValues(infotrons_still_needed, red_disks, no_score_in_supaplex,
103                     level_time_played, no_keys_in_supaplex);
104 #endif
105 }
106
107 void GameActions_SP(byte action[MAX_PLAYERS], boolean warp_mode)
108 {
109   byte single_player_action = action[0];
110   int x, y;
111
112   UpdateEngineValues(mScrollX / TILEX, mScrollY / TILEY);
113
114   subMainGameLoop_Main(single_player_action, warp_mode);
115
116   RedrawPlayfield_SP(FALSE);
117
118   if (!warp_mode)               /* do not redraw values in warp mode */
119     DrawGameDoorValues_SP();
120
121   for (x = DisplayMinX; x <= DisplayMaxX; x++)
122     for (y = DisplayMinY; y <= DisplayMaxY; y++)
123       GfxFrame[x][y]++;
124 }