-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay_xor.c
173 lines (143 loc) · 4.47 KB
/
play_xor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include "play_xor.h"
#include "options.h"
#include "scores.h"
#include "screen.h"
#include "info.h"
#include "player.h"
#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>
#include <curses.h>
void
info_win_repaint()
{
wclear(info_win);
wattrset(info_win, COLOR_PAIR(0));
box(info_win, 0, 0);
info_win_update_player_icon();
info_win_update_map(player.have_map);
info_win_display();
}
int
play_xor(lvl_t level)
{
player.replay = 0;
if (level & FLOW_START)
{
level &= 0x000f;
replay.level = level;
replay.canplay = 1;
replay.hasexit = 0;
for (ctr_t mv = MAX_MOVES; mv >= 0; mv--)
replay.moves[mv] = 0;
init_wall(level, TRUE);
char* fn = options_map_filename(level);
if (!xor_map_create()
|| !xor_map_load_by_filename(fn))
{
scr_wmsg(game_win, "Failed to load map!", 0, 0);
wgetch(game_win);
free(fn);
return FLOW_DO_QUIT;
}
free(fn);
player_init();
game_win_init_views();
splash_level_entry(level);
}
else
level = replay.level;
map->level = level;
game_win_display();
info_win_repaint();
screen_data->game_win_repaint_cb = &game_win_display;
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)
{
int key = wgetch(game_win);
su_t move = MV_NONE;
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 '\r': case 'p':
move = MV_PLAYER_SWAP;
break;
case 'b':
if (!options->oldschool_play
&& player.moves_remaining < MAX_MOVES)
{
replay.moves[player.moves_remaining + 1]
^= MV_REPLAY_BREAK;
if (replay.moves[player.moves_remaining + 1]
& MV_REPLAY_BREAK)
scr_wmsg_pause(game_win, "Breakpoint set", 0, 0, TRUE);
else
scr_wmsg_pause(game_win, "Breakpoint unset", 0, 0,TRUE);
game_win_display();
}
break;
case '1': case '2': case '3':
if (!options->oldschool_play)
{
options->scroll_thresh = key - '0';
char buf[40];
snprintf(buf, 39, "Scroll threshold %d set",
options->scroll_thresh);
scr_wmsg_pause(game_win, buf, 0, 0, TRUE);
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 KEY_RESIZE:
screen_resize();
break;
}
if (move)
{
state = player_move(move);
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)
{
player_exit_animate(&player.xmv[player.player]);
replay.moves[player.moves_remaining] = MV_PLAYER_EXIT;
replay.hasexit = 1;
set_score(map->level, MAX_MOVES - player.moves_remaining);
return FLOW_COMPLETE;
}
if (player.moves_remaining == MAX_MOVES)
return FLOW_DO_QUIT;
if (state == PLAY_QUIT)
return FLOW_CAN_PLAY;
return FLOW_CONTINUE;
}