Extra2D/examples/flappy_bird/pipes.h

72 lines
1.6 KiB
C
Raw Normal View History

// ============================================================================
// Pipes.h - 水管管理器
// 描述: 管理多个水管的生成、移动和回收
// ============================================================================
#pragma once
#include <extra2d.h>
#include "Pipe.h"
namespace flappybird {
/**
* @brief
*
*/
class Pipes : public extra2d::Node {
public:
/**
* @brief
*/
Pipes();
/**
* @brief
*/
~Pipes();
/**
* @brief
* @param dt
*/
void onUpdate(float dt) override;
/**
* @brief
*/
void onEnter() override;
/**
* @brief
*/
void start();
/**
* @brief
*/
void stop();
/**
* @brief
* @return
*/
Pipe* getPipe(int index) { return (index >= 0 && index < 3) ? pipes_[index] : nullptr; }
private:
/**
* @brief
*/
void addPipe();
static constexpr int maxPipes = 3; // 最大水管数量
static constexpr float pipeSpeed = 120.0f; // 水管移动速度(像素/秒)
static constexpr float pipeSpacing = 200.0f; // 水管间距
Pipe* pipes_[maxPipes]; // 水管数组
int pipeCount_ = 0; // 当前水管数量
bool moving_ = false; // 是否正在移动
};
} // namespace flappybird