renamed playfield variable
[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 GfxFrameSP[SP_MAX_PLAYFIELD_WIDTH][SP_MAX_PLAYFIELD_HEIGHT];
13
14
15 void InitGameEngine_SP(void)
16 {
17   int x, y;
18
19   gfx.anim_random_frame = -1;   // (use simple, ad-hoc random numbers)
20
21   game_sp.level_solved = FALSE;
22   game_sp.game_over = 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   game_sp.scroll_xoffset = (EVEN(SCR_FIELDX) ? TILEX / 2 : 0);
32   game_sp.scroll_yoffset = (EVEN(SCR_FIELDY) ? TILEY / 2 : 0);
33
34   if (native_sp_level.width <= SCR_FIELDX)
35     game_sp.scroll_xoffset = TILEX / 2;
36   if (native_sp_level.height <= SCR_FIELDY)
37     game_sp.scroll_yoffset = TILEY / 2;
38
39   for (x = 0; x < SP_MAX_PLAYFIELD_WIDTH; x++)
40   {
41     for (y = 0; y < SP_MAX_PLAYFIELD_HEIGHT; y++)
42     {
43       GfxElementLast[x][y] = -1;
44       GfxGraphicLast[x][y] = -1;
45       GfxGraphic[x][y] = -1;
46       GfxFrameSP[x][y] = 0;
47     }
48   }
49
50   InitScrollPlayfield();
51
52   menPlay_Click();
53 }
54
55 void RedrawPlayfield_SP(boolean force_redraw)
56 {
57   // skip redrawing playfield in warp mode or when testing tapes with "autotest"
58   if (DrawingDeactivatedField())
59     return;
60
61   if (force_redraw)
62     RestorePlayfield();
63
64   UpdatePlayfield(force_redraw);
65 }
66
67 static void UpdateGameDoorValues_SP(void)
68 {
69   game_sp.time_played = TimerVar / FRAMES_PER_SECOND;
70   game_sp.infotrons_still_needed = InfotronsNeeded;
71   game_sp.red_disk_count = RedDiskCount;
72   game_sp.score = 0;            // (currently no score in Supaplex engine)
73 }
74
75 void GameActions_SP(byte action[MAX_PLAYERS], boolean warp_mode)
76 {
77   byte single_player_action = action[0];
78   int x, y;
79
80   UpdateEngineValues(mScrollX / TILEX, mScrollY / TILEY,
81                      MurphyScreenXPos / TILEX, MurphyScreenYPos / TILEY);
82
83   subMainGameLoop_Main(single_player_action, warp_mode);
84
85   RedrawPlayfield_SP(FALSE);
86
87   UpdateGameDoorValues_SP();
88
89   CheckSingleStepMode_SP(PlayField16[MurphyPosIndex] == fiMurphy,
90                          HighByte(PlayField16[MurphyPosIndex]) == 0x2A);
91
92   for (x = DisplayMinX; x <= DisplayMaxX; x++)
93     for (y = DisplayMinY; y <= DisplayMaxY; y++)
94       GfxFrameSP[x][y]++;
95 }
96
97 int getRedDiskReleaseFlag_SP(void)
98 {
99   // 0: when Murphy is moving (including the destination tile!)
100   // 1: when Murphy is not moving for at least one game frame
101
102   return RedDiskReleaseFlag;
103 }