rnd-20100316-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 int GfxElementLast[SP_MAX_PLAYFIELD_WIDTH][SP_MAX_PLAYFIELD_HEIGHT];
10 int GfxGraphicLast[SP_MAX_PLAYFIELD_WIDTH][SP_MAX_PLAYFIELD_HEIGHT];
11 int GfxGraphic[SP_MAX_PLAYFIELD_WIDTH][SP_MAX_PLAYFIELD_HEIGHT];
12 int GfxFrame[SP_MAX_PLAYFIELD_WIDTH][SP_MAX_PLAYFIELD_HEIGHT];
13
14
15 void InitGameEngine_SP()
16 {
17   int x, y;
18
19   gfx.anim_random_frame = -1;   // (use simple, ad-hoc random numbers)
20
21   game_sp.LevelSolved = FALSE;
22   game_sp.GameOver = FALSE;
23
24   game_sp.time_played = 0;
25   game_sp.infotrons_still_needed = native_sp_level.header.InfotronsNeeded;
26   game_sp.red_disk_count = 0;
27   game_sp.score = 0;
28
29   menBorder = setup.sp_show_border_elements;
30
31   for (x = 0; x < SP_MAX_PLAYFIELD_WIDTH; x++)
32   {
33     for (y = 0; y < SP_MAX_PLAYFIELD_HEIGHT; y++)
34     {
35       GfxElementLast[x][y] = -1;
36       GfxGraphicLast[x][y] = -1;
37       GfxGraphic[x][y] = -1;
38       GfxFrame[x][y] = 0;
39     }
40   }
41
42   InitScrollPlayfield();
43
44   menPlay_Click();
45 }
46
47 void RedrawPlayfield_SP(boolean force_redraw)
48 {
49   if (force_redraw)
50     RestorePlayfield();
51
52   UpdatePlayfield(force_redraw);
53
54   BackToFront_SP();
55 }
56
57 void DrawGameDoorValues_SP()
58 {
59   game_sp.time_played = TimerVar / setup.game_frame_delay;
60   game_sp.infotrons_still_needed = InfotronsNeeded;
61   game_sp.red_disk_count = RedDiskCount;
62   game_sp.score = 0;            // (currently no score in Supaplex engine)
63 }
64
65 void GameActions_SP(byte action[MAX_PLAYERS], boolean warp_mode)
66 {
67   byte single_player_action = action[0];
68   int x, y;
69
70   UpdateEngineValues(mScrollX / TILEX, mScrollY / TILEY);
71
72   subMainGameLoop_Main(single_player_action, warp_mode);
73
74   RedrawPlayfield_SP(FALSE);
75
76   if (!warp_mode)               /* do not redraw values in warp mode */
77     DrawGameDoorValues_SP();
78
79   for (x = DisplayMinX; x <= DisplayMaxX; x++)
80     for (y = DisplayMinY; y <= DisplayMaxY; y++)
81       GfxFrame[x][y]++;
82 }