TGC Codebase Backup



C++ Animated Sprite by Srilthe

20th Feb 2010 9:48
Summary

C++ Animated Sprite 2D



Description

C++ Animated Sprite 2D
Move sprite around screen using arrowkeys



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    /*
srilthe@yahoo.com
Sounds http://www.a1freesoundeffects.com/
map editor http://tilemap.co.uk/zipfiles/mapwin1422.zip
characters http://reinerstileset.4players.de/humansE.html
*/

#include "DarkGDK.h"
void DarkGDK ( void )
{	dbSyncOn   ( );
	dbSyncRate ( 60 );
	dbDisableEscapeKey ( );
	dbRandomize ( dbTimer ( ) );
	dbSprite ( 1, 0, 0, 1 );
	dbSetImageColorKey ( 255, 0, 255 );
	dbCreateAnimatedSprite ( 1, "hero_staff_walking.bmp", 9, 8, 1 );
	int iX = 100;
	int iY = 200;
	int iSpritePlay = 0;
	dbLoadMusic ( "OtherWorlds-02.mp3", 1 ); 
	//dbPlayMusic ( 1 ); 
	dbLoopMusic ( 1 );
	while ( LoopGDK ( ) )
	{	
		if ( dbUpKey() && !dbRightKey() && !dbLeftKey() ) // NN
		{	iY -=1; 
			if ( iSpritePlay > 9 )
			{	iSpritePlay = 1;
				dbSetSpriteFrame ( 1, iSpritePlay );
			}
			dbPlaySprite ( 1, 1, 9, 150 ); 
		}
		if ( dbRightKey() && dbUpKey() ) //NE
		{	iX +=1;
			iY -=1;
			if ( ( iSpritePlay < 10 ) || ( iSpritePlay > 18 ) )
			{	iSpritePlay = 10;
				dbSetSpriteFrame ( 1, iSpritePlay );
			}
			dbPlaySprite ( 1, 10, 18, 150 ); 
		}
		if ( dbRightKey() && !dbUpKey() && !dbDownKey() )  //EE
		{	iX +=1;
			if ( ( iSpritePlay < 19 ) || ( iSpritePlay > 27 ) )
			{	iSpritePlay = 19;
				dbSetSpriteFrame ( 1, iSpritePlay );
			}
			dbPlaySprite ( 1, 19, 27, 150 ); 
		}
		if ( dbRightKey() && dbDownKey() ) //SE
		{	iX +=1;
			iY +=1;
			if ( ( iSpritePlay < 28 ) || ( iSpritePlay > 36 ) )
			{	iSpritePlay = 28;
				dbSetSpriteFrame ( 1, iSpritePlay );
			}
			dbPlaySprite ( 1, 28, 36, 150 ); 
		}
		if  ( dbDownKey() && !dbRightKey() && !dbLeftKey() ) //SS
		{	iY +=1; 
			if ( ( iSpritePlay < 37 ) || ( iSpritePlay > 45 ) )
			{	iSpritePlay = 37;
				dbSetSpriteFrame ( 1, iSpritePlay );
			}
			dbPlaySprite ( 1, 37, 45, 150 ); 
		}
		if ( dbLeftKey() && dbDownKey() )  //SW
		{	iX -=1;
			iY +=1;
			if ( ( iSpritePlay < 46 ) || ( iSpritePlay > 54 ) )
			{	iSpritePlay = 46;
				dbSetSpriteFrame ( 1, iSpritePlay );
			}
			dbPlaySprite ( 1, 46, 54, 150 ); 
		}
		if ( dbLeftKey() && !dbUpKey() && !dbDownKey() )  //WW
		{	iX -=1;
			if ( ( iSpritePlay < 55 ) || ( iSpritePlay > 63 ) )
			{	iSpritePlay = 55;
				dbSetSpriteFrame ( 1, iSpritePlay );
			}
			dbPlaySprite ( 1, 55, 63, 150 ); 
		}
		if ( dbLeftKey() && dbUpKey() )  //NW
		{	iX -=1;
			iY -=1;
			if ( ( iSpritePlay < 64 ) || ( iSpritePlay > 72 ) )
			{	iSpritePlay = 64;
				dbSetSpriteFrame ( 1, iSpritePlay );
			}
			dbPlaySprite ( 1, 64, 72, 150 ); 
		}


		if ( dbEscapeKey ( ) )
			break;
		dbSprite ( 1, iX, iY, 1); 
		dbSync ( );
	}
	return;
}