微波EDA网,见证研发工程师的成长!
首页 > 测试测量 > 测试测量技术文库 > LabWindows/CVI虚拟仪器设计技术场景与游戏设计之: 打蜜蜂

LabWindows/CVI虚拟仪器设计技术场景与游戏设计之: 打蜜蜂

时间:11-13 来源:3721RD 点击:

boomtime = 0;
}
if (boomtime == 0 && (!boomflag))
{
SetCtrlAttribute (panelHandle, PANEL_PICTURE_BOOM, ATTR_VISIBLE, 1);
SetCtrlAttribute (panelHandle, PANEL_PICTURE_BOOM, ATTR_LEFT, bee.left);
SetCtrlAttribute (panelHandle, PANEL_PICTURE_BOOM, ATTR_TOP, bee.top+bee.height);
sndPlaySound("boom.wav", SND_SYNC);
boomflag = 1;
}
else
{
SetCtrlAttribute (panelHandle, PANEL_PICTURE_BOOM, ATTR_TOP, boom.top+20);
}
// 重新获得炸弹、蜜蜂等位置信息
position();
if (boom.top>=panelpp.height)
{
boomflag = 0;
}
// 蜜蜂到达边界自动反弹,并重新计算位置
if (bee.left <= 10 || bee.left + bee.width >= panelpp.width – 10)
{
hh = -hh;
}
if (bee.top <= 10 || gun.top - bee.top <= 100)
{
vv = -vv;
}
SetCtrlAttribute (panelHandle, PANEL_PICTURE_BEE, ATTR_LEFT, bee.left+hh*(int)Random
(0, 10));
SetCtrlAttribute (panelHandle, PANEL_PICTURE_BEE, ATTR_TOP, bee.top+vv*(int)Random
(0, 10));
// 蜜蜂炸弹击中枪(飞机)效果
if ((boom.left+boom.width>=gun.left) && (boom.left<=gun.left+gun.width) && (boom.top+
boom.height–30>=gun.top) && (boom.top+boom.height<=gun.top+gun.height) && (boomflag))
{
// 用击中后的图片替换原有图片
SetCtrlAttribute (panelHandle, PANEL_PICTURE_BOOM, ATTR_VISIBLE, 0);
SetCtrlAttribute (panelHandle, PANEL_PICTURE_GUN, ATTR_VISIBLE, 0);
SetCtrlAttribute (panelHandle, PANEL_PICTURE_SHOOTGUN, ATTR_VISIBLE, 1);
SetCtrlAttribute (panelHandle, PANEL_PICTURE_SHOOTGUN, ATTR_LEFT, gun.left);
SetCtrlAttribute (panelHandle, PANEL_PICTURE_SHOOTGUN, ATTR_TOP, gun.top);
// 游戏停止
SetCtrlAttribute (panelHandle, PANEL_TIMER, ATTR_ENABLED, 0);
SetCtrlAttribute (panelHandle, PANEL_TIMER_BEE, ATTR_ENABLED, 0);

SetAsyncTimerAttribute (timerkey, ASYNC_ATTR_ENABLED, 0);
sndPlaySound("dead.wav", SND_SYNC);
popmessage();
}
break;
}
return 0;
}
//退出按钮
int CVICALLBACK quit (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
DiscardPanel (pophandle);
QuitUserInterface (0);
break;
}
return 0;
}
//重新开始按钮
int CVICALLBACK restart (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
// 参数重置
shootflag = 0;
boomflag = 0;
boomtime = 0;
porperty();
// 开始游戏
SetCtrlAttribute (panelHandle, PANEL_TIMER, ATTR_ENABLED, 1);
SetCtrlAttribute (panelHandle, PANEL_TIMER_BEE, ATTR_ENABLED, 1);
SetAsyncTimerAttribute (timerkey, ASYNC_ATTR_ENABLED, 1);
SetCtrlAttribute (panelHandle, PANEL_PICTURE_GUN, ATTR_VISIBLE, 1);
SetCtrlAttribute (panelHandle, PANEL_PICTURE_BEE, ATTR_VISIBLE, 1);
DiscardPanel (pophandle);
break;
}
return 0;
}
//设置枪(飞机)、子弹、蜜蜂、炸弹等控件背景透明
void porperty (void)

