c++愤怒的小鸟

这是一个使用C++编写的命令行版本的愤怒的小鸟游戏代码,包括游戏界面设置、小鸟和猪的移动、碰撞检测以及游戏得分系统等关键逻辑。游戏中的小鸟具有不同技能,猪也有特殊行为,玩家需通过空格键瞄准并发射小鸟来击中目标。
摘要由CSDN通过智能技术生成

这个游戏有些电脑玩起来可能不太行,请谅解

#include <bits/stdc++.h>
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <time.h>
using namespace std;
const double pi = 3.1415926536;
int toint (float a) {
return ((int) (a * 10 + 5)) / 10;
}
void Color (int a) {
if (a == 0 || a == 14 || a == 20) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
} else if (a == 1 || a == 12) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);
} else if (a == 2) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY |FOREGROUND_GREEN);
} else if (a == 3) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE);
} else if (a == 4 || a == 11) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY|FOREGROUND_RED);
} else if (a == 5 || a == 13) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
} else if (a == 7) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_GREEN|FOREGROUND_BLUE);
} else if (a == 15) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
} else if (a == 16) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_GREEN);
} else if (a == 17) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_RED);
} else if (a == 8) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
} else if (a == 6) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY|FOREGROUND_BLUE);
} else if (a == 9) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY|FOREGROUND_RED|BACKGROUND_RED|BACKGROUND_GREEN);
}
}
void SetPos (float x, float y) {
int xx = toint (x), yy = toint (y);
COORD pos;
pos.X = yy * 2;
pos.Y = xx;
SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE), pos);
}
struct node {
int W, W2, S, mS;
float X, Y;
float vx, vy;
float ax, ay;
bool go, boom;
} blt[100001], pig[100001], boo[100001];
int T, yX, yY, Xy, put, K, K2, Sle, What;
int Bot, Pit, Blt, Pig, Sco, pigk, scok;
int m[41][41];
void Cout (int a, int x, int y) {
if (a == 1) {
SetPos (x, y);
Color (5);
cout << put << ' ';
}
if (y == 202) {
SetPos (pig[a].X, pig[a].Y);
cout << " ";
if ((pig[a].W == 2 || pig[a].W == 3) && pig[a].X >= 2) {
SetPos (pig[a].X - 2, pig[a].Y);
cout << " ";
SetPos (pig[a].X - 1, pig[a].Y);
cout << " ";
} else if (pig[a].W == 4) {
SetPos (pig[a].X, pig[a].Y - 1);
cout << " ";
} else if(pig[a].W == 5) {
SetPos (pig[a].X - 1, pig[a].Y);
cout << " ";
SetPos (pig[a].X - 1, pig[a].Y - 1);
cout << " ";
}
}
if (a == 2) {
for (int i = 0; i <= 40; i++) {
for (int j = 0; j <= 40; j++) {
if (i <= 18 && m[i][j] == 1) {
SetPos (i, j);
Color (7);
cout << "■";
}
if (m[i][j] >= 2 && m[i][j] <= 19) {
SetPos (i, j);
Color (5);
cout << "█";
m[i][j]++;
}
if (m[i][j] > 19 && m[i][j] <= 29) {
SetPos (i, j);
Color (0);
cout << "█";
m[i][j]++;
if (m[i][j] == 30) {
SetPos (i, j);
Color (0);
cout << " ";
m[i][j] = 0;
}
if (m[i][j] >= 31 && m[i][j] <= 49) {
SetPos (i, j);
Color (0);
cout << "■";
m[i][j]++;
}
if (m[i][j] == 50) {
SetPos (i, j);
Color (7);
cout << "■";
m[i][j] = 1;
}
}
}
}
}
if (y == 666) {
SetPos (blt[a].X, blt[a].Y);
Color (10 + blt[a].W);
cout<<"●";
}
Color (0);
}
void Go (int a) {
SetPos (blt[a].X, blt[a].Y);
cout << " ";
blt[a].X += blt[a].vx / 2;
blt[a].Y += blt[a].vy / 2;
blt[a].vx += blt[a].ax / 2;
blt[a].vy += blt[a].ay / 2;
if (blt[a].X >= 20) {
blt[a].X = 19;
}
if (blt[a].X > 20 || blt[a].Y > 38 || blt[a].X < 0 || blt[a].Y <= 0) {
blt[a].go = 1;
}
if (blt[a].W2 == 1 && blt[a].Y >= Xy) {
blt[a].go = 1;
Sle = 0;//地跑鸟
}
if (blt[a].W2 == 0) {
for (int i = 0; i <= blt[a].vx / 2 + 1; i++) {
if (blt[a].vx > 0 && m[toint (blt[a].X) + i][toint (blt[a].Y)] == 1) {
if (blt[a].W != 5) {
blt[a].boom = 1;
}
blt[a].X = toint (blt[a].X) + i - 1;
blt[a].Y += blt[a].vy / 2;
blt[a].vx = -blt[a].vx * 0.4;
blt[a].vy = bl
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值