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

📄 rpg.h

📁 c游戏编程从入门到精通_全部源代码和文档
💻 H
📖 第 1 页 / 共 2 页
字号:
     video_buffer[offset+x]=work_sprite[work_offset+x];
	} // end for x

    // move to next line in video buffer and in sprite bitmap buffer

    offset      += SCREEN_WIDTH;
    work_offset += width;

    } // end for y

} // end Draw_Sprite

void Behind_Sprite_Size(sprite_ptr sprite,int height,int width)
{

// this function scans the background behind a sprite so that when the sprite
// is draw, the background isnn'y obliterated

char far *work_back;
int work_offset=0,offset,y;

// alias a pointer to sprite background for ease of access

work_back = sprite->background;

// compute offset of background in video buffer

offset = (sprite->y << 8) + (sprite->y << 6) + sprite->x;

for (y=0; y<height; y++)
    {
    // copy the next row out off screen buffer into sprite background buffer

    _fmemmove((void far *)&work_back[work_offset],
	     (void far *)&video_buffer[offset],
	     width);

    // move to next line in video buffer and in sprite background buffer

    offset      += SCREEN_WIDTH;
    work_offset += width;

    } // end for y

} // end Behind_Sprite

void Erase_Sprite_Size(sprite_ptr sprite,int height,int width)
{
// replace the background that was behind the sprite

// this function replaces the background that was saved from where a sprite
// was going to be placed

char far *work_back;
int work_offset=0,offset,y;

// alias a pointer to sprite background for ease of access

work_back = sprite->background;

// compute offset of background in video buffer

offset = (sprite->y << 8) + (sprite->y << 6) + sprite->x;

for (y=0; y<height; y++)
    {
    // copy the next row out off screen buffer into sprite background buffer

    _fmemmove((void far *)&video_buffer[offset],
	     (void far *)&work_back[work_offset],
	     width);

    // move to next line in video buffer and in sprite background buffer

    offset      += SCREEN_WIDTH;
    work_offset += width;

    } // end for y


} // end Erase_Sprite

void hel(windows_ptr win)
{
	pcx_picture objects_pcx;
	win->kind=BUTTON_PRESS;
	Draw_Windows(win);
	Delay(5);
	win->kind=BUTTON;
	Draw_Windows(win);
	Delay(5);
	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);
	Delay(50);
	Free_Object();
	pause_game=0;
	menuflag=MIN;
}

void loa(windows_ptr win)
{
	FILE *stream="load.dat";
	char flag=';';
	int x,y,fcolor;
	long i;
	int *word=malloc(sizeof(int)*7);
	win->kind=BUTTON_PRESS;
	Draw_Windows(win);
	Delay(5);
	win->kind=BUTTON;
	Draw_Windows(win);
	Free_Object();
	Read_From_File(flag,stream,word);
	sx=word[0];
	for(i=1;i<6;i++)
		my_things[i-1]=word[i];
	pause_game=0;
	menuflag=MIN;
}


void sav(windows_ptr win)
{
	FILE *stream="load.dat";
	char flag=';';
	int x,y,fcolor;
	long i;
	int *word=malloc(sizeof(int)*7);
	win->kind=BUTTON_PRESS;
	Draw_Windows(win);
	Delay(5);
	win->kind=BUTTON;
	Draw_Windows(win);
	Free_Object();
	word[0]=sx;
	for(i=1;i<6;i++)
		word[i]=my_things[i-1];
	word[6]=-1;
	Write_To_File(flag,stream,word);
	pause_game=0;
	menuflag=MIN;
}

