{"id":16811686,"url":"https://github.com/raysan5/raylib-intro-course","last_synced_at":"2025-04-12T22:21:46.034Z","repository":{"id":63272231,"uuid":"565530454","full_name":"raysan5/raylib-intro-course","owner":"raysan5","description":"A small raylib introductory course developing a simple game","archived":false,"fork":false,"pushed_at":"2025-01-21T21:42:50.000Z","size":724,"stargazers_count":252,"open_issues_count":2,"forks_count":16,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-04T01:37:09.947Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/raysan5.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"raysan5","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"custom":null}},"created_at":"2022-11-13T17:43:34.000Z","updated_at":"2025-04-02T17:16:01.000Z","dependencies_parsed_at":"2024-01-14T18:29:27.866Z","dependency_job_id":"98eb63dd-f8d2-4bfb-b0fb-1353ed41a635","html_url":"https://github.com/raysan5/raylib-intro-course","commit_stats":{"total_commits":18,"total_committers":4,"mean_commits":4.5,"dds":0.4444444444444444,"last_synced_commit":"0196629c22945264dd53731c744a22f900541dd8"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raysan5%2Fraylib-intro-course","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raysan5%2Fraylib-intro-course/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raysan5%2Fraylib-intro-course/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raysan5%2Fraylib-intro-course/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/raysan5","download_url":"https://codeload.github.com/raysan5/raylib-intro-course/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248638602,"owners_count":21137688,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T10:19:28.141Z","updated_at":"2025-04-12T22:21:46.014Z","avatar_url":"https://github.com/raysan5.png","language":"C","funding_links":["https://github.com/sponsors/raysan5"],"categories":[],"sub_categories":[],"readme":"\n# raylib Introduction Course\n\n*by Ramon Santamaria ([@raysan5](https://twitter.com/raysan5))*\n\n![blocks game](blocks_game.gif \"Blocks Game\")\n\n## Introduction\n\nIn this introductory course to [raylib](http://www.raylib.com/) we will implement a Blocks game similar to the well-known [Arkanoid](https://en.wikipedia.org/wiki/Arkanoid) (Taito, 1986). Along this process we will learn how the videogames life cycle works, how to manage the window and player inputs, and how to draw some graphics on screen.\n\n[raylib](http://www.raylib.com/) is a simple and easy-to-use library to enjoy videogames programming.\n\n**Learning Outcomes:**\n\n - raylib functionality and possibilities\n - Videogame life cycle (Init -\u003e Update -\u003e Draw -\u003e DeInit)\n - Basic screens management with screens transition\n - Basic shapes drawing (circle, rectangle)\n - Inputs management (keyboard, mouse)\n - Collision detection and resolution\n - Textures loading and drawing\n - Fonts loading and text drawing\n - Sounds and music loading and playing\n \n**NOTE:** All code provided is in C language for simplicity and clearness but it's up to the student to use more complex C++ code structures (OOP) if desired.\n\n## Lessons Summary\n\nLesson | Learning outcome | Source file | Related functions\n:-----:|------------------|:------------|:-----------------:\n[01](#lesson-01-introduction-to-raylib-and-videogames-programming) | raylib functionality, \u003cbr\u003evideogame life cycle, \u003cbr\u003ebasic screens management | [01_blocks_game_intro.c](lessons/01_blocks_game_intro.c) | InitWindow(), CloseWindow(), \u003cbr\u003eBeginDrawing(), EndDrawing()\n[02](#lesson-02-draw-basic-shapes-circle-rectangle) | basic shapes drawing | [02_blocks_game_drawing.c](lessons/02_blocks_game_drawing.c) | DrawRectangle(), DrawCircle()\n[03](#lesson-03-inputs-management-keyboard-mouse) | inputs management | [03_blocks_game_inputs.c](lessons/03_blocks_game_inputs.c) | IsKeyPressed(), IsKeyDown(), \u003cbr\u003eIsMouseButtonPressed(), \u003cbr\u003eIsMouseButtonDown(), \u003cbr\u003eGetMouseX(), GetMouseY()\n[04](#lesson-04-collision-detection-and-resolution) | collision detection and resolution | [04_blocks_game_collisions.c](lessons/04_blocks_game_collisions.c) | CheckCollisionCircleRec(), \u003cbr\u003eCheckCollisionRecs(), \u003cbr\u003eCheckCollisionCircles()\n[05](#lesson-05-textures-loading-and-drawing) | textures loading and drawing | [05_blocks_game_textures.c](lessons/05_blocks_game_textures.c) | LoadTexture(), UnloadTexture(), \u003cbr\u003eDrawTexture()\n[06](#lesson-06-fonts-loading-and-text-drawing) | fonts loading and text drawing | [06_blocks_game_text.c](lessons/06_blocks_game_text.c) | LoadFont(), UnloadFont(), \u003cbr\u003eDrawText(), DrawTextEx()\n[07](#lesson-07-sounds-and-music-loading-and-playing) | sounds and music loading and playing | [07_blocks_game_audio.c](lessons/07_blocks_game_audio.c) | InitAudioDevice(), CloseAudioDevice(), \u003cbr\u003eLoadSound(), UnloadSound(), \u003cbr\u003ePlaySound(), LoadMusicStream(), UnloadMusicStream(), \u003cbr\u003ePlayMusicStream()\n\n**NOTE:** Most of the documentation for the exercise is directly included in the source code files as code comments. Read carefully those comments to understand every task and how implement the proposed solutions.\n\n### Lesson 01: Introduction to raylib and videogames programming\n\n*Lesson code file to review: [01_blocks_game_intro.c](lessons/01_blocks_game_intro.c)*\n\nIn this first lesson we will introduce raylib library and videogames programming principles. We will setup raylib and take a look to its functionality; we will see how videogame life cycle works and we will implement a basic screens management system for our game.\n\n**Introduction to raylib**\n\nraylib is simple and easy-to-use library to learn videogames programming. raylib abstracts the user from the more low level libraries like OpenGL or GLFW3.\n\nHere there are some interesting links to know more about raylib:\n\n - [raylib Features](http://www.raylib.com)\n - [raylib Frequently Asked Questions](https://github.com/raysan5/raylib/blob/master/FAQ.md)\n - [raylib Architecture](https://github.com/raysan5/raylib/wiki/raylib-architecture)\n - [raylib Functions Cheatsheet](http://www.raylib.com/cheatsheet/cheatsheet.html)\n - [raylib Data Structures](https://github.com/raysan5/raylib/wiki/raylib-data-structures)\n - [raylib Examples](http://www.raylib.com/examples.html)\n - [raylib Wiki](https://github.com/raysan5/raylib/wiki)\n\nraylib follows the KISS principle, providing simple functions with clear naming conventions. Main documentation for the library functionality is condensed in a single [cheatsheet](http://www.raylib.com/cheatsheet/cheatsheet.html).\n\n**Environment setup**\n\nraylib can be used with many environment configurations as far as a code-editor and compiler are provided.  \nBy default, [raylib webpage](http://www.raylib.com/) distributes a Windows Installer containing all required tools to develop videogames with raylib in C/C++ on Windows platforms. Tools included with installer are **preconfigured** versions of:\n\n - [w64devkit/MinGW](https://github.com/skeeto/w64devkit) - Minimalistic GNU for Windows, including GCC compiler and several tools and libraries\n - [Notepad++](https://notepad-plus-plus.org) - Windows simple code editor, preconfigured with multiple compiling scripts\n \nIn case some students desire to use other tools or want to work in another environment different than Windows, detailed information is provided on [raylib Wiki](https://github.com/raysan5/raylib/wiki) to configure raylib on multiple environments, including [macOS](https://github.com/raysan5/raylib/wiki/Working-on-macOS) and [GNU Linux](https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux) platforms.\n\n**Basic concept: Game loop**\n\nThe standard videogame game loop or life-cycle consist of 4 parts: **Initialization -\u003e [ Update -\u003e Draw ] -\u003e DeInitialization**\n\nThe following diagram shows this life-cycle, the related processes for every part of the cycle and some of the raylib functions involved in those processes:\n\n![raylib Game Loop](images/raylib_game_loop_full.png)\n\n**Basic concept: Graphic Pipeline**\n\nUnderstanding the Graphics Pipeline is very important to understand the processes that happen in a computer to generate one-frame of the game. Despite it could be a quite advanced topic to go into detail, here it is a general diagram of the process:\n\n![Graphics pipeline](images/graphics_pipeline.png)\n\n**Basic concept: Screens management**\n\nTo manage the different screens for our game we have multiple options, we will start with the most simple one, based in game states tracked by a simple enum.\n\nOn our game loop (Update/Draw) we will just check for current game state and we will Update/Draw required data.\n\nRecommended [raylib examples](http://www.raylib.com/examples.html) to check:\n - [core_basic_window](http://www.raylib.com/examples/core/loader.html?name=core_basic_window) - simple code showing a videogame life cycle\n - [core_basic_screen_manager](https://github.com/raysan5/raylib/blob/master/examples/core/core_basic_screen_manager.c) - basic screens management structure\n \n\n### Lesson 02: Draw basic shapes (circle, rectangle)\n\n*Lesson code file to review: [02_blocks_game_drawing.c](lessons/02_blocks_game_drawing.c)*\n\nTo draw basic shapes, raylib provides the following functions:\n```c\nvoid DrawPixel(int posX, int posY, Color color);\nvoid DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color color);\nvoid DrawCircle(int centerX, int centerY, float radius, Color color);\nvoid DrawCircleLines(int centerX, int centerY, float radius, Color color);\nvoid DrawRectangle(int posX, int posY, int width, int height, Color color);\nvoid DrawRectangleLines(int posX, int posY, int width, int height, Color color);\n```\nMost of those functions are self explanatory, they must be called in the draw part of the game loop, between `BeginDrawing()` and `EndDrawing()`. User needs to provide the drawing position (x, y), size and color. Just note that in case of rectangle-shapes drawing origin is upper-left corner while drawing circle-shapes origin is set in the center of the circle.\n\nRecommended [raylib examples](http://www.raylib.com/examples.html) to check:\n - [shapes_basic_shapes](http://www.raylib.com/examples/shapes/loader.html?name=shapes_basic_shapes) - basic shapes drawing\n - [shapes_logo_raylib](http://www.raylib.com/examples/shapes/loader.html?name=shapes_logo_raylib) - raylib logo drawn using shapes\n\n\n### Lesson 03: Inputs management (keyboard, mouse)\n\n*Lesson code file to review: [03_blocks_game_inputs.c](lessons/03_blocks_game_inputs.c)*\n\nTo manage inputs, raylib provides a set of functions to detect keyboard and mouse current state:\n```c\nbool IsKeyPressed(int key);               // Detect if a key has been pressed once\nbool IsKeyDown(int key);                  // Detect if a key is being pressed\nbool IsKeyReleased(int key);              // Detect if a key has been released once\nbool IsKeyUp(int key);                    // Detect if a key is NOT being pressed\n    \nbool IsMouseButtonPressed(int button);    // Detect if a mouse button has been pressed once\nbool IsMouseButtonDown(int button);       // Detect if a mouse button is being pressed\nbool IsMouseButtonReleased(int button);   // Detect if a mouse button has been released once\nbool IsMouseButtonUp(int button);         // Detect if a mouse button is NOT being pressed\nint GetMouseX(void);                      // Returns mouse position X\nint GetMouseY(void);                      // Returns mouse position Y\nVector2 GetMousePosition(void);           // Returns mouse position XY\n```\nThis set of functions can be used in the `update` part of the game loop to check **if** one key or button has been pressed (or is being pressed in that frame).  \n\nRecommended [raylib examples](http://www.raylib.com/examples.html) to check:\n - [core_input_keys](http://www.raylib.com/examples/core/loader.html?name=core_input_keys) - keyboard inputs check\n - [core_input_mouse](http://www.raylib.com/examples/core/loader.html?name=core_input_mouse) - mouse inputs check\n\n\n### Lesson 04: Collision detection and resolution\n\n*Lesson code file to review: [04_blocks_game_collisions.c](lessons/04_blocks_game_collisions.c)*\n\nTo check collisions between simple shapes (circle, rectangle), raylib provides the following functions:\n```c\nbool CheckCollisionRecs(Rectangle rec1, Rectangle rec2);                                    // Check collision between two rectangles\nbool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2); // Check collision between two circles\nbool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec);                  // Check collision between circle and rectangle\n```\nThose functions return *true* if the involved rectangles/circles collide, is up to the user to resolve that collision in an appropiate way. Keep always in mind that collisions in games are always treatened as two separate parts: **detection** and **resolution**.\n\n\n### Lesson 05: Textures loading and drawing\n\n*Lesson code file to review: [05_blocks_game_textures.c](lessons/05_blocks_game_textures.c)*\n\nActually texture loading and drawing is a quite complex process: \n\nFirst, the image file is loaded, image data is usually decompressed and decodified (.png, .jpg) to obtain a plain array of pixel data; every pixel can be interpreted with different pixel formats (8bit, 16bit, 32bit...) but usually raylib translates that data to RGBA 32Bit (4 channels - RedGrenBlueAlpha, 8bit per channel). Image data is loaded into RAM.\n\nSecond, that image data must be uploaded to VRAM memory (GPU) to be used on screen rendering. \n\nThird, when drawing a texture to screen, texture is actually pasted over a quad (two triangles structure) and processed to display on the screen; that processing occurs in a per-fragment basis... think about it like a per pixel or sub-pixel processing, placing every fragment on the final canvas.\n\nraylib provides multiple functions to deal with textures an images, depending on the intended use of the data, user can choose the right one; for example, most of the time, images will be loaded as textures to be displayed on screen but image data can also be used to generate 3d models, like in the case of [heightmaps](https://www.raylib.com/examples/models/loader.html?name=models_heightmap).\n\nTo load and draw textures, raylib provides the following functions:\n```c\nTexture2D LoadTexture(const char *fileName);       // Load an image file as texture into GPU memory\nvoid UnloadTexture(Texture2D texture);             // Unload texture from GPU memory\n\nvoid DrawTexture(Texture2D texture, int posX, int posY, Color tint); // Draw a texture in the canvas\n```\n\nRecommended [raylib examples](http://www.raylib.com/examples.html) to check:\n - [textures_logo_raylib](http://www.raylib.com/examples/textures/loader.html?name=textures_logo_raylib) - texture loading and drawing\n - [textures_rectangle](http://www.raylib.com/examples/textures/loader.html?name=textures_rectangle) - texture loading and piece drawing\n\n\n### Lesson 06: Fonts loading and text drawing\n\n*Lesson code file to review: [06_blocks_game_text.c](lessons/06_blocks_game_text.c)*\n\nTo draw text, raylib loads a default font on `InitWindow()`, that font is used when drawing text with:\n```c\nvoid DrawText(const char *text, int posX, int posY, int fontSize, Color color);\n```\nBut raylib users can also load custom fonts, raylib support multiple fonts formats, including TTF format and BMFonts. To load custom fonts and draw with them, use the following functions:\n```c\nFont LoadFont(const char *fileName);         // Load a Font image into GPU \nvoid UnloadFont(Font font);                  // Unload Font from GPU memory\n\nvoid DrawTextEx(Font font, const char* text, Vector2 position, int fontSize, int spacing, Color tint);\n```\n\nRecommended [raylib examples](http://www.raylib.com/examples.html) to check:\n - [text_sprite_fonts](http://www.raylib.com/examples/text/loader.html?name=text_sprite_fonts) - sprite fonts loading and drawing\n - [text_bmfonts_ttf](http://www.raylib.com/examples/text/loader.html?name=text_bmfont_ttf) - bmfonts and ttf fonts loading\n - [text_writing_anim](http://www.raylib.com/examples/text/loader.html?name=text_writing_anim) - text writting animation effect\n\n\n### Lesson 07: Sounds and music loading and playing\n\n*Lesson code file to review: [07_blocks_game_audio.c](lessons/07_blocks_game_audio.c)*\n\nTo deal with audio on raylib, first of all, audio device must be initialized. To manage audio device, use the following functions:\n```c\nvoid InitAudioDevice(void);                 // Initialize audio device and context\nvoid CloseAudioDevice(void);                // Close the audio device and context (and music stream)\n```\nTo load and play sounds, raylib provides the following functions:\n```c\nSound LoadSound(const char *fileName);      // Load sound from file into memory\nvoid UnloadSound(Sound sound);              // Unload sound from memory\n\nvoid PlaySound(Sound sound);                // Play a sound\nvoid PauseSound(Sound sound);               // Pause a sound\nvoid ResumeSound(Sound sound);              // Resume a paused sound\nvoid StopSound(Sound sound);                // Stop playing a sound\n```\nTo load and stream music, raylib provides the following functions:\n```c\nMusic LoadMusicStream(const char *fileName);    // Load music stream from file\nvoid UnloadMusicStream(Music music);            // Unload music stream\n\nvoid UpdateMusicStream(Music music);            // Update buffers for music streaming\nvoid PlayMusicStream(Music music);              // Start music playing\nvoid PauseMusicStream(Music music);             // Pause music playing\nvoid ResumeMusicStream(Music music);            // Resume playing paused music\nvoid StopMusicStream(Music music);              // Stop music playing\n```\n\nRecommended [raylib examples](http://www.raylib.com/examples.html) to check:\n - [audio_sound_loading](http://www.raylib.com/examples/audio/loader.html?name=audio_sound_loading) - sounds loading and playing\n - [audio_music_stream](http://www.raylib.com/examples/audio/loader.html?name=audio_music_stream) - music loading and streaming\n\n\n## Getting help \nIt's recommended to join [raylib Discord community](https://discord.gg/raylib) to ask other developers and get help from the community or just showcase your creations.\n\n## License\n\nThis lecture is licensed under a \u003ca rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc/4.0/\"\u003eCreative Commons Attribution-NonCommercial 4.0 International License\u003c/a\u003e.\n\nLessons code is licensed under an unmodified zlib/libpng license.\n\nCheck [LICENSE](LICENSE) for further details.\n\n*Copyright (c) 2017-2022 Ramon Santamaria ([@raysan5](https://twitter.com/raysan5))*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraysan5%2Fraylib-intro-course","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraysan5%2Fraylib-intro-course","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraysan5%2Fraylib-intro-course/lists"}