代码拉取完成,页面将自动刷新
//
// Created by liaoyunjie on 24-5-14.
//
#ifndef AIRCRAFT_H
#define AIRCRAFT_H
#include <QPoint>
#include <list>
#include <mutex>
#include "BaseFlyingObject.h"
#include "Bullet.h"
#include "ImageManager.h"
#include "RandomGenerator.h"
#include "ShootStrategy.h"
#include "prop.h"
class BaseAircraft : public BaseFlyingObject {
protected:
BaseAircraft(FlyingObjectType type, int location_x, int location_y,
int speed_x, int speed_y, int width, int height,
const std::shared_ptr<BaseShootStrategy>& shoot_strategy, int hp,
int direction, int shoot_num, int bullet_power, int shoot_cycle)
: BaseFlyingObject(type, location_x, location_y, speed_x, speed_y, width,
height),
shoot_strategy_(shoot_strategy),
hp_(hp),
direction_(direction),
shoot_num_(shoot_num),
bullet_power_(bullet_power),
shoot_cycle_(shoot_cycle) {}
public:
int factor() const override { return 2; }
int hp() const { return hp_; }
int direction() const { return direction_; }
int shoot_num() const { return shoot_num_; }
int bullet_power() const { return bullet_power_; }
int shoot_cycle() const { return shoot_cycle_; }
auto shoot_strategy() const -> std::shared_ptr<BaseShootStrategy> {
return shoot_strategy_;
}
void decrease_hp(int damage) {
hp_ -= damage;
if (hp_ <= 0) {
vanish();
}
}
void set_shoot_num(int shoot_num) { shoot_num_ = shoot_num; }
void set_shoot_cycle(int shoot_cycle) { shoot_cycle_ = shoot_cycle; }
auto shoot() -> std::list<std::shared_ptr<Bullet>>;
protected:
int hp_;
private:
std::shared_ptr<BaseShootStrategy> shoot_strategy_;
int direction_;
int shoot_num_;
int bullet_power_;
int shoot_cycle_;
int shoot_timer_ = 0;
};
class HeroAircraft final : public BaseAircraft {
public:
static auto instance() -> std::shared_ptr<HeroAircraft>;
HeroAircraft(const HeroAircraft&) = delete;
HeroAircraft& operator=(const HeroAircraft&) = delete;
void forward() override {} // 英雄机靠鼠标控制,forward重写为空
void set_location(const QPoint& pos) {
set_location_x(pos.x());
set_location_y(pos.y());
}
void increase_hp(int hp) {
hp_ += hp;
if (hp_ > HERO_MAX_HP) {
hp_ = HERO_MAX_HP;
}
}
private:
HeroAircraft()
: BaseAircraft(HERO_AIRCRAFT, WINDOW_WIDTH / 2, WINDOW_HEIGHT - 50, 0, 0,
ImageManager::HERO_IMAGE.width(),
ImageManager::HERO_IMAGE.height(),
std::make_shared<DirectShootStrategy>(), HERO_MAX_HP, -1,
1, HERO_BULLET_POWER, HERO_SHOOT_CYCLE) {}
static std::shared_ptr<HeroAircraft> instance_;
static std::once_flag instance_flag_;
};
class EnemyAircraft : public BaseAircraft {
protected:
EnemyAircraft(FlyingObjectType type, int speed_x, int speed_y,
const std::shared_ptr<BaseShootStrategy>& shoot_strategy,
int hp, int direction, int shoot_num, int bullet_power,
int shoot_cycle, int score, int prop_num)
: BaseAircraft(type,
static_cast<int>(RandomGenerator::getRandom0To1() *
(WINDOW_WIDTH -
ImageManager::IMAGE_MAP[type].width())),
WINDOW_HEIGHT * 0.05, speed_x, speed_y,
ImageManager::IMAGE_MAP[type].width(),
ImageManager::IMAGE_MAP[type].height(), shoot_strategy, hp,
direction, shoot_num, bullet_power, shoot_cycle),
score_(score),
prop_num_(prop_num) {}
virtual auto createSingleProp() -> std::shared_ptr<BaseProp> = 0;
public:
auto createProps() -> std::list<std::shared_ptr<BaseProp>>;
void forward() override {
BaseAircraft::forward();
if (location_y() >= WINDOW_HEIGHT) {
vanish();
}
}
int score() const { return score_; }
int prop_num() const { return prop_num_; }
private:
int score_;
int prop_num_;
};
class MobEnemyAircraft final : public EnemyAircraft {
public:
MobEnemyAircraft()
: EnemyAircraft(MOB_ENEMY_AIRCRAFT, 0, MOB_ENEMY_SPEEDY,
std::make_shared<BaseShootStrategy>(), MOB_ENEMY_MAX_HP,
ENEMY_DIRECTION, 1, 0, MOB_ENEMY_SCORE, 100, 0) {}
auto createSingleProp() -> std::shared_ptr<BaseProp> override {
return nullptr;
}
};
class EliteEnemyAircraft final : public EnemyAircraft {
public:
EliteEnemyAircraft()
: EnemyAircraft(
ELITE_ENEMY_AIRCRAFT,
RandomGenerator::getRandom0To1() < 0.5 ? 0 : 1, ELITE_ENEMY_SPPEEDY,
std::make_shared<DirectShootStrategy>(), ELITE_ENEMY_MAX_HP,
ENEMY_DIRECTION, 1, ELITE_ENEMY_BULLET_POWER, ELITE_SHOOT_CYCLE,
ELITE_ENEMY_SCORE, 1) {}
auto createSingleProp() -> std::shared_ptr<BaseProp> override;
};
#endif // AIRCRAFT_H
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。