void men_RPG(windows_ptr win)
{
	windows_ptr restore;
	win->kind=BUTTON_PRESS;
	Draw_Windows(win);
	Delay(5);
	win->kind=BUTTON;
	Draw_Windows(win);
	if(win->status==MIN)
	{
		menu_win=last;
		now_win=(struct windows *)malloc(sizeof(struct windows));
		Object_Init(now_win,BUTTON,WINDOWS_X+2,WINDOWS_Y-BUTTON_Y*4,BUTTON_X-1,BUTTON_Y-1,"load",0,24,0,"",1,loa,ACTIVE);
		now_win->father=win;
		Behind_Object(now_win);
		Draw_Windows(now_win);
		last->next=now_win;
		pre_win=now_win;
		now_win=(struct windows *)malloc(sizeof(struct windows));
		Object_Init(now_win,BUTTON,WINDOWS_X+2,WINDOWS_Y-BUTTON_Y*3,BUTTON_X-1,BUTTON_Y-1,"save",0,24,0,"",1,sav,ACTIVE);
		now_win->father=win;
		Behind_Object(now_win);
		Draw_Windows(now_win);
		pre_win->next=now_win;
		pre_win=now_win;
		now_win=(struct windows *)malloc(sizeof(struct windows));
		Object_Init(now_win,BUTTON,WINDOWS_X+2,WINDOWS_Y-BUTTON_Y*2,BUTTON_X-1,BUTTON_Y-1,"help",0,24,0,"",1,hel,ACTIVE);
		now_win->father=win;
		Behind_Object(now_win);
		Draw_Windows(now_win);
		pre_win->next=now_win;
		pre_win=now_win;
		now_win=(struct windows *)malloc(sizeof(struct windows));
		Object_Init(now_win,BUTTON,WINDOWS_X+2,WINDOWS_Y-BUTTON_Y,BUTTON_X-1,BUTTON_Y-1,"exit",0,24,0,"",1,bt2,ACTIVE);
		now_win->father=win;
		Behind_Object(now_win);
		Draw_Windows(now_win);
//		getch();
//		Erase_Button(now_win);
//		getch();
		pre_win->next=now_win;
		pre_win=now_win;
		last=pre_win;
		pre_win->next=NULL;

		win->status=MAX;
		menuflag=MAX;
	}
	else if(win->status==MAX)
	{
		Free_Object();
		menu_win->next=NULL;
		win->status=MIN;
		menuflag=MIN;
		pause_game=0;
	}
}



void Build_Object_RPG()
{
int index;
//for(index=1;index<256;index++)
//		Set_Palette_Register(index,(RGB_color_ptr)&color[index]);
	now_win=pre_win=(struct windows *)malloc(sizeof(struct windows));
	Object_Init(now_win,BAR,WINDOWS_X,WINDOWS_Y,WINDOWS_X_MOVE,WINDOWS_Y_MOVE,"This is a game desktop",0,24,0,"",1,win,ACTIVE);
	Behind_Object(now_win);
	win_now=now_win;
	Draw_Windows(now_win);
	head_win=now_win;
	now_win=(struct windows *)malloc(sizeof(struct windows));
	Object_Init(now_win,BUTTON,WINDOWS_X+2,WINDOWS_Y+2,BUTTON_X-1,BUTTON_Y-1,"Star",0,24,MIN,"",0,men_RPG,ACTIVE);//start is 5 word which is too long
	Draw_Windows(now_win);
	pre_win->next=now_win;
	pre_win=now_win;
	now_win=(struct windows *)malloc(sizeof(struct windows));
	Object_Init(now_win,BUTTON_CLOSE,WINDOWS_X+WINDOWS_X_MOVE-BUTTON_XY-2,WINDOWS_Y+2,BUTTON_XY-1,BUTTON_XY-1,"",0,24,0,"",0,clo,ACTIVE);
	Draw_Windows(now_win);
	pre_win->next=now_win;
	pre_win=now_win;
	pre_win->next=NULL;
	last=pre_win;

}



