郑州轻工业学院
课 程 设 计 任 务 书
题
快递公司问题件快递公司问题件货款处理关于圆的周长面积重点题型关于解方程组的题及答案关于南海问题
目 基于ucgui的潜艇大战游戏设计
专业、班级 学号 姓名
主要内容、基本要求、主要参考文献等:
1、主要内容
(1)掌握LCD显示图形的方法,掌握LCD显示字符的方法。
(2) 了解图片的组织方式,图片显示的原理,学习LCD的显示原理和控制办法。
(3) 完成潜艇大战的控制功能,随机潜艇函数的创建和调用。
2、基本要求
(1) 编写图形显示函数,在LCD上显示图形
(2) 编写随机函数,在LCD上随机产生潜艇。
(3) 游戏程序设计,实现游戏的控制功能。
3、完成的功能:
1、void submarine_move();//潜水艇移动函数
2、int torpedo_move();//潜水艇发射鱼雷函数
3、int bomb_move();//船发射炮弹函数
4、void explosion(int x1,int y1);//船和潜水艇中弹爆炸画面显示函数
5、void keyboard_control();//键盘控制船移动函数
6、void touch();//触摸控制船移动函数
7、可以看到自己的得分:中弹每种潜水艇的分值都不一样的
基本要求都做到了:1、在lcd上显示图形,船、潜水艇、鱼雷以及炮弹图形显示。
2、调用随机函数rand(),在lcd上随机产生潜艇,并且潜艇速度也是随机的,可以一倍速度和两倍速度,如果想要更刺激的话,可以是三倍速度。
3、对游戏的控制功能:触摸控制,键盘控制都可以,双重功能,使玩家体验更好
4、程序及其解释:
#include "GUI.h"
#include "GUI_Protected.h"
#include
#include
#include
#include
extern const GUI_BITMAP bmMicriumLogo;
extern const GUI_BITMAP bmMicriumLogo1;
extern const GUI_BITMAP bmMicriumLogo2;
extern const GUI_BITMAP bmMicriumLogo3;
extern const GUI_BITMAP bmMicriumLogo4;
extern const GUI_BITMAP bmMicriumLogo5;
extern const GUI_BITMAP bmMicriumLogo6;
extern const GUI_BITMAP bmMicriumLogo7;
extern const GUI_BITMAP bmMicriumLogo8;
extern const GUI_BITMAP bmMicriumLogo_1bpp;
extern const GUI_BITMAP bmship1;
extern const GUI_BITMAP bmship2;
extern const GUI_BITMAP bmsubmarine1;
extern const GUI_BITMAP bmsubmarine1_vert;
extern const GUI_BITMAP bmsubmarine2;
extern const GUI_BITMAP bmsubmarine2_vert;
extern const GUI_BITMAP bmsubmarine3;
extern const GUI_BITMAP bmsubmarine3_vert;
extern const GUI_BITMAP bmsubmarine4;
extern const GUI_BITMAP bmsubmarine4_vert;
extern const GUI_BITMAP bmtorpedo;
extern const GUI_BITMAP bmbomb;
extern const GUI_BITMAP bmexplosion1;
extern const GUI_BITMAP bmexplosion2;
extern const GUI_BITMAP bmexplosion3;
extern const GUI_BITMAP bmexplosion4;
extern const GUI_BITMAP bmexplosion5;
extern const GUI_BITMAP bmexplosion6;
extern const GUI_BITMAP bmexplosion7;
extern const GUI_BITMAP bmexplosion8;
extern const GUI_BITMAP bmexplosion9;
extern const GUI_BITMAP bmexplosion10;
extern const GUI_BITMAP bmexplosion11;
extern const GUI_BITMAP bmexplosion12;
extern const GUI_BITMAP bmexplosion13;
extern const GUI_BITMAP bmexplosion14;
extern const GUI_BITMAP bmexplosion15;
#define GUI_KEY_SPACE 32
int i,j,k,key;
int x[2]={320,-64};
int y[2]={60,120};
const GUI_BITMAP *pBitmap;
int get_x=50,get_y=0,touch_flag=0;
int torpedo_flag=0,torpedo[2],torpedo_x[2],torpedo_y[2],end_torpedo_flag[2];
int bomb_x,bomb_y,bomb[2],bomb_flag=0,end_bomb_flag,explosion_flag;
int bomb_explosion_flag,torpedo_explosion_flag,score;
int submarine1,submarine4;
GUI_PID_STATE TouchState;
//
/*
*******************************************************************
*
* main()
*
*******************************************************************
*/
void MainTask(void) {
void submarine_move();//潜水艇移动函数
int torpedo_move();//潜水艇发射鱼雷函数
int bomb_move();//船发射炮弹函数
void explosion(int x1,int y1);//船和潜水艇中弹爆炸画面显示函数
void keyboard_control();//键盘控制船移动函数
void touch();//触摸控制船移动函数
int Cnt =0;
int YPos;
int flag_x=1,flag_y=1;
//int submarine_flag=1;
int LCDXSize = LCD_GET_XSIZE();
int LCDYSize = LCD_GET_YSIZE();
GUI_Init();
GUI_SetColor(GUI_BLUE);
GUI_SetBkColor(0xFF00FF);
GUI_Clear();
////////////////////////////////////////////////////////
GUI_SetFont(&GUI_Font16_ASCII);
LCD_L0_FillRect(60, 200, 100, 230);//发射按钮
GUI_DispStringHCenterAt("LUNCH", 80, 210);
LCD_L0_FillRect(10, 200, 50, 230);//左按钮
GUI_DispStringHCenterAt("LEFT", 30, 210);
LCD_L0_FillRect(110, 200, 150, 230);//右按钮
GUI_DispStringHCenterAt("RIGHT", 130, 210);
LCD_L0_DrawHLine (0, 28, 320) ;//画上线
LCD_L0_DrawHLine (0, 155, 320) ;//画下线
//////////////////////////////////////////////////////////
pBitmap=&bmMicriumLogo1;
GUI_DrawBitmap(pBitmap,160,200);//显示姓
pBitmap=&bmMicriumLogo2;
GUI_DrawBitmap(pBitmap,180,200);//显示名
pBitmap=&bmMicriumLogo3;
GUI_DrawBitmap(pBitmap,200,200);//显示:
pBitmap=&bmMicriumLogo4;
GUI_DrawBitmap(pBitmap,220,200);//显示毛
pBitmap=&bmMicriumLogo5;
GUI_DrawBitmap(pBitmap,240,200);//显示二
pBitmap=&bmMicriumLogo6;
GUI_DrawBitmap(pBitmap,260,200);//显示松
pBitmap=&bmMicriumLogo7;
GUI_DrawBitmap(pBitmap,160,220);//显示学
pBitmap=&bmMicriumLogo8;
GUI_DrawBitmap(pBitmap,180,220);//显示号
pBitmap=&bmMicriumLogo3;
GUI_DrawBitmap(pBitmap,200,220);//显示:
GUI_DispStringHCenterAt("540907020127", 260, 220);
GUI_DispStringHCenterAt("SCORE:", 60, 170);
//////////////////////////////////////////////////////////
pBitmap=&bmship1;//刚开始显示船初始位置画面
GUI_DrawBitmap(pBitmap,get_x,get_y);
while(1)
{
touch();//触摸控制船移动函数
keyboard_control();//键盘控制船移动函数
///////////////////////////////////////////////
GUI_SetColor(GUI_BLUE);
LCD_L0_DrawHLine (0, 28, 320) ;
LCD_L0_DrawHLine (0, 155, 320) ;//画框
GUI_SetColor(GUI_BLUE);
GUI_DispDecAt(score, 90,170,4);
GUI_SetColor(0xFF00FF);
/////////////////////////////////////////////////////////////
if(touch_flag==0)//如果船没有移动,则延时20MS,否则不再延时20MS(因为控制船移动函数中有延时20MS的函数),这样能够使船和潜水艇移动不受影响
{
GUI_Delay(20);
}
if(touch_flag==1)//同时清除touch_flag值
touch_flag=0;
////////////////////////////////////////////////////////
submarine_move();//潜水艇移动函数
torpedo_move();//潜水艇发射鱼雷函数
if(bomb_flag==1)//判断船是否发射炮弹
bomb_move();
if(torpedo_explosion_flag==1)//船中弹
{
explosion(get_x,get_y+30);
GUI_SetColor(GUI_BLUE);
LCD_L0_DrawHLine (0, 28, 320) ;
get_x=-120;
}
if(torpedo_explosion_flag==0)//船没有中弹
{
pBitmap=&bmship1;
GUI_DrawBitmap(pBitmap,get_x,get_y);
}
if(bomb_explosion_flag==1)//潜水艇中弹
{
for(k=0;k<2;k++)
{
if(bomb[k]==1)//判断是哪个潜水艇中断
{
explosion(x[k],y[k]);
//没中弹一个潜水艇都会得到相应的分值,中弹不同的潜水艇得到的分值也不同
if(k==0)
score+=10*(i+1);
else
score+=10*(j+1);
}
}
}
}
}
////////////////////////////////////////////////////////
void submarine_move()//潜水艇移动函数
{
// GUI_SetColor(0xFF00FF);
for(k=0;k<2;k++)
{
if((x[k]==get_x||x[k]==(get_x+1))&&end_torpedo_flag[k]==0)//判断潜水艇是否到移动到了船下面,如果是:发射炮弹;同时判断一下此炮弹是否消失,如果消失才发射另一枚炮弹
{
torpedo_flag=1;
torpedo[k]=1;
torpedo_x[k]=get_x+k*62+1;
torpedo_y[k]=y[k]-6;
}
//覆盖潜水艇前一次移动的画面
if(k==0)
LCD_L0_FillRect(x[k]+64, y[k], x[k]+66,y[k]+19);
else
LCD_L0_FillRect(x[k]-2, y[k], x[k],y[k]+19);
}
if(x[0]<-64)//如果第一行潜水艇移动到了画面的最左边,潜水艇重新从右边出现
{
x[0]=320;
i=rand()%4;//调用随机函数,随机产生潜水艇
}
x[0]=x[0]-(i%2+1);//第一行潜水艇速度也是随机产生的
//显示第一行潜水艇画面
switch(i)
{
case 0:
{
pBitmap=&bmsubmarine1;
GUI_DrawBitmap(pBitmap,x[0],y[0]);
break;
}
case 1:
{
pBitmap=&bmsubmarine2;
GUI_DrawBitmap(pBitmap,x[0],y[0]);
break;
}
case 2:
{
pBitmap=&bmsubmarine3;
GUI_DrawBitmap(pBitmap,x[0],y[0]);
break;
}
case 3:
{
pBitmap=&bmsubmarine4;
GUI_DrawBitmap(pBitmap,x[0],y[0]);
break;
}
}
if(x[1]>320)//如果第二行潜水艇移动到了画面的最右边,潜水艇重新从左边出现
{
x[1]=-64;
j=rand()%4;
}
x[1]=x[1]+(j%2+1);//第一行潜水艇速度也是随机产生的
//显示第二行潜水艇画面
switch(j)
{
case 0:
{
pBitmap=&bmsubmarine1_vert;
GUI_DrawBitmap(pBitmap,x[1],y[1]);
break;
}
case 1:
{
pBitmap=&bmsubmarine2_vert;
GUI_DrawBitmap(pBitmap,x[1],y[1]);
break;
}
case 2:
{
pBitmap=&bmsubmarine3_vert;
GUI_DrawBitmap(pBitmap,x[1],y[1]);
break;
}
case 3:
{
pBitmap=&bmsubmarine4_vert;
GUI_DrawBitmap(pBitmap,x[1],y[1]);
break;
}
}
}
int torpedo_move()//潜水艇发射鱼雷函数
{
//
GUI_SetColor(0xFF00FF);
for(k=0;k<2;k++)//覆盖鱼雷前一次移动的画面
{
LCD_L0_FillRect(torpedo_x[k], torpedo_y[k], torpedo_x[k]+11,torpedo_y[k]+11);
}
for(k=0;k<2;k++)
{
//判断船是否中弹,
if((torpedo_x[k]>=get_x-11&&torpedo_x[k]<=get_x+64)&&(torpedo_y[k]<=28)&&torpedo[k]==1)
{
torpedo_flag=0;
torpedo_explosion_flag=1;
end_torpedo_flag[k]=0;
torpedo[k]=0;
explosion_flag=1;
//
return 0;
}
}
for(k=0;k<2;k++)
{
if(torpedo[k]==1)//判断哪个潜水艇发射的鱼雷
{
torpedo_y[k]--;
if(torpedo_y[k]>=28)//判断鱼雷是否达到水面,如果没到
{
pBitmap=&bmtorpedo;//显示鱼雷画面
GUI_DrawBitmap(pBitmap,torpedo_x[k],torpedo_y[k]);
end_torpedo_flag[k]=1;//鱼雷到达水面标志位置1,
证明
住所证明下载场所使用证明下载诊断证明下载住所证明下载爱问住所证明下载爱问
还没有到达水面,不能发射另一枚鱼雷
}
else//如果鱼雷达到水面
{
torpedo_y[k]=-12;
torpedo[k]=0;
end_torpedo_flag[k]=0;//鱼雷到达水面标志位置0,证明已到达水面
}
}
}
return 0;
}
int bomb_move()//船发射炮弹函数
{
//
GUI_SetColor(0xFF00FF);
for(k=0;k<2;k++)
{
if((bomb_x>=x[k]&&bomb_x<=x[k]+64)&&(bomb_y>=k*60+29&&bomb_y<=k*60+60+19))//判断潜水艇是否中弹
{
bomb_flag=0;
bomb_explosion_flag=1;
end_bomb_flag=0;
bomb[k]=1;
explosion_flag=1;
LCD_L0_FillRect(bomb_x, bomb_y, bomb_x+9,bomb_y+31);
return 0;
}
}
bomb_y=bomb_y+3;//每次炮弹往下移动的大小
if(bomb_y<124)//防止越界:判断炮弹是否到达海底
{
LCD_L0_FillRect(bomb_x, bomb_y-3, bomb_x+9,bomb_y);//覆盖炮弹前一次移动的画面
pBitmap=&bmbomb;//显示炮弹画面
GUI_DrawBitmap(pBitmap,bomb_x,bomb_y);
end_bomb_flag=1;//炮弹到达海底标志位置1,证明还没有到达海底,不能发射另一枚炮弹
}
else
{
LCD_L0_FillRect(bomb_x, bomb_y-3, bomb_x+9,bomb_y+31);
bomb_flag=0;
end_bomb_flag=0;//炮弹到达水面标志位置0,证明已到达水面
}
return 0;
}
void explosion(e_x,e_y)//船和潜水艇中弹爆炸画面显示函数
{
//
GUI_SetColor(0xFF00FF);
LCD_L0_FillRect(e_x-2 ,e_y, e_x+66,e_y+27);//先覆盖船或者潜水艇画面
pBitmap=&bmexplosion1;//显示中弹爆炸画面
GUI_DrawBitmap(pBitmap,e_x,e_y-30);
pBitmap=&bmexplosion2;
GUI_DrawBitmap(pBitmap,e_x,e_y-30);
GUI_Delay(2);
pBitmap=&bmexplosion3;
GUI_DrawBitmap(pBitmap,e_x,e_y-30);
pBitmap=&bmexplosion4;
GUI_DrawBitmap(pBitmap,e_x,e_y-30);
GUI_Delay(1);
pBitmap=&bmexplosion5;
GUI_DrawBitmap(pBitmap,e_x,e_y-30);
pBitmap=&bmexplosion6;
GUI_DrawBitmap(pBitmap,e_x,e_y-30);
GUI_Delay(2);
pBitmap=&bmexplosion7;
GUI_DrawBitmap(pBitmap,e_x,e_y-30);
pBitmap=&bmexplosion8;
GUI_DrawBitmap(pBitmap,e_x,e_y-30);
GUI_Delay(2);
pBitmap=&bmexplosion9;
GUI_DrawBitmap(pBitmap,e_x,e_y-30);
pBitmap=&bmexplosion10;
GUI_DrawBitmap(pBitmap,e_x,e_y-30);
GUI_Delay(2);
pBitmap=&bmexplosion11;
GUI_DrawBitmap(pBitmap,e_x,e_y-30);
pBitmap=&bmexplosion12;
GUI_DrawBitmap(pBitmap,e_x,e_y-30);
GUI_Delay(1);
pBitmap=&bmexplosion13;
GUI_DrawBitmap(pBitmap,e_x,e_y-30);
pBitmap=&bmexplosion14;
GUI_Delay(2);
GUI_DrawBitmap(pBitmap,e_x,e_y-30);
pBitmap=&bmexplosion15;
GUI_DrawBitmap(pBitmap,e_x,e_y-30);
GUI_SetColor(0xFF00FF);
LCD_L0_FillRect(e_x-2,e_y-30, e_x+66,e_y-30+63);//覆盖最后一张爆炸画面
if(torpedo_explosion_flag==1)//判断船是否被鱼雷击中,如果击中,则torpedo_explosion_flag=2(船不再显示,爆炸画面关闭)
{
torpedo_explosion_flag=2;
end_bomb_flag=0;
}
if(bomb_explosion_flag==1)//判断潜水艇是否中弹,如果中弹,显示完中弹爆炸画面后,关闭爆炸画面
bomb_explosion_flag=0;
if(bomb[0]==1)//如果第一行潜水艇中弹,则和潜水艇已移动到最左边情况一样,要重新从最右边出现
{
x[0]=-65;
bomb[0]=0;//同时此炮弹画面标志位置0,
表
关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf
示不显示此炮弹画面
}
if(bomb[1]==1)//如果第一行潜水艇中弹,则和潜水艇已移动到最左边情况一样,要重新从最右边出现
{
x[1]=321;
bomb[1]=0;//同时此炮弹画面标志位置0,表示不显示此炮弹画面
}
}
void touch()//触摸控制船移动函数
{
if(GUI_TOUCH_GetState(&TouchState))/* Get the touch position in pixel */
{
if((TouchState.x>60)&&(TouchState.x<100)&&(TouchState.y>200)&&(TouchState.y<230))//判断发射炮弹
{
if(end_bomb_flag==0&&torpedo_explosion_flag==0)//如果炮弹已移动到海底并且船并没有中弹,则发射炮弹
{
bomb_x=get_x+28;
bomb_y=get_y+29;
bomb_flag=1;//发射炮弹标志位置1
}
}
else if((TouchState.x>10)&&(TouchState.x<50)&&(TouchState.y>200)&&(TouchState.y<230))//判断向左
{
touch_flag=1;//船移动标志位置1
GUI_Delay(20);
GUI_SetColor(0xFF00FF);
LCD_L0_FillRect(get_x+62,get_y, get_x+66, 27);//覆盖船前一次移动的画面
if(torpedo_explosion_flag==0)//如果船没有中弹
get_x=get_x-2;
if(get_x<0)//防止越界:如果船移动到最左边
get_x=0;
}
else if((TouchState.x>110)&&(TouchState.x<150)&&(TouchState.y>200)&&(TouchState.y<230))//判断向右
{
touch_flag=1;//船移动标志位置1
GUI_Delay(20);
GUI_SetColor(0xFF00FF);
LCD_L0_FillRect(get_x-2,get_y, get_x+2, 27);//覆盖原有痕迹
if(torpedo_explosion_flag==0)//如果船没有中弹
get_x=get_x+2;
if(get_x>256)//防止越界
get_x=256;
}
}
}
void keyboard_control()//键盘控制船移动函数
{
key=GUI_GetKey();
GUI_DispDecAt( key, 200,170,2);
if(key==GUI_KEY_LEFT)
{
touch_flag=1;//船移动标志位置1
GUI_Delay(20);
GUI_SetColor(0xFF00FF);
LCD_L0_FillRect(get_x+60,get_y, get_x+68, get_y+27);//覆盖船前一次移动的画面
if(torpedo_explosion_flag==0)//如果船没有中弹
get_x=get_x-4;
if(get_x<0)//防止越界:如果船移动到最左边
get_x=0;
}
if(key==GUI_KEY_RIGHT)
{
touch_flag=1;//船移动标志位置1
GUI_Delay(20);
GUI_SetColor(0xFF00FF);
LCD_L0_FillRect(get_x-4,get_y, get_x+4,get_y+27);//覆盖原有痕迹
if(torpedo_explosion_flag==0)//如果船没有中弹
get_x=get_x+4;
if(get_x>256)//防止越界
get_x=256;
}
if(key==GUI_KEY_SPACE)
{
if(end_bomb_flag==0&&torpedo_explosion_flag==0)//如果炮弹已移动到海底并且船并没有中弹,则发射炮弹
{
bomb_x=get_x+28;
bomb_y=get_y+29;
bomb_flag=1;//发射炮弹标志位置1
}
}
}
5、
总结
初级经济法重点总结下载党员个人总结TXt高中句型全总结.doc高中句型全总结.doc理论力学知识点总结pdf
:
经过这次课程设计,我更好的了解和理解了嵌入式程序的基本功能,并且深深地爱上了这门学科。
这次我做的课程设计时潜水艇大战游戏,整整用了一周的时间,基本上完成了老师要求,并且解决了画面闪烁的情况,这个游戏的最大特点是能够键盘、触屏双重控制,体验极佳。在做这个课程设计的过程中,自己感受最深的是必须要靠自己亲身编程,亲身调程序。亲手感受你写的程序是否符合你所想的要求,并在此基础上进行改进,可以先完成基本功能,然后再发挥你的想象力,使你的程序更简洁,更明了,更实用,更强大,让你一看你是精心完成的,并且别人也能够看懂你所写的程序,这就是所说的分享精神吧,这个时代就是这样,只有你把你所做的东西分享给别人,这样才能体验到你的价值。
当然做这个课程设计还存在一定的缺点:比如画面有时会变色,
不能玩双人游戏。如果时间充足的话,我会尽力改善画面,使这个游戏做的更完善的。
6、主要参考文献
【1】马忠梅,马广云,徐英惠,田泽.ARM嵌入式处理器结构与应用基础.北京:北京航天航空大学出版社,2002
【2】田泽.嵌入式系统开发与应用实验
教程
人力资源管理pdf成真迷上我教程下载西门子数控教程protel99se入门教程fi6130z安装使用教程
.北京航空航天大学出版社,2004
【3】周立功.ARM微控制器基础与实战[M].北京航天航空大学出版社,2003
完 成 期 限: 2012年6月16日
指导教师签名: 张涛
课程负责人签名: 张涛