Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: jwm-art-net/XorCurses
base: 7c6755cfd4
...
head fork: jwm-art-net/XorCurses
compare: a669d2bf02
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 27 files changed
  • 0 commit comments
  • 1 contributor
View
1  .gitignore
@@ -1,5 +1,6 @@
*.o
xorcurses
*.bz2
+*.xcr
View
8 CHANGES
@@ -1,5 +1,11 @@
-----------------------------------------------
-0.1.4
+0.2.0
+
+* revision bump from 0.1.3 to 0.2.0
+
+* map display bugs fixed - finally.
+
+* level entry and level complete exit animations.
* scores and replays no longer saved in binary
format. binary dot files in a user home dir don't
View
22 ChangeLog
@@ -1,3 +1,25 @@
+2011-12-08 James Morris <james@jwm-art.net>
+
+ * exit.[ch]: new files, implements exit animation of player
+ passing through the exit door (ie player slides into it).
+
+ * info.[ch]: overhaul of map display code. removal of
+ map_overwrite_bad func. half-scale map display code now
+ has an order of precedence for displaying objects in the
+ map: exit, mask, wall, space, which is also useful for
+ erasing a collected mask from map. full-scale map display
+ code has been fixed to erase masks correctly.
+
+ * player.c: remove call to info_win_update_map for every 4th
+ mask collected.
+
+ * splash.c: big mask drawing moved to own function. addition
+ of splatter_masks function (may be removed). moving colour
+ bars animation for entry into a level.q
+
+ * other stuff i can't be bothered to document right now.
+
+
2011-12-04 James Morris <james@jwm-art.net>
* fletcher.[ch]: new file implementing fletcher16 checksum
View
6 Makefile
@@ -22,9 +22,9 @@ CFLAGS:= -std=gnu99 -Wall -Wextra -pedantic -DDATADIR=\"$(SHAREDIR)\"
# movements and bomb detonations. Redirect stderr
# if you use it.
-CFLAGS:=$(CFLAGS) -DDEBUG -ggdb
+#CFLAGS:=$(CFLAGS) -ggdb -DDEBUG
-#CFLAGS:=$(CFLAGS) -O2
+CFLAGS:=$(CFLAGS) -O2
# Add -DTESTMAP to enable access within the level
# menu of the test map (maps/0.txt). NOTE: DO NOT
@@ -38,7 +38,7 @@ CFLAGS:=$(CFLAGS) -DDEBUG -ggdb
PROG:=xorcurses
CC:=gcc
-VERSION:=0.1.4
+VERSION:=0.2.0
CFLAGS:=$(CFLAGS) -DVERSION=\"$(VERSION)\"
View
2  actions.c
@@ -25,6 +25,7 @@ struct xor_action actions[ICON_XXX] = {
{MVI_PLAYER, CT_BLOCK, MV_ANY, MV_NONE} /* questor */
};
+
struct xor_move *
create_xor_move(xy_t x, xy_t y, su_t move)
{
@@ -32,6 +33,7 @@ create_xor_move(xy_t x, xy_t y, su_t move)
if (!(xmv = malloc(sizeof(struct xor_move))))
return 0;
+
xmv->from_obj = map->buf[y][x];
xmv->from_x = x;
xmv->from_y = y;
View
2  control_flow.c
@@ -2,6 +2,7 @@
#include "play_xor.h"
#include "replay.h"
#include <stdlib.h>
+#include "splash.h"
#include "debug.h"
@@ -19,6 +20,7 @@ void control_flow(int level)
return;
}
+ splash_level_entry(level);
flow = replay_xor(level | FLOW_START);
}
else
View
157 exit.c
@@ -0,0 +1,157 @@
+#include "exit.h"
+
+#include "splash.h"
+#include "player.h"
+#include "game_display.h"
+#include "options.h"
+#include "icons.h"
+#include "screen.h"
+#include "debug.h"
+
+#include <time.h>
+
+
+void player_exit_animate(struct xor_move* pmv)
+{
+ struct timespec rpause;
+ struct timespec repause;
+ struct xy* pxy = game_win_map_coord(pmv->from_x, pmv->from_y);
+ struct xor_icon* icon = &icons[pmv->from_obj];
+ int i;
+
+ if (!pxy)
+ return;
+
+ rpause.tv_sec = 0;
+ rpause.tv_nsec = 0;
+
+ if (player.replay)
+ {
+ if (!options->replay_hyper)
+ rpause.tv_nsec =
+ options_replay_speed(options->replay_speed) / 5;
+ }
+ else
+ rpause.tv_nsec = 50000000L;
+
+ if (pmv->dir & MV_VERT)
+ rpause.tv_nsec *= (double)ICON_W / (double)ICON_H;
+
+ switch(pmv->dir)
+ {
+ case MV_LEFT:
+ for (i = 0; i <= ICON_W; ++i)
+ {
+ for (xy_t y = 0; y < ICON_H; ++y)
+ {
+ xy_t ix = i;
+
+ for (xy_t x = 0; x < ICON_W; ++x)
+ {
+ if (ix < ICON_W)
+ {
+ wattrset(game_win, COLOR_PAIR(pmv->from_obj));
+ mvwaddch(game_win, pxy->y + y, pxy->x + x,
+ icon->chrs[y][ix++]);
+ }
+ else
+ {
+ wattrset(game_win, COLOR_PAIR(ICON_SPACE));
+ mvwaddch(game_win, pxy->y + y, pxy->x + x, ' ');
+ }
+ }
+ }
+ wrefresh(game_win);
+ nanosleep(&rpause, &repause);
+ }
+ break;
+
+ case MV_RIGHT:
+ for (i = 0; i <= ICON_W; ++i)
+ {
+ for (xy_t y = 0; y < ICON_H; ++y)
+ {
+ xy_t ix = 0;
+
+ for (xy_t x = 0; x < ICON_W; ++x)
+ {
+ if (i <= x)
+ {
+ wattrset(game_win, COLOR_PAIR(pmv->from_obj));
+ mvwaddch(game_win, pxy->y + y, pxy->x + x,
+ icon->chrs[y][ix++]);
+ }
+ else
+ {
+ wattrset(game_win, COLOR_PAIR(ICON_SPACE));
+ mvwaddch(game_win, pxy->y + y, pxy->x + x, ' ');
+ }
+ }
+ }
+ wrefresh(game_win);
+ nanosleep(&rpause, &repause);
+ }
+ break;
+
+ case MV_UP:
+ for (i = 0; i <= ICON_H; ++i)
+ {
+ for (xy_t y = 0; y < ICON_H; ++y)
+ {
+ xy_t iy = i + y;
+
+ for (xy_t x = 0; x < ICON_W; ++x)
+ {
+ if (iy < ICON_H)
+ {
+ wattrset(game_win, COLOR_PAIR(pmv->from_obj));
+ mvwaddch(game_win, pxy->y + y, pxy->x + x,
+ icon->chrs[iy][x]);
+ }
+ else
+ {
+ wattrset(game_win, COLOR_PAIR(ICON_SPACE));
+ mvwaddch(game_win, pxy->y + y, pxy->x + x, ' ');
+ }
+ }
+ }
+ wrefresh(game_win);
+ nanosleep(&rpause, &repause);
+ }
+ break;
+ case MV_DOWN:
+ for (i = 0; i <= ICON_H; ++i)
+ {
+ xy_t iy = 0;
+
+ for (xy_t y = 0; y < ICON_H; ++y)
+ {
+ for (xy_t x = 0; x < ICON_W; ++x)
+ {
+ if (i < y)
+ {
+ wattrset(game_win, COLOR_PAIR(pmv->from_obj));
+ mvwaddch(game_win, pxy->y + y, pxy->x + x,
+ icon->chrs[iy][x]);
+ }
+ else
+ {
+ wattrset(game_win, COLOR_PAIR(ICON_SPACE));
+ mvwaddch(game_win, pxy->y + y, pxy->x + x, ' ');
+ }
+ }
+
+ if (i < y)
+ ++iy;
+ }
+ wrefresh(game_win);
+ nanosleep(&rpause, &repause);
+ }
+ break;
+ }
+
+ splatter_masks();
+}
+
+
+
View
11 exit.h
@@ -0,0 +1,11 @@
+#ifndef _EXIT_H
+#define _EXIT_H
+
+
+#include "actions.h"
+
+
+void player_exit_animate(struct xor_move*);
+
+
+#endif
View
63 game_display.c
@@ -7,17 +7,22 @@
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
+#include <time.h>
+
+
+static xy_t _ga_w = 0;
+static xy_t _ga_h = 0;
-xy_t _ga_w = 0;
-xy_t _ga_h = 0;
void
-game_win_init_views()
+game_win_init_views(void)
{
_ga_w = screen_data->garea_w;
_ga_h = screen_data->garea_h;
su_t scrt = (player.replay ? 1 : options->scroll_thresh);
- for (su_t p = 0; p < 2; p++) {
+
+ for (su_t p = 0; p < 2; p++)
+ {
xy_t ox = map->view[p].x;
/* prevent void beyond right hand wall of map from displaying
during resize. note that test condition is over-enthusiastic
@@ -26,28 +31,33 @@ game_win_init_views()
of right side map, the garea is being shrunk, and the player
is on the left of the view - the player pos test corrects it.
*/
- if (ox + _ga_w >= MAP_W - 1) {
+ if (ox + _ga_w >= MAP_W - 1)
+ {
ox -= (ox + _ga_w) - MAP_W;
if (map->player[p].x - scrt < ox)
ox -= ox - (map->player[p].x - scrt);
}
else if (ox + _ga_w <= map->player[p].x + scrt)
ox += (map->player[p].x + scrt + 1) - (ox + _ga_w);
+
map->view[p].x = ox;
xy_t oy = map->view[p].y;
- if (oy + _ga_h >= MAP_H - 1) {
+
+ if (oy + _ga_h >= MAP_H - 1)
+ {
oy -= oy + _ga_h - MAP_H;
if (map->player[p].y - scrt < oy)
oy -= oy - (map->player[p].y - scrt);
}
else if (oy + _ga_h <= map->player[p].y + scrt)
oy += (map->player[p].y + scrt + 1) - (oy + _ga_h);
+
map->view[p].y = oy;
}
}
void
-game_win_display()
+game_win_display(void)
{
if (_ga_w != screen_data->garea_w || _ga_h != screen_data->garea_h)
game_win_init_views();
@@ -79,7 +89,7 @@ game_win_show(xy_t tlx, xy_t tly)
}
void
-game_win_swap_update()
+game_win_swap_update(void)
{
su_t p = (player.player) ? 0 : 1;
@@ -99,16 +109,14 @@ void
game_win_move_player(struct xor_move *pmv)
{
xy_t vx = map->view[player.player].x;
-
xy_t vy = map->view[player.player].y;
-
xy_t ovx = vx;
-
xy_t ovy = vy;
su_t scrt = (player.replay ? 1 : options->scroll_thresh);
- switch (pmv->dir) {
+ switch (pmv->dir)
+ {
case MV_LEFT:
if (pmv->to_x < vx + scrt && vx > 0)
vx--;
@@ -128,14 +136,18 @@ game_win_move_player(struct xor_move *pmv)
default:
break;
}
- if (ovx != vx || ovy != vy) {
+
+ if (ovx != vx || ovy != vy)
+ {
map->view[player.player].x = vx;
map->view[player.player].y = vy;
- game_win_display(map);
+ game_win_display();
return;
}
+
game_win_icon_display(pmv->from_x, pmv->from_y, ICON_SPACE);
game_win_icon_display(pmv->to_x, pmv->to_y, pmv->from_obj);
+
wrefresh(game_win);
}
@@ -156,7 +168,9 @@ game_win_map_coord(xy_t x, xy_t y)
return 0;
struct xy *pv = &map->view[player.player];
- if (x >= pv->x && x < pv->x + _ga_w && y >= pv->y && y < pv->y + _ga_h) {
+ if (x >= pv->x && x < pv->x + _ga_w
+ && y >= pv->y && y < pv->y + _ga_h)
+ {
ret->x = (x - pv->x) * ICON_W;
ret->y = (y - pv->y) * ICON_H;
return ret;
@@ -169,13 +183,15 @@ void
game_win_icon_display(xy_t x, xy_t y, su_t icon)
{
xy_t vx = map->view[player.player].x;
-
xy_t vy = map->view[player.player].y;
- if (x < vx || x >= vx + _ga_w || y < vy || y >= vy + _ga_h)
+ if (x < vx || x >= vx + _ga_w
+ || y < vy || y >= vy + _ga_h)
+ {
return;
- xy_t wx = (x - vx) * ICON_W;
+ }
+ xy_t wx = (x - vx) * ICON_W;
xy_t wy = (y - vy) * ICON_H;
wattrset(game_win, COLOR_PAIR(icon));
@@ -257,12 +273,14 @@ game_win_dump_map_sect(xy_t topy, su_t sect, bool show)
switch (icon) {
case ICON_WALL:
wattrset(game_win, COLOR_PAIR(COL_I_MAP_WALL));
- mvwaddch(game_win, oy + sy, ox + x, icon_to_mapchar(icon));
+ mvwaddch(game_win, oy + sy, ox + x,
+ icon_to_mapchar(icon));
break;
case ICON_MASK:
case ICON_EXIT:
wattrset(game_win, COLOR_PAIR(icon));
- mvwaddch(game_win, oy + sy, ox + x, icon_to_mapchar(icon));
+ mvwaddch(game_win, oy + sy, ox + x,
+ icon_to_mapchar(icon));
break;
default:
wattrset(game_win, COLOR_PAIR(ICON_SPACE));
@@ -289,7 +307,7 @@ game_win_dump_map(xy_t topy)
}
void
-game_win_map_display()
+game_win_map_display(void)
{
bool map_scrollable =
(screen_data->garea_h * ICON_H < MAP_H ? TRUE : FALSE);
@@ -330,7 +348,7 @@ game_win_map_display()
case 'M':
case 'q':
case 'Q':
- game_win_display(y);
+ game_win_display();
player.map_view_y = y;
return;
}
@@ -338,3 +356,4 @@ game_win_map_display()
}
}
+
View
9 game_display.h
@@ -18,13 +18,13 @@
#include "types.h"
#include "actions.h"
-void game_win_init_views();
+void game_win_init_views(void);
-void game_win_display();
+void game_win_display(void);
void game_win_show(xy_t tlx, xy_t tly);
-void game_win_swap_update();
+void game_win_swap_update(void);
void game_win_move_player(struct xor_move *xmv);
@@ -48,6 +48,7 @@ void game_win_icon_dump(xy_t x, xy_t y, su_t icon);
*/
void game_win_icon_display(xy_t x, xy_t y, su_t icon);
-void game_win_map_display();
+void game_win_map_display(void);
+
#endif
View
23 icons.c
@@ -1,5 +1,6 @@
#include "icons.h"
+
struct xor_icon icons[ICON_XXX] = {
{
COLOR_BLACK,
@@ -174,6 +175,7 @@ struct xor_icon icons[ICON_XXX] = {
"Explosion3"}
};
+
struct xor_icon wall_icons[4] = {
{
COLOR_RED,
@@ -213,15 +215,15 @@ struct xor_icon wall_icons[4] = {
"Wall4"}
};
-void
-init_icons(void)
+
+void init_icons(void)
{
for (su_t i = 1; i < ICON_XXX; i++)
init_pair(i, icons[i].fg, icons[i].bg);
}
-void
-init_wall(lvl_t level, bool show)
+
+void init_wall(lvl_t level, bool show)
{
NCURSES_COLOR_T bg[6] = {
COLOR_RED,
@@ -250,8 +252,8 @@ init_wall(lvl_t level, bool show)
(show) ? wall_icons[wall].chrs[y][x] : ' ';
}
-void
-win_icon_dump(WINDOW * win, xy_t x, xy_t y, su_t icon)
+
+void win_icon_dump(WINDOW * win, xy_t x, xy_t y, su_t icon)
{
wattrset(win, COLOR_PAIR(icon));
for (xy_t yy = 0; yy < ICON_H; yy++)
@@ -259,8 +261,8 @@ win_icon_dump(WINDOW * win, xy_t x, xy_t y, su_t icon)
mvwaddch(win, y + yy, x + xx, icons[icon].chrs[yy][xx]);
}
-su_t
-mapchar_to_icon(char c)
+
+su_t mapchar_to_icon(char c)
{
switch (c) {
case ' ':
@@ -299,8 +301,8 @@ mapchar_to_icon(char c)
return ICON_SPACE;
}
-char
-icon_to_mapchar(su_t icon)
+
+char icon_to_mapchar(su_t icon)
{
switch (icon) {
case ICON_SPACE:
@@ -338,3 +340,4 @@ icon_to_mapchar(su_t icon)
}
return 0;
}
+
View
4 icons.h
@@ -1,4 +1,4 @@
-/****************************************************************************
+/***************************************************************************
This file is part of XorCurses a port/remake of the game Xor
(originally by Astral Software) to the Linux console using
ncurses.
@@ -14,7 +14,7 @@
to be played. misc conversion routines for map character to
icon type enumeration, etc.
-****************************************************************************/
+***************************************************************************/
#ifndef _ICONS_H
#define _ICONS_H
View
203 info.c
@@ -7,61 +7,88 @@
#include <string.h>
-void
-info_win_update_player_icon()
+void info_win_update_player_icon()
{
win_icon_dump(info_win, 2, 2, ICON_PLAYER0 + player.player);
}
-bool
-map_overwrite_bad(xy_t x, xy_t y)
-{
- xy_t xx = (x % 2) ? x - 1 : x;
-
- xy_t yy = (y % 2) ? y - 1 : y;
- if (x % 2) {
- if (map->buf[y][xx] == ICON_MASK)
- return TRUE;
- }
- else if (x < MAP_W - 1) {
- if (map->buf[y][x + 1] == ICON_MASK)
- return TRUE;
- }
- if (y % 2) {
- if (map->buf[yy][x] == ICON_MASK)
- return TRUE;
- }
- else if (y < MAP_H - 1) {
- if (map->buf[y + 1][x] == ICON_MASK)
- return TRUE;
- }
- if (x % 2 && y % 2) {
- if (map->buf[yy][xx] == ICON_MASK)
- return TRUE;
- }
- else if (x < MAP_W - 1 && y < MAP_H - 1) {
- if (map->buf[y + 1][x + 1] == ICON_MASK)
- return TRUE;
+void info_win_update_map(su_t have_map)
+{
+ for (su_t i = 0, mb = 1; i < 4; i++, mb *= 2)
+ {
+ if (mb & have_map)
+ info_win_dump_map(i);
}
- return FALSE;
+
+ wrefresh(info_win);
}
-void
-info_win_update_map(su_t have_map)
+
+static void scale_dump_map(xy_t qx, xy_t qy)
{
- for (su_t i = 0, mb = 1; i < 4; i++, mb *= 2) {
- if (mb & have_map)
- info_win_dump_map(i);
+ xy_t lx = qx + HMAP_W;
+ xy_t ly = qy + HMAP_H;
+
+ struct xy m[] = { {0, 0}, {1, 0}, {0, 1}, {1, 1} };
+
+ for (xy_t x = qx; x < lx; x += 2)
+ {
+ for (xy_t y = qy; y < ly; y += 2)
+ {
+ su_t icon = 0;
+ su_t i;
+
+ for (i = 0; i < 4; ++i)
+ {
+ su_t t = map->buf[y + m[i].y][x + m[i].x];
+
+ if (t == ICON_EXIT)
+ {
+ icon = t;
+ break;
+ }
+ else if (t == ICON_MASK)
+ icon = t;
+ else if (t == ICON_WALL && icon == 0)
+ icon = t;
+ }
+
+ switch (icon)
+ {
+ case ICON_WALL:
+ wattrset(info_win, COLOR_PAIR(COL_I_MAP_WALL));
+ mvwaddch(info_win,
+ screen_data->map_tly + y / 2,
+ screen_data->map_tlx + x / 2,
+ icon_to_mapchar(icon));
+ break;
+
+ case ICON_MASK:
+ case ICON_EXIT:
+ wattrset(info_win, COLOR_PAIR(icon));
+ mvwaddch(info_win,
+ screen_data->map_tly + y / 2,
+ screen_data->map_tlx + x / 2,
+ icon_to_mapchar(icon));
+ break;
+
+ default:
+ break;
+ }
+ }
}
}
-void
-info_win_dump_map(su_t mappc)
+
+/* here, map pieces are numberd 0 - 3 clockwise from top-right */
+void info_win_dump_map(su_t mappc)
{
xy_t x = 0;
xy_t y = 0;
- switch (mappc) {
+
+ switch (mappc)
+ {
case 0:
x = HMAP_W;
break;
@@ -73,31 +100,40 @@ info_win_dump_map(su_t mappc)
y = HMAP_H;
break;
}
- xy_t d = (screen_data->scale_map == TRUE ? 2 : 1);
+
+ if (screen_data->scale_map)
+ {
+ scale_dump_map(x, y);
+ return;
+ }
+
xy_t lx = x + HMAP_W;
xy_t ly = y + HMAP_H;
- for (xy_t xx = x; xx < lx; xx++) {
- for (xy_t yy = y; yy < ly; yy++) {
+
+ for (xy_t xx = x; xx < lx; xx++)
+ {
+ for (xy_t yy = y; yy < ly; yy++)
+ {
su_t icon = map->buf[yy][xx];
- switch (icon) {
+ switch (icon)
+ {
case ICON_WALL:
- if (screen_data->scale_map == TRUE)
- if (map_overwrite_bad(xx, yy))
- break;
wattrset(info_win, COLOR_PAIR(COL_I_MAP_WALL));
mvwaddch(info_win,
- screen_data->map_tly + yy / d,
- screen_data->map_tlx + xx / d,
+ screen_data->map_tly + yy,
+ screen_data->map_tlx + xx,
icon_to_mapchar(icon));
break;
+
case ICON_MASK:
case ICON_EXIT:
wattrset(info_win, COLOR_PAIR(icon));
mvwaddch(info_win,
- screen_data->map_tly + yy / d,
- screen_data->map_tlx + xx / d,
+ screen_data->map_tly + yy,
+ screen_data->map_tlx + xx,
icon_to_mapchar(icon));
break;
+
default:
break;
}
@@ -105,25 +141,64 @@ info_win_dump_map(su_t mappc)
}
}
-void
-info_win_map_erase_mask(xy_t x, xy_t y)
+
+static void scale_map_erase_mask(xy_t x, xy_t y)
{
- wattrset(info_win, COLOR_PAIR(ICON_SPACE));
- if (!screen_data->scale_map) {
- mvwaddch(info_win,
- screen_data->map_tly + y, screen_data->map_tlx + x,
- icon_to_mapchar(ICON_SPACE));
+ struct xy m[] = { {0, 0}, {1, 0}, {0, 1}, {1, 1} };
+ su_t mappc;
+ su_t icon = 0;
+ su_t i;
+
+ if (y < HMAP_H)
+ mappc = (x < HMAP_W) ? 8 : 1;
+ else
+ mappc = (x < HMAP_W) ? 4 : 2;
+
+ if (!(player.have_map & mappc))
return;
+
+ x = x - (x % 2);
+ y = y - (y % 2);
+
+ for (i = 0; i < 4; ++i)
+ {
+ su_t t = map->buf[y + m[i].y][x + m[i].x];
+
+ if (t == ICON_EXIT)
+ {
+ icon = t;
+ break;
+ }
+ else if (t == ICON_MASK)
+ icon = t;
+ else if (t == ICON_WALL && icon == 0)
+ icon = t;
}
- if (map_overwrite_bad(x, y))
+
+ wattrset(info_win,
+ COLOR_PAIR(icon == ICON_WALL ? COL_I_MAP_WALL : icon));
+ mvwaddch(info_win, screen_data->map_tly + y / 2,
+ screen_data->map_tlx + x / 2,
+ icon_to_mapchar(icon));
+}
+
+
+void info_win_map_erase_mask(xy_t x, xy_t y)
+{
+ if (screen_data->scale_map)
+ {
+ scale_map_erase_mask(x, y);
return;
- mvwaddch(info_win,
- screen_data->map_tly + y / 2,
- screen_data->map_tlx + x / 2, icon_to_mapchar(ICON_SPACE));
+ }
+
+ wattrset(info_win, COLOR_PAIR(ICON_SPACE));
+ mvwaddch(info_win, screen_data->map_tly + y,
+ screen_data->map_tlx + x,
+ icon_to_mapchar(ICON_SPACE));
}
-void
-info_win_display()
+
+void info_win_display()
{
wattrset(info_win, COLOR_PAIR(COL_I_TXT));
mvwprintw(info_win,
View
1  info.h
@@ -23,6 +23,7 @@ void info_win_update_player_icon();
void info_win_update_map(su_t have_map);
+/* here, map pieces are numberd 0 - 3 clockwise from top-right */
void info_win_dump_map(su_t mappc);
void info_win_map_erase_mask(xy_t x, xy_t y);
View
21 map.h
@@ -28,16 +28,19 @@
struct xor_map
{
- char *filename;
- char *name;
- struct xy view[2]; /* start coords of initial player views (file) */
- struct xy mappc[4]; /* coords of map piece 0 1 2 3 */
+ char* filename;
+ char* name;
+
+ struct xy player[2]; /* initial player positions */
+ struct xy view[2]; /* initial player views */
+ struct xy mappc[4]; /* map positions */
+ struct xy teleport[2];/* teleport positions */
+ struct xy tpview[2]; /* teleport exit views */
+
+ ctr_t mask_count;
+ su_t level;
+
map_t *buf[MAP_H + 1];
- struct xy player[2]; /* positions - by scanning map-data */
- struct xy teleport[2]; /* positions, scanned */
- struct xy tpview[2]; /* teleport exit view coords */
- ctr_t mask_count; /* scanned */
- su_t level; /* user's choice */
};
extern struct xor_map *map;
View
36 maps/15.txt
@@ -8,26 +8,26 @@ The Decoder
#### # -#o# E# -# @#
################################
### ! # #
-###D - # ##### ##### #
-# + # ## #### ## #
-# # #<!# ## #### #
-# # #|x# ## #### ## #
-# # # ## ## #
-# ###### ##### ##### #
+###D - # #
+# + # #
+# # #<!# #
+# # #|x# #
+# # # #
# ###### #
-#S###!## ## ## #### #
-# |< # ## ## #### ## #
-# # ###### ## #
-# # # ## ## #### ## #
-# ##o! # ## ## ## #
-# !#-- # ## ## #### #
# ###### #
-# # ##### ## ## #
-#- #o # ## ## #### ## ## #
-# ! # ##### ## ## #
-#x # -# ## ## #### ## ## #
-### # ## ## ## ## #
-#S# # ##### ##### #
+#S###!## #
+# |< # #
+# # #
+# # # #
+# ##o! # #
+# !#-- # #
+# ###### #
+# # #
+#- #o # #
+# ! # #
+#x # -# #
+### # #
+#S# # #
######## #
# MMMM## #
################################
View
115 moves.c
@@ -6,86 +6,86 @@
#include <time.h>
#include "debug.h"
-ct_t
-move_object_init(struct xor_move * move)
+
+ct_t move_object_init(struct xor_move * move)
{
move->to_x = move->from_x;
move->to_y = move->from_y;
- switch (move->dir) {
- case MV_LEFT:
- move->to_x--;
- break;
- case MV_RIGHT:
- move->to_x++;
- break;
- case MV_UP:
- move->to_y--;
- break;
- case MV_DOWN:
- move->to_y++;
- break;
- default:
- return CT_ERROR;
+
+ switch (move->dir)
+ {
+ case MV_LEFT: move->to_x--; break;
+ case MV_RIGHT: move->to_x++; break;
+ case MV_UP: move->to_y--; break;
+ case MV_DOWN: move->to_y++; break;
+ default: return CT_ERROR;
}
+
move->from_obj = map->buf[move->from_y][move->from_x];
- move->to_obj = map->buf[move->to_y][move->to_x];
+ move->to_obj = map->buf[move->to_y][move->to_x];
ct_t cont = actions[move->to_obj].cont;
/* ------------------------------------------ */
/* conditions apply both to player and object */
if (cont == CT_BLOCK || cont == CT_PASS)
return cont;
+
if (move->from_obj == ICON_DOLL)
return CT_BLOCK;
- if (cont == CT_FILTER) {
- if (actions[move->to_obj].cont_dir & move->dir)
- return CT_PASS;
- return CT_BLOCK;
- }
+
+ if (cont == CT_FILTER)
+ return (actions[move->to_obj].cont_dir & move->dir)
+ ? CT_PASS
+ : CT_BLOCK;
+
/* -------------------------------- */
/* conditions which apply to player */
- if (actions[move->from_obj].mvini & MVI_PLAYER) {
- switch (cont) {
+ if (actions[move->from_obj].mvini & MVI_PLAYER)
+ {
+ switch (cont)
+ {
case CT_EXIT:
case CT_PICKUP:
case CT_HARDPUSH:
case CT_TELEPORT:
return cont;
+
default:
- if (cont & CT_PUSH) {
- if (actions[move->to_obj].cont_dir & move->dir)
- return CT_PUSH;
- else
- return CT_BLOCK;
- }
+ if (cont & CT_PUSH)
+ return (actions[move->to_obj].cont_dir & move->dir)
+ ? CT_PUSH
+ : CT_BLOCK;
+
return CT_ERROR;
}
}
+
/* -------------------------------- */
/* conditions which apply to object */
- if (cont & CT_EXPLODE)
- return CT_EXPLODE;
- return CT_BLOCK;
+
+ return (cont & CT_EXPLODE) ? CT_EXPLODE : CT_BLOCK;
}
-void
-move_gravity_process(struct xor_move *xmv)
+
+void move_gravity_process(struct xor_move *xmv)
{
debug("\nmove_gravity_process(xor_move* xmv=%lx)\n",(unsigned long)xmv);
- xmvlist_create();
- xmvlist_append_xor_move(xmv);
- xmvlist_first();
struct timespec rpause;
-
struct timespec repause;
+ xmvlist_create();
+ xmvlist_append_xor_move(xmv);
+ xmvlist_first();
rpause.tv_sec = 0;
+
if (player.replay)
rpause.tv_nsec = options_replay_speed(options->replay_speed);
else
rpause.tv_nsec = 20000000L;
- while (xmvlist->current) {
+
+ while (xmvlist->current)
+ {
struct xor_move *xmv = xmvlist->current->xmv;
debug("xmvlist->current=%lx->xmv=%lx\n",
@@ -93,7 +93,8 @@ move_gravity_process(struct xor_move *xmv)
struct xor_move *cmv = xmv;
- while (cmv) {
+ while (cmv)
+ {
nanosleep(&rpause, &repause);
debug("mv_grv_proc:\n"
@@ -105,13 +106,17 @@ move_gravity_process(struct xor_move *xmv)
ct_t cont = move_object_init(cmv);
- if (actions[cmv->to_obj].mvini == MVI_PLAYER) {
- if (cmv->moves_count > 0) {
+ if (actions[cmv->to_obj].mvini == MVI_PLAYER)
+ {
+ if (cmv->moves_count > 0)
+ {
player_death(cmv->to_obj);
cont = CT_PASS;
}
}
- if (cont == CT_EXPLODE) {
+
+ if (cont == CT_EXPLODE)
+ {
debug("\nBANG!!!\n");
@@ -129,30 +134,34 @@ move_gravity_process(struct xor_move *xmv)
icons[cmv->from_obj].name);
#endif
}
- else if (cont == CT_PASS) {
- map->buf[cmv->from_y][cmv->from_x] = ICON_SPACE;
- map->buf[cmv->to_y][cmv->to_x] = cmv->from_obj;
- game_win_move_object(cmv);
+ else if (cont == CT_PASS)
+ {
xy_t tmpx = cmv->from_x;
-
xy_t tmpy = cmv->from_y;
+ map->buf[tmpy][tmpx] = ICON_SPACE;
+ map->buf[cmv->to_y][cmv->to_x] = cmv->from_obj;
+ game_win_move_object(cmv);
cmv->from_x = cmv->to_x;
cmv->from_y = cmv->to_y;
cmv->moves_count++;
- if (cmv_next) {
+
+ if (cmv_next)
+ {
cmv = cmv_next;
if (!options->replay_hyper)
rpause.tv_nsec /= 1.1;
}
- else {
+ else
+ {
if (cmv->dir == MV_DOWN)
cmv = create_gravity_chain_xydir(tmpx + 1, tmpy,
MV_LEFT);
else
cmv = create_gravity_chain_xydir(tmpx, tmpy - 1,
MV_DOWN);
- if (cmv) {
+ if (cmv)
+ {
xmvlist_append_xor_move(cmv);
if (!options->replay_hyper)
rpause.tv_nsec /= 1.1;
View
62 play_xor.c
@@ -8,6 +8,9 @@
#include "replay.h"
#include "game_display.h"
#include "help.h"
+#include "exit.h"
+#include "splash.h"
+#include "debug.h"
#include <stdlib.h>
#include <time.h>
@@ -45,6 +48,7 @@ play_xor(lvl_t level)
xor_map_load(level);
player_init();
game_win_init_views();
+ splash_level_entry(level);
}
else
level = replay.level;
@@ -55,6 +59,7 @@ play_xor(lvl_t level)
screen_data->info_win_repaint_cb = &info_win_repaint;
info_win_display();
int state = PLAY_CONTINUE;
+ debug("scr w:%d scr h:%d\n",screen_data->garea_w,screen_data->garea_h);
while (state == PLAY_CONTINUE || state == PLAY_PROCESS_MOVE)
{
@@ -63,24 +68,18 @@ play_xor(lvl_t level)
switch (key)
{
- case KEY_LEFT: case 'z':
- move = MV_LEFT;
- break;
- case KEY_RIGHT: case 'x':
- move = MV_RIGHT;
- break;
- case KEY_UP: case '\'':
- move = MV_UP;
- break;
- case KEY_DOWN: case '/':
- move = MV_DOWN;
- break;
+ case KEY_LEFT: case 'z': move = MV_LEFT; break;
+ case KEY_RIGHT: case 'x': move = MV_RIGHT; break;
+ case KEY_UP: case '\'': move = MV_UP; break;
+ case KEY_DOWN: case '/': move = MV_DOWN; break;
+
case '\r': case 'p':
move = MV_PLAYER_SWAP;
break;
+
case 'b':
if (!options->oldschool_play
- && player.moves_remaining < MAX_MOVES)
+ && player.moves_remaining < MAX_MOVES)
{
replay.moves[player.moves_remaining + 1]
^= MV_REPLAY_BREAK;
@@ -92,6 +91,7 @@ play_xor(lvl_t level)
game_win_display();
}
break;
+
case '1': case '2': case '3':
if (!options->oldschool_play)
{
@@ -103,45 +103,53 @@ play_xor(lvl_t level)
game_win_display();
}
break;
- case 'm': case 'M':
- game_win_map_display();
- break;
- case 'h': case 'H':
- help_menu();
- game_win_display();
- break;
- case 'q': case 'Q':
- move = MV_PLAYER_QUIT;
- break;
+
+ case 'm': case 'M': game_win_map_display(); break;
+ case 'h': case 'H': help_menu(); game_win_display(); break;
+ case 'q': case 'Q': move = MV_PLAYER_QUIT; break;
+
case KEY_RESIZE:
screen_resize();
break;
}
- if (move) {
+
+ if (move)
+ {
state = player_move(move);
- if (state & PLAY_RECORD) {
- if (player.set_breakpoint) {
+
+ if (state & PLAY_RECORD)
+ {
+ if (player.set_breakpoint)
+ {
player.set_breakpoint = FALSE;
replay.moves[player.moves_remaining + 1]
|= MV_REPLAY_BREAK;
}
+
if (move == MV_PLAYER_QUIT)
replay.moves[player.moves_remaining] = move;
else
replay.moves[player.moves_remaining--] = move;
+
state ^= PLAY_RECORD;
}
+
info_win_display();
+
if (!(player.p0_alive || player.p1_alive))
return FLOW_DEATH;
}
}
- if (state == PLAY_COMPLETE) {
+
+ if (state == PLAY_COMPLETE)
+ {
+ player_exit_animate(&player.xmv[player.player]);
replay.moves[player.moves_remaining] = MV_PLAYER_EXIT;
replay.hasexit = 1;
save_score(map->level, MAX_MOVES - player.moves_remaining);
return FLOW_COMPLETE;
}
+
if (player.moves_remaining == MAX_MOVES)
return FLOW_DO_QUIT;
View
199 player.c
@@ -12,6 +12,10 @@
#include <time.h>
#include <stdlib.h>
+
+static enum PLAY_STATE player_process_push(struct xor_move* pmv);
+
+
void
player_init()
{
@@ -25,6 +29,15 @@ player_init()
player.wall_vis = TRUE;
player.map_view_y = 0;
player.set_breakpoint = FALSE;
+
+ int p;
+
+ for (p = 0; p < 2; ++p)
+ {
+ player.xmv[p].from_x = map->player[p].x;
+ player.xmv[p].from_y = map->player[p].y;
+ player.xmv[p].from_obj = ICON_PLAYER0 + p;
+ }
}
enum PLAY_STATE
@@ -32,136 +45,115 @@ player_move(su_t move)
{
if (player.moves_remaining == 0)
return PLAY_ZERO_MOVES;
+
if (move & MV_PLAYER_QUIT)
return (player.moves_remaining == MAX_MOVES)
? PLAY_QUIT
: PLAY_QUIT | PLAY_RECORD;
- if (move == MV_PLAYER_SWAP) {
- if ((player.player ? player.p0_alive : player.p1_alive)) {
+
+ if (move == MV_PLAYER_SWAP)
+ {
+ if ((player.player ? player.p0_alive : player.p1_alive))
+ {
player.player ^= 1;
game_win_swap_update();
- game_win_display(map);
+ game_win_display();
info_win_update_player_icon();
return PLAY_CONTINUE | PLAY_RECORD;
}
return PLAY_CONTINUE;
}
- struct xor_move *pmv = create_xor_move(map->player[player.player].x,
- map->player[player.player].y, move);
- /* cont required after switch */
+ struct xor_move* pmv = &player.xmv[player.player];
+ pmv->dir = move;
ct_t cont = move_object_init(pmv);
- switch (cont) {
+ switch (cont)
+ {
case CT_BLOCK:
- free(pmv);
return PLAY_CONTINUE;
+
case CT_EXIT:
- free(pmv);
+
if (player.masks_collected == map->mask_count)
return PLAY_COMPLETE | PLAY_RECORD;
+
return PLAY_CONTINUE;
+
case CT_TELEPORT:
- if (player_teleport(pmv)) {
+
+ if (player_teleport(pmv))
+ {
player_process_old_pos(pmv);
- free(pmv);
return PLAY_CONTINUE | PLAY_RECORD;
}
- free(pmv);
+
return PLAY_CONTINUE;
- break;
+
default:
break;
}
- struct xor_move *omv = player_process_move(pmv);
- if (omv) {
- if (omv == pmv) {
- game_win_move_player(pmv);
- if (cont == CT_PICKUP)
- player_process_collect(pmv);
- player_process_old_pos(pmv);
- }
- else {
- game_win_move_object(omv);
- game_win_move_player(pmv);
- if (cont == CT_PICKUP)
- player_process_collect(pmv);
- pushed_process_new_pos(omv);
- player_process_old_pos(pmv);
- }
- free(pmv);
- return PLAY_PROCESS_MOVE | PLAY_RECORD;
- }
- free(pmv);
- return PLAY_CONTINUE;
-}
+ if (cont & CT_PICKUP)
+ player_process_collect(pmv);
-struct xor_move *
-player_process_move(struct xor_move *pmv)
-{
- struct xor_move *omv = pmv;
-
- enum CONTACT cont = actions[pmv->to_obj].cont;
-
- if (cont != CT_PASS) {
- if (cont & CT_PUSH || cont == CT_HARDPUSH) {
- omv = create_xor_move(pmv->to_x, pmv->to_y, pmv->dir);
- if (move_object_init(omv) != CT_PASS) {
- free(omv);
- return 0; /* blocked, blocking player's move */
- }
- map->buf[omv->from_y][omv->from_x] = ICON_SPACE;
- map->buf[omv->to_y][omv->to_x] = omv->from_obj;
- }
- }
- map->player[player.player].x = pmv->to_x;
- map->player[player.player].y = pmv->to_y;
- map->buf[pmv->to_y][pmv->to_x] = pmv->from_obj;
+ if (cont & CT_PUSH || cont & CT_HARDPUSH)
+ return player_process_push(pmv);
+
+ map->buf[pmv->to_y] [pmv->to_x] = pmv->from_obj;
map->buf[pmv->from_y][pmv->from_x] = ICON_SPACE;
- return omv;
+
+ game_win_move_player(pmv);
+ player_process_old_pos(pmv);
+ pmv->from_x = pmv->to_x;
+ pmv->from_y = pmv->to_y;
+ pmv->from_obj = pmv->to_obj;
+
+ return PLAY_PROCESS_MOVE | PLAY_RECORD;
}
-enum PLAY_STATE
-player_process_old_pos(struct xor_move *pmv)
-{
- debug("\nplayer_process_old_pos(xor_move* pmv=%lx)\n",
- (unsigned long) pmv);
- su_t check1 = (MV_HORIZ & pmv->dir) ? MV_UP : MV_RIGHT;
+enum PLAY_STATE player_process_old_pos(struct xor_move *pmv)
+{
+ debug("(xor_move* pmv=%lx)\n", (unsigned long) pmv);
- su_t check2 = (check1 == MV_UP) ? MV_RIGHT : MV_UP;
+ su_t check1 = (MV_HORIZ & pmv->dir) ? MV_UP : MV_RIGHT;
+ su_t check2 = (check1 == MV_UP) ? MV_RIGHT : MV_UP;
su_t gdir1 = (check1 == MV_UP) ? MV_DOWN : MV_LEFT;
-
su_t gdir2 = (check2 == MV_UP) ? MV_DOWN : MV_LEFT;
xy_t x = pmv->from_x + (check1 == MV_RIGHT ? 1 : 0);
-
- xy_t y = pmv->from_y - (check1 == MV_UP ? 1 : 0);
+ xy_t y = pmv->from_y - (check1 == MV_UP ? 1 : 0);
struct xor_move *gravmv = create_gravity_chain_xydir(x, y, gdir1);
if (gravmv)
move_gravity_process(gravmv);
+
x = pmv->from_x + (check2 == MV_RIGHT ? 1 : 0);
y = pmv->from_y - (check2 == MV_UP ? 1 : 0);
+
if ((gravmv = create_gravity_chain_xydir(x, y, gdir2)))
move_gravity_process(gravmv);
+
return PLAY_PROCESS_MOVE;
}
-enum PLAY_STATE
-pushed_process_new_pos(struct xor_move *omv)
+
+enum PLAY_STATE pushed_process_new_pos(struct xor_move *omv)
{
debug("\npushed_process_new_pos(xor_move* omv=%lx)\n",
(unsigned long) omv);
if (omv->from_obj != ICON_DOLL)
omv->dir = actions[omv->from_obj].mvi_dir;
+
omv->from_x = omv->to_x;
omv->from_y = omv->to_y;
- if (move_object_init(omv) == CT_PASS) {
+
+ if (move_object_init(omv) == CT_PASS)
+ {
/* the call to move_object_init will be repeated by
move_gravity_process... but more importantly, having
it here prevents a bomb exploding when an object is
@@ -175,33 +167,71 @@ pushed_process_new_pos(struct xor_move *omv)
}
else
free(omv);
+
return PLAY_PROCESS_MOVE;
}
-void
-player_process_collect(struct xor_move *pmv)
+
+void player_process_collect(struct xor_move *pmv)
{
- switch (pmv->to_obj) {
+ switch (pmv->to_obj)
+ {
case ICON_MASK:
player.masks_collected++;
+ map->buf[pmv->to_y] [pmv->to_x] = ICON_SPACE;
info_win_map_erase_mask(pmv->to_x, pmv->to_y);
- if ((player.masks_collected % 4) == 0)
- info_win_update_map(player.have_map);
break;
+
case ICON_MAP:
player_process_map_pc(pmv);
break;
+
case ICON_SWITCH:
player.wall_vis = (player.wall_vis ? FALSE : TRUE);
init_wall(map->level, player.wall_vis);
game_win_display();
+
default:
break;
}
}
-void
-player_death(su_t icon)
+
+static enum PLAY_STATE player_process_push(struct xor_move* pmv)
+{
+ struct xor_move* omv =
+ create_xor_move(pmv->to_x, pmv->to_y, pmv->dir);
+
+ if (move_object_init(omv) != CT_PASS)
+ {
+ destroy_gravity_chain(omv);
+ return PLAY_CONTINUE;
+ }
+
+ map->buf[omv->to_y] [omv->to_x] = omv->from_obj;
+ map->buf[omv->from_y][omv->from_x] = ICON_SPACE;
+ map->buf[pmv->to_y] [pmv->to_x] = pmv->from_obj;
+ map->buf[pmv->from_y][pmv->from_x] = ICON_SPACE;
+
+ game_win_icon_display(omv->from_x, omv->from_y, ICON_SPACE);
+ game_win_icon_display(omv->to_x, omv->to_y, omv->from_obj);
+
+ /*game_win_display();*/
+
+ game_win_move_player(pmv);
+ omv->from_x = omv->to_x;
+ omv->from_y = omv->to_y;
+ pushed_process_new_pos(omv);/* and free(omv) */
+ player_process_old_pos(pmv);
+ pmv->from_obj = pmv->to_obj;
+ pmv->from_x = pmv->to_x;
+ pmv->from_y = pmv->to_y;
+
+ return PLAY_PROCESS_MOVE | PLAY_RECORD;
+}
+
+
+void player_death(su_t icon)
{
su_t p = (icon == ICON_PLAYER0) ? 0 : 1;
char *msg[2] = { " Oops! ", "Gotcha!" };
@@ -214,7 +244,9 @@ player_death(su_t icon)
player.player ^= 1;
info_win_update_player_icon();
}
+
scr_wmsg_pause(game_win, msg[p], 0, 0, TRUE);
+
if (player.replay)
nodelay(game_win, TRUE);
@@ -223,21 +255,26 @@ player_death(su_t icon)
game_win_display();
}
-void
-player_process_map_pc(struct xor_move *pmv)
+
+void player_process_map_pc(struct xor_move *pmv)
{
su_t i;
su_t mb = 1;
- for (i = 0; i < 4; i++, mb *= 2) {
- if (pmv->to_x == map->mappc[i].x && pmv->to_y == map->mappc[i].y) {
+ for (i = 0; i < 4; i++, mb *= 2)
+ {
+ if (pmv->to_x == map->mappc[i].x && pmv->to_y == map->mappc[i].y)
+ {
+ debug("collected map piece ix:%d id:%d\n", i, mb);
player.have_map |= mb;
+ debug("player.have_map:%d\n", player.have_map);
info_win_dump_map(i);
}
}
}
+
#if DEBUG
void player_state_print(int state)
View
10 player.h
@@ -33,9 +33,13 @@ enum PLAY_STATE
struct xor_player
{
- ctr_t masks_collected;
- ctr_t moves_remaining;
- xy_t map_view_y;
+ ctr_t masks_collected;
+ ctr_t moves_remaining;
+
+ struct xor_move xmv[2];
+
+ xy_t map_view_y;
+
unsigned player:1; /* set = player 2, not set = player 1 */
unsigned p0_alive:1;
unsigned p1_alive:1;
View
9 replay.c
@@ -8,6 +8,8 @@
#include "options.h"
#include "debug.h"
#include "fletcher.h"
+#include "exit.h"
+#include "splash.h"
#include <string.h>
@@ -83,10 +85,12 @@ void replay_menu_create()
shortcuts[REPLAY_MENU_RESTART] = '*' | MENU_SHORTCUT_ACTIVATES;
}
+
void replay_menu_destroy()
{
}
+
void replay_menu_config_for(int flow)
{
bool replay_continue = FALSE;
@@ -128,7 +132,7 @@ void replay_menu_config_for(int flow)
shortcuts[REPLAY_MENU_PLAY_GAME]
|= MENU_HIDDEN | MENU_DISABLED;
- if (options->oldschool_play)
+ if (options->oldschool_play || !replay.canplay)
{
shortcuts[REPLAY_MENU_BREAK_DEL]
|= (MENU_HIDDEN | MENU_DISABLED);
@@ -311,7 +315,10 @@ player_state_print(state);
return FLOW_DEATH;
if (state == PLAY_COMPLETE)
+ {
+ player_exit_animate(&player.xmv[player.player]);
return FLOW_COMPLETE;
+ }
if (interupt)
return FLOW_INTERUPT_MENU;
View
12 scores.c
@@ -83,6 +83,13 @@ load_scores()
return;
}
+ buf[79] = '\0';
+
+ bp = buf; /* trim newlines etc */
+ while (*bp >= ' ')
+ bp++;
+ *bp = '\0';
+
if (sscanf(buf, "%02x%02x", &read_chka, &read_chkb) != 2)
{
debug("failed to read level %d score checksum\n", i);
@@ -90,6 +97,7 @@ load_scores()
}
bp = buf + 4;
+
fletcher16(&calc_chka, &calc_chkb, (uint8_t*)bp, strlen(bp));
if (read_chka != calc_chka || read_chkb != calc_chkb)
@@ -100,9 +108,9 @@ load_scores()
return;
}
- if (sscanf(buf, "%02d%04d", &lvl, &score) != 2 || lvl != i)
+ if (sscanf(bp, "%02d%04d", &lvl, &score) != 2 || lvl != i)
{
- debug("failed to read level %d score\n", i);
+ debug("failed to read level %d == %d score\n", lvl, i);
return;
}
}
View
4 screen.c
@@ -264,10 +264,10 @@ scr_wmsg_pause(
bool autofree = FALSE;
if (!msgxy) {
msgxy = malloc(sizeof(struct scrxy));
+ msgxy->x = (getmaxx(win) - (len + 2)) / 2;
+ msgxy->y = (getmaxy(win) - 3) / 2;
autofree = TRUE;
}
- msgxy->x = (getmaxx(win) - (len + 2)) / 2;
- msgxy->y = (getmaxy(win) - 3) / 2;
char spc[IOBUF + 1];
for (int i = 0; i <= IOBUF; ++i)
spc[i] = ' ';
View
209 splash.c
@@ -1,9 +1,15 @@
#include "splash.h"
#include "types.h"
#include "screen.h"
+#include "player.h"
+#include "options.h"
+#include "debug.h"
-void
-splash()
+#include <stdlib.h>
+#include <time.h>
+
+
+void splash(void)
{
char *xortitle[] = {
"-- -- --- ---\\",
@@ -14,22 +20,6 @@ splash()
"-- -- --- - Curses",
"X"
};
- char *xormask[] = {
- " ___*******___",
- "/ ------- \\",
- "| |",
- "\\ ---\\ /--- /",
- " | \\--- ---/ |",
- "/ \\",
- "| |",
- "\\ \\\\ // /",
- " \\ \\\\ // /",
- " \\ \\\\ // /",
- " \\ \\_/ /",
- " \\ /",
- " \\___/",
- "X"
- };
char *xorlns[] = {
" --- ---",
" ------ ------",
@@ -50,8 +40,6 @@ splash()
xy_t offx = ((screen_data->garea_w - 8) / 2) * ICON_W;
xy_t offy = ((screen_data->garea_h - 8) / 2) * ICON_H + 1;
- bool msk = FALSE;
-
wclear(game_win);
ptr1 = xortitle;
@@ -72,22 +60,18 @@ splash()
ptr1++;
y++;
}
- ptr1 = xormask;
+
+ splash_mask(offx + 12, offy + 7, 0);
+
+ ptr1 = xorlns;
ptr2 = ptr1[0];
- y = offy + 7;
+ y = offy + 16;
wattrset(game_win, COLOR_PAIR(0));
while (*ptr1[0] != 'X') {
ptr2 = *ptr1;
- x = offx + 12;
- msk = FALSE;
+ x = offx + 0;
while (*ptr2) {
- if (*ptr2 != ' ') {
- wattrset(game_win, COLOR_PAIR(COL_SPLASH_MASK));
- msk = TRUE;
- }
- else if (msk == TRUE)
- wattrset(game_win, COLOR_PAIR(COL_SPLASH_MASK_SOLID));
- if (*ptr2 != '*')
+ if (*ptr2 != ' ')
mvwaddch(game_win, y, x, *ptr2);
x++;
ptr2++;
@@ -95,22 +79,169 @@ splash()
ptr1++;
y++;
}
- ptr1 = xorlns;
- ptr2 = ptr1[0];
- y = offy + 16;
+ wrefresh(game_win);
+}
+
+
+void splash_mask(xy_t offx, xy_t offy, int randcol)
+{
+ char *xormask[] = {
+ " ___*******___",
+ "/ ------- \\",
+ "| |",
+ "\\ ---\\ /--- /",
+ " | \\--- ---/ |",
+ "/ \\",
+ "| |",
+ "\\ \\\\ // /",
+ " \\ \\\\ // /",
+ " \\ \\\\ // /",
+ " \\ \\_/ /",
+ " \\ /",
+ " \\___/",
+ "X"
+ };
+
+ char **ptr1 = xormask;
+ char *ptr2 = ptr1[0];
+
+ xy_t y = offy;
wattrset(game_win, COLOR_PAIR(0));
- while (*ptr1[0] != 'X') {
+
+ int fg = (randcol) ? rand() % ICON_XXX : COL_SPLASH_MASK;
+ int bg = (randcol) ? rand() % ICON_XXX : COL_SPLASH_MASK_SOLID;
+
+ while (*ptr1[0] != 'X')
+ {
ptr2 = *ptr1;
- x = offx + 0;
- while (*ptr2) {
- if (*ptr2 != ' ')
+ xy_t x = offx;
+ bool msk = FALSE;
+ bool out = TRUE;
+
+ while (*ptr2)
+ {
+ if (*ptr2 != ' ') {
+ wattrset(game_win, COLOR_PAIR(fg));
+ msk = TRUE;
+ out = FALSE;
+ }
+ else if (msk == TRUE)
+ wattrset(game_win, COLOR_PAIR(bg));
+
+ if (*ptr2 != '*' && !out)
mvwaddch(game_win, y, x, *ptr2);
+
x++;
ptr2++;
}
ptr1++;
y++;
}
- wrefresh(game_win);
+}
+
+
+void splatter_masks(void)
+{
+ int i;
+ struct timespec rpause;
+ struct timespec repause;
+ rpause.tv_sec = 0;
+ rpause.tv_nsec = 0;
+
+ if (player.replay)
+ {
+ if (!options->replay_hyper)
+ rpause.tv_nsec =
+ options_replay_speed(options->replay_speed) / 5;
+ }
+ else
+ rpause.tv_nsec = 12500000L;
+
+ int maxx = getmaxx(game_win);
+ int maxy = getmaxy(game_win);
+
+ srand(time(0));
+
+ for (i = 0; i < 150; ++i)
+ {
+ splash_mask(-5 + rand() % maxx, -5 + rand() % maxy, 1);
+ scr_wmsg(game_win, " Well Done! Level Complete! ", 0, 0);
+ wrefresh(game_win);
+ nanosleep(&rpause, &repause);
+ }
+
+}
+
+
+void splash_level_entry(lvl_t level)
+{
+ struct timespec rpause;
+ struct timespec repause;
+ const int count = 15; /* iterations */
+ const int cpoff = 9 + (level / 3) % 5; /* ICON_* colour pair offset */
+ const int ccount = (level < 12) ? 6 : 5; /* #colour bands */
+ const int maxx = getmaxx(game_win);
+ const int maxy = getmaxy(game_win);
+ const int c = ' ';
+ int i;
+
+ rpause.tv_sec = 0;
+ rpause.tv_nsec = 0;
+
+ if (player.replay)
+ {
+ if (!options->replay_hyper)
+ rpause.tv_nsec =
+ options_replay_speed(options->replay_speed);
+ }
+ else
+ rpause.tv_nsec = 50000000L;
+
+ for (i = 0; i < count; ++i)
+ {
+ int tmp = maxx / 2;
+ int r1x = tmp - i % 2;
+ int r2x = tmp + i % 2;
+ int r1y = maxy / 2;
+ int r2y = r1y;
+ int cp;
+
+ cp = (ccount * 100 - i) % ccount;
+
+ wattrset(game_win, COLOR_PAIR(cpoff + cp));
+
+ for (tmp = 0; tmp <= r2x - r1x; ++tmp)
+ mvwaddch(game_win, r1y, r1x + tmp, c);
+
+ do
+ {
+ int x, y;
+
+ cp = (cp + 1) % ccount;
+ wattrset(game_win, COLOR_PAIR(cpoff + cp));
+ r1x -= 2;
+ r2x += 2;
+ r1y--;
+ r2y++;
+
+ for (x = r1x; x <= r2x; ++x)
+ {
+ mvwaddch(game_win, r1y, x, c);
+ mvwaddch(game_win, r2y, x, c);
+ }
+
+ for (y = r1y; y <= r2y; ++y)
+ {
+ mvwaddch(game_win, y, r1x, c);
+ mvwaddch(game_win, y, r1x+1, c);
+ mvwaddch(game_win, y, r2x, c);
+ mvwaddch(game_win, y, r2x-1, c);
+ }
+
+ } while(r1x > 0 || r1y > 0);
+
+ wrefresh(game_win);
+ nanosleep(&rpause, &repause);
+ }
}
View
14 splash.h
@@ -15,6 +15,20 @@
#ifndef _SPLASH_H
#define _SPLASH_H
+
+#include "types.h"
+
+
void splash();
+void splash_mask(xy_t offx, xy_t offy, int randcol);
+
+void splatter_masks(void);
+
+
+void splash_wipe_out(void);
+
+void splash_level_entry(lvl_t level);
+
+
#endif
View
68 teleport.c
@@ -7,59 +7,73 @@
#include <time.h>
#include <stdlib.h>
-bool
-player_teleport(struct xor_move * pmv)
+
+bool player_teleport(struct xor_move * pmv)
{
su_t t = map_get_teleport(pmv->to_x, pmv->to_y) ^ 1;
if (t > 1)
return FALSE;
+
player_teleport_animate(pmv, TP_IN);
map->buf[pmv->from_y][pmv->from_x] = ICON_SPACE;
game_win_show(map->tpview[t].x, map->tpview[t].y);
+
/* check teleport destination has not been blown up */
if (map->buf[map->teleport[t].y]
- [map->teleport[t].x] == ICON_TELEPORT) {
+ [map->teleport[t].x] == ICON_TELEPORT)
+ {
/* check teleport exits are not blocked */
xy_t chkx[4] = { 1, 0, -1, 0 };
xy_t chky[4] = { 0, -1, 0, 1 };
- for (su_t i = 0; i < 4; i++) {
+
+ for (su_t i = 0; i < 4; i++)
+ {
xy_t px = map->teleport[t].x + chkx[i];
xy_t py = map->teleport[t].y + chky[i];
- if (map->buf[py][px] == ICON_SPACE) {
+ if (map->buf[py][px] == ICON_SPACE)
+ {
map->buf[py][px] = pmv->from_obj;
map->player[player.player].x = pmv->to_x = px;
map->player[player.player].y = pmv->to_y = py;
xy_t tlx = map->tpview[t].x;
xy_t tly = map->tpview[t].y;
+
if (tlx + screen_data->garea_w >= MAP_W)
tlx -= (tlx + screen_data->garea_w) - MAP_W;
+
if (tly + screen_data->garea_h >= MAP_H)
tly -= (tly + screen_data->garea_h) - MAP_W;
+
map->view[player.player].x = tlx;
map->view[player.player].y = tly;
player_teleport_animate(pmv, TP_OUT);
game_win_display();
flushinp();
+
return TRUE;
}
}
}
+
/* sorry, we can't teleport you today due to snow on the road */
struct timespec rpause;
-
struct timespec repause;
rpause.tv_sec = 0;
rpause.tv_nsec = 0;
- if (player.replay) {
+
+ if (player.replay)
+ {
if (!options->replay_hyper)
- rpause.tv_nsec = options_replay_speed(options->replay_speed) / 5;
+ rpause.tv_nsec =
+ options_replay_speed(options->replay_speed) / 5;
}
else
rpause.tv_nsec = 750000000L;
+
nanosleep(&rpause, &repause);
pmv->to_x = pmv->from_x;
pmv->to_y = pmv->from_y;
@@ -67,54 +81,66 @@ player_teleport(struct xor_move * pmv)
player_teleport_animate(pmv, TP_OUT);
map->buf[pmv->from_y][pmv->from_x] = pmv->from_obj;
flushinp();
+
return FALSE;
}
-void
-player_teleport_animate(struct xor_move *pmv, enum TP_ANIM dir)
+void player_teleport_animate(struct xor_move *pmv, enum TP_ANIM dir)
{
struct xy *dmxy = 0;
-
struct xor_icon *icon = 0;
- if (dir == TP_IN) {
+ if (dir == TP_IN)
+ {
if (!(dmxy = game_win_map_coord(pmv->from_x, pmv->from_y)))
return; /* should be unlikely */
+
icon = &icons[pmv->from_obj];
wattrset(game_win, COLOR_PAIR(ICON_SPACE));
}
- else {
+ else
+ {
if (!(dmxy = game_win_map_coord(pmv->to_x, pmv->to_y)))
return; /* should be unlikely */
+
icon = &icons[pmv->from_obj];
wattrset(game_win, COLOR_PAIR(pmv->from_obj));
}
- struct timespec rpause;
+ struct timespec rpause;
struct timespec repause;
rpause.tv_sec = 0;
rpause.tv_nsec = 0;
- if (player.replay) {
+
+ if (player.replay)
+ {
if (!options->replay_hyper)
- rpause.tv_nsec = options_replay_speed(options->replay_speed) / 5;
+ rpause.tv_nsec =
+ options_replay_speed(options->replay_speed) / 5;
}
else
rpause.tv_nsec = 12500000L;
- xy_t stx, enx, xinc;
- for (xy_t y = dmxy->y; y < dmxy->y + ICON_H; y++) {
- if (y & 1) {
+ for (xy_t y = dmxy->y; y < dmxy->y + ICON_H; y++)
+ {
+ xy_t stx, enx, xinc;
+
+ if (y & 1)
+ {
stx = dmxy->x + ICON_W - 1;
enx = dmxy->x - 1;
xinc = -1;
}
- else {
+ else
+ {
stx = dmxy->x;
enx = dmxy->x + ICON_W;
xinc = 1;
}
- for (xy_t x = stx; x != enx; x += xinc) {
+
+ for (xy_t x = stx; x != enx; x += xinc)
+ {
mvwaddch(game_win, y, x, icon->chrs[y - dmxy->y][x - dmxy->x]);
wrefresh(game_win);
nanosleep(&rpause, &repause);
View
1  xorcurses.c
@@ -41,6 +41,7 @@ main(void)
ret = 1;
goto bail;
}
+
create_scores();
load_scores();
init_icons();

No commit comments for this range

Something went wrong with that request. Please try again.