void Judge_Object_RPG(void)
{
	int xmouse,ymouse,btnmouse;
	static int btn=-1;
	windows_ptr test;
	Squeeze_Mouse(MOUSE_MOTION_REL,&xmouse,&ymouse,&btnmouse);
	if(ymouse==199&&head_win==NULL)
	{
		Squeeze_Mouse(MOUSE_HIDE,0,0,0);
		Build_Object_RPG();
		pause_game=1;
		Squeeze_Mouse(MOUSE_SHOW,0,0,0);
	}
	if(ymouse<=185&&menuflag!=MAX&&head_win!=NULL)
	{
		Squeeze_Mouse(MOUSE_HIDE,0,0,0);
		Free_Object();
		pause_game=0;
		Squeeze_Mouse(MOUSE_SHOW,0,0,0);
	}
	Squeeze_Mouse(MOUSE_BUTT_POS,&xmouse,&ymouse,&btnmouse);
	if(btnmouse==btn)
		return;
	else
		btn=btnmouse;
	xmouse=xmouse/2;
	ymouse=ymouse;
	if(btnmouse==1)
	{
		if(head_win!=NULL)
		{
		test=head_win;
		if((xmouse>=test->top.x&&xmouse<=test->top.x+test->move.x)&&
		(ymouse>=test->top.y&&ymouse<=test->top.y+test->move.y))
		{
			Squeeze_Mouse(MOUSE_HIDE,0,0,0);
			if(test->active==ACTIVE)
				test->windows(test);
			Squeeze_Mouse(MOUSE_SHOW,0,0,0);
		}
		do{
			test=test->next;
			if((xmouse>=test->top.x&&xmouse<=test->top.x+test->move.x)&&
			(ymouse>=test->top.y&&ymouse<=test->top.y+test->move.y))
			{
				Squeeze_Mouse(MOUSE_HIDE,0,0,0);
				if(test->active==ACTIVE)
					test->windows(test);
				Squeeze_Mouse(MOUSE_SHOW,0,0,0);
			}
		}while(test->next!=NULL);
		}
	}
}


void Fill_Screen_Size(int value,int x0,int y0,int x1,int y1)
{
int x,y;
long i=0,height,width;
height=y1-y0+1;
width=x1-x0+1;
x=x0;
while(i<height*width)
{
	y=y0+i/width;
	i=i+width;
	_fmemset(video_buffer+x+y*SCREEN_WIDTH,(char)value,width);
}
}


