~ubuntu-branches/debian/stretch/opentyrian/stretch

« back to all changes in this revision

Viewing changes to src/scroller.c

  • Committer: Package Import Robot
  • Author(s): Etienne Millon
  • Date: 2015-03-31 08:48:54 UTC
  • Revision ID: package-import@ubuntu.com-20150331084854-f5a4uoz7uv3vopk6
Tags: upstream-2.1.20130907+dfsg
ImportĀ upstreamĀ versionĀ 2.1.20130907+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * OpenTyrian: A modern cross-platform port of Tyrian
 
3
 * Copyright (C) 2007-2009  The OpenTyrian Development Team
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License
 
7
 * as published by the Free Software Foundation; either version 2
 
8
 * of the License, or (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
18
 */
 
19
#include "font.h"
 
20
#include "joystick.h"
 
21
#include "jukebox.h"
 
22
#include "keyboard.h"
 
23
#include "loudness.h"
 
24
#include "mtrand.h"
 
25
#include "nortsong.h"
 
26
#include "nortvars.h"
 
27
#include "opentyr.h"
 
28
#include "palette.h"
 
29
#include "scroller.h"
 
30
#include "sprite.h"
 
31
#include "varz.h"
 
32
#include "vga256d.h"
 
33
#include "video.h"
 
34
 
 
35
const struct about_text_type about_text[] =
 
36
{
 
37
        {0x30, "----- ~OpenTyrian~ -----"},
 
38
        {0x00, ""},
 
39
        {0x0b, "...eliminating Microsol,"},
 
40
        {0x0b, "one planet at a time..."},
 
41
        {0x00, ""},
 
42
        {0x00, ""},
 
43
        {0x30, "----- ~Developers~ -----"},
 
44
        {0x00, ""},
 
45
        {0x03, "Carl Reinke // Mindless"},
 
46
        {0x07, "Yuri Schlesner // yuriks"},
 
47
        {0x04, "Casey McCann // syntaxglitch"},
 
48
        {0x00, ""},
 
49
        {0x00, ""},
 
50
        {0x30, "----- ~Thanks~ -----"},
 
51
        {0x00, ""},
 
52
        {0x0e, "Thanks to everyone who has"},
 
53
        {0x0e, "assisted the developers by testing"},
 
54
        {0x0e, "the game and reporting bugs."},
 
55
        {0x00, ""},
 
56
        {0x00, ""},
 
57
        {0x05, "Thanks to ~DOSBox~ for the"},
 
58
        {0x05, "FM-Synthesis emulator and"},
 
59
        {0x05, "~AdPlug~ for the Loudness player."},
 
60
        {0x00, ""},
 
61
        {0x00, ""},
 
62
        {0x32, "And special thanks to ~Jason Emery~"},
 
63
        {0x32, "for making all this possible"},
 
64
        {0x32, "by giving Tyrian to its fans."},
 
65
        {0x00, ""},
 
66
        {0x00, ""},
 
67
/*      {0x00, "This is line color test ~0~."},
 
68
        {0x01, "This is line color test ~1~."},
 
69
        {0x02, "This is line color test ~2~."},
 
70
        {0x03, "This is line color test ~3~."},
 
71
        {0x04, "This is line color test ~4~."},
 
72
        {0x05, "This is line color test ~5~."},
 
73
        {0x06, "This is line color test ~6~."},
 
74
        {0x07, "This is line color test ~7~."},
 
75
        {0x08, "This is line color test ~8~."},
 
76
        {0x09, "This is line color test ~9~."},
 
77
        {0x0a, "This is line color test ~A~."},
 
78
        {0x0b, "This is line color test ~B~."},
 
79
        {0x0c, "This is line color test ~C~."},
 
80
        {0x0d, "This is line color test ~D~."},
 
81
        {0x0e, "This is line color test ~E~."},
 
82
        {0x0f, "This is line color test ~F~."},*/
 
83
        {0x00, ""},
 
84
        {0x00, ""},
 
85
        {0x00, ""},
 
86
        {0x00, ""},
 
87
        {0x00, ""},
 
88
        {0x00, ""},
 
89
        {0x00, "Press a key to leave."},
 
90
        {0x00, NULL}
 
91
};
 
92
 
 
93
#define LINE_HEIGHT 15
 
94
 
 
95
#define MAX_BEER 5
 
96
#define BEER_SHAPE 241
 
97
 
 
98
struct coin_def_type {
 
99
        int shape_num;
 
100
        int frame_count;
 
101
        bool reverse_anim;
 
102
};
 
103
 
 
104
#define MAX_COINS 20
 
105
struct coin_def_type coin_defs[] =
 
106
{
 
107
        {1, 6}, {7, 6}, {20, 6}, {26, 6}, // Coins
 
108
        {14, 5, true}, {32, 5, true}, {51, 5, true} // Gems
 
109
};
 
110
 
 
111
/* Text is an array of strings terminated by a NULL */
 
112
void scroller_sine( const struct about_text_type text[] )
 
113
{
 
114
        bool ale = mt_rand() % 2;
 
115
 
 
116
        int visible_lines = vga_height / LINE_HEIGHT + 1;
 
117
        int current_line = -visible_lines;
 
118
        int y = 0;
 
119
        bool fade_in = true;
 
120
 
 
121
        struct coin_type { int x, y, vel, type, cur_frame; bool backwards; } coins[MAX_COINS];
 
122
        struct { int x, y, ay, vx, vy; } beer[MAX_BEER];
 
123
 
 
124
        if (ale)
 
125
        {
 
126
                memset(beer, 0, sizeof(beer));
 
127
        } else {
 
128
                for (int i = 0; i < MAX_COINS; i++)
 
129
                {
 
130
                        coins[i].x = mt_rand() % (vga_width - 12);
 
131
                        coins[i].y = mt_rand() % (vga_height - 20 - 14);
 
132
 
 
133
                        coins[i].vel = (mt_rand() % 4) + 1;
 
134
                        coins[i].type = mt_rand() % COUNTOF(coin_defs);
 
135
                        coins[i].cur_frame = mt_rand() % coin_defs[coins[i].type].frame_count;
 
136
                        coins[i].backwards = false;
 
137
                }
 
138
        }
 
139
 
 
140
        fade_black(10);
 
141
 
 
142
        wait_noinput(true, true, true);
 
143
 
 
144
        play_song(40); // BEER
 
145
 
 
146
        while (!JE_anyButton())
 
147
        {
 
148
                setdelay(3);
 
149
 
 
150
                JE_clr256(VGAScreen);
 
151
 
 
152
                if (!ale)
 
153
                {
 
154
                        for (int i = 0; i < MAX_COINS/2; i++)
 
155
                        {
 
156
                                struct coin_type *coin = &coins[i];
 
157
                                blit_sprite2(VGAScreen, coin->x, coin->y, eShapes[4], coin_defs[coin->type].shape_num + coin->cur_frame);
 
158
                        }
 
159
                }
 
160
 
 
161
                for (int i = 0; i < visible_lines; i++)
 
162
                {
 
163
                        if (current_line + i >= 0)
 
164
                        {
 
165
                                if (text[current_line + i].text == NULL)
 
166
                                {
 
167
                                        break;
 
168
                                }
 
169
 
 
170
                                int line_x = VGAScreen->w / 2;
 
171
                                int line_y = i * LINE_HEIGHT - y;
 
172
 
 
173
                                // smooths edges on sine-wave text
 
174
                                if (text[i + current_line].effect & 0x20)
 
175
                                {
 
176
                                        draw_font_hv(VGAScreen, line_x + 1, line_y, text[i + current_line].text, normal_font, centered, text[i + current_line].effect & 0x0f, -10);
 
177
                                        draw_font_hv(VGAScreen, line_x - 1, line_y, text[i + current_line].text, normal_font, centered, text[i + current_line].effect & 0x0f, -10);
 
178
                                }
 
179
 
 
180
                                draw_font_hv(VGAScreen, line_x, line_y, text[i + current_line].text, normal_font, centered, text[i + current_line].effect & 0x0f, -4);
 
181
 
 
182
                                if (text[i + current_line].effect & 0x10)
 
183
                                {
 
184
                                        for (int j = 0; j < LINE_HEIGHT; j++)
 
185
                                        {
 
186
                                                if (line_y + j >= 10 && line_y + j <= vga_height - 10)
 
187
                                                {
 
188
                                                        int waver = sinf((((line_y + j) / 2) % 10) / 5.0f * M_PI) * 3;
 
189
                                                        memmove(&((Uint8 *)VGAScreen->pixels)[VGAScreen->pitch * (line_y + j) + waver],
 
190
                                                                        &((Uint8 *)VGAScreen->pixels)[VGAScreen->pitch * (line_y + j)],
 
191
                                                                        VGAScreen->pitch);
 
192
                                                }
 
193
                                        }
 
194
                                }
 
195
                        }
 
196
                }
 
197
 
 
198
                if (++y == LINE_HEIGHT)
 
199
                {
 
200
                        y = 0;
 
201
 
 
202
                        if (current_line < 0 || text[current_line].text != NULL)
 
203
                                ++current_line;
 
204
                        else
 
205
                                current_line = -visible_lines;
 
206
                }
 
207
 
 
208
                if (!ale)
 
209
                {
 
210
                        for (int i = MAX_COINS/2; i < MAX_COINS; i++)
 
211
                        {
 
212
                                struct coin_type *coin = &coins[i];
 
213
                                blit_sprite2(VGAScreen, coin->x, coin->y, eShapes[4], coin_defs[coin->type].shape_num + coin->cur_frame);
 
214
                        }
 
215
                }
 
216
 
 
217
                fill_rectangle_xy(VGAScreen, 0, 0, vga_width - 1, 14, 0);
 
218
                fill_rectangle_xy(VGAScreen, 0, vga_height - 14, vga_width - 1, vga_height - 1, 0);
 
219
 
 
220
                if (!ale)
 
221
                {
 
222
                        for (int i = 0; i < MAX_COINS; i++)
 
223
                        {
 
224
                                struct coin_type *coin = &coins[i];
 
225
 
 
226
                                if (coin->backwards)
 
227
                                {
 
228
                                        coin->cur_frame--;
 
229
                                } else {
 
230
                                        coin->cur_frame++;
 
231
                                }
 
232
                                if (coin->cur_frame == coin_defs[coin->type].frame_count)
 
233
                                {
 
234
                                        if (coin_defs[coin->type].reverse_anim)
 
235
                                        {
 
236
                                                coin->backwards = true;
 
237
                                                coin->cur_frame -= 2;
 
238
                                        } else {
 
239
                                                coin->cur_frame = 0;
 
240
                                        }
 
241
                                }
 
242
                                if (coin->cur_frame == -1)
 
243
                                {
 
244
                                        coin->cur_frame = 1;
 
245
                                        coin->backwards = false;
 
246
                                }
 
247
 
 
248
                                coin->y += coin->vel;
 
249
                                if (coin->y > vga_height - 14)
 
250
                                {
 
251
                                        coin->x = mt_rand() % (vga_width - 12);
 
252
                                        coin->y = 0;
 
253
 
 
254
                                        coin->vel = (mt_rand() % 4) + 1;
 
255
                                        coin->type = mt_rand() % COUNTOF(coin_defs);
 
256
                                        coin->cur_frame = mt_rand() % coin_defs[coin->type].frame_count;
 
257
                                }
 
258
                        }
 
259
                } else {
 
260
                        for (uint i = 0; i < COUNTOF(beer); i++)
 
261
                        {
 
262
                                while (beer[i].vx == 0)
 
263
                                {
 
264
                                        beer[i].x = mt_rand() % (vga_width - 24);
 
265
                                        beer[i].y = mt_rand() % (vga_height - 28 - 50);
 
266
 
 
267
                                        beer[i].vx = (mt_rand() % 5) - 2;
 
268
                                }
 
269
 
 
270
                                beer[i].vy++;
 
271
 
 
272
                                if (beer[i].x + beer[i].vx > vga_width - 24 || beer[i].x + beer[i].vx < 0) // check if the beer hit the sides
 
273
                                {
 
274
                                        beer[i].vx = -beer[i].vx;
 
275
                                }
 
276
                                beer[i].x += beer[i].vx;
 
277
 
 
278
                                if (beer[i].y + beer[i].vy > vga_height - 28) // check if the beer hit the bottom
 
279
                                {
 
280
                                        if ((beer[i].vy) < 8) // make sure the beer bounces!
 
281
                                        {
 
282
                                                beer[i].vy += mt_rand() % 2;
 
283
                                        } else if (beer[i].vy > 16) { // make sure the beer doesn't bounce too high
 
284
                                                beer[i].vy = 16;
 
285
                                        }
 
286
                                        beer[i].vy = -beer[i].vy + (mt_rand() % 3 - 1);
 
287
 
 
288
                                        beer[i].x += (beer[i].vx > 0 ? 1 : -1) * (i % 2 ? 1 : -1);
 
289
                                }
 
290
                                beer[i].y += beer[i].vy;
 
291
 
 
292
                                blit_sprite2x2(VGAScreen, beer[i].x, beer[i].y, eShapes[4], BEER_SHAPE);
 
293
                        }
 
294
                }
 
295
 
 
296
                JE_showVGA();
 
297
 
 
298
                if (fade_in)
 
299
                {
 
300
                        fade_in = false;
 
301
                        fade_palette(colors, 10, 0, 255);
 
302
 
 
303
                        SDL_Color white = { 255, 255, 255 };
 
304
                        set_colors(white, 254, 254);
 
305
                }
 
306
 
 
307
                wait_delay();
 
308
        }
 
309
 
 
310
        fade_black(10);
 
311
}
 
312