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
|
/*------------------------------------------------------------------.
| Copyright 1997, 1998, 2000, 2001 Alexandre Duret-Lutz |
| <duret_g@epita.fr> |
| |
| This file is part of Heroes. |
| |
| Heroes is free software; you can redistribute it and/or modify it |
| under the terms of the GNU General Public License version 2 as |
| published by the Free Software Foundation. |
| |
| Heroes is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| General Public License for more details. |
| |
| You should have received a copy of the GNU General Public License |
| along with this program; if not, write to the Free Software |
| Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 02111-1307 USA |
`------------------------------------------------------------------*/
#include "system.h"
#include "pcx.h"
#include "video.h"
#include "const.h"
#include "keyb.h"
#include "fastmem.h"
#include "endscroll.h"
#include "sprtext.h"
#include "scrtools.h"
#include "timer.h"
#include "heroes.h"
#include "fader.h"
#include "camera.h"
#define XBUF 128
#define YBUF 324
static a_pixel *scroll_buffer;
a_pcx_image dummy_background_img;
/* This is an approximation of sin, using a Lagrange polynomial.
Just to try. */
#define LPI (1<<14)
#define LS(x) ( (x) * (LPI-(x)) >> 20 )
static signed long int
ls (signed long int x)
{
x &= (LPI << 1) - 1;
return (((x & LPI) ? (-LS (x & (LPI - 1))) : LS (x)) * 7 >> 3);
}
static void
copy_background (void)
{
int i;
a_pixel *dest = scroll_buffer;
const a_pixel *src = dummy_background_img.buffer;
for (i = 108; i != 0; i--) {
fastmem4 (src, dest, 128 / 4);
fastmem4 (src, dest + 108 * XBUF, 128 / 4);
fastmem4 (src, dest + 216 * XBUF, 128 / 4);
dest += XBUF;
src += 128;
}
}
static void
draw_background (int x, int y)
{
int i;
a_pixel *dest = corner[0];
const a_pixel *src = scroll_buffer + x + y * XBUF;
for (i = 200; i != 0; i--) {
fastmem4 (src, dest, 320 / 4);
dest += xbuf;
src += XBUF;
}
}
void
dummy_moving_background_render (void)
{
static int frame = 0;
draw_background ((XBUF / 2) - 160 + ls (2 * frame / 3),
(YBUF / 2) - 100 + ls (frame));
frame += read_htimer (background_htimer) << 8;
}
void
dummy_moving_background_init (void)
{
XMALLOC_ARRAY (scroll_buffer, XBUF * YBUF);
pcx_load_from_rsc ("end-scroller-bg-img", &dummy_background_img);
copy_background ();
img_free (&dummy_background_img); /* only free the buffer, not the palette */
}
void
dummy_moving_background_uninit (void)
{
free (scroll_buffer);
}
void
end_scroll (void)
{
a_sprite *theend;
theend = compile_menu_text (_("THE END"), T_CENTERED | T_WAVING, 95, 159);
corner[0] = render_buffer[0] + 10 * xbuf;
std_white_fadein (&dummy_background_img.palette);
do {
dummy_moving_background_render ();
DRAW_SPRITE (theend, corner[0]);
flush_display (corner[0]);
} while (!key_or_joy_ready ());
get_key ();
free_sprite (theend);
}
|