C/C++项目源码——飞机大战

本文介绍了一款自制的C/C++飞机大战项目,目前包含我方和敌方飞机,通过键盘控制飞机移动,空格发射子弹。作者鼓励读者参与讨论并完善项目,如增加子弹与敌机碰撞效果。源码文件包括plane.cpp、bullet.cpp和test.cpp。
摘要由CSDN通过智能技术生成

这是我自己写的一个飞机大战的源码,目前还没有完善,只写了我方飞机和敌方飞机,通过上下左右四个箭头控制我方飞机行动,按空格键,飞机发射子弹。可自行加入其它功能,比如子弹敌机碰撞之后爆炸。下面是我写了的项目源码。

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-
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值