Linux街机游戏源码.docx

上传人:b****6 文档编号:3785209 上传时间:2022-11-25 格式:DOCX 页数:20 大小:20.64KB
下载 相关 举报
Linux街机游戏源码.docx_第1页
第1页 / 共20页
Linux街机游戏源码.docx_第2页
第2页 / 共20页
Linux街机游戏源码.docx_第3页
第3页 / 共20页
Linux街机游戏源码.docx_第4页
第4页 / 共20页
Linux街机游戏源码.docx_第5页
第5页 / 共20页
点击查看更多>>
下载资源
资源描述

Linux街机游戏源码.docx

《Linux街机游戏源码.docx》由会员分享,可在线阅读,更多相关《Linux街机游戏源码.docx(20页珍藏版)》请在冰豆网上搜索。

Linux街机游戏源码.docx

Linux街机游戏源码

C语言编的街机游戏,全部源代码下载,这个是仿LINUX下KTron的游戏,已有其大部分功能

时间:

2007-02-13作者:

佚名编辑:

本站点击:

2650[评论]

-

-

综合资源电子书社区

*****************************游戏说明***********************************

TroneV0.1

仿LINUX下街机游戏KTron。

其实写本游戏的动机就是我一个朋友特别喜欢linux下的KTron这个游戏,

但在WINDOWS下又没找到,而我朋友又不太熟悉LINUX操作,所以我就花了点时间写了Trone,

Trone这个名字也是源于KTron。

注意:

此游戏需要EGAVGA.BGI文件才能运行,该文件在turboc2目录下可找到。

[游戏简介]

这是一个双人玩的策略游戏,游戏有两个点,

第一个游戏者可以按R,G,F,D控制第一个点的走向,

第两个游戏都可以按四个光标键控制第二个点的走向,

谁先碰到边界或已走的路线便输,祝大家玩得开心

有任何问题或建议请与我联系。

此游戏可任意复制,作者保留所有权力!

如果你想要源代码,那么请发邮件给我。

请不要删除此文件,有新功能增加可加在下面:

[TroneV0.1]功能简介

游戏者1控制键:

R,F,D,G

游戏者2控制键:

UP,DOWN,LEFT,RIGHT

F1:

查看帮助信息

F2:

设定游戏速度等级,0为最快,1为正常,2最慢

F3:

设定游戏者1的颜色,有15种颜色可以选择,黑色是背景色,不能选

F4:

设定游戏者2的颜色

F5:

继续游戏

Author:

jadewater(gaowenfeng)

email:

*****************

QQ:

182824199

如果这里不能下载你可以发邮件给我,其中包括4个文件:

Trone.c(源代码),Trone.exe(已编译连接游戏文件),EGAVGA.BGI,游戏说明.txt

*******************************************************************************

这个游戏已编译成可执行文件,可以在附件里找到,如果你不能编译的话可以与我联系,

我可以把已编译的程序与源文件全发给你。

下面的全是原代码。

转载请注明作者,谢谢!

共享是这个时代的主题!

*******************************************************************************

#include

#include

#include

#include

#include

#include

#include

/*功能键设置*/

#defineESC0x001b/*退出游戏*/

#defineF10x3b00/*查看帮助信息,调用HelpMassage()函数*/

#defineF20x3c00/*设定游戏速度等级,调用Set_Level()函数*/

#defineF30x3d00/*设定游戏者1的颜色,调用Set_Color()函数*/

#defineF40x3e00/*设定游戏者2的颜色,调用Set_Color()函数*/

#defineF50x3f00/*以下功能键暂时保留,如果增加功能可使用*/

#defineF60x4000

#defineF70x4100

#defineF80x4200

#defineF90x4300

#defineF100x4400

/*Player1hotkey游戏者1热键上下左右分别用RFDG控制*/

#defineRIGHT171

#defineLEFT168

#defineUP182

#defineDOWN170

/*Player2hotkey游戏者2热键,四个光标键控制方向*/

#defineRIGHT0x4d00

#defineLEFT0x4b00

#defineUP0x4800

#defineDOWN0x5000

/*定义画方框的坐标X,Y,以及颜色Color,Draw为是

(1)否(0)已走过*/

structinformation

{

intcolor,draw;

intx,y;

};

typedefstructinformationINFOR;

/*记录游戏者在把在位置,X与Y其实就是全局数组coordinate[][]的两个下标*/

structplayerxy

{

intx,y;

};

typedefstructplayerxyCurrentCoor;

/*此全局数组是记录画每个框的坐标及颜色以及是否已走过*/

INFORcoordinate[80][60];

time_tTimeout=1;/*限制游戏的快慢,可用Set_Level()设定*/

intsize=8,maxX=79,maxY=56;/*size定义画框的大小,单位为像素,maxX,maxY为数组coordinate下标的最大值*/

/*BackColor为游戏背景色,Player1Color与Player2Color为游戏者默认颜色,可调用Set_Color()函数设定*/

intBackColor=BLACK,Player1Color=WHITE,Player2Color=LIGHTRED;

/*初始化图形模式*/

voidInitialGraphics(void)

{

intgraphdriver=VGA,graphmode=VGAHI;

interrorcode;

initgraph(&graphdriver,&graphmode,"");

errorcode=graphresult();

if(errorcode!

=grOk)

{

printf("Graphicserror:

%s\n",grapherrormsg(errorcode));

GoodBye();

}

}

/*退出游戏显示提示信息,只有不能初始化图形界面才会调用此函数*/

intGoodBye(void)

{

printf("Thankyouverymuch!

\n");

printf("Ifyouhaveanyquestion,\n");

printf("Pleasesendemailtome:

*****************orAddQQ:

182824199\n");

GetKey();

exit(0);

}

/*初始化游戏界面*/

voidInitFace(void)

{

setbkcolor(BackColor);

cleardevice();

setcolor(WHITE);

rectangle(0,0,639,479);

setcolor(LIGHTGREEN);

rectangle(3,3,636,452);

setcolor(LIGHTRED);

rectangle(3,455,250,476);

rectangle(253,455,636,476);

}

/*初始化全局数组coordinate[][]*/

voidInitCoordinate(void)

{

intx,y;

for(x=0;x

for(y=0;y

{

coordinate[x][y].color=BackColor;

coordinate[x][y].draw=0;

coordinate[x][y].x=size*x+4;

coordinate[x][y].y=size*y+4;

}

}

/*初始化游戏者开始位置*/

voidInitPlayerPlace(CurrentCoor*player1,CurrentCoor*player2)

{

player1->x=maxX/3;

player2->x=maxX/3*2;

player1->y=maxY/2;

player2->y=maxY/2;

}

/*画框函数,player为画框位置,who为哪一个游戏者*/

voidDrawbar(CurrentCoorplayer,intwho)

{

intx,y;/*根据游戏者所在coordinate的下标位置取出在屏幕上的位置*/

x=coordinate[player.x][player.y].x;

y=coordinate[player.x][player.y].y;

if(who==1)

{setfillstyle(1,Player1Color);

coordinate[player.x][player.y].color=Player1Color;

}

else

{setfillstyle(1,Player2Color);

coordinate[player.x][player.y].color=Player2Color;

}

bar(x,y,x+7,y+7);

coordinate[player.x][player.y].draw=1;

}

/*帮助信息,按F1调用此函数*/

voidHelpMassage(void)

{

setfillstyle(1,WHITE);

bar(150,160,500,340);

setcolor(LIGHTRED);

rectangle(152,162,498,338);

setcolor(BLACK);

rectangle(154,164,496,180);

rectangle(154,182,496,336);

setcolor(GREEN);

outtextxy(280,170,"TroneV0.1");

setcolor(BLACK);

outtextxy(160,190,"Player1controlkey:

");

outtextxy(160,200,"Player2controlkey:

");

outtextxy(160,220,"Help:

Level:

Exit:

");

outtextxy(160,230,"Playercolor:

");

outtextxy(160,250,"Author:

");

outtextxy(160,260,"E_mail:

");

outtextxy(160,270,"OICQ:

");

setcolor(RED);

outtextxy(330,190,"r,f,d,g");

outtextxy(330,200,"up,down,left,right");

outtextxy(160,220,"F1F2Esc");

outtextxy(160,230,"F3/F4");

outtextxy(220,250,"GaoWenfeng");

outtextxy(220,260,"*****************");

outtextxy(220,270,"182824199");

setcolor(BLUE);

outtextxy(175,290,"Ifyouhaveanyquestionormodifythese");

outtextxy(160,300,"code,Pleasesendemailtome.Thankyou");

outtextxy(160,310,"playthisgame!

");

setcolor(BLACK);

outtextxy(410,320,"02/04/2004");

}

/*获取按键,如果低八位非0则为ASCII码,如为0则为控制键*/

intGetKey(void)

{

intkey;

key=bioskey(0);

if(key<<8)

{

key=key&0x00ff;

if(isalpha(key))/*如果为字母则转换为大写*/

key=toupper(key);

}

returnkey;

}

/*初始化开始方向,只有两个游戏者都按下了方向键才开始游戏*/

voidInitfx(int*player1fx,int*player2fx)

{

intkey;

while(!

(*player1fx)||!

(*player2fx))

{

key=GetKey();

if(key==RIGHT1||key==LEFT1||key==UP1||key==DOWN1)

(*player1fx)=key;

elseif(key==RIGHT||key==LEFT||key==UP||key==DOWN)

(*player2fx)=key;

}

}

/*最主要函数,控制画框方向以及判断是否已死*/

intManageMove(CurrentCoorplayer1,CurrentCoorplayer2)

{

intplayer1fx=0,player2fx=0;/*记录游戏者的方向*/

intdie=0,die1=0,die2=0;/*记录游戏者是否已死*/

intkey;

intcurrentfx1,currentfx2;/*记录游戏者所按的方向键,它需与player1fx与player2fx比较,确定是否转向*/

clock_tcurrent_time,front_time;/*用于控制游戏速度的变量*/

Initfx(&player1fx,&player2fx);

currentfx1=player1fx;

currentfx2=player2fx;

front_time=clock();

while(die==0)

{

if(bioskey

(1))

{

key=Ge

tKey();

if(key==DOWN1||key==UP1||key==LEFT1||key==RIGHT1)

currentfx1=key;

elseif(key==DOWN||key==UP||key==LEFT||key==RIGHT)

currentfx2=key;

}

current_time=clock();

if((current_time-front_time)>Timeout)/*如果超过游戏间隔则开始画*/

{

front_time=current_time;

if(player1fx==RIGHT1||player1fx==LEFT1)/*如果现在方向为左或右则只有按下上下键才改变方向,反之相同*/

{

if(currentfx1==UP1||currentfx1==DOWN1)

{

if(currentfx1==UP1)

player1.y-=1;

else

player1.y+=1;

player1fx=currentfx1;

}

else

{

if(player1fx==RIGHT1)

player1.x+=1;

else

player1.x-=1;

}

}

elseif(player1fx==UP1||player1fx==DOWN1)

{

if(currentfx1==RIGHT1||currentfx1==LEFT1)

{

if(currentfx1==RIGHT1)

player1.x+=1;

else

player1.x-=1;

player1fx=currentfx1;

}

else

{

if(player1fx==UP1)

player1.y-=1;

else

player1.y+=1;

}

}

if(player2fx==RIGHT||player2fx==LEFT)

{

if(currentfx2==UP||currentfx2==DOWN)

{

if(currentfx2==UP)

player2.y-=1;

else

player2.y+=1;

player2fx=currentfx2;

}

else

{

if(player2fx==RIGHT)

player2.x+=1;

else

player2.x-=1;

}

}

elseif(player2fx==UP||player2fx==DOWN)

{

if(currentfx2==RIGHT||currentfx2==LEFT)

{

if(currentfx2==RIGHT)

player2.x+=1;

else

player2.x-=1;

player2fx=currentfx2;

}

else

{

if(player2fx==UP)

player2.y-=1;

else

player2.y+=1;

}

}

if(player1.x<0||player1.x>=maxX||player1.y<0||player1.y>=maxY||coordinate[player1.x][player1.y].draw==1)/*判断是否到边界或是已走路,如果是则退出,否则画框*/

{die1=1;die=1;}

else

Drawbar(player1,1);

if(player2.x<0||player2.x>=maxX||player2.y<0||player2.y>=maxY||coordinate[player2.x][player2.y].draw==1)

{die2=1,die=2;}

else

Drawbar(player2,2);

}

}

if(die1&&die2)

die=3;

returndie;

}

/*设定游戏等级函数*/

voidSet_Level(void)

{

intkey,pass=0,i=0;

clock_tfront_time,current_time;

front_time=clock();

setfillstyle(1,WHITE);

bar(180,150,460,300);

setcolor(LIGHTRED);

rectangle(182,152,458,298);

setcolor(BLACK);

rectangle(184,154,456,174);

rectangle(184,176,456,296);

setcolor(RED);

outtextxy(260,160,"LevelSetting");

setcolor(BLACK);

outtextxy(190,200,"Herehavethreelevel:

");

outtextxy(190,260,"Pleaseinputanumber[0,1,2]:

");

setcolor(BLUE);

outtextxy(200,220,"0:

fast");

outtextxy(200,230,"1:

normal");

outtextxy(200,240,"2:

slow");

while(pass==0)

{

if(bioskey

(1))

{

key=GetKey();

if(key=='0'||key=='1'||key=='2')/*通过设置全局变量Timeout来确定游戏速度*/

{

pass=1;

if(key=='0')Timeout=0;

elseif(key=='1')Timeout=1;

elseTimeout=2;

}

else

{

setcolor(LIGHTRED);

outtextxy(190,280,"Pleaseinput0,1,2!

");

}

}

else

{

current_time=clock();

if(current_time-front_time>6)/*光标闪动效果,不知谁有更有效的方法?

*/

{

front_time=current_time;

i=(i+1)%2;

if(i==0)setcolor(BLACK);

elsesetcolor(WHITE);

outtextxy(420,260,"_");

}

}

}

}

/*设置游戏者颜色,其实就是设置全局变量Player2Color与Player1Color,根据who来判断哪一个游戏者*/

voidSet_Color(intwho)

{

intpass=0,color,key,i=0;

intx,y,count;

clock_tfront_time,current_time;

setfillstyle(1,WHITE);

bar(150,160,500,340);

setcolor(LIGHTRED);

rectangle(152,162,498,338);

setcolor(BLACK);

rectangle(154,164,496,180);

rectangle(154,182,496,336);

setcolor(LIGHTRED);

if(who==1)

outtextxy(245,170,"Player1");

elseif(who==2)

outtextxy(245,170,"Player2");

setcolor(GREEN);

outtextxy(245,170,"ColorSetting");

setcolor(BLACK);

outtextxy(160,190,"Youcanselectundersidecolor:

");

outtextxy(160,300,"Pleaseinputcolornumber[1-f]:

");

for(count=1;count<16;count++)

{

x=189+count*16;

y=220;

setfillstyle(1,count);

bar(x,y,x+14,y+40);

rectangle(x,y,x+14,y+40);

}

outtextxy(

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高中教育 > 语文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1