forked from mtoyoda/sl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
quit.c
207 lines (184 loc) · 5.92 KB
/
quit.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*========================================
* quit.c: quit version 1.0
* Copyright 1993,1998,2013
* Toyoda Masashi
* (mtoyoda@acm.org)
* Copyright 2013
* Kentaro Fukuchi
*========================================
*/
/* quit version 1.00 : initial release. */
/* sl version 5.00 : add -c option */
/* by Toyoda Masashi 2013/ 5/ 5 */
/* sl version 4.00 : add C51, usleep(40000) */
/* by Toyoda Masashi 2002/12/31 */
/* sl version 3.03 : add usleep(20000) */
/* by Toyoda Masashi 1998/ 7/22 */
/* sl version 3.02 : D51 flies! Change options. */
/* by Toyoda Masashi 1993/ 1/19 */
/* sl version 3.01 : Wheel turns smoother */
/* by Toyoda Masashi 1992/12/25 */
/* sl version 3.00 : Add d(D51) option */
/* by Toyoda Masashi 1992/12/24 */
/* sl version 2.02 : Bug fixed.(dust remains in screen) */
/* by Toyoda Masashi 1992/12/17 */
/* sl version 2.01 : Smoke run and disappear. */
/* Change '-a' to accident option. */
/* by Toyoda Masashi 1992/12/16 */
/* sl version 2.00 : Add a(all),l(long),F(Fly!) options. */
/* by Toyoda Masashi 1992/12/15 */
/* sl version 1.02 : Add turning wheel. */
/* by Toyoda Masashi 1992/12/14 */
/* sl version 1.01 : Add more complex smoke. */
/* by Toyoda Masashi 1992/12/14 */
/* sl version 1.00 : SL runs vomitting out smoke. */
/* by Toyoda Masashi 1992/12/11 */
#include <curses.h>
#include <signal.h>
#include <unistd.h>
#include "quit.h"
int LONGER = 0;
#define EXTRACARGONUM 10
static int phase = 0;
static void add_punpun(int, int);
static void add_baka(int, int);
static void add_golua(int, int);
static void add_cargo(int, int);
static void add_smoke(int y, int x);
static int add_quit(int);
int my_mvaddstr(int y, int x, char *str)
{
for (; x < 0; ++x, ++str)
if (*str == '\0')
return ERR;
for (; *str != '\0'; ++str, ++x)
if (mvaddch(y, x, *str) == ERR)
return ERR;
return OK;
}
void option(char *str)
{
while (*str != '\0')
{
switch (*str++)
{
case 'l':
LONGER = 1;
break;
default:
break;
}
}
}
int main(int argc, char *argv[])
{
int x, i;
for (i = 1; i < argc; ++i)
{
if (*argv[i] == '-')
{
option(argv[i] + 1);
}
}
initscr();
signal(SIGINT, SIG_IGN);
noecho();
curs_set(0);
nodelay(stdscr, TRUE);
leaveok(stdscr, TRUE);
scrollok(stdscr, FALSE);
for (x = COLS - 1;; --x)
{
if (add_quit(x) == ERR)
break;
phase++;
getch();
refresh();
usleep(40000);
}
mvcur(0, COLS - 1, LINES - 1, 0);
endwin();
}
int add_quit(int x)
{
static char *quit[QUITHEIGHT] = {QUITSTR01, QUITSTR02, QUITSTR03, QUITSTR04, QUITSTR05, QUITSTR06,
QUITSTR07, QUITSTR08, QUITSTR09, QUITSTR10, QUITSTR11, QUITSTR12,
QUITSTR13, QUITSTR14, QUITSTR15, QUITSTR16, QUITSTR17};
int y, i;
if (x < -QUITLENGTH - LONGER * EXTRACARGONUM * EXTRACARGOLENGTH)
return ERR;
y = (LINES - QUITHEIGHT) / 2;
for (i = 0; i < QUITHEIGHT; ++i)
{
my_mvaddstr(y + i, x, quit[i]);
}
add_punpun(y + 6, x);
add_baka(y + 6, x + 38);
add_golua(y + 6, x + 55);
if (!LONGER)
{
add_smoke(y + 15, x + QUITLENGTH);
}
else
{
for (i = 0; i < EXTRACARGONUM; i++)
{
add_cargo(y + 6, x + QUITLENGTH + i * EXTRACARGOLENGTH);
if (i % 2 == 0)
{
add_baka(y + 6, x + 7 + QUITLENGTH + i * EXTRACARGOLENGTH);
}
else
{
add_golua(y + 6, x + 5 + QUITLENGTH + i * EXTRACARGOLENGTH);
}
}
add_smoke(y + 15, x + QUITLENGTH + EXTRACARGONUM * EXTRACARGOLENGTH);
}
return OK;
}
void add_smoke(int y, int x)
{
static char *Smoke[SMOKEPTNS] = {SMOKE01, SMOKE02, SMOKE03};
my_mvaddstr(y, x, Smoke[x % SMOKEPTNS]);
}
void add_cargo(int y, int x)
{
static char *cargo[EXTRACARGOHEIGHT] = {EXTRACARGO0, EXTRACARGO0, EXTRACARGO0, EXTRACARGO1, EXTRACARGO2,
EXTRACARGO3, EXTRACARGO4, EXTRACARGO5, EXTRACARGO6, EXTRACARGO7,
EXTRACARGO8};
int i;
for (i = 0; i < EXTRACARGOHEIGHT; ++i)
{
my_mvaddstr(y + i, x, cargo[i]);
}
}
void add_punpun(int y, int x)
{
int i;
static char *pun[PUNHEIGHT] = {PUNSTR01, PUNSTR02, PUNSTR03};
for (i = 0; i < PUNHEIGHT; i++)
{
my_mvaddstr(y + i, x + (((unsigned int)x & 4) << 1), pun[i]);
}
}
void add_baka(int y, int x)
{
int i;
static char *baka[BAKAHEIGHT] = {BAKASTR01, BAKASTR02, BAKASTR03};
if ((phase & 15) < 8)
for (i = 0; i < BAKAHEIGHT; i++)
{
my_mvaddstr(y + i, x, baka[i]);
}
}
void add_golua(int y, int x)
{
int i;
static char *golua[GOLUAHEIGHT] = {GOLUASTR01, GOLUASTR02, GOLUASTR03};
if ((phase & 15) >= 8)
for (i = 0; i < GOLUAHEIGHT; i++)
{
my_mvaddstr(y + i, x, golua[i]);
}
}