- b0rk
This commit is contained in:
		
							parent
							
								
									98fae707ee
								
							
						
					
					
						commit
						055f7a0c76
					
				
					 3 changed files with 32 additions and 29 deletions
				
			
		
							
								
								
									
										56
									
								
								cscape.c
									
										
									
									
									
								
							
							
						
						
									
										56
									
								
								cscape.c
									
										
									
									
									
								
							| 
						 | 
					@ -9,7 +9,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define MEERESSPIEGEL 48
 | 
					#define MEERESSPIEGEL 48
 | 
				
			||||||
#define BLICKWEITE    55
 | 
					#define BLICKWEITE    55
 | 
				
			||||||
#define FLUGHOEHE     30
 | 
					#define FLUGHOEHE     100
 | 
				
			||||||
#define MAPSIZE       256
 | 
					#define MAPSIZE       256
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int sintab[360];
 | 
					int sintab[360];
 | 
				
			||||||
| 
						 | 
					@ -37,7 +37,7 @@ void fly(SDL_Surface *screen) {
 | 
				
			||||||
	int iy, ix, iy1, iyp, ixp;
 | 
						int iy, ix, iy1, iyp, ixp;
 | 
				
			||||||
	int x, y, z, s, i, j;
 | 
						int x, y, z, s, i, j;
 | 
				
			||||||
	int map_color;
 | 
						int map_color;
 | 
				
			||||||
	int rng[320];
 | 
						int rng[WIDTH];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(SDL_MUSTLOCK(screen))
 | 
						if(SDL_MUSTLOCK(screen))
 | 
				
			||||||
                if(SDL_LockSurface(screen) < 0) {
 | 
					                if(SDL_LockSurface(screen) < 0) {
 | 
				
			||||||
| 
						 | 
					@ -47,62 +47,62 @@ void fly(SDL_Surface *screen) {
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	/* Richtung wechseln? */
 | 
						/* Richtung wechseln? */
 | 
				
			||||||
	/* if (java.lang.Math.random()<0.5)
 | 
						if (rand()<RAND_MAX/2) {
 | 
				
			||||||
	if (java.lang.Math.random()<1.0)
 | 
							if (rand()<RAND_MAX) {
 | 
				
			||||||
	if (richtung <= 0) richtung = 357;
 | 
								if (richtung <= 0) { richtung = 357; }
 | 
				
			||||||
	else richtung -= 3;
 | 
								else { richtung -= 3; }
 | 
				
			||||||
	else
 | 
							} else {
 | 
				
			||||||
	if (richtung >= 357) richtung = 0;
 | 
								if (richtung >= 357) { richtung = 0; }
 | 
				
			||||||
	else richtung += 3;
 | 
								else { richtung += 3; }
 | 
				
			||||||
	*/
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	/* Bewegen ... */	
 | 
						/* Bewegen ... */	
 | 
				
			||||||
	posy = posy + costab[richtung] / 32;
 | 
						posy = posy + costab[richtung] / 32;
 | 
				
			||||||
	posx = posx + sintab[richtung] / 32;
 | 
						posx = posx + sintab[richtung] / 32;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	posy %= MAPSIZE;
 | 
						posy %= MAPSIZE; if(posy<0) posy+=MAPSIZE;
 | 
				
			||||||
	posx %= MAPSIZE;
 | 
						posx %= MAPSIZE; if(posx<0) posx+=MAPSIZE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Absolute Höhe berechnen */
 | 
						/* Absolute Höhe berechnen */
 | 
				
			||||||
	flughoehe = 100; 
 | 
						flughoehe = FLUGHOEHE + map[posy*MAPSIZE+posx]/2;
 | 
				
			||||||
	/* flughoehe = FLUGHOEHE + ... */
 | 
					 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	/* FIXME */
 | 
						/* FIXME */
 | 
				
			||||||
	for (i=0;i<320;i++) rng[i] = 200;
 | 
						for (i=0;i<WIDTH;i++) rng[i] = HEIGHT;
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	SDL_FillRect(screen, NULL, 0);
 | 
						SDL_FillRect(screen, NULL, 0);
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	for (iy=posy; iy<=posy+BLICKWEITE; iy++) {
 | 
						for (iy=posy; iy<=posy+BLICKWEITE; iy++) {
 | 
				
			||||||
		iy1 = 2 * (iy-posy) + 1;
 | 
							iy1 = 2 * (iy-posy) + 1;
 | 
				
			||||||
		s = 4 + 300 / iy1;
 | 
							s = 4 + (WIDTH-20) / iy1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for (ix=posx-(iy-posy); ix<=posx+(iy-posy); ix++) {
 | 
							for (ix=posx-(iy-posy); ix<=posx+(iy-posy); ix++) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			ixp = posx 
 | 
								ixp = posx 
 | 
				
			||||||
				+ ((ix-posx) * costab[richtung] 
 | 
									+ ((ix-posx) * costab[richtung] 
 | 
				
			||||||
				+ (iy-posy) * sintab[richtung]) / 128;
 | 
									+ (iy-posy) * sintab[richtung]) /(MAPSIZE/2);
 | 
				
			||||||
			iyp = posy 
 | 
								iyp = posy 
 | 
				
			||||||
				+ ((iy-posy) * costab[richtung]
 | 
									+ ((iy-posy) * costab[richtung]
 | 
				
			||||||
				- (ix-posx) * sintab[richtung]) / 128;
 | 
									- (ix-posx) * sintab[richtung]) /(MAPSIZE/2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			x = 160 + 360*(ix-posx) / iy1;
 | 
								x = WIDTH/2 + 360*(ix-posx) / iy1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if(
 | 
								if(
 | 
				
			||||||
				(x>=0) && (x+s<=318) 
 | 
									(x>=0) && (x+s<=WIDTH-2) 
 | 
				
			||||||
				&& ((256*iyp+ixp) > 0) 
 | 
									&& ((MAPSIZE*iyp+ixp) > 0) 
 | 
				
			||||||
				&& ((256*iyp+ixp) < 256*256)
 | 
									&& ((MAPSIZE*iyp+ixp) < MAPSIZE*MAPSIZE)
 | 
				
			||||||
			) {
 | 
								) {
 | 
				
			||||||
		    
 | 
							    
 | 
				
			||||||
				map_color = map[256*iyp+ixp];
 | 
									map_color = map[MAPSIZE*iyp+ixp];
 | 
				
			||||||
				z         = map[256*iyp+ixp];
 | 
									z         = map[MAPSIZE*iyp+ixp];
 | 
				
			||||||
				if(z<MEERESSPIEGEL) z = MEERESSPIEGEL;
 | 
									if(z<MEERESSPIEGEL) z = MEERESSPIEGEL;
 | 
				
			||||||
				y = 100 + 30 * (flughoehe-z) / iy1;
 | 
									y = HEIGHT/2 + 30 * (flughoehe-z) / iy1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if ((y>=0) && (y<=199)) {
 | 
									if ((y>=0) && (y<=HEIGHT-1)) {
 | 
				
			||||||
				for (j=x;j<=x+s;j++)
 | 
									for (j=x;j<=x+s;j++)
 | 
				
			||||||
				for (i=rng[j];i>=y;i--) {
 | 
									for (i=rng[j];i>=y;i--) {
 | 
				
			||||||
					if ((320*i+j>=0) && (320*i+j<320*200))
 | 
										if ((WIDTH*i+j>=0) && (WIDTH*i+j<WIDTH*HEIGHT))
 | 
				
			||||||
					sdl_putpixel(screen, j, i, map_color);
 | 
										sdl_putpixel(screen, j, i, map_color);
 | 
				
			||||||
					if (y<rng[j]) rng[j] = y;
 | 
										if (y<rng[j]) rng[j] = y;
 | 
				
			||||||
				}}
 | 
									}}
 | 
				
			||||||
| 
						 | 
					@ -111,7 +111,7 @@ void fly(SDL_Surface *screen) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
 | 
					        if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
 | 
				
			||||||
	SDL_UpdateRect(screen, 0, 0, 320, 200);
 | 
						SDL_UpdateRect(screen, 0, 0, WIDTH, HEIGHT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	usleep(1000/25);
 | 
						usleep(1000/25);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										3
									
								
								sdl.c
									
										
									
									
									
								
							
							
						
						
									
										3
									
								
								sdl.c
									
										
									
									
									
								
							| 
						 | 
					@ -2,11 +2,12 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <SDL.h>
 | 
					#include <SDL.h>
 | 
				
			||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					#include "sdl.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SDL_Surface* sdl_init() {
 | 
					SDL_Surface* sdl_init() {
 | 
				
			||||||
	SDL_Surface* screen;
 | 
						SDL_Surface* screen;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE);
 | 
						screen = SDL_SetVideoMode(WIDTH, HEIGHT, 8, SDL_SWSURFACE);
 | 
				
			||||||
	if(screen == NULL) {
 | 
						if(screen == NULL) {
 | 
				
			||||||
		fprintf(stderr, "Unable to set video mode: %s\n", 
 | 
							fprintf(stderr, "Unable to set video mode: %s\n", 
 | 
				
			||||||
			SDL_GetError());
 | 
								SDL_GetError());
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								sdl.h
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								sdl.h
									
										
									
									
									
								
							| 
						 | 
					@ -1,4 +1,6 @@
 | 
				
			||||||
/* $Revision$ */
 | 
					/* $Revision$ */
 | 
				
			||||||
 | 
					#define WIDTH  640
 | 
				
			||||||
 | 
					#define HEIGHT 480
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SDL_Surface* sdl_init();
 | 
					SDL_Surface* sdl_init();
 | 
				
			||||||
void sdl_putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel);
 | 
					void sdl_putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue