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

📄 init.cpp

📁 一个45度角场景RPG游戏程序的demo
💻 CPP
字号:
#include "main.h"
#include <stdio.h>

char OldBlockData[YSize][XSize];
int BlockData[YSize][XSize];

void InitClass( )
{
	human[main]=new HUMAN(0,640,0,0,TAlley);
	for (int i=1;i<MaxHuman;i++)
	{
		int aa;
		if (i>3)
			aa=1;
		else
			aa=0;
		human[i]=new HUMAN(i,640+rand()%401-200,320+rand()%401-200,0,aa);
	}
	for (i=0;i<MaxBullet;i++)
	{
		bullet[i]=new BULLET;
	}
	map=new MAP(0,"map00.dat");
}

int GOBD(int y,int x)
{
	if (x>=XSize)
		return 0;
	if (y>=YSize)
		return 0;
	if (x<0)
		return 0;
	if (y<0)
		return 0;
	return OldBlockData[y][x];
}

int GBD(int y,int x)
{
	if (x>=XSize)
		return -1;
	if (y>=YSize)
		return -1;
	if (x<0)
		return -1;
	if (y<0)
		return -1;
	return BlockData[y][x];
}

void InitBlock()
{
	int XYZ[13]={5,5,10,10,12,3,6,9,7,14,13,11,15};

	FILE *file=fopen("block.dat","rb");
	char *p;
	p=&(OldBlockData[0][0]);
    fread(p,sizeof(OldBlockData[0][0]),XSize*YSize,file);
	fclose(file);
	for (int i=0;i<XSize*YSize;i++) 
	{
		*p-=48;
		if (*p==1)
			MaxBlock++;
		p++;
	}
	block=new BLOCK*[MaxBlock];
	int block_count=0;
	for(int xx=0;xx<XSize;xx++)
	{
		for(int yy=0;yy<YSize;yy++)
		{
			if (OldBlockData[yy][xx]==1)
			{
				int type=-1;
				int xyz=GOBD(yy-1,xx)+GOBD(yy,xx-1)*2+GOBD(yy+1,xx)*4+GOBD(yy,xx+1)*8;
				for (i=0;i<13;i++)
				{
					if (XYZ[i]==xyz)
					{
						type=i;
						break;
					}
				}
				if (type==-1)
				{
					if ((xyz==0)||(xyz==1)||(xyz==4))
						type=0;
					if ((xyz==2)||(xyz==8))
						type=2;
				}
				if ((GBD(yy-1,xx)==0)&&(GOBD(yy+1,xx)==1)&&(type==0))
					type=1;
				if ((GBD(yy,xx-1)==2)&&(GOBD(yy,xx+1)==1)&&(type==2))
					type=3;
				BlockData[yy][xx]=type;
				block[block_count]=new BLOCK(type,640+xx*32-yy*32,xx*16+yy*16);
				block_count++;
			}
			else
				BlockData[yy][xx]=-1;
		}
	}
}

void InitLight( )
{
	LightTable=new unsigned char [307200];
	BaseLight=new unsigned char [307200];
	for (int i=0;i<640;i++)
		for (int j=0;j<480;j++)
		{
			BaseLight[i+j*640]=sqrt((i-320)*(i-320)+(j-240)*(j-240)*4)*160/577;
		}
	SmallLight=new unsigned char [10000];
	for (i=0;i<100;i++)
		for (int j=0;j<100;j++)
		{
			int dis=sqrt((i-50)*(i-50)+(j-50)*(j-50))*255/45;
			if (dis<255)
				SmallLight[i+j*100]=dis;
			else
				SmallLight[i+j*100]=255;
		}
}

⌨️ 快捷键说明

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