{
SetCtrlAttribute (panelHandle, PANEL_PICTURE_BEE, ATTR_PICT_BGCOLOR, VAL_TRANSPARENT);
SetCtrlAttribute (panelHandle, PANEL_PICTURE_GUN, ATTR_PICT_BGCOLOR, VAL_TRANSPARENT);
SetCtrlAttribute (panelHandle, PANEL_PICTURE_SHOOTBEE, ATTR_PICT_BGCOLOR, VAL_TRANSPARENT);
SetCtrlAttribute (panelHandle, PANEL_PICTURE_BULLET, ATTR_PICT_BGCOLOR, VAL_TRANSPARENT);
SetCtrlAttribute (panelHandle, PANEL_PICTURE_BOOM, ATTR_PICT_BGCOLOR, VAL_TRANSPARENT);
SetCtrlAttribute (panelHandle, PANEL_PICTURE_SHOOTGUN, ATTR_PICT_BGCOLOR, VAL_TRANS-
PARENT);
//一些控件初始态不可见
SetCtrlAttribute (panelHandle, PANEL_PICTURE_SHOOTBEE, ATTR_VISIBLE, 0);
SetCtrlAttribute (panelHandle, PANEL_PICTURE_BULLET, ATTR_VISIBLE, 0);
SetCtrlAttribute (panelHandle, PANEL_PICTURE_BOOM, ATTR_VISIBLE, 0);
SetCtrlAttribute (panelHandle, PANEL_PICTURE_SHOOTGUN, ATTR_VISIBLE, 0);
}
//获得枪(飞机)、子弹、蜜蜂、炸弹等控件位置
void position (void)
{
//枪(飞机)
GetCtrlAttribute (panelHandle, PANEL_PICTURE_GUN, ATTR_LEFT, &gun.left);
GetCtrlAttribute (panelHandle, PANEL_PICTURE_GUN, ATTR_TOP, &gun.top);
GetCtrlAttribute (panelHandle, PANEL_PICTURE_GUN, ATTR_HEIGHT, &gun.height);
GetCtrlAttribute (panelHandle, PANEL_PICTURE_GUN, ATTR_WIDTH, &gun.width);
//子弹
GetCtrlAttribute (panelHandle, PANEL_PICTURE_BULLET, ATTR_LEFT, &bullet.left);
GetCtrlAttribute (panelHandle, PANEL_PICTURE_BULLET, ATTR_TOP, &bullet.top);
GetCtrlAttribute (panelHandle, PANEL_PICTURE_BULLET, ATTR_HEIGHT, &bullet.height);
GetCtrlAttribute (panelHandle, PANEL_PICTURE_BULLET, ATTR_WIDTH, &bullet.width);
//蜜蜂
GetCtrlAttribute (panelHandle, PANEL_PICTURE_BEE, ATTR_LEFT, &bee.left);
GetCtrlAttribute (panelHandle, PANEL_PICTURE_BEE, ATTR_TOP, &bee.top);
GetCtrlAttribute (panelHandle, PANEL_PICTURE_BEE, ATTR_HEIGHT, &bee.height);
GetCtrlAttribute (panelHandle, PANEL_PICTURE_BEE, ATTR_WIDTH, &bee.width);
//击中蜜蜂
GetCtrlAttribute (panelHandle, PANEL_PICTURE_SHOOTBEE, ATTR_LEFT, &shootbee.left);
GetCtrlAttribute (panelHandle, PANEL_PICTURE_SHOOTBEE, ATTR_TOP, &shootbee.top);
GetCtrlAttribute (panelHandle, PANEL_PICTURE_SHOOTBEE, ATTR_HEIGHT, &shootbee.height);
GetCtrlAttribute (panelHandle, PANEL_PICTURE_SHOOTBEE, ATTR_WIDTH, &shootbee.width);
//炸弹
GetCtrlAttribute (panelHandle, PANEL_PICTURE_BOOM, ATTR_LEFT, &boom.left);
GetCtrlAttribute (panelHandle, PANEL_PICTURE_BOOM, ATTR_TOP, &boom.top);
GetCtrlAttribute (panelHandle, PANEL_PICTURE_BOOM, ATTR_HEIGHT, &boom.height);
GetCtrlAttribute (panelHandle, PANEL_PICTURE_BOOM, ATTR_WIDTH, &boom.width);
//面板
GetPanelAttribute (panelHandle, ATTR_HEIGHT, &panelpp.height);
GetPanelAttribute (panelHandle, ATTR_WIDTH, &panelpp.width);
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top