随便看看吧 得下载raylib
2026-07-10 19:29:47
发布于:新西兰
#include "raylib.h"
#include <iostream>
class Player{
public:
Vector2 position;
float velocityY;
float gravity;
// void moveOnX(double n){
// position.x += n * speed;
// }
// void moveOnY(double n){
// position.y += n * speed;
// }
void limit(){
if (position.x <= 0) position.x = 0;
if (position.x >= 800) position.x = 800;
if (position.y <= 0) position.y = 0, velocityY = -0.1;
if (position.y >= 600) position.y = 600;
}
void update (){
velocityY += gravity;
position.y += velocityY;
}
void flap (){
velocityY = -8;
}
};
class Pipe{
public:
float x;
float gapY;
float gapHeight;
float width = 60;
void update(){
x -= 3;
}
void draw(){
DrawRectangle(
x,
0,
width,
gapY - gapHeight / 2,
BLACK
);
DrawRectangle(
x,
gapY + gapHeight / 2,
width,
600 - (gapY + gapHeight / 2),
BLACK
);
}
};
// class Pipe_Spawner{
// public:
// void Spawn_Pipe(const Pipe& pipe){
// DrawRectangle (pipe.x, 0, pipe.width, pipe.gapY - pipe.gapHeight / 2, BLACK);
// DrawRectangle (pipe.x, pipe.gapY + pipe.gapHeight / 2, pipe.width, 600 - (pipe.gapHeight / 2 + pipe.gapY), BLACK);
// }
// }spawner;
int main (){
// std::cout << 111;
Player player = {{400, 100}, 0, 0.3};
Pipe pipe = {800, 300, 180};
InitWindow(800, 600, "window");
SetTargetFPS(60);
while (!WindowShouldClose()){
player.update();
pipe.update();
if (IsKeyPressed(KEY_SPACE)){
player.flap();
}
// if (IsKeyDown(KEY_W)){
// player.moveOnY(-0.1);
// }if (IsKeyDown(KEY_A)){
// player.moveOnX(-0.1);
// }if (IsKeyDown(KEY_S)){
// player.moveOnY(0.1);
// }if (IsKeyDown(KEY_D)){
// player.moveOnX(0.1);
// }
player.limit();
BeginDrawing();
ClearBackground(Fade(BLUE, 0.1));
// spawner.Spawn_Pipe(pipe);
pipe.draw();
DrawCircle(
player.position.x,
player.position.y,
20,
BLACK
);
EndDrawing();
}
CloseWindow();
return 0;
}
这里空空如也














有帮助,赞一个