球球⼤作战c语⾔源代码,球球⼤作战,源码分享该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include "qiu.h"
int main()
{
initgraph(800, 600);
源代码大电影
mciSendString("open res/彩⾖森林.mp3 alias mus", NULL, NULL, NULL);//加载⾳乐
for(int i=0;i<200;i++)
loadimage(&img[i], "res/1.jpg",i,i);//获取不同⼤⼩的图⽚
srand((unsigned)time(NULL));
settextstyle(30, 0, "⿊体");//这⾥指的彩⾖⼤⼩
setbkmode(0);//去掉⽂字输出的背景
mciSendString("play mus repeat", NULL, NULL, NULL);//播放⾳乐
while (1)
{
for (int i = 0; i<300; i++)
if (sx + color[i].x - 2040 >= 400 - me.size/2 && sx + color[i].x - 2040 <= 400 + me.size/2 &&
sy + color[i].y - 2040 >= 300 - me.size/2 && sy + color[i].y - 2040 <= 300 + me.size/2)
//如果⾃⼰吃到了彩⾖
{
color[i].sign = 0;//这个彩⾖被吃啦,标记⼀下,下次不在这⾥了
me.sign2 = i;
sprintf(_score, "%d", ++score-20);//积分增加
switch ((score)/30)
{
case 0:break;
case 1: me.size = score; break;
case 2: me.size = (score - 60) / 2 + 60; break;
case 3:case 4:me.size = (score - 90) / 3 + 85; break;
case 5:case 6:case 7:
me.size = (score - 150) / 4 + 105; break;
case 8:case 9:case 10:case 11:case 12:case 13:
me.size= (score - 240) / 4 + 127; break;
default://哎呀呀,太⿇烦了,直接⼀个default吧~~~~~~~
me.size = (score - 420) / 6 + 172;
break;
}//这个球长⼤的地⽅没写好,球的长⼤不正常
if (me.size > 199) me.size = 199;
}
if (MouseHit())//是否有⿏标消息
{
msg = GetMouseMsg();//获取⿏标消息
me.x = msg.x, me.y = msg.y;
}
draw(move());
}
}
//分裂与合并还没有写,后⾯再写吧
//我只是⼀个初学c++的新⼈,希望⼤神可以多多提下意见。。//
#pragma once
#include
#include
#include
#include
#include
#pragma comment(lib,"winmm.lib")
#define ox 650 //操纵圆x原点
#define oy 450 //操纵圆y原点
int sx = 0, sy = 0;//移动地图基点
IMAGE img[200];
MOUSEMSG msg;
int score = 20;//得分
char _score[10];
class System
{
public:
int sign = 0;//标记
int sign2 = 0;//记录彩⾖被吃的记录
int x, y;//坐标
int _cr;//颜⾊
int size = 30;//球的⼤⼩
int color[7] = { WHITE, RED, YELLOW, GREEN, BLUE, MAGENTA, LIGHTCYAN }; System() {};
~System() {}
};
System me;//⾃⼰
System color[300];//彩⾖
bool move();
void draw(bool i);
void Colorsys();//彩⾖与草
bool move()
{
if (sqrt((me.x - ox)*(me.x - ox) + (me.y - oy)*(me.y - oy)) <= 100)
{
if (sx > -2400 && sx < 2400)
sx -= (me.x - ox) / 10;
else
{
if (sx <= 0) sx++;
if (sx >= 800) sx--;
}
if (sy > -2300 && sy < 2300)
sy -= (me.y - oy) / 10;
else
{
if (sy <= 0) sy++;
if (sy >= 600) sy--;
}
return 1;
}
return 0;
void draw(bool i)
{
BeginBatchDraw();//批量绘制
cleardevice();
//***************这⾥是地形图******************
setlinecolor(RGB(40, 40, 40));//地形
setlinestyle(PS_DASHDOT, 4);
for (int i = sx - 2400; i <= 2400; i += 80)
line(i, 0, i, 600);
for (int i = sy - 2300; i <= 2300; i += 80)//地图中的虚⾊线
line(0, i, 800, i);
/
/**********************************************
setlinecolor(RED);//地图红⾊边界
setlinestyle(PS_SOLID, 4);
rectangle(sx - 2050, sy - 2052, sx + 2830, sy + 2630);
*************彩⾖与⾃⼰**********************
Colorsys();
for (int i = 0; i < 300; i++)//这⾥画彩⾖
if (color[i].sign == 1)//如果这⾥的彩⾖没有被吃
{
settextcolor(color[i].color[color[i]._cr]);//彩⾖颜⾊
outtextxy(sx + (color[i].x - 2040), sy + (color[i].y - 2040), "*");//画彩⾖}
putimage(400-me.size/2, 300-me.size/2, &img[me.size]);//这是⾃⼰
//******************操纵盘************************
setlinestyle(PS_SOLID, 1);
setlinecolor(WHITE);
circle(ox, oy, 100);
if (i)
{
circle(me.x, me.y, 10);
line(ox, oy, me.x, me.y);
line(me.x, oy, me.x, me.y);
line(ox - 100, oy, ox + 100, oy);
line(ox, oy - 100, ox, oy + 100);
//************************************************ settextcolor(WHITE);//积分颜⾊
outtextxy(5, 5, _score);//积分
EndBatchDraw();//结束批量绘制
}
void Colorsys()//彩⾖相关信息
{
while (me.sign<300)
{
color[me.sign]._cr = rand() % 7;
color[me.sign].x = rand() % (2040 + 2740); color[me.sign].y = rand() % (2040 + 2540); color[me.sign].sign = 1;
me.sign++;
}
if (me.sign2)
{
color[me.sign2]._cr = rand() % 7;
color[me.sign2].x = rand() % (2040 + 2740); color[me.sign2].y = rand() % (2040 + 2540); color[me.sign2].sign = 1;
me.sign2 = 0;
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。