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

📄 rpg.c

📁 c游戏编程从入门到精通_全部源代码和文档
💻 C
字号:
#include "all.h"
#include "rpg.h"
#define UP 0
#define DOWN 1
sprite small;
int done=0;
char *things[5]={"money","ticket","card","key","sport"};
pcx_picture_ptr background;

void Pre_Game(void);
void Game_Load(void);
void Game_End(void);

void main(void)
{
Set_Video_Mode(VGA256);
Pre_Game();
Game_Load();
Game_End();
Set_Video_Mode(TEXT_MODE);
}


void Chat(int x,int y,int seek)
{
int i=0,place=-1,smallplace=-1,chats,index;
int button,number,head_id,say_num;
char *file="room.dat";
char *file2="chat.dat";
int chat_num;
int flag=';';
int end='=';
char *data=malloc(sizeof(char));
int can_chat=0;
pcx_picture objects_pcx;
int chat_here[4];
chat_num=atoi(fread_char_seek(flag,file,6,seek*192,end));
for(chats=0;chats<chat_num*5;chats=chats+5)
{
	chat_here[0]=atoi(fread_char_seek(flag,file,7+chats,seek*192,end));
	chat_here[1]=atoi(fread_char_seek(flag,file,8+chats,seek*192,end));
	chat_here[2]=atoi(fread_char_seek(flag,file,9+chats,seek*192,end));
	chat_here[3]=atoi(fread_char_seek(flag,file,10+chats,seek*192,end));
	data=fread_char_seek(flag,file,11+chats,seek*192,end);
	if(x>=chat_here[0]&&x<=chat_here[2]&&y>=chat_here[1]&&y<=chat_here[3])
	{
		for(index=0;index<5;index++)
			if((strcmp(data,things[index])==0)&&my_things[index]==0)
			{
				my_things[index]=1;
				can_chat=1;
			}
			else if(strcmp(data,"null")==0)
				can_chat=1;
		break;
	}
}
if(can_chat!=0)
{
	say_num=atoi(fread_char_seek(flag,file2,5,seek*1152+chats*192/5,end));
	for(index=0;index<say_num;index++)
	{
		head_id=atoi(fread_char_seek(flag,file2,6+index*2,seek*1152+chats*192/5,end));
		if(head_id==1)
		{
			data=fread_char_seek(flag,file2,1,seek*1152+chats*192/5,end);
			PCX_Load_Screen_Size(data,(pcx_picture_ptr)&objects_pcx,1,60,50,0,0);
			data=fread_char_seek(flag,file2,3,seek*1152+chats*192/5,end);
			WriteHzStr(data,0,70,WHITE);
		}
		else
		{
			data=fread_char_seek(flag,file2,2,seek*1152+chats*192/5,end);
			PCX_Load_Screen_Size(data,(pcx_picture_ptr)&objects_pcx,1,60,50,260,0);
			data=fread_char_seek(flag,file2,4,seek*1152+chats*192/5,end);
			WriteHzStr(data,260,70,WHITE);
		}
		data=fread_char_seek(flag,file2,7+index*2,seek*1152+chats*192/5,end);
		Words_Step(data,10,130,WHITE,5);
		getch();
		Fill_Screen_Size(BLACK,0,120,319,148);
		Fill_Screen_Size(BLACK,0,0,59,119);
		Fill_Screen_Size(BLACK,260,0,319,118);
		if(seek==8)
			done=1;
	}
}
}

void Room(int direction)
{
pcx_picture objects_pcx;
int x=121,y=100,x_old,y_old,button=0,done=0;
int come_in=0;
int flag=';';
int end='=';
int address;
int width;
int up_down;
char *small_map;
char *thing;
char *file="room.dat";
int num,seek;
Squeeze_Mouse(MOUSE_RESET,0,0,0);
mscurson(arrow);
Squeeze_Mouse(MOUSE_HIDE,0,0,0);
for(seek=0;seek<10;seek++)
{
	address=atoi(fread_char_seek(flag,file,1,seek*192,end));
	width=atoi(fread_char_seek(flag,file,2,seek*192,end));
	up_down=atoi(fread_char_seek(flag,file,3,seek*192,end));
	thing=fread_char_seek(flag,file,4,seek*192,end);
	if(direction==up_down)
	{
		if(sx>=address&&sx<address+width&&(strcmp(thing,"null")==0||
			(strcmp(thing,things[0])==0)&&my_things[0]!=0||
			(strcmp(thing,things[1])==0)&&my_things[1]!=0||
			(strcmp(thing,things[2])==0)&&my_things[2]!=0||
			(strcmp(thing,things[3])==0)&&my_things[3]!=0||
			(strcmp(thing,things[4])==0)&&my_things[4]!=0))
		{
			small_map=fread_char_seek(flag,file,5,seek*192,end);
			PCX_Load_Screen_Height(small_map,(pcx_picture_ptr)&objects_pcx,1,120);
			pause_bar=1;
			come_in=1;
			break;
		}
	}
}
if(come_in==1)
{
Behind_Sprite_Size((sprite_ptr)&small,65,45);
Squeeze_Mouse(MOUSE_RESET,0,0,0);
mscurson(arrow);
Squeeze_Mouse(MOUSE_HIDE,0,0,0);
while(done==0)
{
	Squeeze_Mouse(MOUSE_BUTT_POS,&x,&y,&button);
	if(x!=x_old||y!=y_old)
	{
		Erase_Sprite_Size((sprite_ptr)&small,65,45);
	}

	if(x<=116)
	{
		x=116;
	}
	if(x>=436)
	{
		x=436;
	}
	if(y<=0)
	{
		y=0;
	}
	if(y>=55)
	{
		y=55;
	}
	if(button==2)
	{
		done=1;
	}
	if(button==1)
	{
		Chat(x,y,seek);
		Delay(10);
	}
	Squeeze_Mouse(MOUSE_SET_SENSITIVITY,&x,&y,&button);
	if(x!=x_old||y!=y_old)
	{
		small.x=x/2;
		small.y=y;
		Behind_Sprite_Size((sprite_ptr)&small,65,45);
		Draw_Sprite_Size((sprite_ptr)&small,65,45);
		x_old=x;
		y_old=y;

	}
}
}
pause_bar=0;
Squeeze_Mouse(MOUSE_RESET,0,0,0);
mscurson(arrow);
}

