commit e4d8ca2d45a896f2b42df49fb33accaa4133b18b Author: neingeist Date: Mon May 20 11:07:54 2002 +0000 initial CVS import diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0eadb2d --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +LDFLAGS=`sdl-config --libs` +CFLAGS=-g `sdl-config --cflags` + +all: cscape maptest + +cscape: map.o mapcolors.o sdl.o + +maptest: map.o mapcolors.o sdl.o + +clean: + rm -f *.o maptest cscape diff --git a/cscape.c b/cscape.c new file mode 100644 index 0000000..eb6fac2 --- /dev/null +++ b/cscape.c @@ -0,0 +1,113 @@ +#include "math.h" +#include "SDL.h" +#include "sdl.h" + +#define MEERESSPIEGEL 48 +#define BLICKWEITE 55 +#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] = trunc(127 * 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]; +} + +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); + + sleep(30); SDL_Quit(); exit(0); +} + +/* + int posx = 0; + int posy = 0; + int richtung = 0; + + + int flughoehe; + int iy, ix, iy1, iyp, ixp; + int x, y, z, s, i, j; + int map_color; + int rng[] = new int[320]; + + while (true) { + + // Schnarch... + try {Thread.sleep(100);} catch (InterruptedException e) {} + + + /* Richtung wechseln? */ + /* if (java.lang.Math.random()<0.5) + if (java.lang.Math.random()<1.0) + if (richtung <= 0) richtung = 357; + else richtung -= 3; + else + if (richtung >= 357) richtung = 0; + else richtung += 3; + */ + + /* Vorwärts? */ +/* posy = posy + costab[richtung] / 32; + posx = posx + sintab[richtung] / 32; + + if (posy<=0) posy += 256; + if (posx<=0) posx += 256; +*/ + /* Absolute Höhe berechnen */ + /* flughoehe = 100; +*/ + /* + for (i=0;i<320;i++) rng[i] = 200; + System.arraycopy(emptyscreen,0,screen,0,320*200); + + for (iy=posy; iy<=posy+blickweite; iy++) { + + iy1 = 2 * (iy-posy) + 1; + s = 4 + 300 / iy1; + + for (ix=posx-(iy-posy); ix<=posx+(iy-posy); ix++) { + + ixp = posx + ((ix-posx) * costab[richtung] + (iy-posy) * sintab[richtung]) + / 128; + iyp = posy + ((iy-posy) * costab[richtung] - (ix-posx) * sintab[ri +chtung]) / 128; + + x = 160 + 360*(ix-posx) / iy1; + + if ((x>=0) && (x+s<=318) && ((256*iyp+ixp) > 0) && ((256*iyp+ixp) +< 256*256) ) { + + map_color = map[256*iyp+ixp]; + z = map[256*iyp+ixp]; + + if (z < meeresspiegel) z = meeresspiegel; + + y = 100 + 30 * (flughoehe-z) / iy1; + + if ((y>=0) && (y<=199)) { + + for (j=x;j<=x+s;j++) + + for (i=rng[j];i>=y;i--) { + + if ((320*i+j>=0) && (320*i+j<320*200)) + screen[320*i+j] = (byte)map_color; + if (y + +void map_init (char *map, int x, int y) { + int i; + + for (i=0;i +#include "SDL.h" +#include "sdl.h" +#define MAPSIZE 256 + +void map_show(SDL_Surface *screen, char *map, int mapsize) { + int i,j; + + /* Lock the screen for direct access to the pixels */ + if(SDL_MUSTLOCK(screen)) + if(SDL_LockSurface(screen) < 0) { + fprintf(stderr, "Can't lock screen: %s\n", + SDL_GetError()); + return; + } + + for(i=0;i + +SDL_Surface* sdl_init() { + SDL_Surface *screen; + + screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE); + if(screen == NULL) { + fprintf(stderr, "Unable to set video mode: %s\n", + SDL_GetError()); + exit(1); + } + + return screen; +} + +void sdl_putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) +{ + int bpp = surface->format->BytesPerPixel; + /* Here p is the address to the pixel we want to set */ + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + + switch(bpp) { + case 1: + *p = pixel; + break; + + case 2: + *(Uint16 *)p = pixel; + break; + + case 3: + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { + p[0] = (pixel >> 16) & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = pixel & 0xff; + } else { + p[0] = pixel & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = (pixel >> 16) & 0xff; + } + break; + + case 4: + *(Uint32 *)p = pixel; + break; + } +} diff --git a/sdl.h b/sdl.h new file mode 100644 index 0000000..8f8d482 --- /dev/null +++ b/sdl.h @@ -0,0 +1,2 @@ +SDL_Surface* sdl_init(); +void sdl_putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel);