这是我自己写的一个飞机大战的源码,目前还没有完善,只写了我方飞机和敌方飞机,通过上下左右四个箭头控制我方飞机行动,按空格键,飞机发射子弹。可自行加入其它功能,比如子弹敌机碰撞之后爆炸。下面是我写了的项目源码。
plane.cpp
#include "plane.h"
Plane::Plane()
{
}
Plane::Plane(int x, int y, char *imgURL, char *imgURLY, int speed)
{
this->x = x;
this->y = y;
loadimage(img + 1, imgURL); //背景图
loadimage(img + 0, imgURLY);
this->speed = speed;
}
void Plane::drawPlane() //画飞机
{
//SRCAND 方式贴掩码图
putimage(x, y, img + 0,SRCAND);
//SRCPAIN方式贴图背景图
putimage(x, y, img + 1, SRCPAINT);
}
void Plane::keyDown(char userKey) //按键操作
{
switch (userKey)
{
case 'w':
case 'W':
case 72:
this->y -= this->speed;
break;
case 'S':
case 's':
case 80:
this->y += this->speed;
break;
case 'a':
case 'A':
case 75:
this->x -= this->speed;
break;
case 'd':
case 'D':
case 77:
this->x += this-