|
|
|
|
/* $Revision$ */
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include "SDL.h"
|
|
|
|
|
#include "sdl.h"
|
|
|
|
|
#include "map.h"
|
|
|
|
|
|
|
|
|
|
#define MEERESSPIEGEL 48
|
|
|
|
|
#define BLICKWEITE 55
|
|
|
|
|
#define FLUGHOEHE 100
|
|
|
|
|
#define MAPSIZE 256
|
|
|
|
|
|
|
|
|
|
int sintab[360];
|
|
|
|
|
int costab[360];
|
|
|
|
|
char map[MAPSIZE*MAPSIZE];
|
|
|
|
|
SDL_Surface *screen;
|
|
|
|
|
|
|
|
|
|
void init_tabs() {
|
|
|
|
|
int x;
|
|
|
|
|
|
|
|
|
|
for (x=0;x<360; x++)
|
|
|
|
|
sintab[x] = (int) (127.0 * sin(x*M_PI/180));
|
|
|
|
|
for (x=0; x < 90; x++)
|
|
|
|
|
costab[x] = sintab[x+90];
|
|
|
|
|
for (x=90; x < 360; x++)
|
|
|
|
|
costab[x] = -sintab[x-90];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void fly(SDL_Surface *screen) {
|
|
|
|
|
static int
|
|
|
|
|
posx = 0,
|
|
|
|
|
posy = 0,
|
|
|
|
|
richtung = 0,
|
|
|
|
|
flughoehe = 0;
|
|
|
|
|
int iy, ix, iy1, iyp, ixp;
|
|
|
|
|
int x, y, z, s, i, j;
|
|
|
|
|
int map_color;
|
|
|
|
|
int rng[WIDTH];
|
|
|
|
|
|
|
|
|
|
if(SDL_MUSTLOCK(screen))
|
|
|
|
|
if(SDL_LockSurface(screen) < 0) {
|
|
|
|
|
fprintf(stderr, "Can't lock screen: %s\n",
|
|
|
|
|
SDL_GetError());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Richtung wechseln? */
|
|
|
|
|
if (rand()<RAND_MAX/2) {
|
|
|
|
|
if (rand()<RAND_MAX) {
|
|
|
|
|
if (richtung <= 0) { richtung = 357; }
|
|
|
|
|
else { richtung -= 3; }
|
|
|
|
|
} else {
|
|
|
|
|
if (richtung >= 357) { richtung = 0; }
|
|
|
|
|
else { richtung += 3; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Bewegen ... */
|
|
|
|
|
posy = posy + costab[richtung] / 32;
|
|
|
|
|
posx = posx + sintab[richtung] / 32;
|
|
|
|
|
|
|
|
|
|
posy %= MAPSIZE; if(posy<0) posy+=MAPSIZE;
|
|
|
|
|
posx %= MAPSIZE; if(posx<0) posx+=MAPSIZE;
|
|
|
|
|
|
|
|
|
|
/* Absolute H<>he berechnen */
|
|
|
|
|
flughoehe = FLUGHOEHE + map[posy*MAPSIZE+posx]/2;
|
|
|
|
|
|
|
|
|
|
/* FIXME */
|
|
|
|
|
for (i=0;i<WIDTH;i++) rng[i] = HEIGHT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SDL_FillRect(screen, NULL, 0);
|
|
|
|
|
|
|
|
|
|
for (iy=posy; iy<=posy+BLICKWEITE; iy++) {
|
|
|
|
|
iy1 = 2 * (iy-posy) + 1;
|
|
|
|
|
s = 4 + (WIDTH-20) / iy1;
|
|
|
|
|
|
|
|
|
|
for (ix=posx-(iy-posy); ix<=posx+(iy-posy); ix++) {
|
|
|
|
|
|
|
|
|
|
ixp = posx
|
|
|
|
|
+ ((ix-posx) * costab[richtung]
|
|
|
|
|
+ (iy-posy) * sintab[richtung]) /(MAPSIZE/2);
|
|
|
|
|
iyp = posy
|
|
|
|
|
+ ((iy-posy) * costab[richtung]
|
|
|
|
|
- (ix-posx) * sintab[richtung]) /(MAPSIZE/2);
|
|
|
|
|
|
|
|
|
|
x = WIDTH/2 + 360*(ix-posx) / iy1;
|
|
|
|
|
|
|
|
|
|
if(
|
|
|
|
|
(x>=0) && (x+s<=WIDTH-2)
|
|
|
|
|
&& ((MAPSIZE*iyp+ixp) > 0)
|
|
|
|
|
&& ((MAPSIZE*iyp+ixp) < MAPSIZE*MAPSIZE)
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
map_color = map[MAPSIZE*iyp+ixp];
|
|
|
|
|
z = map[MAPSIZE*iyp+ixp];
|
|
|
|
|
if(z<MEERESSPIEGEL) z = MEERESSPIEGEL;
|
|
|
|
|
y = HEIGHT/2 + 30 * (flughoehe-z) / iy1;
|
|
|
|
|
|
|
|
|
|
if ((y>=0) && (y<=HEIGHT-1)) {
|
|
|
|
|
for (j=x;j<=x+s;j++)
|
|
|
|
|
for (i=rng[j];i>=y;i--) {
|
|
|
|
|
if ((WIDTH*i+j>=0) && (WIDTH*i+j<WIDTH*HEIGHT))
|
|
|
|
|
sdl_putpixel(screen, j, i, map_color);
|
|
|
|
|
if (y<rng[j]) rng[j] = y;
|
|
|
|
|
}}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
|
|
|
|
|
SDL_UpdateRect(screen, 0, 0, WIDTH, HEIGHT);
|
|
|
|
|
|
|
|
|
|
usleep(1000/25);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
|
init_tabs();
|
|
|
|
|
map_init(map,MAPSIZE,MAPSIZE);
|
|
|
|
|
map_generate(map,0,0,MAPSIZE-1,MAPSIZE-1);
|
|
|
|
|
|
|
|
|
|
screen = sdl_init();
|
|
|
|
|
map_setpalette(screen);
|
|
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
|
fly(screen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sleep(30); SDL_Quit(); exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|