声明
本文为直播网课的笔记。
笔记对原代码做出了一定的修改,注释,添加,删减。
一、介绍
本项目生成一个小鸟撞墙小游戏。
二、代码
#include <stdlib.h>
#include <cstdio> //Sleep()
#include <graphics.h>
#include <mmsystem.h>
//#include <iostream>
#include<string>
//#include <stdio.h>
#include <time.h>
#include <conio.h> //_getch()函数
#pragma comment (lib,"winmm.lib")
#pragma comment ( lib, "ws2_32.lib " ) //生成可执行文件
using namespace std;
int passbyn = 0; //返回小鸟现在的状态,是否在pillars之间
IMAGE myBird[2],down[2],background,up[2],myend[2];
//柱子属性
struct pillar //柱子成对出现
{
int x, y, height; //height表示上面的柱子所显示的高度,320-height表示下面的柱子所显示的高度
};
//鸟的属性
struct bird
{
int x, y, speed;
};
//鸟的初始属性
struct bird flybird {
124,304,100};
//加载资源
void LoadMyResourse()
{
loadimage(&background, "background.bmp");
loadimage(myBird + 0, "bird.bmp", 48, 48);
loadimage(myBird + 1, "birdy.bmp", 48, 48);
loadimage(myend + 0, "end.bmp");
loadimage(myend + 1, "endy.bmp");
loadimage(down + 0, "down.bmp");
loadimage(down + 1, "downy.bmp");
loadimage(up + 0, "up.bmp");
loadimage(up + 1, "upy.bmp");
}
//做鸟的部分
void drawbird(int x, int y)
{