彩虹糖吃多了
/*亚君的第一次游戏制作 ^_^*/
#include #include
#include
#define PI 3.1415926
#define SL 14 //SL 为s_bar[]的大小 #define HL 12 //Hl 为h_bar[]的大小 #define FPS 60 //delay_fps
#define BALL 5 //第一个房间的圆的个数 #define S2 10 //第二个房间的方块的个数 #define N 100 //蛇的最大长度
int cir_x, cir_y;
int dx,dy;
float rad; //旋转的圆的角度
struct _cir{ //旋转的圆
float x,y;
}cir[6];
struct _snake{
int x,y;
int dx,dy;
int color_r;
int color_g;
int color_b;
}snake[N];
struct _food{
int x,y;
int yes;
int color_r;
int color_g;
int color_b;
int count;
}food;
int judge = 0;
int snakenode;
int win =0;
struct _bar{ //入口的两个矩形
int x, y;
int dy;
int width, height; }rb[2],sb;
struct _sbar{ //第一个房间的小矩形
int x, y;
int dy;
int width, height; }sbar[SL];
struct _hbar{
int x, y;
int dx;
int width, height; }hbar[HL],door1;
struct _ball{
int x,y;
int dx,dy;
}ball[BALL];
struct _sb2{
int x,y;
int height, width;
int dy;
}sb2[S2];
void Game_view(); void Data_circle(); void Control_circle(); void Data_rb(); void Control_rb(); void Draw_rb(); void Data_sbar(); void Control_sbar(); void Draw_sbar(); void Data_hbar(); void Control_hbar(); void Draw_hbar(); void Data_sb(); void Control_sb(); void Draw_sb();
void Data_Testball(); void Control_Testball(); void Draw_Testball(); void Data_cir();
void Control_cir(); void Data_sb2();
void Control_sb2(); void Draw_sb2();
void Door1();
void Data_door1();
int main(void)
{
initgraph(1024,576);
MUSIC mus; // 定义一个音乐对象
mus.OpenFile("res\\t.mp3"); // 打开文件 //要改
mus.SetVolume(0.2f); // 设置音量,参数范围从 0.0f 到 1.0f
setcaption("彩虹糖吃多了");
PIMAGE bkp=newimage();
getimage(bkp,"res\\4.jpg",0,0);
putimage(0,0,bkp);
setfont(50,0,"宋体");
setbkmode(TRANSPARENT);
outtextxy(350,20,"彩");
Sleep(600);
outtextxy(350,20,"彩虹");
Sleep(600);
outtextxy(350,20,"彩虹吃");
Sleep(600);
outtextxy(350,20,"彩虹吃多");
Sleep(600);
outtextxy(350,20,"彩虹吃多了");
Sleep(600);
outtextxy(350,250,"Oh,no!");
Sleep(600);
cleardevice();
putimage(0,0,bkp);
outtextxy(350,20,"彩虹糖吃多了");
Sleep(600);
setfont(18,0,"");
outtextxy(400,80,"版权所有,欢迎繁殖,错了,是翻制------------亚君出品");
outtextxy(400,500,"随便按下一个贱,进入游戏");
outtextxy(0,522,"bug很多,那是为了照顾我的智商,自己写的游戏都没通关过,只要不触碰移动的长方形或圆形,顺利进入第三个房间,");
outtextxy(0,540,"会有贪吃蛇, 吃到二十个食物就算通关。");
outtextxy(0,558,"此为简单版,即使触碰到运动的物体也不会失败,可直接到第二个房间的出口玩彩虹贪吃蛇。");
getch();
cleardevice();
HWND hWnd=getHWnd();
PIMAGE img=newimage();
getimage(img,"res\\1.png",0,0);
randomize();
int t =0,js =0; //用来判断是否over
Data_circle();
Data_rb();
Data_sbar();
Data_hbar();
Data_sb();
Data_Testball();
Data_cir();
Data_sb2();
Data_door1();
for(;is_run();delay_fps(FPS))
{
Control_circle();
Control_rb();
Control_sbar();
Control_hbar();
Control_sb();
Control_Testball();
Control_sb2();
if (mus.GetPlayStatus() == MUSIC_MODE_STOP)
{
// 发现停止了就重新播放
// Play函数:参数1表示开始播放的地方,参数2是结束的地方
// 如果两个参数都不写,就当前位置开始播,只填第一个表示播放到结束为止
mus.Play(0);
}
cleardevice();
putimage_alphablend(NULL,img,0,0,0xcc,0,0,0,0);
setfillcolor(BLUE);
fillellipse(cir_x,cir_y,10,10);
Game_view();
Door1();
{
if((rb[0].x <= cir_x && cir_x <= rb[0].x +rb[0].width && rb[0].y+rb[0].height >= cir_y -10) &&
(rb[1].x <= cir_x && cir_x <= rb[1].x +rb[1].width && rb[1].y >= cir_y+10))
t=1;
for(int i =0;i=hbar[i].x && cir_x <=hbar[i].x +hbar[i].width && hbar[i].y <= cir_y +10) &&
(cir_x>=hbar[i].x && cir_x <=hbar[i].x +hbar[i].width && hbar[i].y +hbar[i].height >= cir_y -10))
t=1;
}
for(int k =0;k= 40 && cir_y<= 330 )
t=1;
}
if(cir_y+10 >= sb.y && cir_y-10 <= sb.y +sb.height&& cir_x >= sb.x &&
cir_x <=sb.x+sb.width )
t = 1;
for(int m=0;m= sb2[h].x && cir_x -10 <=sb2[h].x +sb2[h].width &&
cir_y+10 >=sb2[h].y &&
cir_y - 10 <= sb2[h].y +sb2[h].height)
t = 1;
}
}
if(t)
{
MessageBox(hWnd,"You Over"," ",NULL);
return 0;
}
{
if(cir_y>= 30 && cir_y <= 270 && cir_x <= 110 )
cir_x = 110;
if(cir_y>= 30 && cir_y <= 320 && cir_x >= 560 )
cir_x = 560;
if(cir_y>= 306 && cir_y <= 330 && cir_x <= 110)
cir_x = 110;
if(cir_y >= 360 && cir_y <=540 && cir_x <= 110)
cir_x = 110;
if(cir_y >= 360 && cir_y <= 480 && cir_x >= 560)
cir_x = 560;
if(cir_y >= 510 && cir_y <=560 && cir_x >= 560)
cir_x = 560;
if(cir_x >= 110 && cir_x <= 560 && cir_y <= 30)
cir_y = 30;
if(cir_x >= 110 && cir_x <= 275 && cir_y >= 320 && cir_y <= 331)
cir_y = 320;
if(cir_x >= 305 && cir_x <= 560 && cir_y >= 320 && cir_y <= 331)
cir_y = 320;
if(cir_x >= 110 && cir_x <= 275 && cir_y <= 360 && cir_y >= 359)
cir_y = 360;
if(cir_x >= 305 && cir_x <= 560 && cir_y <= 360 && cir_y >= 359)
cir_y = 360;
if(cir_x >= 100 && cir_x <= 560 && cir_y >= 540)
cir_y = 540;
}
if(cir_x >= 580 && cir_x <= 581 && cir_y>=480 && cir_y <= 510)
{
cir_x = 0;
cir_y = 0;
judge = 1;
}
if(judge)
{
food.count = 0;
food.yes = 0;
snake[0].x= 600;
snake[0].y= 490;
snake[0].dx = 20;
snake[0].color_r = 0;
snake[0].color_g = 0;
snake[0].color_b = 225;
snake[1].x = 580;
snake[1].y = 490;
snake[1].color_r = 0;
snake[1].color_g = 80;
snake[1].color_b = 80;
snakenode =2;
for(;is_run() ;delay_fps(8))
{
int js = 0;
cleardevice();
putimage_alphablend(NULL,img,0,0,0xcc,0,0,0,0);
Game_view();
for (int t=0;t0;s--)
{
snake[s].x =snake[s-1].x;
snake[s].y = snake[s-1].y;
}
snake[0].x +=snake[0].dx;
snake[0].y +=snake[0].dy ;
for(int d =4 ;d 1014) snake[0].x = 600;
if(snake[0].x < 600) snake[0].x = 1014;
if(snake[0].y <10 ) snake[0].y = 566;
if(snake[0].y > 566) snake[0].y = 10;
if(pow(snake[0].x -food.x ,2)+pow(snake[0].y- food.y,2) <=250)
{
snakenode++;
food.count++;
food.yes = 0;
snake[snakenode-1].color_r=food.color_r;
snake[snakenode-1].color_g=food.color_g;
snake[snakenode-1].color_b=food.color_b;
}
if(keystate(VK_SPACE)) system("PAUSE");
xyprintf(935,0,"score: %d",food.count);
if(food.count ==20)
goto label;
}
if(keystate(VK_SPACE)) getch();
}
}
mus.Close(); // 关闭音乐文件
label:
MessageBox(hWnd,"You WIN"," ",NULL);
delimage(img);
getch();
closegraph();
return 0;
}
void Game_view() //房间地图
{ setfillcolor(GREEN);
Draw_rb();
Draw_sbar();
Draw_hbar();
Draw_sb();
Draw_Testball();
Draw_sb2();
Control_cir();
rectangle(0,0,40,270);
rectangle(0,306,40,576);
line(100,270,80,270);
line(80,270,80,0);
line(80,0,590,0);
line(590,0,590,480);
line(590,480,570,480);
line(570,480,570,350);
line(570,350,305,350);
line(305,350,305,330);
line(305,330,570,330);
line(570,330,570,20);
line(570,20,100,20);
line(100,20,100,270);
line(80,306,80,570);
line(80,570,590,570);
line(590,570,590,510);
line(590,510,570,510);
line(570,510,570,550);
line(570,550,100,550);
line(100,550,100,350);
line(100,350,275,350);
line(275,350,275,330);
line(275,330,100,330);
line(100,330,100,306);
line(100,306,80,306);
}
void Data_circle()
{
cir_x = 10;
cir_y = 288;
}
void Control_circle()
{
if(keystate(VK_UP)) dy = -1;
if(keystate(VK_DOWN)) dy = 1 ;
if(keystate(VK_LEFT)) dx = -1;
if(keystate(VK_RIGHT)) dx = 1 ;
if(cir_x <=10 && cir_x >5) cir_x = 10;
if(cir_x>=10 && cir_x <=40 && cir_y <= 280 && cir_y>5) cir_y = 280;
if(cir_x>=10 && cir_x <=40 && cir_y >= 296) cir_y = 296;
if(cir_x>=0&& cir_x <=5 && cir_y >=0 && cir_y <=5)
{
dx =0;
dy =0;
}
cir_x += dx;
cir_y += dy;
dx =0;
dy =0;
}
void Data_rb()
{
rb[0].x = 54;
rb[0].y = 188;
rb[0].height = 100;
rb[0].width = 20;
rb[0].dy = -1;
rb[1].x = 54;
rb[1].y = 288;
rb[1].height = 100;
rb[1].width = 20;
rb[1].dy = 1;
}
void Control_rb()
{
if(rb[0].y >= 188) rb[0].dy = -1;
if(rb[0].y <= 160) rb[0].dy = 1;
rb[0].y += rb[0].dy;
if(rb[1].y >= 316) rb[1].dy = -1;
if(rb[1].y <= 288) rb[1].dy = 1;
rb[1].y += rb[1].dy;
}
void Data_sbar()
{
int y_aixs= 306;
for(int i= 0; i=down) sbar[i].dy = -1;
up -=20;
down -=20;
}
for(int k= 0;k=350) hbar[0].dx= -1;
hbar[0].x += hbar[0].dx;
if(hbar[1].x<=180) hbar[1].dx= 1;
if(hbar[1].x+hbar[1].width >=390) hbar[1].dx= -1;
hbar[1].x += hbar[1].dx;
for(int i =2;i= 570) hbar[i].dx = -1;
hbar[i].x += hbar[i].dx;
}
}
void Draw_hbar()
{
for(int i =0;i =130) sb.dy = -1;
sb.y += sb.dy;
}
void Draw_sb()
{
bar(sb.x,sb.y,sb.x+sb.width,sb.y+sb.height);
}
void Data_Testball() {
ball[0].x = 200;
ball[0].y = 100;
ball[0].dy = 1;
ball[1].x = 250;
ball[1].y = 200;
ball[1].dy = -1;
ball[2].x = 300;
ball[2].y = 150;
ball[2].dy = 1;
ball[3].x = 500;
ball[3].y = 300;
ball[3].dy = -1;
ball[4].x = 515;
ball[4].y = 155;
ball[4].dy = -1;
}
void Draw_Testball()
{
for(int i=0;i=hbar[i].x
&&ball[k].y +10 == hbar[i].y)|| ball[k].y >=320 )
ball[k].dy = -1;
if((ball[k].x-10 <= hbar[i].x+hbar[i].width && ball[k].x +10 >=hbar[i].x &&ball[k].y- 10 == hbar[i].y +hbar[i].height)||ball[k].y <=30)
ball[k].dy = 1;
if((ball[k].x +10 == hbar[i].x && ball[k].y +10>=hbar[i].y && ball[k].y-10 <= hbar[i].y+hbar[i].height) || ball[k].x >=560)
ball[k].dx = -1;
if((ball[k].x -10 == hbar[i].x +hbar[i].width && ball[k].y +10>=hbar[i].y && ball[k].y-10 <= hbar[i].y+hbar[i].height) || ball[k].x <= 165)
ball[k].dx = 1;
}
for(int j=0;j= 550) sb2[i].dy *= -1;
}
sb2[i].y += sb2[i].dy;
}
}
void Draw_sb2()
{
for(int i=0;i=250 &&cir_x <=560 &&cir_y >=300)
while(door1.width >=0)
door1.width --;
if(cir_x>=250 &&cir_x <=560 &&cir_y <=300)
while(door1.width <=30)
door1.width ++; }
void Data_door1() {
door1.x = 275;
door1.y = 330;
door1.width = 30;
door1.height = 20; }