summaryrefslogtreecommitdiff
path: root/noncore/games/sfcave-sdl/terrain.cpp
Side-by-side diff
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()
{
dir = 1;
offset = 0;
maxHeight = 50;
mapTop[0] = (int)(nextInt(50)) + 5;
mapBottom[0] = sHeight - (maxHeight - mapTop[0]);
for ( int i = 1 ; i < MAPSIZE ; ++i )
setPoint( i );
SDL_FillRect( terrainSurface, 0, 0 );
+
// Draw Terrain into surface
Sint16 px[5];
Sint16 py[5];
for ( int i = 0 ; i < MAPSIZE ; ++i )
{
int left = (i*segSize);
int right = ((i+1)*segSize);
px[0] = left;
py[0] = mapTop[i];
px[1] = right;
py[1] = mapTop[i+1];
@@ -82,25 +83,24 @@ void Terrain :: initTerrain()
}
}
void Terrain :: moveTerrain( int amountToMove )
{
stars->move();
offset += amountToMove;
speed = offset/segSize;
-// printf( "offset - %d, speed - %d\n", offset, speed );
if ( offset >= segSize )
{
for ( int i = 0 ; i < (MAPSIZE)-speed ; ++i )
{
mapTop[i] = mapTop[i+speed];
mapBottom[i] = mapBottom[i+speed];
}
for ( int i = (MAPSIZE)-speed ; i < MAPSIZE ; ++i )
{
setPoint( i );
}
@@ -186,77 +186,61 @@ void Terrain :: increaseMaxHeight( int amount )
maxHeight += amount;
}
void Terrain :: drawTerrain( SDL_Surface *screen )
{
// Blit terrain surface onto screen
SDL_Rect dst;
dst.x = offset;
dst.y = 0;
dst.w = sWidth;
dst.h = sHeight;
-// dst.h = maxHeight;
SDL_Rect dst2;
dst2.x = 0;
dst2.y = 0;
SDL_BlitSurface(terrainSurface, &dst, screen, &dst2 );
stars->draw( screen );
-
-// dst.y = sHeight - maxHeight;
-// dst2.y = sHeight - maxHeight;
-// SDL_BlitSurface(terrainSurface, &dst, screen, &dst2 );
-
-/*
- for ( int i = 0 ; i < MAPSIZE ; ++i )
- {
- int x1 = (i*segSize) - (offset*speed);
- int x2 = ((i+1)*segSize)-(offset*speed);
- if ( x2 >= sWidth )
- x2 = sWidth-1;
- aalineRGBA( screen, x1, mapTop[i], x2, mapTop[i+1], 0, 220, 0, 255 );
- aalineRGBA( screen, x1, mapBottom[i], x2, mapBottom[i+1], 0, 220, 0, 255 );
- }
-*/
}
bool Terrain :: checkCollision( int x, int y, int h )
{
if ( y < 0 || y > sHeight )
return true;
+
// First get segment that matches x
SDL_LockSurface( terrainSurface );
Uint32 c = getpixel( terrainSurface, x, y );
SDL_UnlockSurface( terrainSurface );
if ( c == 0 )
return false;
else
return true;
}
// Test
#ifdef DEBUG_TERRAIN
SDL_Surface *screen;
Terrain *terrain;
void go()
{
- /* Initialize SDL */
+ // Initialize SDL
if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
{
fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
int videoflags = SDL_SWSURFACE ;
if ( (screen=SDL_SetVideoMode(280, 320,32,videoflags)) == NULL )
{
fprintf(stderr, "Couldn't set %ix%i video mode: %s\n",WIDTH,HEIGHT,SDL_GetError());