void Boy(sprite_ptr sprite)
{
static int index,old=0,direction=0,change=0;
char get_key;

if(kbhit())
{
get_key=getch();
Clear_Key_Buffer();

if(get_key==sprite->key.up)
{
	sprite->curr_frame=6;
	Draw_Sprite(sprite);
	change=1;
	Room(UP);
	PCX_Load_Scroll("shtu.pcx",background,1);
	sprite->curr_frame=7;
	Delay(10);
}
if(get_key==sprite->key.right)
{
	sx+=8;
	if(old==-1)
	{
		sprite->curr_frame=(sprite->curr_frame+4)%8;
		direction=sprite->curr_frame;
	}
	else
	{
		sprite->curr_frame=0;
		direction=sprite->curr_frame;
	}
	old=-1;
	if(sx>639)
		sx=0;
}
if(get_key==sprite->key.down)
{
	sprite->curr_frame=3;
	Draw_Sprite(sprite);
	change=1;
	Room(DOWN);
	PCX_Load_Scroll("shtu.pcx",background,1);
	sprite->curr_frame=2;
	Delay(10);
}
if(get_key==sprite->key.left)
{
	sx-=8;
	if(old==1)
	{
		sprite->curr_frame=(sprite->curr_frame+4)%8;
		direction=sprite->curr_frame;
	}
	else
	{
		sprite->curr_frame=1;
		direction=sprite->curr_frame;
	}
	old=1;
	if(sx<0)
		sx=639;
}

if(get_key==sprite->key.quit)
{
	done=1;
}
Show_View_Port_Pcx(background,sx);
Draw_Sprite(sprite);
if(change==1)
{
	sprite->curr_frame=direction;
	change=0;
}
Delay(10);
}
else
{
	PCX_Load_Scroll("shtu.pcx",background,1);
	Show_View_Port_Pcx(background,sx);
	sprite->curr_frame=(sprite->curr_frame+4)%8;
	Draw_Sprite(sprite);
	Delay(10);
}
}




void Build_Screen(void)
{
int index;
char key[7]={'w','x','a','d','s','q','z'};
pcx_picture objects_pcx;
for(index=1;index<255;index++)
	Get_Palette_Register(index,(RGB_color_ptr)&color[index]);

PCX_Load_Screen("boy.pcx",1);

now=pre=(struct sprite *)malloc(sizeof(struct sprite_type));
head=now;
Sprite_Init(now,160,168,0,0,0,0,Boy,key);
for(index=0;index<MAX_SPRITE_FRAMES;index++)
	PCX_Grab_Bitmap_Screen((pcx_picture_ptr)&objects_pcx,now,index,index,0);
now->curr_frame=0;
now->next=NULL;

Fill_Screen(0);

PCX_Load_Screen_Height("mouse.pcx",(pcx_picture_ptr)&objects_pcx,1,65);
Sprite_Init_Size((sprite_ptr)&small,0,0,0,0,0,0,65,45,1);
PCX_Grab_Bitmap_Size_Screen((pcx_picture_ptr)&objects_pcx,(sprite_ptr)&small,0,0,0,65,45);
Fill_Screen(0);

background=(struct pcx_picture *)malloc(sizeof(struct pcx_picture_typ));
PCX_Init_Scroll(background);
PCX_Load_Scroll("shtu.pcx",background,1);
Show_View_Port_Pcx(background,sx);
Draw_Sprite(now);
PCX_Load_Screen_Height("help2.pcx",(pcx_picture_ptr)&objects_pcx,1,120);
Delay(50);
PCX_Load_Screen_Height("help.pcx",(pcx_picture_ptr)&objects_pcx,1,120);
}



void Game_Load(void)
{
Build_Screen();
Delay(20);
Squeeze_Mouse(MOUSE_RESET,0,0,0);
mscurson(handcurs);
while(done!=1){
	if(pause_game!=1)
		Judge_Sprite();
	if(pause_bar!=1)
		Judge_Object_RPG();
}

Sprite_Delete_Size((sprite_ptr)&small,1);
Sprite_Delete(now);
}

⌨️ 快捷键说明

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