void Pre_Game(void)
{
RGB_color star;
int index,x=0,y=0,i;
for(index=1;index<256;index++)
	Get_Palette_Register(index,(RGB_color_ptr)&color[index]);

BMP_Load_Screen("pre_game.bmp");
Boutctextxy(2,2,BLACK,50,40,"校园网事");
Delay(20);
Words_Step("之",150,90,BLACK,5);
Delay(10);
Words_Step("学思湖畔",190,110,BLACK,5);
getch();
Fade_Lights();
Fill_Screen(0);

for(index=1;index<256;index++)
	Set_Palette_Register(index,(RGB_color_ptr)&color[index]);


for(index=200;index<=202;index++)
{
	star.red=0;
	star.green=0;
	star.blue=0;
	Set_Palette_Register(index,(RGB_color_ptr)&star);
}
randomize();
for(index=0;index<=5;index++)
{
	x=random(320);
	y=random(200);
	Plot_Pixel_Fast(x,y,200);
	Plot_Pixel_Fast(x,y-1,201);
	Plot_Pixel_Fast(x+1,y,201);
	Plot_Pixel_Fast(x,y+1,201);
	Plot_Pixel_Fast(x,y+2,201);
	Plot_Pixel_Fast(x-1,y,201);
	Plot_Pixel_Fast(x,y-2,202);
	Plot_Pixel_Fast(x+2,y,202);
	Plot_Pixel_Fast(x,y+3,202);
	Plot_Pixel_Fast(x-2,y,202);
}
do{
	for(index=0;index<=2;index++)
	{
		star.red=106+index*10;
		star.green=106+index*10;
		star.blue=0;
		Set_Palette_Register(200+index,(RGB_color_ptr)&star);
		Delay(10);
	}
	Delay(10);
	for(index=2;index>=0;index--)
	{
		star.red=0;
		star.green=0;
		star.blue=0;
		Set_Palette_Register(200+index,(RGB_color_ptr)&star);
		Delay(10);
	}
}while(!kbhit());
for(index=0;index<=2;index++)
{
	star.red=106+index*10;
	star.green=106+index*10;
	star.blue=0;
	Set_Palette_Register(200+index,(RGB_color_ptr)&star);
	Delay(10);
}


Words_Step("小时候喜欢看天上的星星,它将黑夜编",30,30,WHITE,5);
Words_Step("织成一张美丽的网,驱走孤独、驱散寂寞。",0,60,WHITE,5);
Words_Step("长大了,依然喜欢仰望星空的感觉。",30,100,WHITE,5);
Words_Step("可此时夜晚又多了一个能够陪伴我的朋友:",0,130,WHITE,5);
Words_Step("网",110,160,WHITE,10);
Words_Step("络",150,160,WHITE,10);
Fade_Lights();
Fill_Screen(0);

for(index=1;index<256;index++)
	Set_Palette_Register(index,(RGB_color_ptr)&color[index]);
Blit_String(70,185,WHITE,date(),1);
Delay(40);
Fade_Lights();
Fill_Screen(0);

BMP_Load_Screen("chatroom.bmp");
Delay(10);
Words_Step("红色头发:",0,10,230,0);
Words_Step("很幸运最后一次上网还能见到你",75,10,BLACK,5);
Delay(10);
Words_Step("红色头发:",0,30,230,0);
Words_Step("明天我真的要永远离开了",75,30,BLACK,5);
Delay(10);
Words_Step("红色头发:",0,50,230,0);
Words_Step("这些天和你的聊天让我懂了很多",75,50,BLACK,5);
Delay(10);
Words_Step("红色头发:",0,70,230,0);
Words_Step("真的非常希望在现实中与你相遇",75,70,BLACK,5);
Delay(10);
Words_Step("红色头发:",0,90,230,0);
Words_Step("可是。。。",75,90,BLACK,5);
Delay(10);
Words_Step("红色头发:",0,110,230,0);
Words_Step("我要走了",75,110,BLACK,5);
Delay(10);
Words_Step("红色头发",0,130,230,0);
Blit_String(75,135,240,"3166 :)",1);
getch();
Fill_Screen(0);
}


void Game_End(void)
{
int index;
Fill_Screen(0);

for(index=1;index<256;index++)
	Set_Palette_Register(index,(RGB_color_ptr)&color[index]);
Words_Step("请记住:网络永远是虚幻的",30,180,WHITE,5);
Delay(10);
Boutctextxy(8,8,WHITE,80,20,"完");
getch();
//Fade_Lights();
Fill_Screen(0);

for(index=1;index<256;index++)
	Set_Palette_Register(index,(RGB_color_ptr)&color[index]);
Words_Step("策划:",30,30,WHITE,5);
Delay(10);
Words_Step("浦滨",100,30,WHITE,5);
Delay(10);
Words_Step("制作:",30,60,WHITE,5);
Delay(10);
Words_Step("浦滨",100,60,WHITE,5);
Delay(10);
Words_Step("美工:",30,90,WHITE,5);
Delay(10);
Words_Step("浦滨",100,90,WHITE,5);
Delay(10);
Words_Step("时间:",30,120,WHITE,5);
Delay(10);
Words_Step("二零零一年十二月",100,120,WHITE,5);
Delay(10);
Blit_String(30,150,WHITE,"email:",1);
Delay(20);
Blit_String(100,150,WHITE,"pubingk@citiz.net",1);
//Delay(20);
//Blit_String(50,180,RED,"http://www.dotry.com",1);
getch();
//Fade_Lights();
Fill_Screen(0);
}

⌨️ 快捷键说明

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