summaryrefslogtreecommitdiff
path: root/noncore/games/sfcave-sdl/terrain.cpp
Unidiff
Diffstat (limited to 'noncore/games/sfcave-sdl/terrain.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/sfcave-sdl/terrain.cpp22
1 files changed, 3 insertions, 19 deletions
diff --git a/noncore/games/sfcave-sdl/terrain.cpp b/noncore/games/sfcave-sdl/terrain.cpp
index c001a56..b243f45 100644
--- a/noncore/games/sfcave-sdl/terrain.cpp
+++ b/noncore/games/sfcave-sdl/terrain.cpp
@@ -38,24 +38,25 @@ void Terrain :: initTerrain()
38{ 38{
39 dir = 1; 39 dir = 1;
40 offset = 0; 40 offset = 0;
41 41
42 maxHeight = 50; 42 maxHeight = 50;
43 43
44 mapTop[0] = (int)(nextInt(50)) + 5; 44 mapTop[0] = (int)(nextInt(50)) + 5;
45 mapBottom[0] = sHeight - (maxHeight - mapTop[0]); 45 mapBottom[0] = sHeight - (maxHeight - mapTop[0]);
46 for ( int i = 1 ; i < MAPSIZE ; ++i ) 46 for ( int i = 1 ; i < MAPSIZE ; ++i )
47 setPoint( i ); 47 setPoint( i );
48 48
49 SDL_FillRect( terrainSurface, 0, 0 ); 49 SDL_FillRect( terrainSurface, 0, 0 );
50
50 // Draw Terrain into surface 51 // Draw Terrain into surface
51 Sint16 px[5]; 52 Sint16 px[5];
52 Sint16 py[5]; 53 Sint16 py[5];
53 54
54 for ( int i = 0 ; i < MAPSIZE ; ++i ) 55 for ( int i = 0 ; i < MAPSIZE ; ++i )
55 { 56 {
56 int left = (i*segSize); 57 int left = (i*segSize);
57 int right = ((i+1)*segSize); 58 int right = ((i+1)*segSize);
58 px[0] = left; 59 px[0] = left;
59 py[0] = mapTop[i]; 60 py[0] = mapTop[i];
60 px[1] = right; 61 px[1] = right;
61 py[1] = mapTop[i+1]; 62 py[1] = mapTop[i+1];
@@ -82,25 +83,24 @@ void Terrain :: initTerrain()
82 } 83 }
83 84
84 85
85} 86}
86 87
87void Terrain :: moveTerrain( int amountToMove ) 88void Terrain :: moveTerrain( int amountToMove )
88{ 89{
89 stars->move(); 90 stars->move();
90 91
91 offset += amountToMove; 92 offset += amountToMove;
92 speed = offset/segSize; 93 speed = offset/segSize;
93 94
94 //printf( "offset - %d, speed - %d\n", offset, speed );
95 if ( offset >= segSize ) 95 if ( offset >= segSize )
96 { 96 {
97 for ( int i = 0 ; i < (MAPSIZE)-speed ; ++i ) 97 for ( int i = 0 ; i < (MAPSIZE)-speed ; ++i )
98 { 98 {
99 mapTop[i] = mapTop[i+speed]; 99 mapTop[i] = mapTop[i+speed];
100 mapBottom[i] = mapBottom[i+speed]; 100 mapBottom[i] = mapBottom[i+speed];
101 } 101 }
102 102
103 for ( int i = (MAPSIZE)-speed ; i < MAPSIZE ; ++i ) 103 for ( int i = (MAPSIZE)-speed ; i < MAPSIZE ; ++i )
104 { 104 {
105 setPoint( i ); 105 setPoint( i );
106 } 106 }
@@ -186,77 +186,61 @@ void Terrain :: increaseMaxHeight( int amount )
186 maxHeight += amount; 186 maxHeight += amount;
187} 187}
188 188
189void Terrain :: drawTerrain( SDL_Surface *screen ) 189void Terrain :: drawTerrain( SDL_Surface *screen )
190{ 190{
191 // Blit terrain surface onto screen 191 // Blit terrain surface onto screen
192 192
193 SDL_Rect dst; 193 SDL_Rect dst;
194 dst.x = offset; 194 dst.x = offset;
195 dst.y = 0; 195 dst.y = 0;
196 dst.w = sWidth; 196 dst.w = sWidth;
197 dst.h = sHeight; 197 dst.h = sHeight;
198 //dst.h = maxHeight;
199 198
200 SDL_Rect dst2; 199 SDL_Rect dst2;
201 dst2.x = 0; 200 dst2.x = 0;
202 dst2.y = 0; 201 dst2.y = 0;
203 202
204 SDL_BlitSurface(terrainSurface, &dst, screen, &dst2 ); 203 SDL_BlitSurface(terrainSurface, &dst, screen, &dst2 );
205 204
206 stars->draw( screen ); 205 stars->draw( screen );
207
208 //dst.y = sHeight - maxHeight;
209 //dst2.y = sHeight - maxHeight;
210 //SDL_BlitSurface(terrainSurface, &dst, screen, &dst2 );
211
212/*
213 for ( int i = 0 ; i < MAPSIZE ; ++i )
214 {
215 int x1 = (i*segSize) - (offset*speed);
216 int x2 = ((i+1)*segSize)-(offset*speed);
217 if ( x2 >= sWidth )
218 x2 = sWidth-1;
219 aalineRGBA( screen, x1, mapTop[i], x2, mapTop[i+1], 0, 220, 0, 255 );
220 aalineRGBA( screen, x1, mapBottom[i], x2, mapBottom[i+1], 0, 220, 0, 255 );
221 }
222*/
223} 206}
224 207
225bool Terrain :: checkCollision( int x, int y, int h ) 208bool Terrain :: checkCollision( int x, int y, int h )
226{ 209{
227 if ( y < 0 || y > sHeight ) 210 if ( y < 0 || y > sHeight )
228 return true; 211 return true;
212
229 // First get segment that matches x 213 // First get segment that matches x
230 SDL_LockSurface( terrainSurface ); 214 SDL_LockSurface( terrainSurface );
231 215
232 Uint32 c = getpixel( terrainSurface, x, y ); 216 Uint32 c = getpixel( terrainSurface, x, y );
233 217
234 SDL_UnlockSurface( terrainSurface ); 218 SDL_UnlockSurface( terrainSurface );
235 219
236 if ( c == 0 ) 220 if ( c == 0 )
237 return false; 221 return false;
238 else 222 else
239 return true; 223 return true;
240} 224}
241 225
242 226
243// Test 227// Test
244#ifdef DEBUG_TERRAIN 228#ifdef DEBUG_TERRAIN
245SDL_Surface *screen; 229SDL_Surface *screen;
246Terrain *terrain; 230Terrain *terrain;
247 231
248void go() 232void go()
249{ 233{
250 /* Initialize SDL */ 234 // Initialize SDL
251 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) 235 if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
252 { 236 {
253 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); 237 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
254 exit(1); 238 exit(1);
255 } 239 }
256 atexit(SDL_Quit); 240 atexit(SDL_Quit);
257 241
258 int videoflags = SDL_SWSURFACE ; 242 int videoflags = SDL_SWSURFACE ;
259 243
260 if ( (screen=SDL_SetVideoMode(280, 320,32,videoflags)) == NULL ) 244 if ( (screen=SDL_SetVideoMode(280, 320,32,videoflags)) == NULL )
261 { 245 {
262 fprintf(stderr, "Couldn't set %ix%i video mode: %s\n",WIDTH,HEIGHT,SDL_GetError()); 246 fprintf(stderr, "Couldn't set %ix%i video mode: %s\n",WIDTH,HEIGHT,SDL_GetError());