下一张有惊喜:
string grass[1] = { " " };
string soil[30];
string bullet[1] = { "▂" };
int SoilHieght[9] = { 2,2,2,10,20,7,7,7,7 };
Sprite Grass[9], Soil[9], Bullet[10005], bhp, rhp;
bool flag[10005], gameover;
int blueHP, redHP;
Sprite letin(Sprite a)
{
a.x = max(a.x, 0); a.x = min(a.x, 27);
a.y = max(a.y, 0); a.y = min(a.y, 117);
return a;
}
int NowBackgroundColor(Sprite a)
{
for (int i = 0; i <= 8; i++)
{
if (CheckCollision(Soil[i], a)) return 96;
if (a.height == 1 && CheckCollision(Grass[i], a)) return 32;
}
return 224;
}
int jemian()
{
HindCursor();
system("mode con cols=120 lines=30");
for (int i = 0; i < 30; i++) soil[i] = grass[0];
Grass[0] = NewSprite(grass, 12, 1, 32, 6, 52);
Grass[1] = NewSprite(grass, 12, 1, 32, 11, 18);
Grass[2] = NewSprite(grass, 12, 1, 32, 11, 91);
Grass[3] = NewSprite(grass, 15, 1, 32, 18, 50);
Grass[4] = NewSprite(grass, 53, 1, 32, 9, 34);
Grass[5] = NewSprite(grass, 32, 1, 32, 14, 14);
Grass[6] = NewSprite(grass, 38, 1, 32, 14, 70);
Grass[7] = NewSprite(grass, 34, 1, 32, 22, 14);
Grass[8] = NewSprite(grass, 41, 1, 32, 22, 67);
color(224);
for (int i = 0; i <= 30; i++)
for (int j = 0; j < 119; j++) printf(" ");
for (int i = 0; i <= 8; i++)
{
Soil[i] = NewSprite(soil, Grass[i].width, SoilHieght[i], 96, Grass[i].x + 1, Grass[i].y);
Soil[i].Draw();
}
for (int i = 0; i <= 8; i++) Grass[i].Draw();
string player[2] = { "●", "■" };
string HP[1] = { "■■■■■■■■■■" };
Sprite red = NewSprite(player, 2, 2, 4 | 224, 4, 54);
Sprite blue = NewSprite(player, 2, 2, 1 | 224, 4, 57);
bhp = NewSprite(HP, 20, 1, 1 | 224, 0, 3);
rhp = NewSprite(HP, 20, 1, 4 | 224, 0, 97);
int bluejump = 0, redjump = 0;
bool bluejumping = false, redjumping = false;
int tbluejump = 0, tredjump = 0;
int bulleti = 0, tbluebullet = 0, tredbullet = 0;
int bhps = 5, rhps = 5;
blueHP = 50; redHP = 50; gameover = false;
memset(flag, 0, sizeof(flag));
red.Draw(); blue.Draw();
bhp.Draw(); rhp.Draw();
color(0 | 224);
gotoxy(0, 1); printf("%d", bhps);
gotoxy(0, 118); printf("%d", rhps);
while (1)
{
bool bluemove = false;
int bnx = blue.x, bny = blue.y, rnx = red.x, rny = red.y;
Sprite b = NewSprite(player, 2, 2, 1 | 224, bnx, bny);
Sprite r = NewSprite(player, 2, 2, 4 | 224, rnx, rny);
color(224);
for (int i = 0; i < 3; i++)
{
if (CheckCollision(blue, Soil[0]) || CheckCollision(blue, Grass[0]) ||
CheckCollision(red, Soil[0]) || CheckCollision(red, Grass[0]))
{
gotoxy(6 + i, 51); printf(" ");
gotoxy(6 + i, 64); printf(" ");
}
if (CheckCollision(blue, Soil[1]) || CheckCollision(blue, Grass[1]) ||
CheckCollision(red, Soil[1]) || CheckCollision(red, Grass[1]))
{
gotoxy(11 + i, 17); printf(" ");
gotoxy(11 + i, 30); printf(" ");
}
if (CheckCollision(blue, Soil[2]) || CheckCollision(blue, Grass[2]) ||
CheckCollision(red, Soil[2]) || CheckCollision(red, Grass[2]))
{
gotoxy(11 + i, 90); printf(" ");
gotoxy(11 + i, 103); printf(" ");
}
}
for (int i = 0; i < 5; i++)
if (CheckCollision(blue, Soil[4]) || CheckCollision(blue, Grass[4]) ||
CheckCollision(red, Soil[4]) || CheckCollision(red, Grass[4]))
{
gotoxy(9 + i, 33); printf(" ");
gotoxy(9 + i, 87); printf(" ");
}
/*
for (int i = 0; i < 7; i++)
{
if (CheckCollision(blue, Soil[5]) || CheckCollision(blue, Grass[5]))
gotoxy(14 + i, 12); printf(" ");
if (CheckCollision(blue, Soil[6]) || CheckCollision(blue, Grass[6]))
gotoxy(14 + i, 108); printf(" ");
if (CheckCollision(blue, Soil[7]) || CheckCollision(blue, Grass[7]))
gotoxy(22 + i, 12); printf(" ");
if (CheckCollision(blue, Soil[8]) || CheckCollision(blue, Soil[8]))
gotoxy(22 + i, 108); printf(" ");
}*/
blue.Draw(); red.Draw();
if (KEY_DOWN(VK_LEFT))
{
int COLOR = NowBackgroundColor(b);
blue.direction = -1;
color(COLOR);
blue.Clean();
blue.y--;
blue.Color = 1 | COLOR;
blue = letin(blue);
blue.Draw(); red.Draw();
}
if (KEY_DOWN(VK_RIGHT))
{
int COLOR = NowBackgroundColor(b);
blue.direction = 1;
blue.Color = 1 | COLOR;
color(COLOR);
blue.Clean();
blue.y++;
blue = letin(blue);
blue.Draw(); red.Draw();
}
if (KEY_DOWN(VK_UP))
if (bluejumping == false)
{
tbluejump = -1;
bluejump = 0;
bluejumping = true;
}
if (bluejumping)
{
int COLOR = NowBackgroundColor(blue);
blue.Color = 1 | COLOR;
color(COLOR);
blue.Clean();
if (tbluejump != -2)
{
blue.x += tbluejump;
bluejump += tbluejump;
}
for (int i = 0; i <= 8; i++)
if (blue.x == Grass[i].x - 2 && blue.y >= Grass[i].y - 1 && blue.y + blue.width <= Grass[i].y + Grass[i].width + 1)
{
tbluejump = 0;
bluejumping = false;
break;
}
blue = letin(blue);
blue.Draw(); red.Draw();
if (bluejump == -5) tbluejump = 1;
}
else
{
int j;
for (j = 0; j <= 8; j++)
if (blue.x == Grass[j].x - 2 && blue.y >= Grass[j].y - 1 && blue.y + blue.width <= Grass[j].y + Grass[j].width + 1)
break;
if (j == 9)
{
int COLOR = NowBackgroundColor(b);
color(COLOR);
blue.Clean();
blue.x++;
blue.Color = 1 | COLOR;
blue.Draw(); red.Draw();
}
}
if (KEY_DOWN(0x58))
{
if (!tbluebullet)
{
Bullet[++bulleti] = NewSprite(bullet, 2, 1, 0 | 224, blue.x, blue.y + blue.direction * 2);
Bullet[bulleti].direction = blue.direction;
Bullet[bulleti].Draw();
tbluebullet = 1;
}
}
if (blue.x >= 26)
{
if (blueHP % 10 == 0) blueHP -= 10;
else blueHP -= blueHP % 10;
bhp.width = 0;
}
if (KEY_DOWN(0x41))
{
int COLOR = NowBackgroundColor(r);
color(COLOR);
red.Clean();
red.y--; red.direction = -1;
red.Color = 4 | COLOR;
red = letin(red);
blue.Draw(); red.Draw();
}
if (KEY_DOWN(0x44))
{
int COLOR = NowBackgroundColor(r);
color(COLOR);
red.Clean();
red.y++; red.direction = 1;
red.Color = 4 | COLOR;
red = letin(red);
blue.Draw(); red.Draw();
}
if (KEY_DOWN(0x57))
if (redjumping == false)
{
tredjump = -1;
redjump = 0;
redjumping = true;
}
if (redjumping)
{
int COLOR = NowBackgroundColor(red);
red.Color = 4 | COLOR;
color(COLOR);
red.Clean();
if (tredjump != -2)
{
red.x += tredjump;
redjump += tredjump;
}
for (int i = 0; i <= 8; i++)
if (red.x == Grass[i].x - 2 && red.y >= Grass[i].y - 1 && red.y + red.width <= Grass[i].y + Grass[i].width + 1)
{
tredjump = 0;
redjumping = false;
break;
}
red = letin(red);
blue.Draw(); red.Draw();
if (redjump == -5) tredjump = 1;
}
else
{
int j;
for (j = 0; j <= 8; j++)
if (red.x == Grass[j].x - 2 && red.y >= Grass[j].y - 1 && red.y + red.width <= Grass[j].y + Grass[j].width + 1)
break;
if (j == 9)
{
int COLOR = NowBackgroundColor(r);
color(COLOR);
red.Clean();
red.x++;
red.Color = 4 | COLOR;
blue.Draw(); red.Draw();
}
}
if (KEY_DOWN(0x59))
{
if (!tredbullet)
{
Bullet[++bulleti] = NewSprite(bullet, 2, 1, 0 | 224, red.x, red.y + red.direction * 2);
Bullet[bulleti].direction = red.direction;
Bullet[bulleti].Draw();
tredbullet = 1;
}
}
if (red.x >= 28)
{
if (redHP % 10 == 0) redHP -= 10;
else redHP -= redHP % 10;
rhp.width = 0;
}
if (tbluebullet)
{
if (tbluebullet == 15) tbluebullet = 0;
else tbluebullet++;
}
if (tredbullet)
{
if (tredbullet == 15) tredbullet = 0;
else tredbullet++;
}
for (int i = 0; i <= 8; i++) Grass[i].Draw();
for (int i = 1; i <= bulleti; i++)
{
if (flag[i]) continue;
int COLOR = NowBackgroundColor(Bullet[i]);
color(0 | COLOR);
Bullet[i].Clean();
Bullet[i].y += Bullet[i].direction * 2;
COLOR = NowBackgroundColor(Bullet[i]);
Bullet[i].Color = 0 | COLOR;
Bullet[i].Draw();
if (Bullet[i].y <= 1 || Bullet[i].y >= 117 ||
CheckCollision(Bullet[i], blue) || CheckCollision(Bullet[i], red))
{
Bullet[i].Clean();
if (CheckCollision(Bullet[i], blue))
{
blueHP--;
color(224);
bhp.Clean();
bhp.width -= 2;
bhp.Draw();
int COLOR = NowBackgroundColor(blue);
blue.Color = 1 | COLOR;
color(COLOR);
blue.Clean();
blue.y += Bullet[i].direction * 3;
blue = letin(blue);
blue.Draw(); red.Draw();
}
if (CheckCollision(Bullet[i], red))
{
redHP--;
color(224);
rhp.Clean();
rhp.width -= 2;
rhp.y += 2;
rhp.Draw();
int COLOR = NowBackgroundColor(red);
red.Color = 4 | COLOR;
color(COLOR);
red.Clean();
red.y += Bullet[i].direction * 3;
red = letin(red);
blue.Draw(); red.Draw();
}
Bullet[i].x = 0; Bullet[i].y = 0;
flag[i] = true;
continue;
}
}
if (blueHP % 10 == 0 && bhp.width <= 0)
{
bhps--;
bhp.width = 20;
gotoxy(0, 1); color(0 | 224); printf("%d", bhps);
bhp.Draw();
int COLOR = NowBackgroundColor(blue);
blue.Color = 1 | 224;
color(COLOR);
blue.Clean(); blue.x = 4; blue.y = 57;
blue.Draw();
}
if (redHP % 10 == 0 && rhp.width <= 0)
{
rhps--;
rhp.width = 20; rhp.y = 97;
gotoxy(0, 118); color(0 | 224); printf("%d", rhps);
rhp.Draw();
int COLOR = NowBackgroundColor(red);
red.Color = 4 | 224;
color(COLOR);
red.Clean(); red.x = 4; red.y = 54;
red.Draw();
}
if (redHP <= 0)
{
gotoxy(12, 53);
color(1 | 96);
printf("玩家1获胜!");
gameover = true;
break;
}
if (blueHP <= 0)
{
gotoxy(12, 53);
color(4 | 96);
printf("玩家2获胜!");
gameover = true;
break;
}
if (gameover) break;
Sleep(25);
}
Button Exit = NewButton(14, 55, 0 | 96, "退出");
while (1)
{
if (Preserve(Exit)) exit(0);
Sleep(25);
}
return 0;
}
老规矩,1024赞不出教程。