⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stillobj.cpp

📁 游戏c++开发简例
💻 CPP
字号:
#include "gl.h"
#include "gengine.h"
#include "..\common.h"

Anything::Anything()
{
	pic = NULL;
}

Anything::~Anything()
{
	if( pic ){
		for( int i=0; i<frames;i++ )
			delete pic[i];
		delete pic;
	}
}

int StillObj::LoadPicture( char *entname, int level )
{
	char entryname[64], levelNo[3] = "00";
	if( level < 0 || level > 99 )
		return -1;

	strcpy( entryname, entname );
	// free pictures
	if( pic ){
		for( int i=0; i<frames;i++ )
			delete pic[i];
		delete pic;
	}
	// create entryname
	if( level < 10 )
		_itoa( level, levelNo+1, 10 );
	else
		_itoa( level, levelNo, 10 );
	strcat( entryname, levelNo );

	char *fname;	//该文件包含所有图片的文件名
	// open default config file
	if( ConfigSetFile( DEFAULT_CONFIG_FILE_NAME ) != 0 ){
		FailMsg( "Open config file failed" );
	}
	if(( fname = ConfigGetString( "graphic engine", entryname, NULL )) == NULL ){
		FailMsg( "config file error" );
	}

	File *sfp;
	char temp[256];
	sfp = cfile.Open( fname );
	if( sfp == NULL ){
		FailMsg( "open pic file failed" );
	}
	if( sfp->Gets( temp, 256 ) == NULL )
		return -1;
	frames = atoi( temp );

	pic = (Bitmap**)new char[frames*sizeof( Bitmap* )];
	if( pic == NULL )
		return -1;
	ZeroMemory( pic, frames*sizeof( Bitmap* ));

	for( int i=0; i<frames; i++ ){
		if( sfp->Gets( temp, 256 ) == NULL )
			break;
		if( temp[strlen(temp)-2] == '\r' || temp[strlen(temp)-2] == '\n' )
			temp[strlen(temp)-2] = 0;
		if(( pic[i] = ::LoadPicture( temp, 1 )) == NULL )
			FailMsg( "read pic file failed" );
	}
	sfp->Close();
	return 0;
}

// 地面
int Ground::LoadPicture( int level )
{// 根据配置文件读入相应的图片
	width = 64;
	height = 31;
	baseX = 32;
	baseY = 16;

	return StillObj::LoadPicture( "groundpic", level );
}

void Ground::Draw( Bitmap* dest, int x, int y, int picno )
{
	if( picno < frames ){
		SpriteBlitBeta( dest, x - baseX, y - baseY, pic[picno] );
	}
}

// 墙基
int WallBase::LoadPicture( int level )
{
	width = 64;
	height = 31;
	baseX = 32;
	baseY = 16;

	return StillObj::LoadPicture( "wallbasepic", level );
}

void WallBase::Draw( Bitmap* dest, int x, int y, int picno )
{
	if( picno < frames ){
		SpriteBlitBeta( dest, x - baseX, y - baseY, pic[picno] );
	}
}

// 墙壁
short Wall::bright[32] = {0};
int Wall::LoadPicture( int level )
{// 根据配置文件读入相应的图片
	width = 32;
	height = 97;
	baseX = 16;
	baseY = 96;

	return StillObj::LoadPicture( "wallpic", level );
}

void Wall::Draw( Bitmap* dest, int x, int y, int picno )
{
	if( picno < frames ){
		//SpriteSetDrawMode( Bitmap::BetaMode, GetBrightness(x,y));
		SpriteBlitBeta10MMX( dest, x-baseX, y-baseY, pic[picno], 
			GetBrightness( x-baseX, y-16 ), GetBrightness( x+15, y-16 ), bright );
		//SpriteBlitBeta9MMX( dest, x-baseX, y-baseY, pic[picno], GetBrightness( x, y-16 ));
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -