Created
March 27, 2026 03:29
-
-
Save erikyuzwa/16448ccf79fbbca7eb3d33e9c159ae12 to your computer and use it in GitHub Desktop.
first game window using raylib and c++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "raylib.h" | |
| #include <iostream> | |
| #include <string> | |
| struct Player { | |
| Vector2 position; | |
| float speed; | |
| }; | |
| const auto SPRITE_WIDTH = 32.0f; | |
| const auto SPRITE_HEIGHT = 32.0f; | |
| int main(int argc, char* argv[]){ | |
| auto window_width = 800; | |
| auto window_height = 450; | |
| std::string title = "Raylib Basic Window"; | |
| InitWindow(window_width, window_height, title.c_str()); | |
| SetTargetFPS(60); | |
| Player player; | |
| player.position = {window_width / 2.0f, window_height / 2.0f}; | |
| player.speed = 200.0f; | |
| while(!WindowShouldClose()) { | |
| float dt = GetFrameTime(); | |
| if (IsKeyDown(KEY_UP)) player.position.y -= player.speed * dt; | |
| if (IsKeyDown(KEY_DOWN)) player.position.y += player.speed * dt; | |
| if (IsKeyDown(KEY_LEFT)) player.position.x -= player.speed * dt; | |
| if (IsKeyDown(KEY_RIGHT)) player.position.x += player.speed * dt; | |
| BeginDrawing(); | |
| ClearBackground(SKYBLUE); | |
| DrawFPS(10, 10); | |
| DrawText("Raylib C++ Starter", 10, 30, 20, YELLOW); | |
| DrawRectangleV(player.position, {SPRITE_WIDTH, SPRITE_HEIGHT}, RED); | |
| EndDrawing(); | |
| } | |
| CloseWindow(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment