乒乓球游戏:C++ GDExtension 实现

这个提交包含在:
2026-08-05 15:10:47 +08:00
父节点 7b7757c002
当前提交 7228d302f5
修改 117 个文件,包含 803 行新增121 行删除
+52
查看文件
@@ -0,0 +1,52 @@
#ifndef PINGPONG_GAME_H
#define PINGPONG_GAME_H
#include <godot_cpp/classes/node2d.hpp>
#include <godot_cpp/classes/label.hpp>
namespace godot {
class PingPongGame : public Node2D {
GDCLASS(PingPongGame, Node2D)
private:
int left_score = 0;
int right_score = 0;
int max_score = 5;
Label *left_score_label = nullptr;
Label *right_score_label = nullptr;
void update_score_display();
protected:
static void _bind_methods();
public:
PingPongGame();
~PingPongGame();
void _ready() override;
// 得分处理
void _on_ball_scored(int which);
// 重置整局游戏
void reset_game();
// 属性 getter/setter
void set_left_score(int p_score);
int get_left_score() const;
void set_right_score(int p_score);
int get_right_score() const;
void set_max_score(int p_score);
int get_max_score() const;
// 信号: game_over(int winner) — 0=左边赢, 1=右边赢
};
}
#endif // PINGPONG_GAME_H