带宽测试
这个提交包含在:
@@ -3,9 +3,34 @@
|
||||
|
||||
#include <godot_cpp/classes/node2d.hpp>
|
||||
#include <godot_cpp/classes/label.hpp>
|
||||
#include <godot_cpp/classes/input_event.hpp>
|
||||
|
||||
namespace godot {
|
||||
|
||||
class PingPongBall;
|
||||
|
||||
// ═══════════════════════════════════════════════════════
|
||||
// 视觉常量 — 以后替换素材时删除本段
|
||||
// (颜色值定义在 pingpong_game.cpp 中)
|
||||
// ═══════════════════════════════════════════════════════
|
||||
static constexpr float FIELD_INSET = 15.0f;
|
||||
static constexpr float CENTER_LINE_DASH = 20.0f;
|
||||
static constexpr float CENTER_LINE_GAP = 12.0f;
|
||||
|
||||
// 游戏状态
|
||||
enum GameState {
|
||||
WAITING,
|
||||
COUNTDOWN,
|
||||
PLAYING,
|
||||
SCORED,
|
||||
GAME_OVER
|
||||
};
|
||||
|
||||
// 倒计时参数
|
||||
static constexpr float COUNTDOWN_INTERVAL = 0.75f;
|
||||
static constexpr int COUNTDOWN_START = 3;
|
||||
static constexpr float SCORED_PAUSE = 1.2f;
|
||||
|
||||
class PingPongGame : public Node2D {
|
||||
GDCLASS(PingPongGame, Node2D)
|
||||
|
||||
@@ -14,10 +39,20 @@ private:
|
||||
int right_score = 0;
|
||||
int max_score = 5;
|
||||
|
||||
// 状态机
|
||||
GameState state = WAITING;
|
||||
float state_timer = 0.0f;
|
||||
int countdown_number = COUNTDOWN_START;
|
||||
|
||||
// 子节点引用
|
||||
Label *left_score_label = nullptr;
|
||||
Label *right_score_label = nullptr;
|
||||
Label *message_label = nullptr;
|
||||
PingPongBall *ball = nullptr;
|
||||
|
||||
void update_score_display();
|
||||
void set_state(GameState p_state);
|
||||
void show_message(const String &p_text);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
@@ -27,12 +62,16 @@ public:
|
||||
~PingPongGame();
|
||||
|
||||
void _ready() override;
|
||||
void _process(double delta) override;
|
||||
void _draw() override;
|
||||
void _input(const Ref<InputEvent> &event) override;
|
||||
|
||||
// 得分处理
|
||||
void _on_ball_scored(int which);
|
||||
|
||||
// 重置整局游戏
|
||||
void reset_game();
|
||||
void start_countdown();
|
||||
|
||||
// 属性 getter/setter
|
||||
void set_left_score(int p_score);
|
||||
|
||||
在新工单中引用
屏蔽一个用户