// (c) 1994-2017 by Artsoft Entertainment
// Holger Schemel
// info@artsoft.org
-// http://www.artsoft.org/
+// https://www.artsoft.org/
// ----------------------------------------------------------------------------
// mm_game.c
// ============================================================================
+#include <math.h>
+
#include "main_mm.h"
#include "mm_main.h"
#include "mm_game.h"
#include "mm_tools.h"
-/* graphic position values for game controls */
+// graphic position values for game controls
#define ENERGY_XSIZE 32
#define ENERGY_YSIZE MAX_LASER_ENERGY
#define OVERLOAD_XSIZE ENERGY_XSIZE
#define OVERLOAD_YSIZE MAX_LASER_OVERLOAD
-/* values for Explode_MM() */
+// values for Explode_MM()
#define EX_PHASE_START 0
#define EX_NORMAL 0
#define EX_KETTLE 1
#define EX_SHORT 2
-/* special positions in the game control window (relative to control window) */
+// special positions in the game control window (relative to control window)
#define XX_LEVEL 36
#define YY_LEVEL 23
#define XX_KETTLES 29
#define XX_OVERLOAD 60
#define YY_OVERLOAD YY_ENERGY
-/* special positions in the game control window (relative to main window) */
+// special positions in the game control window (relative to main window)
#define DX_LEVEL (DX + XX_LEVEL)
#define DY_LEVEL (DY + YY_LEVEL)
#define DX_KETTLES (DX + XX_KETTLES)
#define IS_LOOP_SOUND(s) ((s) == SND_FUEL)
#define IS_MUSIC_SOUND(s) ((s) == SND_TYGER || (s) == SND_VOYAGER)
-/* game button identifiers */
+// game button identifiers
#define GAME_CTRL_ID_LEFT 0
#define GAME_CTRL_ID_MIDDLE 1
#define GAME_CTRL_ID_RIGHT 2
#define NUM_GAME_BUTTONS 3
-/* values for DrawLaser() */
+// values for DrawLaser()
#define DL_LASER_DISABLED 0
#define DL_LASER_ENABLED 1
-/* values for 'click_delay_value' in ClickElement() */
-#define CLICK_DELAY_SHORT 125
-#define CLICK_DELAY_LONG 250
-#define AUTO_ROTATE_DELAY CLICK_DELAY_SHORT
-
-/* forward declaration for internal use */
+// values for 'click_delay_value' in ClickElement()
+#define CLICK_DELAY_FIRST 12 // delay (frames) after first click
+#define CLICK_DELAY 6 // delay (frames) for pressed butten
+
+#define AUTO_ROTATE_DELAY CLICK_DELAY
+#define INIT_GAME_ACTIONS_DELAY (ONE_SECOND_DELAY / GAME_FRAME_DELAY)
+#define NUM_INIT_CYCLE_STEPS 16
+#define PACMAN_MOVE_DELAY 12
+#define ENERGY_DELAY (ONE_SECOND_DELAY / GAME_FRAME_DELAY)
+#define HEALTH_DEC_DELAY 3
+#define HEALTH_INC_DELAY 9
+#define HEALTH_DELAY(x) ((x) ? HEALTH_DEC_DELAY : HEALTH_INC_DELAY)
+
+#define BEGIN_NO_HEADLESS \
+ { \
+ boolean last_headless = program.headless; \
+ \
+ program.headless = FALSE; \
+
+#define END_NO_HEADLESS \
+ program.headless = last_headless; \
+ } \
+
+// forward declaration for internal use
static int MovingOrBlocked2Element_MM(int, int);
static void Bang_MM(int, int);
static void RaiseScore_MM(int);
+static void RaiseScoreElement_MM(int);
static void RemoveMovingField_MM(int, int);
static void InitMovingField_MM(int, int, int);
static void ContinueMoving_MM(int, int);
static void Moving2Blocked_MM(int, int, int *, int *);
+// bitmap for laser beam detection
+static Bitmap *laser_bitmap = NULL;
+
+// variables for laser control
+static int last_LX = 0, last_LY = 0, last_hit_mask = 0;
+static int hold_x = -1, hold_y = -1;
+
+// variables for pacman control
+static int pacman_nr = -1;
+
+// various game engine delay counters
+static DelayCounter rotate_delay = { AUTO_ROTATE_DELAY };
+static DelayCounter pacman_delay = { PACMAN_MOVE_DELAY };
+static DelayCounter energy_delay = { ENERGY_DELAY };
+static DelayCounter overload_delay = { 0 };
+
+// element masks for scanning pixels of MM elements
+static const char mm_masks[10][16][16 + 1] =
+{
+ {
+ " ",
+ " XXXXX ",
+ " XXXXXXX ",
+ " XXXXXXXXXXX ",
+ " XXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXXX",
+ " XXXXXXXXXXXXXX",
+ " XXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXX ",
+ " XXXXXXXXXXXX ",
+ " XXXXXXXXXXXX ",
+ },
+ {
+ " ",
+ " XXXXXXXX ",
+ " XXXXXXXXXXXX ",
+ " XXXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXX ",
+ " XXXXXXXXXXXX ",
+ " XXXXXXXXXXXX ",
+ },
+ {
+ " ",
+ " XXXXXX ",
+ " XXXXXXXXX ",
+ " XXXXXXXXXXX ",
+ "XXXXXXXXXXXXX ",
+ "XXXXXXXXXXXXX ",
+ "XXXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXX ",
+ " XXXXXXXXXXXX ",
+ " XXXXXXXXXXXX ",
+ },
+ {
+ " ",
+ " XXXXXX ",
+ " XXXXXXXX ",
+ " XXXXXXXXXX ",
+ " XXXXXXXXXXX ",
+ " XXXXXXXXXXX ",
+ " XXXXXXXXXXXX ",
+ " XXXXXXXXXXXX ",
+ " XXXXXXXXXXXX ",
+ " XXXXXXXXXXXX ",
+ " XXXXXXXXXXXX ",
+ " XXXXXXXXXXXX ",
+ " XXXXXXXXXXXX ",
+ " XXXXXXXXXXXX ",
+ " XXXXXXXXXXXX ",
+ " XXXXX XXXXX ",
+ },
+ {
+ " XXXXXX XXXXXX ",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ " ",
+ " ",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ " XXXXXX XXXXXX ",
+ },
+ {
+ " XXXXXX XXXXXX ",
+ "XXXXXXX XXXXXXX",
+ "XXXXXXX XXXXXXX",
+ "XXXXXXX XXXXXXX",
+ "XXXXXXX XXXXXXX",
+ "XXXXXXX XXXXXXX",
+ "XXXXXXX XXXXXXX",
+ " XXXXXX XXXXXX ",
+ " XXXXXX XXXXXX ",
+ "XXXXXXX XXXXXXX",
+ "XXXXXXX XXXXXXX",
+ "XXXXXXX XXXXXXX",
+ "XXXXXXX XXXXXXX",
+ "XXXXXXX XXXXXXX",
+ "XXXXXXX XXXXXXX",
+ " XXXXXX XXXXXX ",
+ },
+ {
+ " XX XXXXX ",
+ " XXX XXXX ",
+ " XXXX XXX X",
+ " XXXXXXXXX XX",
+ " XXXXXXXXX XXX",
+ "XXXXXXXXX XXXX",
+ "XXXXXXXX XXXXX",
+ " XXXX XXX ",
+ " XXX XXXX ",
+ "XXXXX XXXXXXXX",
+ "XXXX XXXXXXXXX",
+ "XXX XXXXXXXXX ",
+ "XX XXXXXXXXX ",
+ "X XXX XXXX ",
+ " XXXX XXX ",
+ " XXXXX XX ",
+ },
+ {
+ " XXXXX XX ",
+ " XXXX XXX ",
+ "X XXX XXXX ",
+ "XX XXXXXXXXX ",
+ "XXX XXXXXXXXX ",
+ "XXXX XXXXXXXXX",
+ "XXXXX XXXXXXXX",
+ " XXX XXXX ",
+ " XXXX XXX ",
+ "XXXXXXXX XXXXX",
+ "XXXXXXXXX XXXX",
+ " XXXXXXXXX XXX",
+ " XXXXXXXXX XX",
+ " XXXX XXX X",
+ " XXX XXXX ",
+ " XX XXXXX ",
+ },
+ {
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXX",
+ },
+ {
+ " ",
+ " XXXX ",
+ " XXXXXXXX ",
+ " XXXXXXXXXX ",
+ " XXXXXXXXXXXX ",
+ " XXXXXXXXXXXX ",
+ " XXXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXXX ",
+ " XXXXXXXXXXXXXX ",
+ " XXXXXXXXXXXX ",
+ " XXXXXXXXXXXX ",
+ " XXXXXXXXXX ",
+ " XXXXXXXX ",
+ " XXXX ",
+ " ",
+ },
+};
static int get_element_angle(int element)
{
{
int opposite_angle = angle + ANG_RAY_180;
- /* make sure "opposite_angle" is in valid interval [0, 15] */
+ // make sure "opposite_angle" is in valid interval [0, 15]
return (opposite_angle + 16) % 16;
}
{
int reflected_angle = 16 - laser_angle + mirror_angle;
- /* make sure "reflected_angle" is in valid interval [0, 15] */
+ // make sure "reflected_angle" is in valid interval [0, 15]
return (reflected_angle + 16) % 16;
}
+static void DrawLaserLines(struct XY *points, int num_points, int mode)
+{
+ Pixel pixel_drawto = (mode == DL_LASER_ENABLED ? pen_ray : pen_bg);
+ Pixel pixel_buffer = (mode == DL_LASER_ENABLED ? WHITE_PIXEL : BLACK_PIXEL);
+
+ DrawLines(drawto, points, num_points, pixel_drawto);
+
+ BEGIN_NO_HEADLESS
+ {
+ DrawLines(laser_bitmap, points, num_points, pixel_buffer);
+ }
+ END_NO_HEADLESS
+}
+
+static boolean CheckLaserPixel(int x, int y)
+{
+ Pixel pixel;
+
+ BEGIN_NO_HEADLESS
+ {
+ pixel = ReadPixel(laser_bitmap, x, y);
+ }
+ END_NO_HEADLESS
+
+ return (pixel == WHITE_PIXEL);
+}
+
+static void CheckExitMM(void)
+{
+ int exit_element = EL_EMPTY;
+ int exit_x = 0;
+ int exit_y = 0;
+ int x, y;
+ static int xy[4][2] =
+ {
+ { +1, 0 },
+ { 0, -1 },
+ { -1, 0 },
+ { 0, +1 }
+ };
+
+ for (y = 0; y < lev_fieldy; y++)
+ {
+ for (x = 0; x < lev_fieldx; x++)
+ {
+ if (Tile[x][y] == EL_EXIT_CLOSED)
+ {
+ // initiate opening animation of exit door
+ Tile[x][y] = EL_EXIT_OPENING;
+
+ exit_element = EL_EXIT_OPEN;
+ exit_x = x;
+ exit_y = y;
+ }
+ else if (IS_RECEIVER(Tile[x][y]))
+ {
+ // remove field that blocks receiver
+ int phase = Tile[x][y] - EL_RECEIVER_START;
+ int blocking_x, blocking_y;
+
+ blocking_x = x + xy[phase][0];
+ blocking_y = y + xy[phase][1];
+
+ if (IN_LEV_FIELD(blocking_x, blocking_y))
+ {
+ Tile[blocking_x][blocking_y] = EL_EMPTY;
+
+ DrawField_MM(blocking_x, blocking_y);
+ }
+
+ exit_element = EL_RECEIVER;
+ exit_x = x;
+ exit_y = y;
+ }
+ }
+ }
+
+ if (exit_element != EL_EMPTY)
+ PlayLevelSound_MM(exit_x, exit_y, exit_element, MM_ACTION_OPENING);
+}
+
static void InitMovDir_MM(int x, int y)
{
- int element = Feld[x][y];
+ int element = Tile[x][y];
static int direction[3][4] =
{
{ MV_RIGHT, MV_UP, MV_LEFT, MV_DOWN },
{ MV_LEFT, MV_RIGHT, MV_UP, MV_DOWN }
};
- switch(element)
+ switch (element)
{
case EL_PACMAN_RIGHT:
case EL_PACMAN_UP:
case EL_PACMAN_LEFT:
case EL_PACMAN_DOWN:
- Feld[x][y] = EL_PACMAN;
+ Tile[x][y] = EL_PACMAN;
MovDir[x][y] = direction[0][element - EL_PACMAN_RIGHT];
break;
}
}
-static void InitField(int x, int y, boolean init_game)
+static void InitField(int x, int y)
{
- int element = Feld[x][y];
+ int element = Tile[x][y];
switch (element)
{
case EL_DF_EMPTY:
- Feld[x][y] = EL_EMPTY;
+ Tile[x][y] = EL_EMPTY;
break;
case EL_KETTLE:
{
if (IS_BEAMER_OLD(element))
{
- Feld[x][y] = EL_BEAMER_BLUE_START + (element - EL_BEAMER_START);
- element = Feld[x][y];
+ Tile[x][y] = EL_BEAMER_BLUE_START + (element - EL_BEAMER_START);
+ element = Tile[x][y];
}
if (!IS_FIBRE_OPTIC(element))
{
static int steps_grid_auto = 0;
- if (game_mm.num_cycle == 0) /* initialize cycle steps for grids */
+ if (game_mm.num_cycle == 0) // initialize cycle steps for grids
steps_grid_auto = RND(16) * (RND(2) ? -1 : +1);
if (IS_GRID_STEEL_AUTO(element) ||
}
}
-static void InitCycleElements()
+static void InitCycleElements_RotateSingleStep(void)
{
- int i, j;
+ int i;
- if (game_mm.num_cycle == 0) /* no elements to cycle */
+ if (game_mm.num_cycle == 0) // no elements to cycle
return;
- for (i = 0; i < 16; i++)
+ for (i = 0; i < game_mm.num_cycle; i++)
{
- for (j = 0; j < game_mm.num_cycle; j++)
- {
- int x = game_mm.cycle[j].x;
- int y = game_mm.cycle[j].y;
- int step = SIGN(game_mm.cycle[j].steps);
- int last_element = Feld[x][y];
- int next_element = get_rotated_element(last_element, step);
-
- if (!game_mm.cycle[j].steps)
- continue;
-
- Feld[x][y] = next_element;
-
- DrawField_MM(x, y);
- game_mm.cycle[j].steps -= step;
- }
-
- BackToFront();
- ColorCycling();
+ int x = game_mm.cycle[i].x;
+ int y = game_mm.cycle[i].y;
+ int step = SIGN(game_mm.cycle[i].steps);
+ int last_element = Tile[x][y];
+ int next_element = get_rotated_element(last_element, step);
-#ifdef DEBUG
- if (setup.quick_doors)
+ if (!game_mm.cycle[i].steps)
continue;
-#endif
- Delay(AUTO_ROTATE_DELAY);
+ Tile[x][y] = next_element;
+
+ game_mm.cycle[i].steps -= step;
}
}
-static void InitLaser()
+static void InitLaser(void)
{
- int start_element = Feld[laser.start_edge.x][laser.start_edge.y];
+ int start_element = Tile[laser.start_edge.x][laser.start_edge.y];
int step = (IS_LASER(start_element) ? 4 : 0);
LX = laser.start_edge.x * TILEX;
laser.num_beamers = 0;
laser.beamer_edge[0] = 0;
- AddLaserEdge(LX, LY); /* set laser starting edge */
+ laser.dest_element = EL_EMPTY;
+ laser.wall_mask = 0;
+
+ AddLaserEdge(LX, LY); // set laser starting edge
pen_ray = GetPixelFromRGB(window,
native_mm_level.laser_red * 0xFF,
native_mm_level.laser_blue * 0xFF);
}
-void InitGameEngine_MM()
+void InitGameEngine_MM(void)
{
int i, x, y;
- /* set global game control values */
+ BEGIN_NO_HEADLESS
+ {
+ // initialize laser bitmap to current playfield (screen) size
+ ReCreateBitmap(&laser_bitmap, drawto->width, drawto->height);
+ ClearRectangle(laser_bitmap, 0, 0, drawto->width, drawto->height);
+ }
+ END_NO_HEADLESS
+
+ // set global game control values
game_mm.num_cycle = 0;
game_mm.num_pacman = 0;
game_mm.score = 0;
- game_mm.energy_left = native_mm_level.time;
+ game_mm.energy_left = 0; // later set to "native_mm_level.time"
game_mm.kettles_still_needed =
(native_mm_level.auto_count_kettles ? 0 : native_mm_level.kettles_needed);
game_mm.lights_still_needed = 0;
game_mm.game_over = FALSE;
game_mm.game_over_cause = 0;
- /* set global laser control values (must be set before "InitLaser()") */
+ game_mm.laser_overload_value = 0;
+ game_mm.laser_enabled = FALSE;
+
+ // set global laser control values (must be set before "InitLaser()")
laser.start_edge.x = 0;
laser.start_edge.y = 0;
laser.start_angle = 0;
laser.dest_element = EL_EMPTY;
laser.wall_mask = 0;
+ last_LX = 0;
+ last_LY = 0;
+ last_hit_mask = 0;
+
+ hold_x = -1;
+ hold_y = -1;
+
+ pacman_nr = -1;
+
CT = Ct = 0;
+ rotate_delay.count = 0;
+ pacman_delay.count = 0;
+ energy_delay.count = 0;
+ overload_delay.count = 0;
+
+ ClickElement(-1, -1, -1);
+
for (x = 0; x < lev_fieldx; x++)
{
for (y = 0; y < lev_fieldy; y++)
{
- Feld[x][y] = Ur[x][y];
+ Tile[x][y] = Ur[x][y];
Hit[x][y] = Box[x][y] = 0;
Angle[x][y] = 0;
MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
Frame[x][y] = 0;
Stop[x][y] = FALSE;
- InitField(x, y, TRUE);
+ InitField(x, y);
}
}
-#if 0
- CloseDoor(DOOR_CLOSE_1);
-#endif
-
DrawLevel_MM();
}
-void InitGameEngine_MM_AfterFadingIn()
+void InitGameActions_MM(void)
{
- InitCycleElements();
- InitLaser();
+ int num_init_game_frames = INIT_GAME_ACTIONS_DELAY;
+ int cycle_steps_done = 0;
+ int i;
-#if 0
- /* copy default game door content to main double buffer */
- BlitBitmap(pix[PIX_DOOR], drawto,
- DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
-#endif
+ InitLaser();
-#if 0
- DrawText(DX_LEVEL, DY_LEVEL,
- int2str(level_nr, 2), FONT_TEXT_2);
- DrawText(DX_KETTLES, DY_KETTLES,
- int2str(game_mm.kettles_still_needed, 3), FONT_TEXT_2);
- DrawText(DX_SCORE, DY_SCORE,
- int2str(game_mm.score, 4), FONT_TEXT_2);
-#endif
+ for (i = 0; i <= num_init_game_frames; i++)
+ {
+ if (i == num_init_game_frames)
+ StopSound_MM(SND_MM_GAME_LEVELTIME_CHARGING);
+ else if (setup.sound_loops)
+ PlaySoundLoop_MM(SND_MM_GAME_LEVELTIME_CHARGING);
+ else
+ PlaySound_MM(SND_MM_GAME_LEVELTIME_CHARGING);
-#if 0
- UnmapGameButtons();
- MapGameButtons();
-#endif
+ game_mm.energy_left = native_mm_level.time * i / num_init_game_frames;
-#if 0
- /* copy actual game door content to door double buffer for OpenDoor() */
- BlitBitmap(drawto, pix[PIX_DB_DOOR],
- DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
-#endif
+ UpdateAndDisplayGameControlValues();
-#if 0
- OpenDoor(DOOR_OPEN_ALL);
-#endif
+ while (cycle_steps_done < NUM_INIT_CYCLE_STEPS * i / num_init_game_frames)
+ {
+ InitCycleElements_RotateSingleStep();
- if (setup.sound_loops)
- PlaySoundExt(SND_FUEL, SOUND_MAX_VOLUME, SOUND_MAX_RIGHT, SND_CTRL_PLAY_LOOP);
+ cycle_steps_done++;
+ }
-#if 0 // !!! TEMPORARILY DISABLED !!!
- for (i = 0; i <= game_mm.energy_left; i += 2)
- {
- if (!setup.sound_loops)
- PlaySoundStereo(SND_FUEL, SOUND_MAX_RIGHT);
+ AdvanceFrameCounter();
+ AdvanceGfxFrame();
-#if 0
- BlitBitmap(pix[PIX_DOOR], drawto,
- DOOR_GFX_PAGEX4 + XX_ENERGY,
- DOOR_GFX_PAGEY1 + YY_ENERGY + ENERGY_YSIZE - i,
- ENERGY_XSIZE, i,
- DX_ENERGY, DY_ENERGY + ENERGY_YSIZE - i);
-#endif
+ DrawLevel_MM();
- redraw_mask |= REDRAW_DOOR_1;
BackToFront();
ColorCycling();
if (setup.quick_doors)
continue;
#endif
-
- Delay(20);
}
- if (setup.sound_loops)
- StopSound(SND_FUEL);
-#endif
+ ScanLaser();
-#if 0
- if (setup.sound_music && num_bg_loops)
- PlayMusic(level_nr % num_bg_loops);
-#endif
+ if (game_mm.kettles_still_needed == 0)
+ CheckExitMM();
- ScanLaser();
+ SetTileCursorXY(laser.start_edge.x, laser.start_edge.y);
+ SetTileCursorActive(TRUE);
}
void AddLaserEdge(int lx, int ly)
{
- if (lx < -2 || ly < -2 || lx >= SXSIZE + 2 || ly >= SYSIZE + 2)
+ int clx = dSX + lx;
+ int cly = dSY + ly;
+
+ if (clx < -2 || cly < -2 || clx >= SXSIZE + 2 || cly >= SYSIZE + 2)
{
- Error(ERR_WARN, "AddLaserEdge: out of bounds: %d, %d", lx, ly);
+ Warn("AddLaserEdge: out of bounds: %d, %d", lx, ly);
return;
}
- laser.edge[laser.num_edges].x = SX + 2 + lx;
- laser.edge[laser.num_edges].y = SY + 2 + ly;
+ laser.edge[laser.num_edges].x = cSX2 + lx;
+ laser.edge[laser.num_edges].y = cSY2 + ly;
laser.num_edges++;
laser.redraw = TRUE;
laser.num_damages++;
}
-boolean StepBehind()
+static boolean StepBehind(void)
{
if (laser.num_edges)
{
int x = LX - XS;
int y = LY - YS;
- int last_x = laser.edge[laser.num_edges - 1].x - SX - 2;
- int last_y = laser.edge[laser.num_edges - 1].y - SY - 2;
+ int last_x = laser.edge[laser.num_edges - 1].x - cSX2;
+ int last_y = laser.edge[laser.num_edges - 1].y - cSY2;
return ((x - last_x) * XS < 0 || (y - last_y) * YS < 0);
}
return IMG_MM_MASK_CIRCLE;
}
-int ScanPixel()
+static int ScanPixel(void)
{
int hit_mask = 0;
#if 0
- printf("ScanPixel: start scanning at (%d, %d) [%d, %d] [%d, %d]\n",
- LX, LY, LX / TILEX, LY / TILEY, LX % TILEX, LY % TILEY);
+ Debug("game:mm:ScanPixel", "start scanning at (%d, %d) [%d, %d] [%d, %d]",
+ LX, LY, LX / TILEX, LY / TILEY, LX % TILEX, LY % TILEY);
#endif
- /* follow laser beam until it hits something (at least the screen border) */
+ // follow laser beam until it hits something (at least the screen border)
while (hit_mask == HIT_MASK_NO_HIT)
{
int i;
#if 0
- /* for safety */
+ // for safety
if (SX + LX < REAL_SX || SX + LX >= REAL_SX + FULL_SXSIZE ||
SY + LY < REAL_SY || SY + LY >= REAL_SY + FULL_SYSIZE)
{
- printf("ScanPixel: touched screen border!\n");
+ Debug("game:mm:ScanPixel", "touched screen border!");
return HIT_MASK_ALL;
}
int py = LY + (i / 2) * 2;
int dx = px % TILEX;
int dy = py % TILEY;
- int lx = (px + TILEX) / TILEX - 1; /* ...+TILEX...-1 to get correct */
- int ly = (py + TILEY) / TILEY - 1; /* negative values! */
+ int lx = (px + TILEX) / TILEX - 1; // ...+TILEX...-1 to get correct
+ int ly = (py + TILEY) / TILEY - 1; // negative values!
Pixel pixel;
if (IN_LEV_FIELD(lx, ly))
{
- int element = Feld[lx][ly];
+ int element = Tile[lx][ly];
if (element == EL_EMPTY || element == EL_EXPLODING_TRANSP)
{
}
else
{
- int graphic_mask = getMaskFromElement(element);
- Bitmap *bitmap;
- int src_x, src_y;
- int mask_x, mask_y;
-
- getGraphicSource(graphic_mask, 0, &bitmap, &src_x, &src_y);
+ int pos = getMaskFromElement(element) - IMG_MM_MASK_MCDUFFIN_RIGHT;
- mask_x = src_x + dx;
- mask_y = src_y + dy;
-
- pixel = (ReadPixel(bitmap, mask_x, mask_y) ? 1 : 0);
+ pixel = (mm_masks[pos][dy / 2][dx / 2] == 'X' ? 1 : 0);
}
}
else
{
- pixel = (SX + px < REAL_SX || SX + px >= REAL_SX + FULL_SXSIZE ||
- SY + py < REAL_SY || SY + py >= REAL_SY + FULL_SYSIZE);
+ pixel = (cSX + px < REAL_SX || cSX + px >= REAL_SX + FULL_SXSIZE ||
+ cSY + py < REAL_SY || cSY + py >= REAL_SY + FULL_SYSIZE);
}
if ((Sign[laser.current_angle] & (1 << i)) && pixel)
if (hit_mask == HIT_MASK_NO_HIT)
{
- /* hit nothing -- go on with another step */
+ // hit nothing -- go on with another step
LX += XS;
LY += YS;
}
return hit_mask;
}
-void ScanLaser()
+void ScanLaser(void)
{
int element;
int end = 0, rf = laser.num_edges;
- /* do not scan laser again after the game was lost for whatever reason */
+ // do not scan laser again after the game was lost for whatever reason
if (game_mm.game_over)
return;
DrawLaser(0, DL_LASER_ENABLED);
#if 0
- printf("Start scanning with LX == %d, LY == %d, XS == %d, YS == %d\n",
- LX, LY, XS, YS);
+ Debug("game:mm:ScanLaser",
+ "Start scanning with LX == %d, LY == %d, XS == %d, YS == %d",
+ LX, LY, XS, YS);
#endif
while (1)
hit_mask = ScanPixel();
#if 0
- printf("Hit something at LX == %d, LY == %d, XS == %d, YS == %d\n",
- LX, LY, XS, YS);
+ Debug("game:mm:ScanLaser",
+ "Hit something at LX == %d, LY == %d, XS == %d, YS == %d",
+ LX, LY, XS, YS);
#endif
- /* hit something -- check out what it was */
+ // hit something -- check out what it was
ELX = (LX + XS) / TILEX;
ELY = (LY + YS) / TILEY;
#if 0
- printf("hit_mask (1) == '%x' (%d, %d) (%d, %d)\n",
- hit_mask, LX, LY, ELX, ELY);
+ Debug("game:mm:ScanLaser", "hit_mask (1) == '%x' (%d, %d) (%d, %d)",
+ hit_mask, LX, LY, ELX, ELY);
#endif
if (!IN_LEV_FIELD(ELX, ELY) || !IN_PIX_FIELD(LX, LY))
{
/* we have hit the top-left and bottom-right element --
choose the top-left one */
- /* !!! SEE ABOVE !!! */
+ // !!! SEE ABOVE !!!
ELX = (LX - 2) / TILEX;
ELY = (LY - 2) / TILEY;
}
#if 0
- printf("hit_mask (2) == '%x' (%d, %d) (%d, %d)\n",
- hit_mask, LX, LY, ELX, ELY);
+ Debug("game:mm:ScanLaser", "hit_mask (2) == '%x' (%d, %d) (%d, %d)",
+ hit_mask, LX, LY, ELX, ELY);
#endif
- element = Feld[ELX][ELY];
+ element = Tile[ELX][ELY];
laser.dest_element = element;
#if 0
- printf("Hit element %d at (%d, %d) [%d, %d] [%d, %d] [%d]\n",
- element, ELX, ELY,
- LX, LY,
- LX % TILEX, LY % TILEY,
- hit_mask);
+ Debug("game:mm:ScanLaser",
+ "Hit element %d at (%d, %d) [%d, %d] [%d, %d] [%d]",
+ element, ELX, ELY,
+ LX, LY,
+ LX % TILEX, LY % TILEY,
+ hit_mask);
#endif
#if 0
if (!IN_LEV_FIELD(ELX, ELY))
- printf("WARNING! (1) %d, %d (%d)\n", ELX, ELY, element);
+ Debug("game:mm:ScanLaser", "WARNING! (1) %d, %d (%d)",
+ ELX, ELY, element);
#endif
if (element == EL_EMPTY)
{
- if (!HitOnlyAnEdge(element, hit_mask))
+ if (!HitOnlyAnEdge(hit_mask))
break;
}
else if (element == EL_FUSE_ON)
}
#if 0
- if (laser.dest_element != Feld[ELX][ELY])
+ if (laser.dest_element != Tile[ELX][ELY])
{
- printf("ALARM: laser.dest_element == %d, Feld[ELX][ELY] == %d\n",
- laser.dest_element, Feld[ELX][ELY]);
+ Debug("game:mm:ScanLaser",
+ "ALARM: laser.dest_element == %d, Tile[ELX][ELY] == %d",
+ laser.dest_element, Tile[ELX][ELY]);
}
#endif
if (!end && !laser.stops_inside_element && !StepBehind())
{
#if 0
- printf("ScanLaser: Go one step back\n");
+ Debug("game:mm:ScanLaser", "Go one step back");
#endif
LX -= XS;
if (rf)
DrawLaser(rf - 1, DL_LASER_ENABLED);
- Ct = CT = Counter();
+ Ct = CT = FrameCounter;
#if 0
if (!IN_LEV_FIELD(ELX, ELY))
- printf("WARNING! (2) %d, %d\n", ELX, ELY);
+ Debug("game:mm:ScanLaser", "WARNING! (2) %d, %d", ELX, ELY);
#endif
}
-void DrawLaserExt(int start_edge, int num_edges, int mode)
+static void DrawLaserExt(int start_edge, int num_edges, int mode)
{
int element;
int elx, ely;
#if 0
- printf("DrawLaserExt: start_edge, num_edges, mode == %d, %d, %d\n",
- start_edge, num_edges, mode);
+ Debug("game:mm:DrawLaserExt", "start_edge, num_edges, mode == %d, %d, %d",
+ start_edge, num_edges, mode);
#endif
if (start_edge < 0)
{
- Error(ERR_WARN, "DrawLaserExt: start_edge < 0");
+ Warn("DrawLaserExt: start_edge < 0");
return;
}
if (num_edges < 0)
{
- Error(ERR_WARN, "DrawLaserExt: num_edges < 0");
+ Warn("DrawLaserExt: num_edges < 0");
return;
}
#if 0
if (mode == DL_LASER_DISABLED)
{
- printf("DrawLaser: Delete laser from edge %d\n", start_edge);
+ Debug("game:mm:DrawLaserExt", "Delete laser from edge %d", start_edge);
}
#endif
- /* now draw the laser to the backbuffer and (if enabled) to the screen */
- DrawLines(drawto, &laser.edge[start_edge], num_edges,
- (mode == DL_LASER_ENABLED ? pen_ray : pen_bg));
+ // now draw the laser to the backbuffer and (if enabled) to the screen
+ DrawLaserLines(&laser.edge[start_edge], num_edges, mode);
redraw_mask |= REDRAW_FIELD;
if (mode == DL_LASER_ENABLED)
return;
- /* after the laser was deleted, the "damaged" graphics must be restored */
+ // after the laser was deleted, the "damaged" graphics must be restored
if (laser.num_damages)
{
int damage_start = 0;
int i;
- /* determine the starting edge, from which graphics need to be restored */
+ // determine the starting edge, from which graphics need to be restored
if (start_edge > 0)
{
for (i = 0; i < laser.num_damages; i++)
}
}
- /* restore graphics from this starting edge to the end of damage list */
+ // restore graphics from this starting edge to the end of damage list
for (i = damage_start; i < laser.num_damages; i++)
{
int lx = laser.damage[i].x;
int ly = laser.damage[i].y;
- int element = Feld[lx][ly];
+ int element = Tile[lx][ly];
if (Hit[lx][ly] == laser.damage[i].edge)
if (!((IS_BEAMER(element) || IS_FIBRE_OPTIC(element)) &&
elx = laser.damage[damage_start].x;
ely = laser.damage[damage_start].y;
- element = Feld[elx][ely];
+ element = Tile[elx][ely];
#if 0
if (IS_BEAMER(element))
int i;
for (i = 0; i < laser.num_beamers; i++)
- printf("-> %d\n", laser.beamer_edge[i]);
- printf("DrawLaserExt: IS_BEAMER: [%d]: Hit[%d][%d] == %d [%d]\n",
- mode, elx, ely, Hit[elx][ely], start_edge);
- printf("DrawLaserExt: IS_BEAMER: %d / %d\n",
- get_element_angle(element), laser.damage[damage_start].angle);
+ Debug("game:mm:DrawLaserExt", "-> %d", laser.beamer_edge[i]);
+
+ Debug("game:mm:DrawLaserExt", "IS_BEAMER: [%d]: Hit[%d][%d] == %d [%d]",
+ mode, elx, ely, Hit[elx][ely], start_edge);
+ Debug("game:mm:DrawLaserExt", "IS_BEAMER: %d / %d",
+ get_element_angle(element), laser.damage[damage_start].angle);
}
#endif
laser.num_beamers > 0 &&
start_edge == laser.beamer_edge[laser.num_beamers - 1])
{
- /* element is outgoing beamer */
+ // element is outgoing beamer
laser.num_damages = damage_start + 1;
if (IS_BEAMER(element))
}
else
{
- /* element is incoming beamer or other element */
+ // element is incoming beamer or other element
laser.num_damages = damage_start;
laser.current_angle = laser.damage[laser.num_damages].angle;
}
}
else
{
- /* no damages but McDuffin himself (who needs to be redrawn anyway) */
+ // no damages but McDuffin himself (who needs to be redrawn anyway)
elx = laser.start_edge.x;
ely = laser.start_edge.y;
- element = Feld[elx][ely];
+ element = Tile[elx][ely];
}
laser.num_edges = start_edge + 1;
if (start_edge == 0)
laser.current_angle = laser.start_angle;
- LX = laser.edge[start_edge].x - (SX + 2);
- LY = laser.edge[start_edge].y - (SY + 2);
+ LX = laser.edge[start_edge].x - cSX2;
+ LY = laser.edge[start_edge].y - cSY2;
XS = 2 * Step[laser.current_angle].x;
YS = 2 * Step[laser.current_angle].y;
#if 0
- printf("DrawLaser: Set (LX, LY) to (%d, %d) [%d]\n",
- LX, LY, element);
+ Debug("game:mm:DrawLaserExt", "Set (LX, LY) to (%d, %d) [%d]",
+ LX, LY, element);
#endif
if (start_edge > 0)
int step_size;
#if 0
- printf("element == %d\n", element);
+ Debug("game:mm:DrawLaserExt", "element == %d", element);
#endif
- if (IS_22_5_ANGLE(laser.current_angle)) /* neither 90° nor 45° angle */
+ if (IS_22_5_ANGLE(laser.current_angle)) // neither 90° nor 45° angle
step_size = ((IS_BEAMER(element) || IS_FIBRE_OPTIC(element)) ? 4 : 3);
else
step_size = 8;
(laser.num_beamers == 0 ||
start_edge != laser.beamer_edge[laser.num_beamers - 1])))
{
- /* element is incoming beamer or other element */
+ // element is incoming beamer or other element
step_size = -step_size;
laser.num_edges--;
}
#if 0
if (IS_BEAMER(element))
- {
- printf("start_edge == %d, laser.beamer_edge == %d\n",
- start_edge, laser.beamer_edge);
- }
+ Debug("game:mm:DrawLaserExt",
+ "start_edge == %d, laser.beamer_edge == %d",
+ start_edge, laser.beamer_edge);
#endif
LX += step_size * XS;
}
#if 0
- printf("DrawLaser: Finally: (LX, LY) to (%d, %d) [%d]\n",
- LX, LY, element);
+ Debug("game:mm:DrawLaserExt", "Finally: (LX, LY) to (%d, %d) [%d]",
+ LX, LY, element);
#endif
}
{
if (laser.num_edges - start_edge < 0)
{
- Error(ERR_WARN, "DrawLaser: laser.num_edges - start_edge < 0");
+ Warn("DrawLaser: laser.num_edges - start_edge < 0");
return;
}
- /* check if laser is interrupted by beamer element */
+ // check if laser is interrupted by beamer element
if (laser.num_beamers > 0 &&
start_edge < laser.beamer_edge[laser.num_beamers - 1])
{
int i;
int tmp_start_edge = start_edge;
- /* draw laser segments forward from the start to the last beamer */
+ // draw laser segments forward from the start to the last beamer
for (i = 0; i < laser.num_beamers; i++)
{
int tmp_num_edges = laser.beamer_edge[i] - tmp_start_edge;
continue;
#if 0
- printf("DrawLaser: DL_LASER_ENABLED: i==%d: %d, %d\n",
- i, laser.beamer_edge[i], tmp_start_edge);
+ Debug("game:mm:DrawLaser", "DL_LASER_ENABLED: i==%d: %d, %d",
+ i, laser.beamer_edge[i], tmp_start_edge);
#endif
DrawLaserExt(tmp_start_edge, tmp_num_edges, DL_LASER_ENABLED);
tmp_start_edge = laser.beamer_edge[i];
}
- /* draw last segment from last beamer to the end */
+ // draw last segment from last beamer to the end
DrawLaserExt(tmp_start_edge, laser.num_edges - tmp_start_edge,
DL_LASER_ENABLED);
}
int last_num_edges = laser.num_edges;
int num_beamers = laser.num_beamers;
- /* delete laser segments backward from the end to the first beamer */
- for (i = num_beamers-1; i >= 0; i--)
+ // delete laser segments backward from the end to the first beamer
+ for (i = num_beamers - 1; i >= 0; i--)
{
int tmp_num_edges = last_num_edges - laser.beamer_edge[i];
#if 0
if (last_num_edges - start_edge <= 0)
- printf("DrawLaser: DL_LASER_DISABLED: %d, %d\n",
- last_num_edges, start_edge);
+ Debug("game:mm:DrawLaser", "DL_LASER_DISABLED: %d, %d",
+ last_num_edges, start_edge);
#endif
- /* delete first segment from start to the first beamer */
+ // special case when rotating first beamer: delete laser edge on beamer
+ // (but do not start scanning on previous edge to prevent mirror sound)
+ if (last_num_edges - start_edge == 1 && start_edge > 0)
+ DrawLaserLines(&laser.edge[start_edge - 1], 2, DL_LASER_DISABLED);
+
+ // delete first segment from start to the first beamer
DrawLaserExt(start_edge, last_num_edges - start_edge, DL_LASER_DISABLED);
}
}
{
DrawLaserExt(start_edge, laser.num_edges - start_edge, mode);
}
+
+ game_mm.laser_enabled = mode;
+}
+
+void DrawLaser_MM(void)
+{
+ DrawLaser(0, game_mm.laser_enabled);
}
boolean HitElement(int element, int hit_mask)
{
- if (HitOnlyAnEdge(element, hit_mask))
+ if (HitOnlyAnEdge(hit_mask))
return FALSE;
if (IS_MOVING(ELX, ELY) || IS_BLOCKED(ELX, ELY))
element = MovingOrBlocked2Element_MM(ELX, ELY);
#if 0
- printf("HitElement (1): element == %d\n", element);
+ Debug("game:mm:HitElement", "(1): element == %d", element);
#endif
#if 0
if ((ELX * TILEX + 14 - LX) * YS == (ELY * TILEY + 14 - LY) * XS)
- printf("HitElement (%d): EXACT MATCH @ (%d, %d)\n", element, ELX, ELY);
+ Debug("game:mm:HitElement", "(%d): EXACT MATCH @ (%d, %d)",
+ element, ELX, ELY);
else
- printf("HitElement (%d): FUZZY MATCH @ (%d, %d)\n", element, ELX, ELY);
+ Debug("game:mm:HitElement", "(%d): FUZZY MATCH @ (%d, %d)",
+ element, ELX, ELY);
#endif
AddDamagedField(ELX, ELY);
- /* this is more precise: check if laser would go through the center */
+ // this is more precise: check if laser would go through the center
if ((ELX * TILEX + 14 - LX) * YS != (ELY * TILEY + 14 - LY) * XS)
{
- /* skip the whole element before continuing the scan */
+ // skip the whole element before continuing the scan
do
{
LX += XS;
}
#if 0
- printf("HitElement (2): element == %d\n", element);
+ Debug("game:mm:HitElement", "(2): element == %d", element);
#endif
if (LX + 5 * XS < 0 ||
}
#if 0
- printf("HitElement (3): element == %d\n", element);
+ Debug("game:mm:HitElement", "(3): element == %d", element);
#endif
if (IS_POLAR(element) &&
((element - EL_POLAR_START) % 2 ||
(element - EL_POLAR_START) / 2 != laser.current_angle % 8))
{
- PlaySoundStereo(SND_KINK, ST(ELX));
+ PlayLevelSound_MM(ELX, ELY, element, MM_ACTION_HITTING);
laser.num_damages--;
if (IS_POLAR_CROSS(element) &&
(element - EL_POLAR_CROSS_START) != laser.current_angle % 4)
{
- PlaySoundStereo(SND_KINK, ST(ELX));
+ PlayLevelSound_MM(ELX, ELY, element, MM_ACTION_HITTING);
laser.num_damages--;
{
#if 0
if ((ELX * TILEX + 14 - LX) * YS == (ELY * TILEY + 14 - LY) * XS)
- printf("EXACT MATCH @ (%d, %d)\n", ELX, ELY);
+ Debug("game:mm:HitElement", "EXACT MATCH @ (%d, %d)", ELX, ELY);
else
- printf("FUZZY MATCH @ (%d, %d)\n", ELX, ELY);
+ Debug("game:mm:HitElement", "FUZZY MATCH @ (%d, %d)", ELX, ELY);
#endif
LX = ELX * TILEX + 14;
XS = 2 * Step[laser.current_angle].x;
YS = 2 * Step[laser.current_angle].y;
- if (!IS_22_5_ANGLE(laser.current_angle)) /* 90° or 45° angle */
+ if (!IS_22_5_ANGLE(laser.current_angle)) // 90° or 45° angle
step_size = 8;
else
step_size = 4;
LX += step_size * XS;
LY += step_size * YS;
-#if 0
- /* draw sparkles on mirror */
- if ((IS_MIRROR(element) || IS_MIRROR_FIXED(element)) &&
+ // draw sparkles on mirror
+ if ((IS_MIRROR(element) ||
+ IS_MIRROR_FIXED(element) ||
+ element == EL_PRISM) &&
current_angle != laser.current_angle)
{
- MoveSprite(vp, &Pfeil[2], 4 + 16 * ELX, 5 + 16 * ELY + 1);
+ MovDelay[ELX][ELY] = 11; // start animation
}
-#endif
if ((!IS_POLAR(element) && !IS_POLAR_CROSS(element)) &&
current_angle != laser.current_angle)
- PlaySoundStereo(SND_LASER, ST(ELX));
+ PlayLevelSound_MM(ELX, ELY, element, MM_ACTION_HITTING);
laser.overloaded =
(get_opposite_angle(laser.current_angle) ==
if (element == EL_BOMB || element == EL_MINE)
{
- PlaySoundStereo(SND_KINK, ST(ELX));
+ PlayLevelSound_MM(ELX, ELY, element, MM_ACTION_HITTING);
if (element == EL_MINE)
laser.overloaded = TRUE;
if (game_mm.kettles_still_needed > 0)
game_mm.kettles_still_needed--;
- RaiseScore_MM(10);
+ game.snapshot.collected_item = TRUE;
if (game_mm.kettles_still_needed == 0)
{
- int x, y;
- static int xy[4][2] =
- {
- { +1, 0 },
- { 0, -1 },
- { -1, 0 },
- { 0, +1 }
- };
-
- PlaySoundStereo(SND_KLING, ST(ELX));
-
- for (y = 0; y < lev_fieldy; y++)
- {
- for (x = 0; x < lev_fieldx; x++)
- {
- /* initiate opening animation of exit door */
- if (Feld[x][y] == EL_EXIT_CLOSED)
- Feld[x][y] = EL_EXIT_OPENING;
-
- /* remove field that blocks receiver */
- if (IS_RECEIVER(Feld[x][y]))
- {
- int phase = Feld[x][y] - EL_RECEIVER_START;
- int blocking_x, blocking_y;
-
- blocking_x = x + xy[phase][0];
- blocking_y = y + xy[phase][1];
-
- if (IN_LEV_FIELD(blocking_x, blocking_y))
- {
- Feld[blocking_x][blocking_y] = EL_EMPTY;
-
- DrawField_MM(blocking_x, blocking_y);
- }
- }
- }
- }
+ CheckExitMM();
DrawLaser(0, DL_LASER_ENABLED);
}
{
game_mm.num_keys++;
}
- else if (element == EL_LIGHTBALL)
- {
- RaiseScore_MM(10);
- }
else if (IS_PACMAN(element))
{
DeletePacMan(ELX, ELY);
- RaiseScore_MM(50);
}
+ RaiseScoreElement_MM(element);
+
return FALSE;
}
if (element == EL_LIGHTBULB_OFF || element == EL_LIGHTBULB_ON)
{
- PlaySoundStereo(SND_KINK, ST(ELX));
+ PlayLevelSound_MM(ELX, ELY, element, MM_ACTION_HITTING);
DrawLaser(0, DL_LASER_ENABLED);
- if (Feld[ELX][ELY] == EL_LIGHTBULB_OFF)
+ if (Tile[ELX][ELY] == EL_LIGHTBULB_OFF)
{
- Feld[ELX][ELY] = EL_LIGHTBULB_ON;
+ Tile[ELX][ELY] = EL_LIGHTBULB_ON;
game_mm.lights_still_needed--;
}
else
{
- Feld[ELX][ELY] = EL_LIGHTBULB_OFF;
+ Tile[ELX][ELY] = EL_LIGHTBULB_OFF;
game_mm.lights_still_needed++;
}
}
#if 0
- printf("HitElement (4): element == %d\n", element);
+ Debug("game:mm:HitElement", "(4): element == %d", element);
#endif
if ((IS_BEAMER(element) || IS_FIBRE_OPTIC(element)) &&
int step_size;
#if 0
- printf("HitElement (BEAMER): element == %d\n", element);
+ Debug("game:mm:HitElement", "(BEAMER): element == %d", element);
#endif
laser.num_damages--;
if (IS_BEAMER(element))
{
- laser.current_angle = get_element_angle(Feld[ELX][ELY]);
+ laser.current_angle = get_element_angle(Tile[ELX][ELY]);
XS = 2 * Step[laser.current_angle].x;
YS = 2 * Step[laser.current_angle].y;
}
return TRUE;
}
-boolean HitOnlyAnEdge(int element, int hit_mask)
+boolean HitOnlyAnEdge(int hit_mask)
{
- /* check if the laser hit only the edge of an element and, if so, go on */
+ // check if the laser hit only the edge of an element and, if so, go on
#if 0
- printf("LX, LY, hit_mask == %d, %d, %d\n", LX, LY, hit_mask);
+ Debug("game:mm:HitOnlyAnEdge", "LX, LY, hit_mask == %d, %d, %d",
+ LX, LY, hit_mask);
#endif
if ((hit_mask == HIT_MASK_TOPLEFT ||
hit_mask == HIT_MASK_TOPRIGHT ||
hit_mask == HIT_MASK_BOTTOMLEFT ||
hit_mask == HIT_MASK_BOTTOMRIGHT) &&
- laser.current_angle % 4) /* angle is not 90° */
+ laser.current_angle % 4) // angle is not 90°
{
int dx, dy;
dx = -1;
dy = +1;
}
- else /* (hit_mask == HIT_MASK_BOTTOMRIGHT) */
+ else // (hit_mask == HIT_MASK_BOTTOMRIGHT)
{
dx = +1;
dy = +1;
LY += YS;
#if 0
- printf("[HitOnlyAnEdge() == TRUE]\n");
+ Debug("game:mm:HitOnlyAnEdge", "[HitOnlyAnEdge() == TRUE]");
#endif
return TRUE;
}
#if 0
- printf("[HitOnlyAnEdge() == FALSE]\n");
+ Debug("game:mm:HitOnlyAnEdge", "[HitOnlyAnEdge() == FALSE]");
#endif
return FALSE;
boolean HitPolarizer(int element, int hit_mask)
{
- if (HitOnlyAnEdge(element, hit_mask))
+ if (HitOnlyAnEdge(hit_mask))
return FALSE;
if (IS_DF_GRID(element))
int grid_angle = get_element_angle(element);
#if 0
- printf("HitPolarizer: angle: grid == %d, laser == %d\n",
- grid_angle, laser.current_angle);
+ Debug("game:mm:HitPolarizer", "angle: grid == %d, laser == %d",
+ grid_angle, laser.current_angle);
#endif
AddLaserEdge(LX, LY);
if (laser.current_angle == grid_angle ||
laser.current_angle == get_opposite_angle(grid_angle))
{
- /* skip the whole element before continuing the scan */
+ // skip the whole element before continuing the scan
do
{
LX += XS;
LY += YS;
#if 0
- printf("HitPolarizer: LX, LY == %d, %d [%d, %d] [%d, %d]\n",
- LX, LY,
- LX / TILEX, LY / TILEY,
- LX % TILEX, LY % TILEY);
+ Debug("game:mm:HitPolarizer", "LX, LY == %d, %d [%d, %d] [%d, %d]",
+ LX, LY,
+ LX / TILEX, LY / TILEY,
+ LX % TILEX, LY % TILEY);
#endif
return FALSE;
{
return HitReflectingWalls(element, hit_mask);
}
- else /* IS_GRID_WOOD */
+ else // IS_GRID_WOOD
{
return HitAbsorbingWalls(element, hit_mask);
}
boolean HitLaserSource(int element, int hit_mask)
{
- if (HitOnlyAnEdge(element, hit_mask))
- return FALSE;
+ if (HitOnlyAnEdge(hit_mask))
+ return FALSE;
- PlaySoundStereo(SND_AUTSCH, ST(ELX));
- laser.overloaded = TRUE;
+ PlayLevelSound_MM(ELX, ELY, element, MM_ACTION_HITTING);
- return TRUE;
+ laser.overloaded = TRUE;
+
+ return TRUE;
}
boolean HitLaserDestination(int element, int hit_mask)
{
- if (HitOnlyAnEdge(element, hit_mask))
+ if (HitOnlyAnEdge(hit_mask))
return FALSE;
if (element != EL_EXIT_OPEN &&
game_mm.kettles_still_needed == 0 &&
laser.current_angle == get_opposite_angle(get_element_angle(element))))
{
- PlaySoundStereo(SND_HOLZ, ST(ELX));
+ PlayLevelSound_MM(ELX, ELY, element, MM_ACTION_HITTING);
+
return TRUE;
}
AddDamagedField(ELX, ELY);
if (game_mm.lights_still_needed == 0)
+ {
game_mm.level_solved = TRUE;
+ SetTileCursorActive(FALSE);
+ }
+
return TRUE;
}
boolean HitReflectingWalls(int element, int hit_mask)
{
- /* check if laser hits side of a wall with an angle that is not 90° */
+ // check if laser hits side of a wall with an angle that is not 90°
if (!IS_90_ANGLE(laser.current_angle) && (hit_mask == HIT_MASK_TOP ||
hit_mask == HIT_MASK_LEFT ||
hit_mask == HIT_MASK_RIGHT ||
hit_mask == HIT_MASK_BOTTOM))
{
- PlaySoundStereo(SND_HUI, ST(ELX));
+ PlayLevelSound_MM(ELX, ELY, element, MM_ACTION_HITTING);
LX -= XS;
LY -= YS;
if (!IS_DF_GRID(element))
AddLaserEdge(LX, LY);
- /* check if laser hits wall with an angle of 45° */
+ // check if laser hits wall with an angle of 45°
if (!IS_22_5_ANGLE(laser.current_angle))
{
if (hit_mask == HIT_MASK_TOP || hit_mask == HIT_MASK_BOTTOM)
laser.current_angle = get_mirrored_angle(laser.current_angle,
ANG_MIRROR_0);
}
- else /* hit_mask == HIT_MASK_LEFT || hit_mask == HIT_MASK_RIGHT */
+ else // hit_mask == HIT_MASK_LEFT || hit_mask == HIT_MASK_RIGHT
{
LY += 2 * YS;
laser.current_angle = get_mirrored_angle(laser.current_angle,
return FALSE;
}
- else /* hit_mask == HIT_MASK_LEFT || hit_mask == HIT_MASK_RIGHT */
+ else // hit_mask == HIT_MASK_LEFT || hit_mask == HIT_MASK_RIGHT
{
laser.current_angle = get_mirrored_angle(laser.current_angle,
ANG_MIRROR_90);
}
}
- /* reflection at the edge of reflecting DF style wall */
+ // reflection at the edge of reflecting DF style wall
if (IS_DF_WALL_STEEL(element) && IS_22_5_ANGLE(laser.current_angle))
{
if (((laser.current_angle == 1 || laser.current_angle == 3) &&
(hit_mask == HIT_MASK_TOPRIGHT || hit_mask == HIT_MASK_BOTTOMLEFT ?
ANG_MIRROR_135 : ANG_MIRROR_45);
- PlaySoundStereo(SND_HUI, ST(ELX));
+ PlayLevelSound_MM(ELX, ELY, element, MM_ACTION_HITTING);
AddDamagedField(ELX, ELY);
AddLaserEdge(LX, LY);
}
}
- /* reflection inside an edge of reflecting DF style wall */
+ // reflection inside an edge of reflecting DF style wall
if (IS_DF_WALL_STEEL(element) && IS_22_5_ANGLE(laser.current_angle))
{
if (((laser.current_angle == 1 || laser.current_angle == 3) &&
hit_mask == (HIT_MASK_ALL ^ HIT_MASK_TOPRIGHT) ?
ANG_MIRROR_135 : ANG_MIRROR_45);
- PlaySoundStereo(SND_HUI, ST(ELX));
+ PlayLevelSound_MM(ELX, ELY, element, MM_ACTION_HITTING);
/*
AddDamagedField(ELX, ELY);
}
}
- /* check if laser hits DF style wall with an angle of 90° */
+ // check if laser hits DF style wall with an angle of 90°
if (IS_DF_WALL(element) && IS_90_ANGLE(laser.current_angle))
{
if ((IS_HORIZ_ANGLE(laser.current_angle) &&
(IS_VERT_ANGLE(laser.current_angle) &&
(!(hit_mask & HIT_MASK_LEFT) || !(hit_mask & HIT_MASK_RIGHT))))
{
- static int last_LX = 0, last_LY = 0, last_hit_mask = 0;
-
- /* laser at last step touched nothing or the same side of the wall */
+ // laser at last step touched nothing or the same side of the wall
if (LX != last_LX || LY != last_LY || hit_mask == last_hit_mask)
{
AddDamagedField(ELX, ELY);
}
}
- if (!HitOnlyAnEdge(element, hit_mask))
+ if (!HitOnlyAnEdge(hit_mask))
{
laser.overloaded = TRUE;
boolean HitAbsorbingWalls(int element, int hit_mask)
{
- if (HitOnlyAnEdge(element, hit_mask))
+ if (HitOnlyAnEdge(hit_mask))
return FALSE;
if (ABS(XS) == 4 &&
element == EL_BLOCK_WOOD ||
element == EL_GATE_WOOD)
{
- PlaySoundStereo(SND_HOLZ, ST(ELX));
+ PlayLevelSound_MM(ELX, ELY, element, MM_ACTION_HITTING);
return TRUE;
}
{
int mask;
- mask = (LX + XS) / MINI_TILEX - ELX * 2 + 1; /* Quadrant (horizontal) */
- mask <<= (((LY + YS) / MINI_TILEY - ELY * 2) > 0) * 2; /* || (vertical) */
+ mask = (LX + XS) / MINI_TILEX - ELX * 2 + 1; // Quadrant (horizontal)
+ mask <<= (((LY + YS) / MINI_TILEY - ELY * 2) > 0) * 2; // || (vertical)
- /* check if laser hits wall with an angle of 90° */
+ // check if laser hits wall with an angle of 90°
if (IS_90_ANGLE(laser.current_angle))
mask += mask * (2 + IS_HORIZ_ANGLE(laser.current_angle) * 2);
{
int elx = (LX - 2 * XS) / TILEX;
int ely = (LY - 2 * YS) / TILEY;
- int element2 = Feld[elx][ely];
+ int element2 = Tile[elx][ely];
int mask;
if (element2 != EL_EMPTY && !IS_WALL_AMOEBA(element2))
return TRUE;
}
-void OpenExit(int x, int y)
+static void OpenExit(int x, int y)
{
int delay = 6;
- if (!MovDelay[x][y]) /* next animation frame */
+ if (!MovDelay[x][y]) // next animation frame
MovDelay[x][y] = 4 * delay;
- if (MovDelay[x][y]) /* wait some time before next frame */
+ if (MovDelay[x][y]) // wait some time before next frame
{
int phase;
if (!MovDelay[x][y])
{
- Feld[x][y] = EL_EXIT_OPEN;
+ Tile[x][y] = EL_EXIT_OPEN;
DrawField_MM(x, y);
}
}
}
-void OpenSurpriseBall(int x, int y)
+static void OpenSurpriseBall(int x, int y)
{
int delay = 2;
- if (!MovDelay[x][y]) /* next animation frame */
+ if (!MovDelay[x][y]) // next animation frame
MovDelay[x][y] = 50 * delay;
- if (MovDelay[x][y]) /* wait some time before next frame */
+ if (MovDelay[x][y]) // wait some time before next frame
{
MovDelay[x][y]--;
getGraphicSource(graphic, 0, &bitmap, &gx, &gy);
BlitBitmap(bitmap, drawto, gx + dx, gy + dy, 6, 6,
- SX + x * TILEX + dx, SY + y * TILEY + dy);
+ cSX + x * TILEX + dx, cSY + y * TILEY + dy);
MarkTileDirty(x, y);
}
if (!MovDelay[x][y])
{
- Feld[x][y] = Store[x][y];
+ Tile[x][y] = Store[x][y];
Store[x][y] = 0;
DrawField_MM(x, y);
}
}
-void MeltIce(int x, int y)
+static void MeltIce(int x, int y)
{
int frames = 5;
int delay = 5;
- if (!MovDelay[x][y]) /* next animation frame */
+ if (!MovDelay[x][y]) // next animation frame
MovDelay[x][y] = frames * delay;
- if (MovDelay[x][y]) /* wait some time before next frame */
+ if (MovDelay[x][y]) // wait some time before next frame
{
int phase;
int wall_mask = Store2[x][y];
- int real_element = Feld[x][y] - EL_WALL_CHANGING + EL_WALL_ICE;
+ int real_element = Tile[x][y] - EL_WALL_CHANGING + EL_WALL_ICE;
MovDelay[x][y]--;
phase = frames - MovDelay[x][y] / delay - 1;
{
int i;
- Feld[x][y] = real_element & (wall_mask ^ 0xFF);
+ Tile[x][y] = real_element & (wall_mask ^ 0xFF);
Store[x][y] = Store2[x][y] = 0;
- DrawWalls_MM(x, y, Feld[x][y]);
+ DrawWalls_MM(x, y, Tile[x][y]);
- if (Feld[x][y] == EL_WALL_ICE)
- Feld[x][y] = EL_EMPTY;
+ if (Tile[x][y] == EL_WALL_ICE)
+ Tile[x][y] = EL_EMPTY;
for (i = (laser.num_damages > 0 ? laser.num_damages - 1 : 0); i >= 0; i--)
if (laser.damage[i].is_mirror)
}
}
-void GrowAmoeba(int x, int y)
+static void GrowAmoeba(int x, int y)
{
int frames = 5;
int delay = 1;
- if (!MovDelay[x][y]) /* next animation frame */
+ if (!MovDelay[x][y]) // next animation frame
MovDelay[x][y] = frames * delay;
- if (MovDelay[x][y]) /* wait some time before next frame */
+ if (MovDelay[x][y]) // wait some time before next frame
{
int phase;
int wall_mask = Store2[x][y];
- int real_element = Feld[x][y] - EL_WALL_CHANGING + EL_WALL_AMOEBA;
+ int real_element = Tile[x][y] - EL_WALL_CHANGING + EL_WALL_AMOEBA;
MovDelay[x][y]--;
phase = MovDelay[x][y] / delay;
if (!MovDelay[x][y])
{
- Feld[x][y] = real_element;
+ Tile[x][y] = real_element;
Store[x][y] = Store2[x][y] = 0;
- DrawWalls_MM(x, y, Feld[x][y]);
+ DrawWalls_MM(x, y, Tile[x][y]);
DrawLaser(0, DL_LASER_ENABLED);
}
else if (!(MovDelay[x][y] % delay) && IN_SCR_FIELD(x, y))
}
}
+static void DrawFieldAnimated_MM(int x, int y)
+{
+ int element = Tile[x][y];
+
+ if (IS_BLOCKED(x, y))
+ return;
+
+ DrawField_MM(x, y);
+
+ if (IS_MIRROR(element) ||
+ IS_MIRROR_FIXED(element) ||
+ element == EL_PRISM)
+ {
+ if (MovDelay[x][y] != 0) // wait some time before next frame
+ {
+ MovDelay[x][y]--;
+
+ if (MovDelay[x][y] != 0)
+ {
+ int graphic = IMG_TWINKLE_WHITE;
+ int frame = getGraphicAnimationFrame(graphic, 10 - MovDelay[x][y]);
+
+ DrawGraphicThruMask_MM(SCREENX(x), SCREENY(y), graphic, frame);
+ }
+ }
+ }
+
+ laser.redraw = TRUE;
+}
+
static void Explode_MM(int x, int y, int phase, int mode)
{
int num_phase = 9, delay = 2;
laser.redraw = TRUE;
- if (phase == EX_PHASE_START) /* initialize 'Store[][]' field */
+ if (phase == EX_PHASE_START) // initialize 'Store[][]' field
{
- int center_element = Feld[x][y];
+ int center_element = Tile[x][y];
if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
{
- /* put moving element to center field (and let it explode there) */
+ // put moving element to center field (and let it explode there)
center_element = MovingOrBlocked2Element_MM(x, y);
RemoveMovingField_MM(x, y);
- Feld[x][y] = center_element;
+ Tile[x][y] = center_element;
}
if (center_element == EL_BOMB || IS_MCDUFFIN(center_element))
Store[x][y] = EL_EMPTY;
Store2[x][y] = mode;
- Feld[x][y] = EL_EXPLODING_OPAQUE;
+ Tile[x][y] = EL_EXPLODING_OPAQUE;
MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
Frame[x][y] = 1;
if (phase == half_phase)
{
- Feld[x][y] = EL_EXPLODING_TRANSP;
+ Tile[x][y] = EL_EXPLODING_TRANSP;
if (x == ELX && y == ELY)
ScanLaser();
{
if (Store[x][y] == EL_BOMB)
{
- laser.num_damages--;
DrawLaser(0, DL_LASER_DISABLED);
- laser.num_edges = 0;
+ InitLaser();
Bang_MM(laser.start_edge.x, laser.start_edge.y);
Store[x][y] = EL_EMPTY;
+
+ game_mm.game_over = TRUE;
+ game_mm.game_over_cause = GAME_OVER_BOMB;
+
+ SetTileCursorActive(FALSE);
+
+ laser.overloaded = FALSE;
}
else if (IS_MCDUFFIN(Store[x][y]))
{
- game_mm.game_over = TRUE;
- game_mm.game_over_cause = GAME_OVER_BOMB;
Store[x][y] = EL_EMPTY;
+
+ game.restart_game_message = "Bomb killed Mc Duffin! Play it again?";
}
- Feld[x][y] = Store[x][y];
+ Tile[x][y] = Store[x][y];
Store[x][y] = Store2[x][y] = 0;
MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
- InitField(x, y, FALSE);
+ InitField(x, y);
DrawField_MM(x, y);
}
else if (!(phase % delay) && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
getGraphicSource(graphic, graphic_phase, &bitmap, &src_x, &src_y);
BlitBitmap(bitmap, drawto_field, src_x, src_y, TILEX, TILEY,
- FX + x * TILEX, FY + y * TILEY);
+ cFX + x * TILEX, cFY + y * TILEY);
MarkTileDirty(x, y);
}
static void Bang_MM(int x, int y)
{
- int element = Feld[x][y];
+ int element = Tile[x][y];
int mode = EX_NORMAL;
#if 0
DrawLaser(0, DL_LASER_ENABLED);
#endif
- switch(element)
+ switch (element)
{
case EL_KETTLE:
mode = EX_KETTLE;
}
if (IS_PACMAN(element))
- PlaySoundStereo(SND_QUIEK, ST(x));
+ PlayLevelSound_MM(x, y, element, MM_ACTION_EXPLODING);
else if (element == EL_BOMB || IS_MCDUFFIN(element))
- PlaySoundStereo(SND_ROAAAR, ST(x));
+ PlayLevelSound_MM(x, y, element, MM_ACTION_EXPLODING);
else if (element == EL_KEY)
- PlaySoundStereo(SND_KLING, ST(x));
+ PlayLevelSound_MM(x, y, element, MM_ACTION_EXPLODING);
else
- PlaySoundStereo((mode == EX_SHORT ? SND_WHOOSH : SND_KABUMM), ST(x));
+ PlayLevelSound_MM(x, y, element, MM_ACTION_EXPLODING);
Explode_MM(x, y, EX_PHASE_START, mode);
}
{ MV_RIGHT, MV_LEFT, MV_UP }
};
- int element = Feld[x][y];
+ int element = Tile[x][y];
int old_move_dir = MovDir[x][y];
int right_dir = turn[old_move_dir].right;
int back_dir = turn[old_move_dir].back;
boolean can_turn_right = FALSE;
if (IN_LEV_FIELD(right_x, right_y) &&
- IS_EATABLE4PACMAN(Feld[right_x][right_y]))
+ IS_EATABLE4PACMAN(Tile[right_x][right_y]))
can_turn_right = TRUE;
if (can_turn_right)
static void StartMoving_MM(int x, int y)
{
- int element = Feld[x][y];
+ int element = Tile[x][y];
if (Stop[x][y])
return;
{
int newx, newy;
- if (MovDelay[x][y]) /* wait some time before next movement */
+ if (MovDelay[x][y]) // wait some time before next movement
{
MovDelay[x][y]--;
return;
}
- /* now make next step */
+ // now make next step
- Moving2Blocked_MM(x, y, &newx, &newy); /* get next screen position */
+ Moving2Blocked_MM(x, y, &newx, &newy); // get next screen position
if (element == EL_PACMAN &&
- IN_LEV_FIELD(newx, newy) && IS_EATABLE4PACMAN(Feld[newx][newy]) &&
+ IN_LEV_FIELD(newx, newy) && IS_EATABLE4PACMAN(Tile[newx][newy]) &&
!ObjHit(newx, newy, HIT_POS_CENTER))
{
- Store[newx][newy] = Feld[newx][newy];
- Feld[newx][newy] = EL_EMPTY;
+ Store[newx][newy] = Tile[newx][newy];
+ Tile[newx][newy] = EL_EMPTY;
DrawField_MM(newx, newy);
}
else if (!IN_LEV_FIELD(newx, newy) || !IS_FREE(newx, newy) ||
ObjHit(newx, newy, HIT_POS_CENTER))
{
- /* object was running against a wall */
+ // object was running against a wall
TurnRound(x, y);
static void ContinueMoving_MM(int x, int y)
{
- int element = Feld[x][y];
+ int element = Tile[x][y];
int direction = MovDir[x][y];
int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
MovPos[x][y] += step;
- if (ABS(MovPos[x][y]) >= TILEX) /* object reached its destination */
+ if (ABS(MovPos[x][y]) >= TILEX) // object reached its destination
{
- Feld[x][y] = EL_EMPTY;
- Feld[newx][newy] = element;
+ Tile[x][y] = EL_EMPTY;
+ Tile[newx][newy] = element;
MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
MovDelay[newx][newy] = 0;
}
}
}
- else /* still moving on */
+ else // still moving on
{
DrawField_MM(x, y);
}
laser.redraw = TRUE;
}
-void ClickElement(int mx, int my, int button)
+boolean ClickElement(int x, int y, int button)
{
- static unsigned int click_delay = 0;
- static int click_delay_value = CLICK_DELAY_SHORT;
+ static DelayCounter click_delay = { CLICK_DELAY };
static boolean new_button = TRUE;
+ boolean element_clicked = FALSE;
int element;
- int x = (mx - SX) / TILEX, y = (my - SY) / TILEY;
- /* do not rotate objects hit by the laser after the game was solved */
+ if (button == -1)
+ {
+ // initialize static variables
+ click_delay.count = 0;
+ click_delay.value = CLICK_DELAY;
+ new_button = TRUE;
+
+ return FALSE;
+ }
+
+ // do not rotate objects hit by the laser after the game was solved
if (game_mm.level_solved && Hit[x][y])
- return;
+ return FALSE;
if (button == MB_RELEASED)
{
new_button = TRUE;
- click_delay_value = CLICK_DELAY_SHORT;
+ click_delay.value = CLICK_DELAY;
- /* release eventually hold auto-rotating mirror */
+ // release eventually hold auto-rotating mirror
RotateMirror(x, y, MB_RELEASED);
- return;
+ return FALSE;
}
- if (!DelayReached(&click_delay, click_delay_value) && !new_button)
- return;
+ if (!FrameReached(&click_delay) && !new_button)
+ return FALSE;
- if (button == MB_MIDDLEBUTTON) /* middle button has no function */
- return;
+ if (button == MB_MIDDLEBUTTON) // middle button has no function
+ return FALSE;
- if (!IN_PIX_FIELD(mx - SX, my - SY))
- return;
+ if (!IN_LEV_FIELD(x, y))
+ return FALSE;
- if (Feld[x][y] == EL_EMPTY)
- return;
+ if (Tile[x][y] == EL_EMPTY)
+ return FALSE;
- element = Feld[x][y];
+ element = Tile[x][y];
if (IS_MIRROR(element) ||
IS_BEAMER(element) ||
IS_DF_MIRROR_AUTO(element))
{
RotateMirror(x, y, button);
+
+ element_clicked = TRUE;
}
else if (IS_MCDUFFIN(element))
{
InitLaser();
- Feld[x][y] = element;
+ Tile[x][y] = element;
DrawField_MM(x, y);
/*
if (!laser.fuse_off)
ScanLaser();
+
+ element_clicked = TRUE;
}
else if (element == EL_FUSE_ON && laser.fuse_off)
{
if (x != laser.fuse_x || y != laser.fuse_y)
- return;
+ return FALSE;
laser.fuse_off = FALSE;
laser.fuse_x = laser.fuse_y = -1;
DrawGraphic_MM(x, y, IMG_MM_FUSE_ACTIVE);
ScanLaser();
+
+ element_clicked = TRUE;
}
else if (element == EL_FUSE_ON && !laser.fuse_off && new_button)
{
DrawLaser(0, DL_LASER_DISABLED);
DrawGraphic_MM(x, y, IMG_MM_FUSE);
+
+ element_clicked = TRUE;
}
else if (element == EL_LIGHTBALL)
{
Bang_MM(x, y);
- RaiseScore_MM(10);
+ RaiseScoreElement_MM(element);
DrawLaser(0, DL_LASER_ENABLED);
+
+ element_clicked = TRUE;
}
- click_delay_value = (new_button ? CLICK_DELAY_LONG : CLICK_DELAY_SHORT);
+ click_delay.value = (new_button ? CLICK_DELAY_FIRST : CLICK_DELAY);
new_button = FALSE;
+
+ return element_clicked;
}
void RotateMirror(int x, int y, int button)
{
- static int hold_x = -1, hold_y = -1;
-
if (button == MB_RELEASED)
{
- /* release eventually hold auto-rotating mirror */
+ // release eventually hold auto-rotating mirror
hold_x = -1;
hold_y = -1;
return;
}
- if (IS_MIRROR(Feld[x][y]) ||
- IS_POLAR_CROSS(Feld[x][y]) ||
- IS_POLAR(Feld[x][y]) ||
- IS_BEAMER(Feld[x][y]) ||
- IS_DF_MIRROR(Feld[x][y]) ||
- IS_GRID_STEEL_AUTO(Feld[x][y]) ||
- IS_GRID_WOOD_AUTO(Feld[x][y]))
+ if (IS_MIRROR(Tile[x][y]) ||
+ IS_POLAR_CROSS(Tile[x][y]) ||
+ IS_POLAR(Tile[x][y]) ||
+ IS_BEAMER(Tile[x][y]) ||
+ IS_DF_MIRROR(Tile[x][y]) ||
+ IS_GRID_STEEL_AUTO(Tile[x][y]) ||
+ IS_GRID_WOOD_AUTO(Tile[x][y]))
{
- Feld[x][y] = get_rotated_element(Feld[x][y], BUTTON_ROTATION(button));
+ Tile[x][y] = get_rotated_element(Tile[x][y], BUTTON_ROTATION(button));
}
- else if (IS_DF_MIRROR_AUTO(Feld[x][y]))
+ else if (IS_DF_MIRROR_AUTO(Tile[x][y]))
{
if (button == MB_LEFTBUTTON)
{
- /* left mouse button only for manual adjustment, no auto-rotating;
- freeze mirror for until mouse button released */
+ // left mouse button only for manual adjustment, no auto-rotating;
+ // freeze mirror for until mouse button released
hold_x = x;
hold_y = y;
}
else if (button == MB_RIGHTBUTTON && (hold_x != x || hold_y != y))
{
- Feld[x][y] = get_rotated_element(Feld[x][y], ROTATE_RIGHT);
+ Tile[x][y] = get_rotated_element(Tile[x][y], ROTATE_RIGHT);
}
}
- if (IS_GRID_STEEL_AUTO(Feld[x][y]) || IS_GRID_WOOD_AUTO(Feld[x][y]))
+ if (IS_GRID_STEEL_AUTO(Tile[x][y]) || IS_GRID_WOOD_AUTO(Tile[x][y]))
{
int edge = Hit[x][y];
if (edge == 0)
{
- Error(ERR_WARN, "RotateMirror: inconsistent field Hit[][]!\n");
+ Warn("RotateMirror: inconsistent field Hit[][]!\n");
+
edge = 1;
}
DrawField_MM(x, y);
- if ((IS_BEAMER(Feld[x][y]) ||
- IS_POLAR(Feld[x][y]) ||
- IS_POLAR_CROSS(Feld[x][y])) && x == ELX && y == ELY)
+ if ((IS_BEAMER(Tile[x][y]) ||
+ IS_POLAR(Tile[x][y]) ||
+ IS_POLAR_CROSS(Tile[x][y])) && x == ELX && y == ELY)
{
check = 0;
- if (IS_BEAMER(Feld[x][y]))
+ if (IS_BEAMER(Tile[x][y]))
{
#if 0
- printf("TEST (%d, %d) [%d] [%d]\n",
- LX, LY,
- laser.beamer_edge, laser.beamer[1].num);
+ Debug("game:mm:RotateMirror", "TEST (%d, %d) [%d] [%d]",
+ LX, LY, laser.beamer_edge, laser.beamer[1].num);
#endif
laser.num_edges--;
}
}
-void AutoRotateMirrors()
+static void AutoRotateMirrors(void)
{
- static unsigned int rotate_delay = 0;
int x, y;
- if (!DelayReached(&rotate_delay, AUTO_ROTATE_DELAY))
+ if (!FrameReached(&rotate_delay))
return;
for (x = 0; x < lev_fieldx; x++)
{
for (y = 0; y < lev_fieldy; y++)
{
- int element = Feld[x][y];
+ int element = Tile[x][y];
- /* do not rotate objects hit by the laser after the game was solved */
+ // do not rotate objects hit by the laser after the game was solved
if (game_mm.level_solved && Hit[x][y])
continue;
if (bits & HIT_POS_CENTER)
{
- if (ReadPixel(drawto, SX + obx + 15, SY + oby + 15) == pen_ray)
+ if (CheckLaserPixel(cSX + obx + 15,
+ cSY + oby + 15))
return TRUE;
}
if (bits & HIT_POS_EDGE)
{
for (i = 0; i < 4; i++)
- if (ReadPixel(drawto,
- SX + obx + 31 * (i % 2),
- SY + oby + 31 * (i / 2)) == pen_ray)
+ if (CheckLaserPixel(cSX + obx + 31 * (i % 2),
+ cSY + oby + 31 * (i / 2)))
return TRUE;
}
if (bits & HIT_POS_BETWEEN)
{
for (i = 0; i < 4; i++)
- if (ReadPixel(drawto,
- SX + 4 + obx + 22 * (i % 2),
- SY + 4 + oby + 22 * (i / 2)) == pen_ray)
+ if (CheckLaserPixel(cSX + 4 + obx + 22 * (i % 2),
+ cSY + 4 + oby + 22 * (i / 2)))
return TRUE;
}
if (color_status == STATIC_COLORS)
return;
- CC = Counter();
+ CC = FrameCounter;
- if (CC < Cc || CC > Cc + 50)
+ if (CC < Cc || CC > Cc + 2)
{
Cc = CC;
}
}
-static void GameActions_MM_Ext(byte action[MAX_PLAYERS], boolean warp_mode)
+static void GameActions_MM_Ext(void)
{
- static unsigned int action_delay = 0;
- static unsigned int pacman_delay = 0;
- static unsigned int energy_delay = 0;
- static unsigned int overload_delay = 0;
int element;
int x, y, i;
int r, d;
- WaitUntilDelayReached(&action_delay, GameFrameDelay);
-
for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
Stop[x][y] = FALSE;
for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
{
- element = Feld[x][y];
+ element = Tile[x][y];
if (!IS_MOVING(x, y) && CAN_MOVE(element))
StartMoving_MM(x, y);
MeltIce(x, y);
else if (IS_WALL_CHANGING(element) && Store[x][y] == EL_WALL_AMOEBA)
GrowAmoeba(x, y);
+ else
+ DrawFieldAnimated_MM(x, y);
}
AutoRotateMirrors();
#if 1
- /* !!! CHANGE THIS: REDRAW ONLY WHEN NEEDED !!! */
+ // !!! CHANGE THIS: REDRAW ONLY WHEN NEEDED !!!
- /* redraw after Explode_MM() ... */
+ // redraw after Explode_MM() ...
if (laser.redraw)
DrawLaser(0, DL_LASER_ENABLED);
laser.redraw = FALSE;
#endif
- CT = Counter();
+ CT = FrameCounter;
- if (game_mm.num_pacman && DelayReached(&pacman_delay, 250))
+ if (game_mm.num_pacman && FrameReached(&pacman_delay))
{
MovePacMen();
}
}
- if (DelayReached(&energy_delay, 4000))
+ if (FrameReached(&energy_delay))
{
- game_mm.energy_left--;
- if (game_mm.energy_left >= 0)
+ if (game_mm.energy_left > 0)
{
-#if 0
- BlitBitmap(pix[PIX_DOOR], drawto,
- DOOR_GFX_PAGEX5 + XX_ENERGY, DOOR_GFX_PAGEY1 + YY_ENERGY,
- ENERGY_XSIZE, ENERGY_YSIZE - game_mm.energy_left,
- DX_ENERGY, DY_ENERGY);
-#endif
+ game_mm.energy_left--;
+
redraw_mask |= REDRAW_DOOR_1;
}
- else if (setup.time_limit)
+ else if (game.time_limit && !game_mm.game_over)
{
int i;
DrawLaser(0, DL_LASER_ENABLED);
BackToFront();
- Delay(50);
+ Delay_WithScreenUpdates(50);
}
- StopSound(SND_WARNTON);
+ StopSound_MM(SND_MM_GAME_HEALTH_CHARGING);
+#if 0
FadeMusic();
+#endif
DrawLaser(0, DL_LASER_DISABLED);
game_mm.game_over = TRUE;
game_mm.game_over_cause = GAME_OVER_NO_ENERGY;
-#if 0
- if (Request("Out of magic energy ! Play it again ?",
- REQ_ASK | REQ_STAY_CLOSED))
- {
- InitGame();
- }
- else
- {
- game_status = MAINMENU;
- DrawMainMenu();
- }
-#endif
+ SetTileCursorActive(FALSE);
+
+ game.restart_game_message = "Out of magic energy! Play it again?";
return;
}
element = laser.dest_element;
#if 0
- if (element != Feld[ELX][ELY])
+ if (element != Tile[ELX][ELY])
{
- printf("element == %d, Feld[ELX][ELY] == %d\n",
- element, Feld[ELX][ELY]);
+ Debug("game:mm:GameActions_MM_Ext", "element == %d, Tile[ELX][ELY] == %d",
+ element, Tile[ELX][ELY]);
}
#endif
!IS_WALL_AMOEBA(element))
return;
+ overload_delay.value = HEALTH_DELAY(laser.overloaded);
+
if (((laser.overloaded && laser.overload_value < MAX_LASER_OVERLOAD) ||
(!laser.overloaded && laser.overload_value > 0)) &&
- DelayReached(&overload_delay, 60 + !laser.overloaded * 120))
+ FrameReached(&overload_delay))
{
if (laser.overloaded)
laser.overload_value++;
laser.overload_value = 0;
}
+ game_mm.laser_overload_value = laser.overload_value;
+
if (laser.overload_value < MAX_LASER_OVERLOAD - 8)
{
int color_up = 0xFF * laser.overload_value / MAX_LASER_OVERLOAD;
(native_mm_level.laser_blue ? color_down : 0x00));
DrawLaser(0, DL_LASER_ENABLED);
- BackToFront();
- }
-
- if (laser.overloaded)
- {
- if (setup.sound_loops)
- PlaySoundExt(SND_WARNTON, SOUND_MAX_VOLUME, SOUND_MAX_RIGHT,
- SND_CTRL_PLAY_LOOP);
- else
- PlaySoundStereo(SND_WARNTON, SOUND_MAX_RIGHT);
}
if (!laser.overloaded)
- StopSound(SND_WARNTON);
+ StopSound_MM(SND_MM_GAME_HEALTH_CHARGING);
+ else if (setup.sound_loops)
+ PlaySoundLoop_MM(SND_MM_GAME_HEALTH_CHARGING);
+ else
+ PlaySound_MM(SND_MM_GAME_HEALTH_CHARGING);
if (laser.overloaded)
{
{
int i;
+ UpdateAndDisplayGameControlValues();
+
for (i = 15; i >= 0; i--)
{
#if 0
DrawLaser(0, DL_LASER_ENABLED);
BackToFront();
- Delay(50);
+ Delay_WithScreenUpdates(50);
}
DrawLaser(0, DL_LASER_DISABLED);
game_mm.game_over = TRUE;
game_mm.game_over_cause = GAME_OVER_OVERLOADED;
-#if 0
- if (Request("Magic spell hit Mc Duffin ! Play it again ?",
- REQ_ASK | REQ_STAY_CLOSED))
- {
- InitGame();
- }
- else
- {
- game_status = MAINMENU;
- DrawMainMenu();
- }
-#endif
+ SetTileCursorActive(FALSE);
+
+ game.restart_game_message = "Magic spell hit Mc Duffin! Play it again?";
return;
}
CT -= Ct;
- if (element == EL_BOMB && CT > 1500)
+ if (element == EL_BOMB && CT > native_mm_level.time_bomb)
{
if (game_mm.cheat_no_explosion)
return;
-#if 0
- laser.num_damages--;
- DrawLaser(0, DL_LASER_DISABLED);
- laser.num_edges = 0;
-#endif
-
Bang_MM(ELX, ELY);
laser.dest_element = EL_EXPLODING_OPAQUE;
-#if 0
- Bang_MM(ELX, ELY);
- laser.num_damages--;
- DrawLaser(0, DL_LASER_DISABLED);
-
- laser.num_edges = 0;
- Bang_MM(laser.start_edge.x, laser.start_edge.y);
-
- if (Request("Bomb killed Mc Duffin ! Play it again ?",
- REQ_ASK | REQ_STAY_CLOSED))
- {
- InitGame();
- }
- else
- {
- game_status = MAINMENU;
- DrawMainMenu();
- }
-#endif
-
return;
}
- if (element == EL_FUSE_ON && CT > 500)
+ if (element == EL_FUSE_ON && CT > native_mm_level.time_fuse)
{
laser.fuse_off = TRUE;
laser.fuse_x = ELX;
DrawGraphic_MM(ELX, ELY, IMG_MM_FUSE);
}
- if (element == EL_BALL_GRAY && CT > 1500)
+ if (element == EL_BALL_GRAY && CT > native_mm_level.time_ball)
{
static int new_elements[] =
{
int new_element = new_elements[RND(num_new_elements)];
Store[ELX][ELY] = new_element + RND(get_num_elements(new_element));
- Feld[ELX][ELY] = EL_GRAY_BALL_OPENING;
+ Tile[ELX][ELY] = EL_GRAY_BALL_OPENING;
- /* !!! CHECK AGAIN: Laser on Polarizer !!! */
+ // !!! CHECK AGAIN: Laser on Polarizer !!!
ScanLaser();
return;
DrawLaser(0, DL_LASER_ENABLED);
- Delay(50);
+ Delay_WithScreenUpdates(50);
}
- Feld[ELX][ELY] = element;
+ Tile[ELX][ELY] = element;
DrawField_MM(ELX, ELY);
#if 0
- printf("NEW ELEMENT: (%d, %d)\n", ELX, ELY);
+ Debug("game:mm:GameActions_MM_Ext", "NEW ELEMENT: (%d, %d)", ELX, ELY);
#endif
- /* above stuff: GRAY BALL -> PRISM !!! */
+ // above stuff: GRAY BALL -> PRISM !!!
/*
LX = ELX * TILEX + 14;
LY = ELY * TILEY + 14;
#endif
ScanLaser();
-
- /*
- printf("TEST ELEMENT: %d\n", Feld[0][0]);
- */
#endif
return;
}
- if (IS_WALL_ICE(element) && CT > 1000)
+ if (IS_WALL_ICE(element) && CT > 50)
{
- PlaySoundStereo(SND_SLURP, ST(ELX));
+ PlayLevelSound_MM(ELX, ELY, element, MM_ACTION_SHRINKING);
{
- Feld[ELX][ELY] = Feld[ELX][ELY] - EL_WALL_ICE + EL_WALL_CHANGING;
+ Tile[ELX][ELY] = Tile[ELX][ELY] - EL_WALL_ICE + EL_WALL_CHANGING;
Store[ELX][ELY] = EL_WALL_ICE;
Store2[ELX][ELY] = laser.wall_mask;
- laser.dest_element = Feld[ELX][ELY];
+ laser.dest_element = Tile[ELX][ELY];
return;
}
if (i == 4)
{
- Feld[ELX][ELY] &= (laser.wall_mask ^ 0xFF);
+ Tile[ELX][ELY] &= (laser.wall_mask ^ 0xFF);
phase = 0;
}
- DrawWallsAnimation_MM(ELX, ELY, Feld[ELX][ELY], phase, laser.wall_mask);
+ DrawWallsAnimation_MM(ELX, ELY, Tile[ELX][ELY], phase, laser.wall_mask);
BackToFront();
- Delay(100);
+ Delay_WithScreenUpdates(100);
}
- if (Feld[ELX][ELY] == EL_WALL_ICE)
- Feld[ELX][ELY] = EL_EMPTY;
+ if (Tile[ELX][ELY] == EL_WALL_ICE)
+ Tile[ELX][ELY] = EL_EMPTY;
/*
laser.num_edges--;
- LX = laser.edge[laser.num_edges].x - (SX + 2);
- LY = laser.edge[laser.num_edges].y - (SY + 2);
+ LX = laser.edge[laser.num_edges].x - cSX2;
+ LY = laser.edge[laser.num_edges].y - cSY2;
*/
for (i = (laser.num_damages > 0 ? laser.num_damages - 1 : 0); i >= 0; i--)
return;
}
- if (IS_WALL_AMOEBA(element) && CT > 1200)
+ if (IS_WALL_AMOEBA(element) && CT > 60)
{
int k1, k2, k3, dx, dy, de, dm;
- int element2 = Feld[ELX][ELY];
+ int element2 = Tile[ELX][ELY];
if (element2 != EL_EMPTY && !IS_WALL_AMOEBA(element))
return;
{
if (laser.wall_mask & (1 << i))
{
- if (ReadPixel(drawto,
- SX + ELX * TILEX + 14 + (i % 2) * 2,
- SY + ELY * TILEY + 31 * (i / 2)) == pen_ray)
+ if (CheckLaserPixel(cSX + ELX * TILEX + 14 + (i % 2) * 2,
+ cSY + ELY * TILEY + 31 * (i / 2)))
break;
- if (ReadPixel(drawto,
- SX + ELX * TILEX + 31 * (i % 2),
- SY + ELY * TILEY + 14 + (i / 2) * 2) == pen_ray)
+
+ if (CheckLaserPixel(cSX + ELX * TILEX + 31 * (i % 2),
+ cSY + ELY * TILEY + 14 + (i / 2) * 2))
break;
}
}
{
if (laser.wall_mask & (1 << i))
{
- if (ReadPixel(drawto,
- SX + ELX * TILEX + 31 * (i % 2),
- SY + ELY * TILEY + 31 * (i / 2)) == pen_ray)
+ if (CheckLaserPixel(cSX + ELX * TILEX + 31 * (i % 2),
+ cSY + ELY * TILEY + 31 * (i / 2)))
break;
}
}
if (laser.num_beamers > 0 ||
k1 < 1 || k2 < 4 || k3 < 4 ||
- ReadPixel(drawto, SX + ELX * TILEX + 14, SY + ELY * TILEY + 14)
- == pen_ray)
+ CheckLaserPixel(cSX + ELX * TILEX + 14,
+ cSY + ELY * TILEY + 14))
{
laser.num_edges = r;
laser.num_damages = d;
DrawLaser(0, DL_LASER_DISABLED);
}
- Feld[ELX][ELY] = element | laser.wall_mask;
+ Tile[ELX][ELY] = element | laser.wall_mask;
dx = ELX;
dy = ELY;
- de = Feld[ELX][ELY];
+ de = Tile[ELX][ELY];
dm = laser.wall_mask;
#if 1
ScanLaser();
DrawLaser(0, DL_LASER_ENABLED);
- PlaySoundStereo(SND_AMOEBE, ST(dx));
+ PlayLevelSound_MM(dx, dy, element, MM_ACTION_GROWING);
- Feld[x][y] = Feld[x][y] - EL_WALL_AMOEBA + EL_WALL_CHANGING;
+ Tile[x][y] = Tile[x][y] - EL_WALL_AMOEBA + EL_WALL_CHANGING;
Store[x][y] = EL_WALL_AMOEBA;
Store2[x][y] = wall_mask;
ScanLaser();
DrawLaser(0, DL_LASER_ENABLED);
- PlaySoundStereo(SND_AMOEBE, ST(dx));
+ PlayLevelSound_MM(dx, dy, element, MM_ACTION_GROWING);
for (i = 4; i >= 0; i--)
{
DrawWallsAnimation_MM(dx, dy, de, i, dm);
BackToFront();
- Delay(20);
+ Delay_WithScreenUpdates(20);
}
DrawLaser(0, DL_LASER_ENABLED);
}
if ((element == EL_BLOCK_WOOD || element == EL_BLOCK_STONE) &&
- laser.stops_inside_element && CT > 1500)
+ laser.stops_inside_element && CT > native_mm_level.time_block)
{
int x, y;
int k;
x = ELX + Step[k * 4].x;
y = ELY + Step[k * 4].y;
- if (!IN_LEV_FIELD(x, y) || Feld[x][y] != EL_EMPTY)
+ if (!IN_LEV_FIELD(x, y) || Tile[x][y] != EL_EMPTY)
continue;
if (ObjHit(x, y, HIT_POS_CENTER | HIT_POS_EDGE | HIT_POS_BETWEEN))
return;
}
- PlaySoundStereo(SND_BONG, ST(ELX));
+ PlayLevelSound_MM(ELX, ELY, element, MM_ACTION_PUSHING);
- Feld[ELX][ELY] = 0;
- Feld[x][y] = element;
+ Tile[ELX][ELY] = 0;
+ Tile[x][y] = element;
DrawGraphic_MM(ELX, ELY, IMG_EMPTY);
DrawField_MM(x, y);
return;
}
- if (element == EL_FUEL_FULL && CT > 200)
+ if (element == EL_FUEL_FULL && CT > 10)
{
for (i = game_mm.energy_left; i <= MAX_LASER_ENERGY; i+=2)
{
redraw_mask |= REDRAW_DOOR_1;
BackToFront();
- Delay(20);
+ Delay_WithScreenUpdates(20);
}
game_mm.energy_left = MAX_LASER_ENERGY;
- Feld[ELX][ELY] = EL_FUEL_EMPTY;
+ Tile[ELX][ELY] = EL_FUEL_EMPTY;
DrawField_MM(ELX, ELY);
DrawLaser(0, DL_LASER_ENABLED);
return;
}
-void GameActions_MM(byte action[MAX_PLAYERS], boolean warp_mode)
+void GameActions_MM(struct MouseActionInfo action)
{
- if (!button_status)
- ClickElement(0, 0, MB_NOT_PRESSED);
+ boolean element_clicked = ClickElement(action.lx, action.ly, action.button);
+ boolean button_released = (action.button == MB_RELEASED);
+
+ GameActions_MM_Ext();
- GameActions_MM_Ext(action, warp_mode);
+ CheckSingleStepMode_MM(element_clicked, button_released);
}
-void MovePacMen()
+void MovePacMen(void)
{
- static int p = -1;
int mx, my, ox, oy, nx, ny;
int element;
int l;
- if (++p >= game_mm.num_pacman)
- p = 0;
+ if (++pacman_nr >= game_mm.num_pacman)
+ pacman_nr = 0;
- game_mm.pacman[p].dir--;
+ game_mm.pacman[pacman_nr].dir--;
for (l = 1; l < 5; l++)
{
- game_mm.pacman[p].dir++;
+ game_mm.pacman[pacman_nr].dir++;
- if (game_mm.pacman[p].dir > 4)
- game_mm.pacman[p].dir = 1;
+ if (game_mm.pacman[pacman_nr].dir > 4)
+ game_mm.pacman[pacman_nr].dir = 1;
- if (game_mm.pacman[p].dir % 2)
+ if (game_mm.pacman[pacman_nr].dir % 2)
{
mx = 0;
- my = game_mm.pacman[p].dir - 2;
+ my = game_mm.pacman[pacman_nr].dir - 2;
}
else
{
my = 0;
- mx = 3 - game_mm.pacman[p].dir;
+ mx = 3 - game_mm.pacman[pacman_nr].dir;
}
- ox = game_mm.pacman[p].x;
- oy = game_mm.pacman[p].y;
+ ox = game_mm.pacman[pacman_nr].x;
+ oy = game_mm.pacman[pacman_nr].y;
nx = ox + mx;
ny = oy + my;
- element = Feld[nx][ny];
+ element = Tile[nx][ny];
if (nx < 0 || nx > 15 || ny < 0 || ny > 11)
continue;
if (ObjHit(nx, ny, HIT_POS_CENTER))
continue;
- Feld[ox][oy] = EL_EMPTY;
- Feld[nx][ny] =
+ Tile[ox][oy] = EL_EMPTY;
+ Tile[nx][ny] =
EL_PACMAN_RIGHT - 1 +
- (game_mm.pacman[p].dir - 1 +
- (game_mm.pacman[p].dir % 2) * 2);
+ (game_mm.pacman[pacman_nr].dir - 1 +
+ (game_mm.pacman[pacman_nr].dir % 2) * 2);
- game_mm.pacman[p].x = nx;
- game_mm.pacman[p].y = ny;
+ game_mm.pacman[pacman_nr].x = nx;
+ game_mm.pacman[pacman_nr].y = ny;
DrawGraphic_MM(ox, oy, IMG_EMPTY);
if (element != EL_EMPTY)
{
- int graphic = el2gfx(Feld[nx][ny]);
+ int graphic = el2gfx(Tile[nx][ny]);
Bitmap *bitmap;
int src_x, src_y;
int i;
getGraphicSource(graphic, 0, &bitmap, &src_x, &src_y);
- CT = Counter();
- ox = SX + ox * TILEX;
- oy = SY + oy * TILEY;
+ CT = FrameCounter;
+ ox = cSX + ox * TILEX;
+ oy = cSY + oy * TILEY;
for (i = 1; i < 33; i += 2)
BlitBitmap(bitmap, window,
src_x, src_y, TILEX, TILEY,
ox + i * mx, oy + i * my);
- Ct = Ct + Counter() - CT;
+ Ct = Ct + FrameCounter - CT;
}
DrawField_MM(nx, ny);
}
}
-void GameWon_MM()
-{
- int hi_pos;
- boolean raise_level = FALSE;
-
-#if 0
- if (local_player->MovPos)
- return;
-
- local_player->LevelSolved = FALSE;
-#endif
-
- if (game_mm.energy_left)
- {
- if (setup.sound_loops)
- PlaySoundExt(SND_SIRR, SOUND_MAX_VOLUME, SOUND_MAX_RIGHT,
- SND_CTRL_PLAY_LOOP);
-
- while (game_mm.energy_left > 0)
- {
- if (!setup.sound_loops)
- PlaySoundStereo(SND_SIRR, SOUND_MAX_RIGHT);
-
- /*
- if (game_mm.energy_left > 0 && !(game_mm.energy_left % 10))
- RaiseScore_MM(native_mm_level.score[SC_ZEITBONUS]);
- */
-
- RaiseScore_MM(5);
-
- game_mm.energy_left--;
- if (game_mm.energy_left >= 0)
- {
-#if 0
- BlitBitmap(pix[PIX_DOOR], drawto,
- DOOR_GFX_PAGEX5 + XX_ENERGY, DOOR_GFX_PAGEY1 + YY_ENERGY,
- ENERGY_XSIZE, ENERGY_YSIZE - game_mm.energy_left,
- DX_ENERGY, DY_ENERGY);
-#endif
- redraw_mask |= REDRAW_DOOR_1;
- }
-
- BackToFront();
- Delay(10);
- }
-
- if (setup.sound_loops)
- StopSound(SND_SIRR);
- }
- else if (native_mm_level.time == 0) /* level without time limit */
- {
- if (setup.sound_loops)
- PlaySoundExt(SND_SIRR, SOUND_MAX_VOLUME, SOUND_MAX_RIGHT,
- SND_CTRL_PLAY_LOOP);
-
- while (TimePlayed < 999)
- {
- if (!setup.sound_loops)
- PlaySoundStereo(SND_SIRR, SOUND_MAX_RIGHT);
- if (TimePlayed < 999 && !(TimePlayed % 10))
- RaiseScore_MM(native_mm_level.score[SC_ZEITBONUS]);
- if (TimePlayed < 900 && !(TimePlayed % 10))
- TimePlayed += 10;
- else
- TimePlayed++;
-
- /*
- DrawText(DX_TIME, DY_TIME, int2str(TimePlayed, 3), FONT_TEXT_2);
- */
-
- BackToFront();
- Delay(10);
- }
-
- if (setup.sound_loops)
- StopSound(SND_SIRR);
- }
-
-#if 0
- FadeSounds();
-#endif
-
- CloseDoor(DOOR_CLOSE_1);
-
- Request("Level solved !", REQ_CONFIRM);
-
- if (level_nr == leveldir_current->handicap_level)
- {
- leveldir_current->handicap_level++;
- SaveLevelSetup_SeriesInfo();
- }
-
- if (level_editor_test_game)
- game_mm.score = -1; /* no highscore when playing from editor */
- else if (level_nr < leveldir_current->last_level)
- raise_level = TRUE; /* advance to next level */
-
- if ((hi_pos = NewHiScore_MM()) >= 0)
- {
- game_status = HALLOFFAME;
-
- // DrawHallOfFame(hi_pos);
-
- if (raise_level)
- level_nr++;
- }
- else
- {
- game_status = MAINMENU;
-
- if (raise_level)
- level_nr++;
-
- // DrawMainMenu();
- }
-
- BackToFront();
-}
-
-int NewHiScore_MM()
-{
- int k, l;
- int position = -1;
-
- // LoadScore(level_nr);
-
- if (strcmp(setup.player_name, EMPTY_PLAYER_NAME) == 0 ||
- game_mm.score < highscore[MAX_SCORE_ENTRIES - 1].Score)
- return -1;
-
- for (k = 0; k < MAX_SCORE_ENTRIES; k++)
- {
- if (game_mm.score > highscore[k].Score)
- {
- /* player has made it to the hall of fame */
-
- if (k < MAX_SCORE_ENTRIES - 1)
- {
- int m = MAX_SCORE_ENTRIES - 1;
-
-#ifdef ONE_PER_NAME
- for (l = k; l < MAX_SCORE_ENTRIES; l++)
- if (!strcmp(setup.player_name, highscore[l].Name))
- m = l;
- if (m == k) /* player's new highscore overwrites his old one */
- goto put_into_list;
-#endif
-
- for (l = m; l>k; l--)
- {
- strcpy(highscore[l].Name, highscore[l - 1].Name);
- highscore[l].Score = highscore[l - 1].Score;
- }
- }
-
-#ifdef ONE_PER_NAME
- put_into_list:
-#endif
- strncpy(highscore[k].Name, setup.player_name, MAX_PLAYER_NAME_LEN);
- highscore[k].Name[MAX_PLAYER_NAME_LEN] = '\0';
- highscore[k].Score = game_mm.score;
- position = k;
-
- break;
- }
-
-#ifdef ONE_PER_NAME
- else if (!strncmp(setup.player_name, highscore[k].Name,
- MAX_PLAYER_NAME_LEN))
- break; /* player already there with a higher score */
-#endif
-
- }
-
- // if (position >= 0)
- // SaveScore(level_nr);
-
- return position;
-}
-
static void InitMovingField_MM(int x, int y, int direction)
{
int newx = x + (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
MovDir[x][y] = direction;
MovDir[newx][newy] = direction;
- if (Feld[newx][newy] == EL_EMPTY)
- Feld[newx][newy] = EL_BLOCKED;
+ if (Tile[newx][newy] == EL_EMPTY)
+ Tile[newx][newy] = EL_BLOCKED;
}
static void Moving2Blocked_MM(int x, int y, int *goes_to_x, int *goes_to_y)
static int MovingOrBlocked2Element_MM(int x, int y)
{
- int element = Feld[x][y];
+ int element = Tile[x][y];
if (element == EL_BLOCKED)
{
Blocked2Moving_MM(x, y, &oldx, &oldy);
- return Feld[oldx][oldy];
+ return Tile[oldx][oldy];
}
return element;
#if 0
static void RemoveField(int x, int y)
{
- Feld[x][y] = EL_EMPTY;
+ Tile[x][y] = EL_EMPTY;
MovPos[x][y] = 0;
MovDir[x][y] = 0;
MovDelay[x][y] = 0;
{
int oldx = x, oldy = y, newx = x, newy = y;
- if (Feld[x][y] != EL_BLOCKED && !IS_MOVING(x, y))
+ if (Tile[x][y] != EL_BLOCKED && !IS_MOVING(x, y))
return;
if (IS_MOVING(x, y))
{
Moving2Blocked_MM(x, y, &newx, &newy);
- if (Feld[newx][newy] != EL_BLOCKED)
+ if (Tile[newx][newy] != EL_BLOCKED)
return;
}
- else if (Feld[x][y] == EL_BLOCKED)
+ else if (Tile[x][y] == EL_BLOCKED)
{
Blocked2Moving_MM(x, y, &oldx, &oldy);
if (!IS_MOVING(oldx, oldy))
return;
}
- Feld[oldx][oldy] = EL_EMPTY;
- Feld[newx][newy] = EL_EMPTY;
+ Tile[oldx][oldy] = EL_EMPTY;
+ Tile[newx][newy] = EL_EMPTY;
MovPos[oldx][oldy] = MovDir[oldx][oldy] = MovDelay[oldx][oldy] = 0;
MovPos[newx][newy] = MovDir[newx][newy] = MovDelay[newx][newy] = 0;
static void RaiseScore_MM(int value)
{
game_mm.score += value;
-
-#if 0
- DrawText(DX_SCORE, DY_SCORE, int2str(game_mm.score, 4),
- FONT_TEXT_2);
-#endif
}
void RaiseScoreElement_MM(int element)
{
- switch(element)
+ switch (element)
{
case EL_PACMAN:
+ case EL_PACMAN_RIGHT:
+ case EL_PACMAN_UP:
+ case EL_PACMAN_LEFT:
+ case EL_PACMAN_DOWN:
RaiseScore_MM(native_mm_level.score[SC_PACMAN]);
break;
RaiseScore_MM(native_mm_level.score[SC_KEY]);
break;
+ case EL_KETTLE:
+ case EL_CELL:
+ RaiseScore_MM(native_mm_level.score[SC_COLLECTIBLE]);
+ break;
+
+ case EL_LIGHTBALL:
+ RaiseScore_MM(native_mm_level.score[SC_LIGHTBALL]);
+ break;
+
default:
break;
}
}
+
+
+// ----------------------------------------------------------------------------
+// Mirror Magic game engine snapshot handling functions
+// ----------------------------------------------------------------------------
+
+void SaveEngineSnapshotValues_MM(void)
+{
+ int x, y;
+
+ engine_snapshot_mm.game_mm = game_mm;
+ engine_snapshot_mm.laser = laser;
+
+ for (x = 0; x < MAX_PLAYFIELD_WIDTH; x++)
+ {
+ for (y = 0; y < MAX_PLAYFIELD_HEIGHT; y++)
+ {
+ engine_snapshot_mm.Ur[x][y] = Ur[x][y];
+ engine_snapshot_mm.Hit[x][y] = Hit[x][y];
+ engine_snapshot_mm.Box[x][y] = Box[x][y];
+ engine_snapshot_mm.Angle[x][y] = Angle[x][y];
+ engine_snapshot_mm.Frame[x][y] = Frame[x][y];
+ }
+ }
+
+ engine_snapshot_mm.LX = LX;
+ engine_snapshot_mm.LY = LY;
+ engine_snapshot_mm.XS = XS;
+ engine_snapshot_mm.YS = YS;
+ engine_snapshot_mm.ELX = ELX;
+ engine_snapshot_mm.ELY = ELY;
+ engine_snapshot_mm.CT = CT;
+ engine_snapshot_mm.Ct = Ct;
+
+ engine_snapshot_mm.last_LX = last_LX;
+ engine_snapshot_mm.last_LY = last_LY;
+ engine_snapshot_mm.last_hit_mask = last_hit_mask;
+ engine_snapshot_mm.hold_x = hold_x;
+ engine_snapshot_mm.hold_y = hold_y;
+ engine_snapshot_mm.pacman_nr = pacman_nr;
+
+ engine_snapshot_mm.rotate_delay = rotate_delay;
+ engine_snapshot_mm.pacman_delay = pacman_delay;
+ engine_snapshot_mm.energy_delay = energy_delay;
+ engine_snapshot_mm.overload_delay = overload_delay;
+}
+
+void LoadEngineSnapshotValues_MM(void)
+{
+ int x, y;
+
+ // stored engine snapshot buffers already restored at this point
+
+ game_mm = engine_snapshot_mm.game_mm;
+ laser = engine_snapshot_mm.laser;
+
+ for (x = 0; x < MAX_PLAYFIELD_WIDTH; x++)
+ {
+ for (y = 0; y < MAX_PLAYFIELD_HEIGHT; y++)
+ {
+ Ur[x][y] = engine_snapshot_mm.Ur[x][y];
+ Hit[x][y] = engine_snapshot_mm.Hit[x][y];
+ Box[x][y] = engine_snapshot_mm.Box[x][y];
+ Angle[x][y] = engine_snapshot_mm.Angle[x][y];
+ Frame[x][y] = engine_snapshot_mm.Frame[x][y];
+ }
+ }
+
+ LX = engine_snapshot_mm.LX;
+ LY = engine_snapshot_mm.LY;
+ XS = engine_snapshot_mm.XS;
+ YS = engine_snapshot_mm.YS;
+ ELX = engine_snapshot_mm.ELX;
+ ELY = engine_snapshot_mm.ELY;
+ CT = engine_snapshot_mm.CT;
+ Ct = engine_snapshot_mm.Ct;
+
+ last_LX = engine_snapshot_mm.last_LX;
+ last_LY = engine_snapshot_mm.last_LY;
+ last_hit_mask = engine_snapshot_mm.last_hit_mask;
+ hold_x = engine_snapshot_mm.hold_x;
+ hold_y = engine_snapshot_mm.hold_y;
+ pacman_nr = engine_snapshot_mm.pacman_nr;
+
+ rotate_delay = engine_snapshot_mm.rotate_delay;
+ pacman_delay = engine_snapshot_mm.pacman_delay;
+ energy_delay = engine_snapshot_mm.energy_delay;
+ overload_delay = engine_snapshot_mm.overload_delay;
+
+ RedrawPlayfield_MM();
+}
+
+static int getAngleFromTouchDelta(int dx, int dy, int base)
+{
+ double pi = 3.141592653;
+ double rad = atan2((double)-dy, (double)dx);
+ double rad2 = (rad < 0 ? rad + 2 * pi : rad);
+ double deg = rad2 * 180.0 / pi;
+
+ return (int)(deg * base / 360.0 + 0.5) % base;
+}
+
+int getButtonFromTouchPosition(int x, int y, int dst_mx, int dst_my)
+{
+ // calculate start (source) position to be at the middle of the tile
+ int src_mx = cSX + x * TILESIZE_VAR + TILESIZE_VAR / 2;
+ int src_my = cSY + y * TILESIZE_VAR + TILESIZE_VAR / 2;
+ int dx = dst_mx - src_mx;
+ int dy = dst_my - src_my;
+ int element;
+ int base = 16;
+ int phases = 16;
+ int angle_old = -1;
+ int angle_new = -1;
+ int button = 0;
+ int i;
+
+ if (!IN_LEV_FIELD(x, y))
+ return 0;
+
+ element = Tile[x][y];
+
+ if (!IS_MCDUFFIN(element) &&
+ !IS_MIRROR(element) &&
+ !IS_BEAMER(element) &&
+ !IS_POLAR(element) &&
+ !IS_POLAR_CROSS(element) &&
+ !IS_DF_MIRROR(element))
+ return 0;
+
+ angle_old = get_element_angle(element);
+
+ if (IS_MCDUFFIN(element))
+ {
+ angle_new = (dx > 0 && ABS(dy) < ABS(dx) ? ANG_RAY_RIGHT :
+ dy < 0 && ABS(dx) < ABS(dy) ? ANG_RAY_UP :
+ dx < 0 && ABS(dy) < ABS(dx) ? ANG_RAY_LEFT :
+ dy > 0 && ABS(dx) < ABS(dy) ? ANG_RAY_DOWN :
+ -1);
+ }
+ else if (IS_MIRROR(element) ||
+ IS_DF_MIRROR(element))
+ {
+ for (i = 0; i < laser.num_damages; i++)
+ {
+ if (laser.damage[i].x == x &&
+ laser.damage[i].y == y &&
+ ObjHit(x, y, HIT_POS_CENTER))
+ {
+ angle_old = get_mirrored_angle(laser.damage[i].angle, angle_old);
+ angle_new = getAngleFromTouchDelta(dx, dy, base) % phases;
+
+ break;
+ }
+ }
+ }
+
+ if (angle_new == -1)
+ {
+ if (IS_MIRROR(element) ||
+ IS_DF_MIRROR(element) ||
+ IS_POLAR(element))
+ base = 32;
+
+ if (IS_POLAR_CROSS(element))
+ phases = 4;
+
+ angle_new = getAngleFromTouchDelta(dx, dy, base) % phases;
+ }
+
+ button = (angle_new == angle_old ? 0 :
+ (angle_new - angle_old + phases) % phases < (phases / 2) ?
+ MB_LEFTBUTTON : MB_RIGHTBUTTON);
+
+ return button;
+}