├── 3D ├── Create_Custom_Cube_Mesh.c ├── FPS_-_Generate_CubeStructure.c ├── FPS_50x50CubeGround.c ├── FPS_CameraInCubedBox.c ├── FPS_Custom_Camera.c ├── FPS_Shoot_Bullet.c ├── FPS_ShootatBoxTarget.c ├── Function_BoxCollision3d.c └── Function_SphereBoxCollision3d.c ├── Beginners_-_3_DimensionalArray.c ├── Beginners_-_Array_Of_Strings.c ├── Beginners_-_Create_Sprite_from_array.c ├── Beginners_-_CreateandDrawinside_Texture.c ├── Beginners_-_DrawTexturePro_RectsScaleOrigin.c ├── Beginners_-_Drawtext_integers.c ├── Beginners_-_Enum.c ├── Beginners_-_FormatText.c ├── Beginners_-_GetImageData.c ├── Beginners_-_GetKeyPressed_Buffer.c ├── Beginners_-_GetMonitorWidth_Height.c ├── Beginners_-_GetMouseX_GetMouseY.c ├── Beginners_-_GetScreenWidthHeight.c ├── Beginners_-_GetTime.c ├── Beginners_-_Goto_Label.c ├── Beginners_-_Image_Perlin.c ├── Beginners_-_LoadFileText_SaveFileText.c ├── Beginners_-_ModifyMultiDArrayFunction.c ├── Beginners_-_MouseOrKeyDown.c ├── Beginners_-_Mouse_Position_and_DrawText.c ├── Beginners_-_Pass_Array_Function.c ├── Beginners_-_Player_Struct.c ├── Beginners_-_Print_DebugConsole.c ├── Beginners_-_RectangleCollision.c ├── Beginners_-_ScissorMode.c ├── Beginners_-_SetClipboardText.c ├── Beginners_-_SetClipboard_mergeintegers.c ├── Beginners_-_SetClipboard_strcat.c ├── Beginners_-_Sizeof_array_size.c ├── Beginners_-_Sprite_RotationScaling.c ├── Beginners_-_Stack_Struct_Array.c ├── Beginners_-_String_To_Integer.c ├── Beginners_-_String_To_Integers.c ├── Beginners_-_String_functions.c ├── Beginners_-_String_inside_char.c ├── Beginners_-_StructDesignatedInitializer.c ├── Beginners_-_StructStackListFunction.c ├── Beginners_-_Struct_in_Struct.c ├── Beginners_-_Structs_arrays2.c ├── Beginners_-_TakeScreenshot.c ├── Beginners_-_Using_Color.c ├── Beginners_-_Vector2.c ├── Beginners_-_cos_and_sin.c ├── Beginners_-_ifelse_One_Line.c ├── Beginners_-_sizeof_variablesmemory.c ├── Beginners_-_strcpy_struct_char.c ├── Beginners_-_switch_default.c ├── Beginners_-_tilemap_minimum.c ├── Beginners_-_voidFunctions.c ├── Books ├── GenAlg_MachL │ ├── README.TXT │ ├── Swarm01.c │ └── Swarm02.c ├── MathGraphicsGames │ ├── Bresenham_filledcircle.c │ └── bresenham_circle.c └── README.TXT ├── Collision_-_CircleRectCollide.c ├── Collision_-_Get_Lines_Intersect.c ├── Collision_-_LinesegCircleCollide.c ├── Collision_-_PointTileMAPCollide.c ├── Collision_-_PolyvsPoly_Collide.c ├── Collision_-_RectTileMAPCollide.c ├── Collision_-_rectsoverlap.c ├── Empty_Template.c ├── Example_-_2D_ShootBullets.c ├── Example_-_Additive_Blend_Smoke_trail.c ├── Example_-_AiRadar_movetotarget.c ├── Example_-_ArrayToCode-Paste.c ├── Example_-_Bresenham_oval_array.c ├── Example_-_BruteForceCircleFill2.c ├── Example_-_BruteForceCirclefill.c ├── Example_-_Collision_map.c ├── Example_-_Flood_Path_Map.c ├── Example_-_MapSmoothplayer.c ├── Example_-_MiniMap.c ├── Example_-_Orientation_PointvsLine.c ├── Example_-_PlayerJumping.c ├── Example_-_Rainbow_Backgrounds.c ├── Example_-_Rayio.c ├── Example_-_Switch_array_hills.c ├── Example_-_Turret_TurnToTarget.c ├── File_-_ReadAndWrite_Array.c ├── File_-_ReadDirIntoCharArray.c ├── File_-_fopen_writefile.c ├── Function_-_float_random.c ├── Functions_-_Clamp.c ├── Functions_-_angledifference.c ├── Functions_-_distance_EuclMan.c ├── Functions_-_drawroundedrect.c ├── Functions_-_getangle.c ├── Functions_-_scanlinefill_bresenhamline.c ├── Gui └── Simple_message_window.c ├── ProcGen ├── Doors_Based_Dungeon_Map.c ├── DrawColoredPillar01.c ├── GianaRect.c ├── GianaRectCOLOR.c ├── GrowZonesProcess.c ├── Heightmap_onesideofline.c ├── Hill_Algorithm_2dMap_Height.c ├── Islands_caves_BandW.c ├── OceanLands.c ├── Random_Rect_Edges_mapgenerator.c ├── Texture_Stone6.c ├── WaveFunctionCollapse.c ├── WaveFunctionCollapse_Commented.c ├── WaveFunctionCollapse_var2.c ├── Xtexture.c ├── pattern_map_generator.c ├── wip_-_infinite_scroll.c └── wip_-_infinitemap.c ├── README.md ├── RTS ├── 2UnitsMoveAside.c ├── FlowFieldTest.c ├── VectorForceObject.c ├── VectorForceObjectSteering.c └── Vector_Force_Object_Tiles.c ├── Remakes └── Morrowind_CharacterInventory.c ├── Scripts └── BatchgifToSpriteSheet.c ├── Space2d └── Create_Rotate_ship_center.c ├── SpriteEditor ├── Example_-_ClipboardArrayToImage.c ├── Template_-_Palettes.c ├── drawsprite_template.c ├── grid_rotate_interpolate.c ├── gridrotate.c └── spriteeditor.c ├── Template_-_BreathFDist_TileMap.c ├── Template_-_Map_BreathFdist_Smooth.c ├── ai ├── AgentsCoverHeatmap.c ├── AgentsCoverHeatmapGFX.c ├── Example_-_Agents_ChaseDoorPath.c ├── Example_-_Breadcrumb.c ├── Example_-_MakePathFloodFill.c ├── Example_-_Pattern_Movement.c ├── ExpandingGridFloodFill.c ├── GeneticAlgorithm_BoardWarSimulation.c ├── GeneticAlgorithm_BoardWarSimulationMOD.c ├── SimulateRandomAvoidCollision │ ├── README.MD │ ├── resources │ │ ├── spacerocks.png │ │ └── spaceships.png │ ├── spacesimulate.c │ ├── spacesimulate.exe │ ├── spacesimulateMult.c │ └── spacesimulateMult.exe ├── StepByStep_Dijkstra_Maps.c ├── Tanks │ ├── README.MD │ ├── resources │ │ ├── sprites.png │ │ └── tiles.png │ ├── tanks.7z │ ├── tanks.c │ └── tanks.exe ├── Whiskers_agents_tilemap.c ├── Whiskers_agents_tilemap_v2.c ├── Whiskers_agents_tilemap_v3.c ├── Whiskers_agents_tilemap_v4.c └── racing │ ├── README.MD │ ├── racing.c │ ├── racing.exe │ ├── racing_situation1.c │ └── racing_situation1.exe ├── effects ├── CopperBars.c ├── ScreenCircleTransitionCLEAN.c ├── ScreenTransitionCircle.c └── explosions_01.c ├── games ├── DoubleJointed │ ├── README.MD │ ├── doublejointed.c │ ├── doublejointed.exe │ └── resources │ │ ├── Mrskelly.png │ │ └── Onedragon.png ├── DoubleJointed_Step3 │ ├── README.MD │ ├── doublejointed.c │ ├── doublejointed.exe │ └── resources │ │ ├── Mrskelly.png │ │ └── Onedragon.png ├── DoubleJointed_step2 │ ├── README.MD │ ├── doublejointed.c │ ├── doublejointed.exe │ └── resources │ │ ├── Mrskelly.png │ │ └── Onedragon.png ├── SlideLaser.c ├── SlideLaser_lvl2.c ├── addamsfamily.c ├── blockshooter │ ├── block_part1.c │ ├── block_part2.c │ ├── block_part3.c │ ├── block_part4.c │ ├── block_part5.c │ ├── block_part6.c │ └── block_part7-final.c ├── bubblebobble.c ├── wip - spiderVSman.c └── wip-DudeSpaceMining.c └── los └── positiontogridpositions.c /3D/FPS_50x50CubeGround.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | #include 4 | 5 | 6 | int main(void) 7 | { 8 | // Initialization 9 | //-------------------------------------------------------------------------------------- 10 | const int screenWidth = 800; 11 | const int screenHeight = 450; 12 | 13 | InitWindow(screenWidth, screenHeight, "raylib example."); 14 | 15 | // We generate a checked image for texturing 16 | Image checked = GenImageChecked(2, 2, 1, 1, RED, GREEN); 17 | Texture2D texture = LoadTextureFromImage(checked); 18 | UnloadImage(checked); 19 | 20 | Model model = { 0 }; 21 | model = LoadModelFromMesh(GenMeshCube(1.0f, 1.0f, 1.0f)); 22 | 23 | // Set checked texture as default diffuse component for all models material 24 | model.materials[0].maps[MAP_DIFFUSE].texture = texture; 25 | 26 | // Define the camera to look into our 3d world 27 | Camera camera = { { 5.0f, 5.0f, 5.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 }; 28 | 29 | 30 | SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set camera mode 31 | //SetCameraMode(camera, CAMERA_ORBITAL); // Set a orbital camera mode 32 | 33 | 34 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 35 | //-------------------------------------------------------------------------------------- 36 | 37 | // Main game loop 38 | while (!WindowShouldClose()) // Detect window close button or ESC key 39 | { 40 | // Update 41 | //---------------------------------------------------------------------------------- 42 | UpdateCamera(&camera); // Update internal camera and our camera 43 | 44 | //---------------------------------------------------------------------------------- 45 | // Draw 46 | //---------------------------------------------------------------------------------- 47 | BeginDrawing(); 48 | 49 | ClearBackground(RAYWHITE); 50 | 51 | BeginMode3D(camera); 52 | 53 | for(int x=0;x<50;x++){ 54 | for(int z=0;z<50;z++){ 55 | Vector3 position; 56 | position.x = x; 57 | position.y = 0; 58 | position.z = z; 59 | DrawModel(model, position, 1.0f, WHITE); 60 | } 61 | } 62 | 63 | EndMode3D(); 64 | 65 | DrawFPS(0,0); 66 | 67 | 68 | EndDrawing(); 69 | //---------------------------------------------------------------------------------- 70 | } 71 | 72 | // De-Initialization 73 | UnloadTexture(texture); // Unload texture 74 | 75 | // Unload models data (GPU VRAM) 76 | UnloadModel(model); 77 | 78 | //-------------------------------------------------------------------------------------- 79 | CloseWindow(); // Close window and OpenGL context 80 | //-------------------------------------------------------------------------------------- 81 | 82 | return 0; 83 | 84 | 85 | } 86 | 87 | -------------------------------------------------------------------------------- /Beginners_-_3_DimensionalArray.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | 5 | int main(void) 6 | { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const int screenWidth = 800; 10 | const int screenHeight = 450; 11 | 12 | InitWindow(screenWidth, screenHeight, "raylib example."); 13 | 14 | // We set up our 3 dimensional array here. It is a int array. 15 | int map[10][10][10] = {0}; // the ={} means all the starting values are set to 0. 16 | 17 | // Here we put some values inside the array. 18 | map[0][0][0] = 10; 19 | map[9][0][0] = 20; // With a setup size of 10 the maximum slot to be used is 9! 20 | map[0][0][9] = 30; 21 | map[9][0][9] = 40; 22 | 23 | // Boolean map. Only true or false. 24 | bool boolmap[10][10][10] = {false}; 25 | boolmap[1][1][2] = true; 26 | 27 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 28 | //-------------------------------------------------------------------------------------- 29 | 30 | // Main game loop 31 | while (!WindowShouldClose()) // Detect window close button or ESC key 32 | { 33 | // Update 34 | //---------------------------------------------------------------------------------- 35 | 36 | 37 | //---------------------------------------------------------------------------------- 38 | // Draw 39 | //---------------------------------------------------------------------------------- 40 | BeginDrawing(); 41 | 42 | ClearBackground(RAYWHITE); 43 | 44 | // Here we show the contents of the 3 dimensional array on the screen. 45 | DrawText(FormatText("map[0][0][0]: %i",map[0][0][0]),100,100,20,BLACK); 46 | DrawText(FormatText("map[9][0][0]: %i",map[9][0][0]),100,120,20,BLACK); 47 | DrawText(FormatText("map[0][0][9]: %i",map[0][0][9]),100,140,20,BLACK); 48 | DrawText(FormatText("map[9][0][9]: %i",map[9][0][9]),100,160,20,BLACK); 49 | DrawText(FormatText("default ={0} slot of map[1][1][1]: %i",map[1][1][1]),100,180,20,BLACK); 50 | 51 | // Check if boolmap[1][1][2] = true or false. 52 | if(boolmap[1][1][2]==true) 53 | { 54 | DrawText("boolmap[1][1][2] set to true.",100,200,20,BLACK); 55 | }else{ 56 | DrawText("boolmap[1][1][2] set to false.",100,200,20,BLACK); 57 | } 58 | 59 | 60 | EndDrawing(); 61 | //---------------------------------------------------------------------------------- 62 | } 63 | 64 | // De-Initialization 65 | //-------------------------------------------------------------------------------------- 66 | CloseWindow(); // Close window and OpenGL context 67 | //-------------------------------------------------------------------------------------- 68 | 69 | return 0; 70 | 71 | 72 | } 73 | -------------------------------------------------------------------------------- /Beginners_-_Array_Of_Strings.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | #include "string.h" 4 | 5 | #define MAX_ITEMS 10 6 | #define MAX_ITEMSSSIZE 32 7 | 8 | int main(void) 9 | { 10 | // Initialization 11 | //-------------------------------------------------------------------------------------- 12 | const int screenWidth = 800; 13 | const int screenHeight = 450; 14 | 15 | InitWindow(screenWidth, screenHeight, "raylib example."); 16 | 17 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 18 | //-------------------------------------------------------------------------------------- 19 | // Maxim number of items here is 9. End with 'End' 20 | char myitems[MAX_ITEMS][MAX_ITEMSSSIZE] = { 21 | "Sword", 22 | "Shield", 23 | "Axe", 24 | "Helmet", 25 | "End" 26 | }; 27 | 28 | // Main game loop 29 | while (!WindowShouldClose()) // Detect window close button or ESC key 30 | { 31 | // Update 32 | //---------------------------------------------------------------------------------- 33 | 34 | 35 | //---------------------------------------------------------------------------------- 36 | // Draw 37 | //---------------------------------------------------------------------------------- 38 | BeginDrawing(); 39 | 40 | ClearBackground(RAYWHITE); 41 | 42 | // Draw the items on the screen and exit if the item is "End" 43 | DrawText("Inventory:",70,80,20,BLACK); 44 | for(int i=0;i // Required for: free() 4 | 5 | // 6 | // How to draw into a image and then read the image data and use that. 7 | // 8 | 9 | int main(void) 10 | { 11 | // Initialization 12 | //-------------------------------------------------------------------------------------- 13 | const int screenWidth = 800; 14 | const int screenHeight = 450; 15 | 16 | InitWindow(screenWidth, screenHeight, "raylib example."); 17 | 18 | // Create a Perlin Image 19 | Image tempImage = GenImageColor(32,32,BLACK); 20 | ImageDrawCircle(&tempImage,16,16,10,RED); 21 | Color *mapPixels = GetImageData(tempImage); 22 | 23 | // We will put the image data from the rectangle in this map. 24 | int map[32][32] = {0}; 25 | 26 | for (int y = 0; y < tempImage.height; y++) 27 | { 28 | for (int x = 0; x < tempImage.width; x++) 29 | { 30 | if ((mapPixels[y*tempImage.width + x].r != 0)){ // Collision: if other than 0. 31 | map[x][y] = 1; 32 | } 33 | } 34 | } 35 | 36 | 37 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 38 | //-------------------------------------------------------------------------------------- 39 | 40 | // Main game loop 41 | while (!WindowShouldClose()) // Detect window close button or ESC key 42 | { 43 | // Update 44 | //---------------------------------------------------------------------------------- 45 | 46 | //---------------------------------------------------------------------------------- 47 | // Draw 48 | //---------------------------------------------------------------------------------- 49 | BeginDrawing(); 50 | 51 | ClearBackground(RAYWHITE); 52 | 53 | for(int y=0;y<32;y++){ 54 | for(int x=0;x<32;x++){ 55 | if(map[x][y]==1)DrawRectangle(x*16,y*8,16,8,RED); 56 | } 57 | } 58 | 59 | EndDrawing(); 60 | //---------------------------------------------------------------------------------- 61 | } 62 | 63 | // De-Initialization 64 | //-------------------------------------------------------------------------------------- 65 | free(mapPixels); // Unload color array 66 | UnloadImage(tempImage); // Unload image from RAM 67 | CloseWindow(); // Close window and OpenGL context 68 | //-------------------------------------------------------------------------------------- 69 | 70 | return 0; 71 | 72 | 73 | } 74 | -------------------------------------------------------------------------------- /Beginners_-_GetKeyPressed_Buffer.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | 5 | int main(void) 6 | { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const int screenWidth = 800; 10 | const int screenHeight = 450; 11 | 12 | InitWindow(screenWidth, screenHeight, "raylib example."); 13 | 14 | SetTargetFPS(5); // Set our game to run at 5 frames-per-second 15 | //-------------------------------------------------------------------------------------- 16 | 17 | int keypressedcount=0; 18 | // Main game loop 19 | while (!WindowShouldClose()) // Detect window close button or ESC key 20 | { 21 | // Update 22 | //---------------------------------------------------------------------------------- 23 | 24 | // See if the keyboard has been used. 25 | int key = GetKeyPressed(); // read/remove key from buffer. 26 | // Here we count how many keys are inside the buffer. (set framerate to low for effect!) 27 | int len = 0; 28 | while(key>0){ 29 | len++; 30 | key = GetKeyPressed();// get/remove key from buffer. 31 | } 32 | 33 | //---------------------------------------------------------------------------------- 34 | // Draw 35 | //---------------------------------------------------------------------------------- 36 | BeginDrawing(); 37 | 38 | ClearBackground(RAYWHITE); 39 | 40 | // Draw our info. 41 | DrawText("Quickly hammer on the keyboard to fill up the keyboard buffer.",100,200,20,GRAY); 42 | DrawText(FormatText("GetKeyPressed() buffer length : %i",len),100,100,20,RED); 43 | 44 | 45 | EndDrawing(); 46 | //---------------------------------------------------------------------------------- 47 | } 48 | 49 | // De-Initialization 50 | //-------------------------------------------------------------------------------------- 51 | CloseWindow(); // Close window and OpenGL context 52 | //-------------------------------------------------------------------------------------- 53 | 54 | return 0; 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /Beginners_-_GetMonitorWidth_Height.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | 5 | int main(void) 6 | { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const int screenWidth = GetMonitorWidth(0); 10 | const int screenHeight = GetMonitorHeight(0); 11 | 12 | InitWindow(screenWidth, screenHeight, "raylib example."); 13 | 14 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 15 | //-------------------------------------------------------------------------------------- 16 | 17 | // Main game loop 18 | while (!WindowShouldClose()) // Detect window close button or ESC key 19 | { 20 | // Update 21 | //---------------------------------------------------------------------------------- 22 | 23 | 24 | //---------------------------------------------------------------------------------- 25 | // Draw 26 | //---------------------------------------------------------------------------------- 27 | BeginDrawing(); 28 | 29 | ClearBackground(RAYWHITE); 30 | DrawText("Press Escape to end..",100,400,120,GRAY); 31 | 32 | EndDrawing(); 33 | //---------------------------------------------------------------------------------- 34 | } 35 | 36 | // De-Initialization 37 | //-------------------------------------------------------------------------------------- 38 | CloseWindow(); // Close window and OpenGL context 39 | //-------------------------------------------------------------------------------------- 40 | 41 | return 0; 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /Beginners_-_GetMouseX_GetMouseY.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | int main(void) 5 | { 6 | // Initialization 7 | //-------------------------------------------------------------------------------------- 8 | const int screenWidth = 800; 9 | const int screenHeight = 450; 10 | 11 | InitWindow(screenWidth, screenHeight, "raylib example."); 12 | 13 | 14 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 15 | //-------------------------------------------------------------------------------------- 16 | 17 | // Main game loop 18 | while (!WindowShouldClose()) // Detect window close button or ESC key 19 | { 20 | // Update 21 | //---------------------------------------------------------------------------------- 22 | 23 | //---------------------------------------------------------------------------------- 24 | // Draw 25 | //---------------------------------------------------------------------------------- 26 | BeginDrawing(); 27 | 28 | ClearBackground(RAYWHITE); 29 | 30 | DrawText(FormatText("GetMouseX() : %i",GetMouseX()),100,100,20,BLACK); 31 | DrawText(FormatText("GetMouseY() : %i",GetMouseY()),100,120,20,BLACK); 32 | 33 | 34 | EndDrawing(); 35 | //---------------------------------------------------------------------------------- 36 | } 37 | 38 | // De-Initialization 39 | //-------------------------------------------------------------------------------------- 40 | CloseWindow(); // Close window and OpenGL context 41 | //-------------------------------------------------------------------------------------- 42 | 43 | return 0; 44 | 45 | 46 | } 47 | 48 | -------------------------------------------------------------------------------- /Beginners_-_GetScreenWidthHeight.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | 5 | int main(void) 6 | { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const int screenWidth = 800; 10 | const int screenHeight = 450; 11 | 12 | InitWindow(screenWidth, screenHeight, "raylib example."); 13 | 14 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 15 | //-------------------------------------------------------------------------------------- 16 | 17 | // Main game loop 18 | while (!WindowShouldClose()) // Detect window close button or ESC key 19 | { 20 | // Update 21 | //---------------------------------------------------------------------------------- 22 | 23 | 24 | //---------------------------------------------------------------------------------- 25 | // Draw 26 | //---------------------------------------------------------------------------------- 27 | BeginDrawing(); 28 | 29 | ClearBackground(RAYWHITE); 30 | 31 | DrawText(FormatText("GetScreenWidth() : %i",GetScreenWidth()),100,100,20,GRAY); 32 | DrawText(FormatText("GetScreenHeight() : %i",GetScreenHeight()),100,120,20,GRAY); 33 | 34 | EndDrawing(); 35 | //---------------------------------------------------------------------------------- 36 | } 37 | 38 | // De-Initialization 39 | //-------------------------------------------------------------------------------------- 40 | CloseWindow(); // Close window and OpenGL context 41 | //-------------------------------------------------------------------------------------- 42 | 43 | return 0; 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /Beginners_-_GetTime.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | int main(void) 5 | { 6 | // Initialization 7 | //-------------------------------------------------------------------------------------- 8 | const int screenWidth = 800; 9 | const int screenHeight = 450; 10 | 11 | InitWindow(screenWidth, screenHeight, "raylib example."); 12 | 13 | 14 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 15 | //-------------------------------------------------------------------------------------- 16 | 17 | // Main game loop 18 | while (!WindowShouldClose()) // Detect window close button or ESC key 19 | { 20 | // Update 21 | //---------------------------------------------------------------------------------- 22 | 23 | //---------------------------------------------------------------------------------- 24 | // Draw 25 | //---------------------------------------------------------------------------------- 26 | BeginDrawing(); 27 | 28 | ClearBackground(RAYWHITE); 29 | 30 | // Note that time is a float = %f 31 | DrawText(FormatText("GetTime() since initlib : %f",GetTime()),100,100,20,BLACK); 32 | 33 | 34 | 35 | EndDrawing(); 36 | //---------------------------------------------------------------------------------- 37 | } 38 | 39 | // De-Initialization 40 | //-------------------------------------------------------------------------------------- 41 | CloseWindow(); // Close window and OpenGL context 42 | //-------------------------------------------------------------------------------------- 43 | 44 | return 0; 45 | 46 | 47 | } 48 | 49 | -------------------------------------------------------------------------------- /Beginners_-_Goto_Label.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | 5 | int main(void) 6 | { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const int screenWidth = 800; 10 | const int screenHeight = 450; 11 | 12 | InitWindow(screenWidth, screenHeight, "raylib example."); 13 | 14 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 15 | //-------------------------------------------------------------------------------------- 16 | 17 | // Goto label: example. 18 | // 19 | // With a goto you can jump out of nested loop immediately. 20 | 21 | 22 | int i=0; 23 | while(1){ 24 | i++; 25 | if(i>1000)goto label; 26 | } 27 | label:{}; //notice the code block that needs to be there to work. 28 | 29 | 30 | // Main game loop 31 | while (!WindowShouldClose()) // Detect window close button or ESC key 32 | { 33 | // Update 34 | //---------------------------------------------------------------------------------- 35 | 36 | 37 | //---------------------------------------------------------------------------------- 38 | // Draw 39 | //---------------------------------------------------------------------------------- 40 | BeginDrawing(); 41 | 42 | ClearBackground(RAYWHITE); 43 | 44 | DrawText("Goto example..worked!",100,100,20,DARKGRAY); 45 | 46 | EndDrawing(); 47 | //---------------------------------------------------------------------------------- 48 | } 49 | 50 | // De-Initialization 51 | //-------------------------------------------------------------------------------------- 52 | CloseWindow(); // Close window and OpenGL context 53 | //-------------------------------------------------------------------------------------- 54 | 55 | return 0; 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /Beginners_-_Image_Perlin.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | int main(void) 5 | { 6 | // Initialization 7 | //-------------------------------------------------------------------------------------- 8 | const int screenWidth = 800; 9 | const int screenHeight = 450; 10 | 11 | InitWindow(screenWidth, screenHeight, "raylib example."); 12 | 13 | // Create a Perlin Image 14 | Image perlinImage = GenImagePerlinNoise(screenWidth, screenHeight,0,0,1.5f); 15 | 16 | // Images are inside the CPU and not fast. Use Textures(GPU) for quick manipulation. 17 | 18 | 19 | Texture2D texture = { 0 }; 20 | 21 | texture = LoadTextureFromImage(perlinImage); 22 | 23 | // Unload image data (CPU RAM) 24 | UnloadImage(perlinImage); 25 | 26 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 27 | //-------------------------------------------------------------------------------------- 28 | 29 | // Main game loop 30 | while (!WindowShouldClose()) // Detect window close button or ESC key 31 | { 32 | // Update 33 | //---------------------------------------------------------------------------------- 34 | 35 | //---------------------------------------------------------------------------------- 36 | // Draw 37 | //---------------------------------------------------------------------------------- 38 | BeginDrawing(); 39 | 40 | ClearBackground(RAYWHITE); 41 | 42 | DrawTexture(texture, 0, 0, WHITE); 43 | 44 | EndDrawing(); 45 | //---------------------------------------------------------------------------------- 46 | } 47 | 48 | // De-Initialization 49 | //-------------------------------------------------------------------------------------- 50 | UnloadTexture(texture); // Unload texture from VRAM 51 | CloseWindow(); // Close window and OpenGL context 52 | //-------------------------------------------------------------------------------------- 53 | 54 | return 0; 55 | 56 | 57 | } 58 | 59 | -------------------------------------------------------------------------------- /Beginners_-_LoadFileText_SaveFileText.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | #include "string.h" 4 | 5 | int main(void) 6 | { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const int screenWidth = 800; 10 | const int screenHeight = 450; 11 | 12 | InitWindow(screenWidth, screenHeight, "raylib example."); 13 | 14 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 15 | //-------------------------------------------------------------------------------------- 16 | 17 | // We create a char with some text in it. It must end with '\0' 18 | char savethis[100]="is this allright?\0"; 19 | // Save this string as test.txt to the current folder. 20 | SaveFileText("test.txt",savethis); 21 | // Create a char to let our pointer use. 22 | static char myloadstring[128]; 23 | // Create a pointer to our char. 24 | static char *loadthis = myloadstring; 25 | // Load the text we saved previously into the loadthis. 26 | loadthis = LoadFileText("test.txt"); 27 | 28 | // Main game loop 29 | while (!WindowShouldClose()) // Detect window close button or ESC key 30 | { 31 | // Update 32 | //---------------------------------------------------------------------------------- 33 | 34 | 35 | //---------------------------------------------------------------------------------- 36 | // Draw 37 | //---------------------------------------------------------------------------------- 38 | BeginDrawing(); 39 | 40 | ClearBackground(RAYWHITE); 41 | 42 | // Draw the text from pointer char 'loadthis' to the screen. 43 | DrawText(loadthis,50,50,20,BLACK); 44 | 45 | EndDrawing(); 46 | //---------------------------------------------------------------------------------- 47 | } 48 | 49 | // De-Initialization 50 | //-------------------------------------------------------------------------------------- 51 | CloseWindow(); // Close window and OpenGL context 52 | //-------------------------------------------------------------------------------------- 53 | 54 | return 0; 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /Beginners_-_ModifyMultiDArrayFunction.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | // Let the compiler know we are using a function outside the main function. 5 | // We need to pass the size of the last dimension of the array here. 6 | void changemap(int map[][10],int x,int y); 7 | 8 | 9 | int main(void) 10 | { 11 | // Initialization 12 | //-------------------------------------------------------------------------------------- 13 | const int screenWidth = 800; 14 | const int screenHeight = 450; 15 | 16 | InitWindow(screenWidth, screenHeight, "raylib example."); 17 | 18 | int map[10][10] = {0}; 19 | changemap(map,9,9); 20 | 21 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 22 | //-------------------------------------------------------------------------------------- 23 | 24 | // Main game loop 25 | while (!WindowShouldClose()) // Detect window close button or ESC key 26 | { 27 | // Update 28 | //---------------------------------------------------------------------------------- 29 | 30 | //---------------------------------------------------------------------------------- 31 | // Draw 32 | //---------------------------------------------------------------------------------- 33 | BeginDrawing(); 34 | 35 | ClearBackground(RAYWHITE); 36 | 37 | for(int y=0;y<10;y++){ 38 | for(int x=0;x<10;x++){ 39 | DrawText(FormatText("%i",map[x][y]),x*20,y*20,20,BLACK); 40 | }} 41 | 42 | EndDrawing(); 43 | //---------------------------------------------------------------------------------- 44 | } 45 | 46 | // De-Initialization 47 | //-------------------------------------------------------------------------------------- 48 | CloseWindow(); // Close window and OpenGL context 49 | //-------------------------------------------------------------------------------------- 50 | 51 | return 0; 52 | 53 | 54 | } 55 | 56 | // This is our function passed with a multi dim array 57 | // It is outside the main function. 58 | // void means it returns nothing. 59 | // We need to pass it the last dimension size 60 | void changemap(int map[][10],int x,int y){ 61 | map[x][y] = 99; 62 | } 63 | -------------------------------------------------------------------------------- /Beginners_-_MouseOrKeyDown.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | 5 | int main(void) 6 | { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const int screenWidth = 800; 10 | const int screenHeight = 450; 11 | 12 | InitWindow(screenWidth, screenHeight, "raylib example."); 13 | 14 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 15 | //-------------------------------------------------------------------------------------- 16 | 17 | // Main game loop 18 | while (!WindowShouldClose()) // Detect window close button or ESC key 19 | { 20 | // Update 21 | //---------------------------------------------------------------------------------- 22 | 23 | 24 | //---------------------------------------------------------------------------------- 25 | // Draw 26 | //---------------------------------------------------------------------------------- 27 | BeginDrawing(); 28 | 29 | ClearBackground(RAYWHITE); 30 | 31 | // Here we test is mouse button 0 or 1 or 2 is down. 32 | if(IsMouseButtonDown(0)){ 33 | DrawText("Mouse Button 0 is Down.",50,100,20,BLACK); 34 | }else{ 35 | DrawText("Mouse Button 0 is NOT Down.",50,100,20,BLACK); 36 | } 37 | if(IsMouseButtonDown(1)){ 38 | DrawText("Mouse Button 1 is Down.",50,120,20,BLACK); 39 | }else{ 40 | DrawText("Mouse Button 1 is NOT Down.",50,120,20,BLACK); 41 | } 42 | if(IsMouseButtonDown(2)){ 43 | DrawText("Mouse Button 2 is Down.",50,140,20,BLACK); 44 | }else{ 45 | DrawText("Mouse Button 2 is NOT Down.",50,140,20,BLACK); 46 | } 47 | 48 | // Here we test if the space key is down. 49 | if(IsKeyDown(KEY_SPACE)){ 50 | DrawText("KEY_SPACE is Down.",370,100,20,BLACK); 51 | }else{ 52 | DrawText("KEY_SPACE is NOT Down.",370,100,20,BLACK); 53 | } 54 | 55 | // Here we test if any key is down. 56 | // Note that the value i 5 | #include 6 | 7 | int main(void) 8 | { 9 | // Initialization 10 | //-------------------------------------------------------------------------------------- 11 | const int screenWidth = 800; 12 | const int screenHeight = 450; 13 | 14 | InitWindow(screenWidth, screenHeight, "raylib example."); 15 | 16 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 17 | //-------------------------------------------------------------------------------------- 18 | 19 | int test1=100; 20 | int test2=500; 21 | // Here we print to the console. 22 | fprintf(stderr, "testing.\n"); // '\n' is line feed 23 | fprintf(stderr, "this value here :%i\n",test1); 24 | fprintf(stderr, "this value here :%i and that value there :%i\n",test1,test2); 25 | // Main game loop 26 | while (!WindowShouldClose()) // Detect window close button or ESC key 27 | { 28 | // Update 29 | //---------------------------------------------------------------------------------- 30 | 31 | 32 | //---------------------------------------------------------------------------------- 33 | // Draw 34 | //---------------------------------------------------------------------------------- 35 | BeginDrawing(); 36 | 37 | ClearBackground(RAYWHITE); 38 | 39 | 40 | EndDrawing(); 41 | //---------------------------------------------------------------------------------- 42 | } 43 | 44 | // De-Initialization 45 | //-------------------------------------------------------------------------------------- 46 | CloseWindow(); // Close window and OpenGL context 47 | //-------------------------------------------------------------------------------------- 48 | 49 | return 0; 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /Beginners_-_RectangleCollision.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | int main(void) 5 | { 6 | // Initialization 7 | //-------------------------------------------------------------------------------------- 8 | const int screenWidth = 800; 9 | const int screenHeight = 450; 10 | 11 | InitWindow(screenWidth, screenHeight, "raylib example."); 12 | 13 | 14 | 15 | 16 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 17 | //-------------------------------------------------------------------------------------- 18 | 19 | // Main game loop 20 | while (!WindowShouldClose()) // Detect window close button or ESC key 21 | { 22 | // Update 23 | //---------------------------------------------------------------------------------- 24 | Vector2 mousePos = GetMousePosition(); 25 | //---------------------------------------------------------------------------------- 26 | // Draw 27 | //---------------------------------------------------------------------------------- 28 | BeginDrawing(); 29 | 30 | ClearBackground(RAYWHITE); 31 | 32 | // Create our first rectangle 33 | Rectangle r1; 34 | r1.x = 100; 35 | r1.y = 100; 36 | r1.width = 80; 37 | r1.height = 50; 38 | // Create our second rectangle 39 | Rectangle r2; 40 | r2.x = mousePos.x; 41 | r2.y = mousePos.y; 42 | r2.width = 50; 43 | r2.height = 50; 44 | 45 | // Draw our rectangles 46 | DrawRectangleRec(r1,BLUE); 47 | DrawRectangleRec(r2,RED); 48 | 49 | // Check collision between rectangles. 50 | if (CheckCollisionRecs(r1,r2)) 51 | { 52 | DrawText("Collision!!",0,0,20,RED); 53 | } 54 | 55 | DrawText("Example of how use rect collision.", 100, 180, 40, LIGHTGRAY); 56 | 57 | EndDrawing(); 58 | //---------------------------------------------------------------------------------- 59 | } 60 | 61 | // De-Initialization 62 | //-------------------------------------------------------------------------------------- 63 | CloseWindow(); // Close window and OpenGL context 64 | //-------------------------------------------------------------------------------------- 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /Beginners_-_ScissorMode.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | 5 | int main(void) 6 | { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const int screenWidth = 800; 10 | const int screenHeight = 450; 11 | 12 | InitWindow(screenWidth, screenHeight, "raylib example."); 13 | 14 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 15 | //-------------------------------------------------------------------------------------- 16 | 17 | // Main game loop 18 | while (!WindowShouldClose()) // Detect window close button or ESC key 19 | { 20 | // Update 21 | //---------------------------------------------------------------------------------- 22 | 23 | 24 | //---------------------------------------------------------------------------------- 25 | // Draw 26 | //---------------------------------------------------------------------------------- 27 | BeginDrawing(); 28 | 29 | ClearBackground(RAYWHITE); 30 | 31 | // Here we start the scissormode. 32 | BeginScissorMode(100,100,screenWidth-200,screenHeight-200); 33 | DrawRectangle(0,0,screenWidth,screenHeight,RED); 34 | // We need to end the scissormode to be able to draw outside that area. 35 | EndScissorMode(); 36 | DrawText("ScissorMode example.",0,0,30,GRAY); 37 | 38 | 39 | 40 | EndDrawing(); 41 | //---------------------------------------------------------------------------------- 42 | } 43 | 44 | // De-Initialization 45 | //-------------------------------------------------------------------------------------- 46 | CloseWindow(); // Close window and OpenGL context 47 | //-------------------------------------------------------------------------------------- 48 | 49 | return 0; 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /Beginners_-_SetClipboardText.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | 5 | int main(void) 6 | { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const int screenWidth = 800; 10 | const int screenHeight = 450; 11 | 12 | InitWindow(screenWidth, screenHeight, "raylib example."); 13 | 14 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 15 | //-------------------------------------------------------------------------------------- 16 | 17 | const char* output = "Test"; 18 | SetClipboardText(output); 19 | 20 | 21 | 22 | // Main game loop 23 | while (!WindowShouldClose()) // Detect window close button or ESC key 24 | { 25 | // Update 26 | //---------------------------------------------------------------------------------- 27 | 28 | 29 | //---------------------------------------------------------------------------------- 30 | // Draw 31 | //---------------------------------------------------------------------------------- 32 | BeginDrawing(); 33 | 34 | ClearBackground(RAYWHITE); 35 | 36 | DrawText("Check your clipboard buffer CTRL+V",50,100,20,DARKGRAY); 37 | 38 | EndDrawing(); 39 | //---------------------------------------------------------------------------------- 40 | } 41 | 42 | // De-Initialization 43 | //-------------------------------------------------------------------------------------- 44 | CloseWindow(); // Close window and OpenGL context 45 | //-------------------------------------------------------------------------------------- 46 | 47 | return 0; 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /Beginners_-_SetClipboard_mergeintegers.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | #include 4 | 5 | int main(void) 6 | { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const int screenWidth = 800; 10 | const int screenHeight = 450; 11 | 12 | InitWindow(screenWidth, screenHeight, "raylib example."); 13 | 14 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 15 | //-------------------------------------------------------------------------------------- 16 | 17 | char output1[16] = "Test1\n"; // new line is '\n' 18 | int i = 247593; 19 | char output2[10]; 20 | // put int into output2 21 | sprintf(output2, "%d", i); 22 | // Put output2 behind output1 23 | strcat(output1,output2); 24 | 25 | // Copy results to clipboard. 26 | SetClipboardText(output1); 27 | 28 | 29 | 30 | 31 | // Main game loop 32 | while (!WindowShouldClose()) // Detect window close button or ESC key 33 | { 34 | // Update 35 | //---------------------------------------------------------------------------------- 36 | 37 | 38 | //---------------------------------------------------------------------------------- 39 | // Draw 40 | //---------------------------------------------------------------------------------- 41 | BeginDrawing(); 42 | 43 | ClearBackground(RAYWHITE); 44 | 45 | DrawText("Check your clipboard buffer CTRL+V",50,100,20,DARKGRAY); 46 | 47 | EndDrawing(); 48 | //---------------------------------------------------------------------------------- 49 | } 50 | 51 | // De-Initialization 52 | //-------------------------------------------------------------------------------------- 53 | CloseWindow(); // Close window and OpenGL context 54 | //-------------------------------------------------------------------------------------- 55 | 56 | return 0; 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /Beginners_-_SetClipboard_strcat.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | #include 4 | 5 | int main(void) 6 | { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const int screenWidth = 800; 10 | const int screenHeight = 450; 11 | 12 | InitWindow(screenWidth, screenHeight, "raylib example."); 13 | 14 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 15 | //-------------------------------------------------------------------------------------- 16 | 17 | char output1[16] = "Test1"; 18 | char output2[16] = "Test1"; 19 | 20 | strcat(output1,output2); 21 | 22 | SetClipboardText(output1); 23 | 24 | 25 | 26 | 27 | // Main game loop 28 | while (!WindowShouldClose()) // Detect window close button or ESC key 29 | { 30 | // Update 31 | //---------------------------------------------------------------------------------- 32 | 33 | 34 | //---------------------------------------------------------------------------------- 35 | // Draw 36 | //---------------------------------------------------------------------------------- 37 | BeginDrawing(); 38 | 39 | ClearBackground(RAYWHITE); 40 | 41 | DrawText("Check your clipboard buffer CTRL+V",50,100,20,DARKGRAY); 42 | 43 | EndDrawing(); 44 | //---------------------------------------------------------------------------------- 45 | } 46 | 47 | // De-Initialization 48 | //-------------------------------------------------------------------------------------- 49 | CloseWindow(); // Close window and OpenGL context 50 | //-------------------------------------------------------------------------------------- 51 | 52 | return 0; 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /Beginners_-_Sizeof_array_size.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | void passarray(Vector2 pol[]); 5 | 6 | int main(void) 7 | { 8 | // Initialization 9 | //-------------------------------------------------------------------------------------- 10 | const int screenWidth = 800; 11 | const int screenHeight = 450; 12 | 13 | InitWindow(screenWidth, screenHeight, "raylib example."); 14 | 15 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 16 | //-------------------------------------------------------------------------------------- 17 | 18 | // Main game loop 19 | while (!WindowShouldClose()) // Detect window close button or ESC key 20 | { 21 | // Update 22 | //---------------------------------------------------------------------------------- 23 | 24 | 25 | //---------------------------------------------------------------------------------- 26 | // Draw 27 | //---------------------------------------------------------------------------------- 28 | BeginDrawing(); 29 | 30 | ClearBackground(RAYWHITE); 31 | // 32 | // Create a Vector2 array and create some points in it 33 | // 34 | Vector2 pol[3]; 35 | pol[0] = (Vector2){100,100}; 36 | pol[1] = (Vector2){20,300}; 37 | pol[2] = (Vector2){180,300}; 38 | // 39 | // Here we pass the Vector2 array into the function. 40 | passarray(pol); 41 | 42 | // Here we get the array size using sizeof. 43 | int size = 0; 44 | size = sizeof(pol)/sizeof(pol[0]); 45 | 46 | 47 | DrawText(FormatText("%i",size),10,10,20,BLACK); 48 | 49 | EndDrawing(); 50 | //---------------------------------------------------------------------------------- 51 | } 52 | 53 | // De-Initialization 54 | //-------------------------------------------------------------------------------------- 55 | CloseWindow(); // Close window and OpenGL context 56 | //-------------------------------------------------------------------------------------- 57 | 58 | return 0; 59 | 60 | 61 | } 62 | 63 | // 64 | // Fonction that takes a array of Vector2 for use in the function. 65 | void passarray(Vector2 pol[]){ 66 | // Draw a triangle. 67 | DrawTriangle(pol[0],pol[1],pol[2],RED); 68 | } 69 | -------------------------------------------------------------------------------- /Beginners_-_Sprite_RotationScaling.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | 5 | int main(void) 6 | { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const int screenWidth = 800; 10 | const int screenHeight = 450; 11 | 12 | InitWindow(screenWidth, screenHeight, "raylib example."); 13 | 14 | 15 | 16 | 17 | // Create a Image in memory 18 | RenderTexture2D target = LoadRenderTexture(32, 32); 19 | 20 | int sprite[8][8] = {{1,1,1,1,0,0,0,0}, 21 | {0,1,1,1,0,0,0,0}, 22 | {0,0,1,1,1,2,2,2}, 23 | {0,0,0,1,1,2,2,2}, 24 | {0,0,0,1,1,2,2,2}, 25 | {1,1,1,1,1,2,2,2}, 26 | {0,0,1,1,1,2,2,2}, 27 | {0,0,0,0,0,2,2,2}}; 28 | 29 | // Clear our texture(image) before entering the game loop 30 | BeginTextureMode(target); 31 | ClearBackground(BLANK); // Make the entire Sprite Transparent. 32 | EndTextureMode(); 33 | // Draw something on it. 34 | for (int y=0;y<8;y++) 35 | { 36 | for (int x=0;x<8; x++) 37 | { 38 | // Our sprite color 1 39 | if (sprite[y][x]==1) 40 | { 41 | BeginTextureMode(target); 42 | DrawRectangle(x*4,y*4,4,4,RED); 43 | EndTextureMode(); 44 | } 45 | // Our sprite color 2 46 | if (sprite[y][x]==2) 47 | { 48 | BeginTextureMode(target); 49 | DrawRectangle(x*4,y*4,4,8,BLACK); 50 | EndTextureMode(); 51 | } 52 | } 53 | } 54 | 55 | // Source rectangle (part of the texture to use for drawing) 56 | Rectangle sourceRec = { 0.0f, 0.0f, 32, 32 }; 57 | // Origin of the texture (rotation/scale point), it's relative to destination rectangle size 58 | Vector2 origin = { 16, 16 }; 59 | 60 | float rotation=0.0f; 61 | 62 | 63 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 64 | //-------------------------------------------------------------------------------------- 65 | 66 | // Main game loop 67 | while (!WindowShouldClose()) // Detect window close button or ESC key 68 | { 69 | // Update 70 | //---------------------------------------------------------------------------------- 71 | rotation+=1; 72 | if(rotation>359)rotation=0; 73 | //---------------------------------------------------------------------------------- 74 | // Draw 75 | //---------------------------------------------------------------------------------- 76 | BeginDrawing(); 77 | 78 | ClearBackground(RAYWHITE); 79 | 80 | DrawText("Sprite Creation and Rotation.", 100, 180, 40, LIGHTGRAY); 81 | 82 | DrawTexturePro(target.texture, sourceRec, (Rectangle){ GetMouseX(), GetMouseY(), 32, 32 }, origin, (float)rotation, WHITE); 83 | 84 | 85 | EndDrawing(); 86 | //---------------------------------------------------------------------------------- 87 | } 88 | 89 | // De-Initialization 90 | //-------------------------------------------------------------------------------------- 91 | UnloadRenderTexture(target); // Unload render texture 92 | //-------------------------------------------------------------------------------------- 93 | CloseWindow(); // Close window and OpenGL context 94 | //-------------------------------------------------------------------------------------- 95 | 96 | return 0; 97 | 98 | 99 | } 100 | -------------------------------------------------------------------------------- /Beginners_-_Stack_Struct_Array.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | #include 4 | 5 | #define MAX_POINTS 1000 6 | #define MAX_BATCH_ELEMENTS 8192 7 | 8 | typedef struct Points{ 9 | Vector2 position; 10 | } Points; 11 | 12 | int main(void) 13 | { 14 | // Initialization 15 | //-------------------------------------------------------------------------------------- 16 | const int screenWidth = 800; 17 | const int screenHeight = 450; 18 | 19 | InitWindow(screenWidth, screenHeight, "raylib example."); 20 | 21 | Points *mypoint = (Points *)malloc(MAX_POINTS*sizeof(Points)); // Points array 22 | 23 | int pointscount = 10; 24 | 25 | for (int i=0;i0 if the char is different. ==0 if the same. 54 | DrawText(FormatText("char lower in lower case is : %s",strlwr(lower)),100,260,20,DARKGRAY); 55 | DrawText(FormatText("char higher in higher case is : %s",strupr(higher)),100,280,20,DARKGRAY); 56 | 57 | 58 | EndDrawing(); 59 | //---------------------------------------------------------------------------------- 60 | } 61 | 62 | // De-Initialization 63 | //-------------------------------------------------------------------------------------- 64 | CloseWindow(); // Close window and OpenGL context 65 | //-------------------------------------------------------------------------------------- 66 | 67 | return 0; 68 | 69 | 70 | } 71 | -------------------------------------------------------------------------------- /Beginners_-_String_inside_char.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | 5 | int main(void) 6 | { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const int screenWidth = 800; 10 | const int screenHeight = 450; 11 | 12 | InitWindow(screenWidth, screenHeight, "raylib example."); 13 | 14 | 15 | // The last number of the char array[5] contains the ending code. 16 | char messy[6] = "hello"; 17 | // We need to set up the char that contains the text with a lenght. 18 | int lenofmessy = 6; 19 | 20 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 21 | //-------------------------------------------------------------------------------------- 22 | 23 | // Main game loop 24 | while (!WindowShouldClose()) // Detect window close button or ESC key 25 | { 26 | // Update 27 | //---------------------------------------------------------------------------------- 28 | 29 | 30 | //---------------------------------------------------------------------------------- 31 | // Draw 32 | //---------------------------------------------------------------------------------- 33 | BeginDrawing(); 34 | 35 | ClearBackground(RAYWHITE); 36 | 37 | // Here we draw the char! 38 | DrawText(messy,100,100,20,BLACK); 39 | 40 | // Draw the string(the char array) backwards. 41 | for(int i=lenofmessy-1;i>-1;i--){ 42 | DrawText(FormatText("%01c",messy[i]),100+(((lenofmessy-2)*20)-(i*20)),120,20,BLACK); 43 | 44 | } 45 | EndDrawing(); 46 | //---------------------------------------------------------------------------------- 47 | } 48 | 49 | // De-Initialization 50 | //-------------------------------------------------------------------------------------- 51 | CloseWindow(); // Close window and OpenGL context 52 | //-------------------------------------------------------------------------------------- 53 | 54 | return 0; 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /Beginners_-_StructDesignatedInitializer.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | struct unit{ 5 | int empty; 6 | bool active; 7 | int x; 8 | int y; 9 | int damage; 10 | char name[10]; 11 | }; 12 | 13 | static struct unit myUnit = {.active = true, .x = 100, .y = 200, .name="hello"}; 14 | 15 | int main(void) 16 | { 17 | // Initialization 18 | //-------------------------------------------------------------------------------------- 19 | const int screenWidth = 800; 20 | const int screenHeight = 450; 21 | 22 | InitWindow(screenWidth, screenHeight, "raylib example."); 23 | 24 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 25 | //-------------------------------------------------------------------------------------- 26 | 27 | // Main game loop 28 | while (!WindowShouldClose()) // Detect window close button or ESC key 29 | { 30 | // Update 31 | //---------------------------------------------------------------------------------- 32 | 33 | 34 | //---------------------------------------------------------------------------------- 35 | // Draw 36 | //---------------------------------------------------------------------------------- 37 | BeginDrawing(); 38 | 39 | ClearBackground(RAYWHITE); 40 | 41 | if(myUnit.active){ 42 | DrawText("Active:true",100,200,20,BLACK); 43 | } 44 | DrawText(FormatText("This should be empty : %i",myUnit.empty),100,180,20,BLACK); 45 | DrawText(FormatText("%i , %i",myUnit.x,myUnit.y),100,220,20,BLACK); 46 | DrawText(FormatText("%s",myUnit.name),100,240,20,BLACK); 47 | 48 | EndDrawing(); 49 | //---------------------------------------------------------------------------------- 50 | } 51 | 52 | // De-Initialization 53 | //-------------------------------------------------------------------------------------- 54 | CloseWindow(); // Close window and OpenGL context 55 | //-------------------------------------------------------------------------------------- 56 | 57 | return 0; 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /Beginners_-_StructStackListFunction.c: -------------------------------------------------------------------------------- 1 | // 2 | // Stack and List and other data structures are not build into the c language. 3 | // If you need to convert code that has stacks or lists you need to write or re use code 4 | // for that. 5 | // 6 | // As far as I have gotten to know Clang and sources about it you need to use 7 | // arrays for these. A stack is a array with several functions to manipulate 8 | // it. Most known are Pop And Push. With making you own stack from a array 9 | // the Push adds the data to the highest location[0..highest] in the array. You actually 10 | // need to keep track of this by a counter that holds the size of your stack. (You need to 11 | // create arrays in Clang at program start and thus need to estimate how large they might 12 | // need to be.) 13 | // A pop removes the highest location from the array and decreases the counter with one. 14 | // 15 | // You can write more functions to remove items from the middle of the list or stack. You then 16 | // need to shift or "sort" the array. 17 | 18 | #define MAXSTACKSIZE 1024 // how large a stack do we need? 19 | 20 | #include "raylib.h" 21 | 22 | // Our stack 23 | static int mystacklen=0; 24 | typedef struct stack{ 25 | int x; 26 | int y; 27 | }stack; 28 | 29 | 30 | 31 | static stack mystack[MAXSTACKSIZE]; // Here this stack is global to our program. 32 | 33 | static void push(struct stack in); 34 | static void pop(void); 35 | 36 | int main(void) 37 | { 38 | // Initialization 39 | //-------------------------------------------------------------------------------------- 40 | const int screenWidth = 800; 41 | const int screenHeight = 450; 42 | 43 | InitWindow(screenWidth, screenHeight, "raylib example."); 44 | 45 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 46 | //-------------------------------------------------------------------------------------- 47 | // Create a struct called banana and pass it to the push function. 48 | struct stack banana; 49 | banana.x = 10; 50 | banana.y = 20; 51 | push(banana); 52 | 53 | // Main game loop 54 | while (!WindowShouldClose()) // Detect window close button or ESC key 55 | { 56 | // Update 57 | //---------------------------------------------------------------------------------- 58 | if(IsKeyReleased(KEY_SPACE)){ 59 | // Another way to create and pass a struct through a function. 60 | struct stack banana={GetRandomValue(0,100),0}; 61 | push(banana); 62 | } 63 | if(IsKeyReleased(KEY_ENTER)){ 64 | pop(); 65 | } 66 | 67 | //---------------------------------------------------------------------------------- 68 | // Draw 69 | //---------------------------------------------------------------------------------- 70 | BeginDrawing(); 71 | 72 | ClearBackground(RAYWHITE); 73 | DrawText("Press space to add to stack, enter to remove",200,10,20,DARKGRAY); 74 | DrawText(FormatText("Stack size : %i",mystacklen),320,30,20,DARKGRAY); 75 | for(int i=0;i0)mystacklen-=1; 95 | } 96 | void push(struct stack in){ 97 | mystack[mystacklen] = in; 98 | mystacklen+=1; 99 | } 100 | -------------------------------------------------------------------------------- /Beginners_-_Struct_in_Struct.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | struct inventory{ 5 | bool pepper; 6 | bool salt; 7 | bool potion; 8 | }; 9 | 10 | struct aiMushroom{ 11 | int x; 12 | int y; 13 | int energy; 14 | struct inventory leftPocket; 15 | }; 16 | 17 | static struct aiMushroom myaiMushroom = {10,20,99,{true,false,true}}; 18 | 19 | int main(void) 20 | { 21 | // Initialization 22 | //-------------------------------------------------------------------------------------- 23 | const int screenWidth = 800; 24 | const int screenHeight = 450; 25 | 26 | InitWindow(screenWidth, screenHeight, "raylib example."); 27 | 28 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 29 | //-------------------------------------------------------------------------------------- 30 | 31 | // Main game loop 32 | while (!WindowShouldClose()) // Detect window close button or ESC key 33 | { 34 | // Update 35 | //---------------------------------------------------------------------------------- 36 | 37 | 38 | //---------------------------------------------------------------------------------- 39 | // Draw 40 | //---------------------------------------------------------------------------------- 41 | BeginDrawing(); 42 | 43 | ClearBackground(RAYWHITE); 44 | 45 | DrawText("The mushroom is here at :",100,180,20,BLACK); 46 | DrawText(FormatText("x: %i y: %i Energy : %i",myaiMushroom.x,myaiMushroom.y,myaiMushroom.energy),100,200,20,BLACK); 47 | if(myaiMushroom.leftPocket.pepper){ 48 | DrawText("The mushroom has pepper in his left pocket..",100,220,20,BLACK); 49 | }else{ 50 | DrawText("The mushroom has no pepper in his left pocket..",100,220,20,BLACK); 51 | } 52 | 53 | EndDrawing(); 54 | //---------------------------------------------------------------------------------- 55 | } 56 | 57 | // De-Initialization 58 | //-------------------------------------------------------------------------------------- 59 | CloseWindow(); // Close window and OpenGL context 60 | //-------------------------------------------------------------------------------------- 61 | 62 | return 0; 63 | 64 | 65 | } 66 | -------------------------------------------------------------------------------- /Beginners_-_TakeScreenshot.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | 5 | int main(void) 6 | { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const int screenWidth = 800; 10 | const int screenHeight = 450; 11 | 12 | InitWindow(screenWidth, screenHeight, "raylib example."); 13 | 14 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 15 | //-------------------------------------------------------------------------------------- 16 | 17 | // Main game loop 18 | while (!WindowShouldClose()) // Detect window close button or ESC key 19 | { 20 | // Update 21 | //---------------------------------------------------------------------------------- 22 | if(IsKeyPressed(KEY_S)){ 23 | TakeScreenshot("screenshot.png"); 24 | // Be sure to not place this function inside a loop where 25 | // it saves a screenshot every frame! 26 | } 27 | 28 | //---------------------------------------------------------------------------------- 29 | // Draw 30 | //---------------------------------------------------------------------------------- 31 | BeginDrawing(); 32 | 33 | ClearBackground(RAYWHITE); 34 | DrawText("Press key 's' to take a screenshot..",200,200,20,GRAY); 35 | 36 | EndDrawing(); 37 | //---------------------------------------------------------------------------------- 38 | } 39 | 40 | // De-Initialization 41 | //-------------------------------------------------------------------------------------- 42 | CloseWindow(); // Close window and OpenGL context 43 | //-------------------------------------------------------------------------------------- 44 | 45 | return 0; 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Beginners_-_Using_Color.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | void floodit(); 5 | 6 | int main(void) 7 | { 8 | // Initialization 9 | //-------------------------------------------------------------------------------------- 10 | const int screenWidth = 800; 11 | const int screenHeight = 450; 12 | 13 | InitWindow(screenWidth, screenHeight, "Raylib examples."); 14 | 15 | 16 | 17 | 18 | 19 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 20 | //-------------------------------------------------------------------------------------- 21 | 22 | // Main game loop 23 | while (!WindowShouldClose()) // Detect window close button or ESC key 24 | { 25 | // Update 26 | //---------------------------------------------------------------------------------- 27 | //---------------------------------------------------------------------------------- 28 | // Draw 29 | //---------------------------------------------------------------------------------- 30 | BeginDrawing(); 31 | 32 | ClearBackground(RAYWHITE); 33 | 34 | DrawText("Creating RGB colors.", 100, 180, 40, LIGHTGRAY); 35 | 36 | // (Color){Red[0..255],Green[0..255],Blue[0.255],Alpha[0.255(non transparent)]} 37 | DrawRectangle(100 +0 *1,100,64,32,(Color){255,0,0,255}); 38 | DrawRectangle(100 +64 *2,100,64,32,(Color){0,255,0,255}); 39 | DrawRectangle(100 +64 *4,100,64,32,(Color){0,0,255,255}); 40 | 41 | 42 | EndDrawing(); 43 | //---------------------------------------------------------------------------------- 44 | } 45 | 46 | // De-Initialization 47 | //-------------------------------------------------------------------------------------- 48 | CloseWindow(); // Close window and OpenGL context 49 | //-------------------------------------------------------------------------------------- 50 | 51 | return 0; 52 | 53 | 54 | } 55 | 56 | -------------------------------------------------------------------------------- /Beginners_-_Vector2.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | 5 | int main(void) 6 | { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const int screenWidth = 800; 10 | const int screenHeight = 450; 11 | 12 | InitWindow(screenWidth, screenHeight, "raylib example."); 13 | 14 | // Create a vector and set it up. 15 | Vector2 position = (Vector2){100,100}; 16 | // Create a empty vector. 17 | Vector2 position2; 18 | 19 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 20 | //-------------------------------------------------------------------------------------- 21 | 22 | // Main game loop 23 | while (!WindowShouldClose()) // Detect window close button or ESC key 24 | { 25 | // Update 26 | //---------------------------------------------------------------------------------- 27 | 28 | position2 = GetMousePosition(); 29 | 30 | //---------------------------------------------------------------------------------- 31 | // Draw 32 | //---------------------------------------------------------------------------------- 33 | BeginDrawing(); 34 | 35 | ClearBackground(RAYWHITE); 36 | 37 | DrawLine(position.x,position.y,position2.x,position2.y,RED); 38 | 39 | EndDrawing(); 40 | //---------------------------------------------------------------------------------- 41 | } 42 | 43 | // De-Initialization 44 | //-------------------------------------------------------------------------------------- 45 | CloseWindow(); // Close window and OpenGL context 46 | //-------------------------------------------------------------------------------------- 47 | 48 | return 0; 49 | 50 | 51 | } 52 | -------------------------------------------------------------------------------- /Beginners_-_cos_and_sin.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | #include // needed for cos and sin. 4 | 5 | int main(void) 6 | { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const int screenWidth = 800; 10 | const int screenHeight = 450; 11 | 12 | InitWindow(screenWidth, screenHeight, "raylib example."); 13 | 14 | Vector2 position; 15 | position.x = screenWidth/2; 16 | position.y = screenHeight/2; 17 | float angle=GetRandomValue(0,359); 18 | 19 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 20 | //-------------------------------------------------------------------------------------- 21 | 22 | // Main game loop 23 | while (!WindowShouldClose()) // Detect window close button or ESC key 24 | { 25 | // Update 26 | //---------------------------------------------------------------------------------- 27 | 28 | // cos and sin here. 29 | position.x += (float)cos(angle)*4; 30 | position.y += (float)sin(angle)*4; 31 | 32 | if(GetRandomValue(0,100)<5)angle=GetRandomValue(0,359); 33 | if(position.x>screenWidth || position.x<0 || position.y<0 || position.y>screenHeight){ 34 | position.x=screenWidth/2; 35 | position.y=screenHeight/2; 36 | } 37 | 38 | //---------------------------------------------------------------------------------- 39 | // Draw 40 | //---------------------------------------------------------------------------------- 41 | BeginDrawing(); 42 | 43 | ClearBackground(RAYWHITE); 44 | 45 | 46 | DrawCircle(position.x,position.y,20,RED); 47 | 48 | 49 | EndDrawing(); 50 | //---------------------------------------------------------------------------------- 51 | } 52 | 53 | // De-Initialization 54 | //-------------------------------------------------------------------------------------- 55 | CloseWindow(); // Close window and OpenGL context 56 | //-------------------------------------------------------------------------------------- 57 | 58 | return 0; 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /Beginners_-_ifelse_One_Line.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | 5 | int main(void) 6 | { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const int screenWidth = 800; 10 | const int screenHeight = 450; 11 | 12 | InitWindow(screenWidth, screenHeight, "raylib example."); 13 | 14 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 15 | //-------------------------------------------------------------------------------------- 16 | 17 | // Main game loop 18 | while (!WindowShouldClose()) // Detect window close button or ESC key 19 | { 20 | // Update 21 | //---------------------------------------------------------------------------------- 22 | 23 | 24 | //---------------------------------------------------------------------------------- 25 | // Draw 26 | //---------------------------------------------------------------------------------- 27 | BeginDrawing(); 28 | 29 | ClearBackground(RAYWHITE); 30 | 31 | // This is one way to use the 'if' command. If there is only 1 line after the if 32 | // Notice that the else is on the next line. 33 | if(GetMouseX()0) 71 | { 72 | x=x+1; 73 | y=y-1; 74 | p=p+(x*2)-(y*2)+5; 75 | } 76 | } 77 | } 78 | void putpixelBres(int xc, int yc, int x, int y,Color col) 79 | { 80 | DrawLine(xc+x, yc+y,xc-x, yc+y, col); 81 | DrawLine(xc-x, yc+y,xc-x, yc-y, col); //** 82 | DrawLine(xc+x, yc-y,xc+x, yc+y, col); 83 | DrawLine(xc+y, yc+x,xc-y, yc+x, col); 84 | DrawLine(xc+y, yc-x,xc-y, yc-x, col); 85 | } 86 | 87 | -------------------------------------------------------------------------------- /Books/MathGraphicsGames/bresenham_circle.c: -------------------------------------------------------------------------------- 1 | // 2 | // Bresenham circle algorithm. (centerx, centery, radius.) 3 | // 4 | // From the book - mathmatics for computer graphics and game programming. 5 | // 6 | 7 | 8 | #include "raylib.h" 9 | 10 | void circleBres(int xc, int yc, int r); 11 | void putpixelBres(int xc, int yc, int x, int y); 12 | 13 | int main(void) 14 | { 15 | // Initialization 16 | //-------------------------------------------------------------------------------------- 17 | const int screenWidth = 800; 18 | const int screenHeight = 450; 19 | 20 | InitWindow(screenWidth, screenHeight, "raylib example."); 21 | 22 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 23 | //-------------------------------------------------------------------------------------- 24 | 25 | // Main game loop 26 | while (!WindowShouldClose()) // Detect window close button or ESC key 27 | { 28 | // Update 29 | //---------------------------------------------------------------------------------- 30 | 31 | 32 | //---------------------------------------------------------------------------------- 33 | // Draw 34 | //---------------------------------------------------------------------------------- 35 | BeginDrawing(); 36 | 37 | ClearBackground(RAYWHITE); 38 | circleBres(100,100,100); 39 | 40 | EndDrawing(); 41 | //---------------------------------------------------------------------------------- 42 | } 43 | 44 | // De-Initialization 45 | //-------------------------------------------------------------------------------------- 46 | CloseWindow(); // Close window and OpenGL context 47 | //-------------------------------------------------------------------------------------- 48 | 49 | return 0; 50 | 51 | 52 | } 53 | 54 | void circleBres(int xc, int yc, int r) 55 | { 56 | int x=0; 57 | int y=r; 58 | int p=1-r; 59 | while(x<=y){ 60 | putpixelBres(xc,yc,x,y); 61 | if(p<=0){ 62 | x=x+1; 63 | y=y; 64 | p=p+(x*2)+3; 65 | }else if(p>0) 66 | { 67 | x=x+1; 68 | y=y-1; 69 | p=p+(x*2)-(y*2)+5; 70 | } 71 | } 72 | } 73 | void putpixelBres(int xc, int yc, int x, int y) 74 | { 75 | DrawPixel(xc+x, yc+y, RED); 76 | DrawPixel(xc-x, yc+y, RED); 77 | DrawPixel(xc+x, yc-y, RED); 78 | DrawPixel(xc-x, yc-y, RED); 79 | DrawPixel(xc+y, yc+x, RED); 80 | DrawPixel(xc-y, yc+x, RED); 81 | DrawPixel(xc+y, yc-x, RED); 82 | DrawPixel(xc-y, yc-x, RED); 83 | } 84 | -------------------------------------------------------------------------------- /Books/README.TXT: -------------------------------------------------------------------------------- 1 | 2 | Folder : GenAlg_MachL = Genetic Algorithms and Machine Learning for Programmers: Create AI Models and Evolve Solutions 3 | -------------------------------------------------------------------------------- /Collision_-_CircleRectCollide.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | 5 | // These are the circlerect collision function. The clamp one is needed for the circlerectcollide. 6 | static bool circlerectcollide(int cx,int cy,int cr, int rx, int ry,int rw,int rh); 7 | static float Clamp(float value, float min, float max); 8 | 9 | int main(void) 10 | { 11 | // Initialization 12 | //-------------------------------------------------------------------------------------- 13 | const int screenWidth = 800; 14 | const int screenHeight = 450; 15 | 16 | InitWindow(screenWidth, screenHeight, "raylib example."); 17 | 18 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 19 | //-------------------------------------------------------------------------------------- 20 | 21 | // Main game loop 22 | while (!WindowShouldClose()) // Detect window close button or ESC key 23 | { 24 | // Update 25 | //---------------------------------------------------------------------------------- 26 | 27 | Rectangle r=(Rectangle){GetMouseX(),GetMouseY(),128,64}; 28 | Vector2 c=(Vector2){400,200}; 29 | float cr=50; 30 | //---------------------------------------------------------------------------------- 31 | // Draw 32 | //---------------------------------------------------------------------------------- 33 | BeginDrawing(); 34 | 35 | ClearBackground(RAYWHITE); 36 | 37 | DrawRectangle(r.x,r.y,r.width,r.height,BLACK); 38 | DrawCircle(c.x,c.y,cr,BLUE); 39 | 40 | if(circlerectcollide(c.x,c.y,cr,r.x,r.y,r.width,r.height)){ 41 | DrawText("COLLISION..",20,0,30,RED); 42 | } 43 | 44 | EndDrawing(); 45 | //---------------------------------------------------------------------------------- 46 | } 47 | 48 | // De-Initialization 49 | //-------------------------------------------------------------------------------------- 50 | CloseWindow(); // Close window and OpenGL context 51 | //-------------------------------------------------------------------------------------- 52 | 53 | return 0; 54 | 55 | 56 | } 57 | 58 | bool circlerectcollide(int cx,int cy,int cr, int rx, int ry,int rw,int rh){ 59 | float closestx = Clamp(cx, rx, rx+rw); 60 | float closesty = Clamp(cy, ry, ry+rh); 61 | float distancex = cx - closestx; 62 | float distancey = cy - closesty; 63 | float distancesquared = (distancex * distancex) + (distancey * distancey); 64 | return distancesquared < (cr * cr); 65 | } 66 | 67 | // Clamp float value 68 | float Clamp(float value, float min, float max) 69 | { 70 | const float res = value < min ? min : value; 71 | return res > max ? max : res; 72 | } 73 | -------------------------------------------------------------------------------- /Collision_-_Get_Lines_Intersect.c: -------------------------------------------------------------------------------- 1 | // Segmented line vs circle collision. 2 | 3 | #include "raylib.h" 4 | 5 | bool get_line_intersect(float p0_x, float p0_y, float p1_x, float p1_y, float p2_x ,float p2_y, float p3_x, float p3_y); 6 | 7 | int main(void) 8 | { 9 | // Initialization 10 | //-------------------------------------------------------------------------------------- 11 | const int screenWidth = 800; 12 | const int screenHeight = 450; 13 | 14 | InitWindow(screenWidth, screenHeight, "raylib example."); 15 | 16 | // Create 4 vectors for 2 lines.. 17 | Vector2 line1a=(Vector2){100,100}; 18 | Vector2 line1b=(Vector2){200,200}; 19 | Vector2 line2a; 20 | Vector2 line2b; 21 | 22 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 23 | //-------------------------------------------------------------------------------------- 24 | 25 | // Main game loop 26 | while (!WindowShouldClose()) // Detect window close button or ESC key 27 | { 28 | // Update 29 | //---------------------------------------------------------------------------------- 30 | 31 | // The second line is below the mouse pointer. 32 | line2a.x = GetMouseX(); 33 | line2a.y = GetMouseY(); 34 | line2b.x = line2a.x - 100; 35 | line2b.y = line2a.y + 100; 36 | 37 | //---------------------------------------------------------------------------------- 38 | // Draw 39 | //---------------------------------------------------------------------------------- 40 | BeginDrawing(); 41 | 42 | ClearBackground(RAYWHITE); 43 | 44 | 45 | // Here we draw the first line. 46 | DrawLine(line1a.x,line1a.y,line1b.x,line1b.y,RED); 47 | // Here we draw the second line, the one below the mouse pointer. 48 | DrawLine(line2a.x,line2a.y,line2b.x,line2b.y,GREEN); 49 | 50 | // Here we check if the two lines on the screen touch each other. 51 | if(get_line_intersect(line1a.x,line1a.y,line1b.x,line1b.y,line2a.x,line2a.y,line2b.x,line2b.y)){ 52 | DrawText("Collision between lines!!",0,0,40,RED); // Let the user know there has been a collision. 53 | }else{ // If no lines touch then show a message. 54 | DrawText("Move the mouse line on the other line!!",0,0,20,BLACK); 55 | } 56 | 57 | EndDrawing(); 58 | //---------------------------------------------------------------------------------- 59 | } 60 | 61 | // De-Initialization 62 | //-------------------------------------------------------------------------------------- 63 | CloseWindow(); // Close window and OpenGL context 64 | //-------------------------------------------------------------------------------------- 65 | 66 | return 0; 67 | 68 | 69 | } 70 | 71 | // This function was originally by andre la moth. 72 | bool get_line_intersect(float p0_x, float p0_y, float p1_x, float p1_y, float p2_x ,float p2_y, float p3_x, float p3_y){ 73 | float s1_x; 74 | float s1_y; 75 | float s2_x; 76 | float s2_y; 77 | 78 | s1_x = p1_x - p0_x; 79 | s1_y = p1_y - p0_y; 80 | s2_x = p3_x - p2_x; 81 | s2_y = p3_y - p2_y; 82 | 83 | float s; 84 | float t; 85 | 86 | s = (-s1_y * (p0_x - p2_x) + s1_x * (p0_y - p2_y)) / (-s2_x * s1_y + s1_x * s2_y); 87 | t = ( s2_x * (p0_y - p2_y) - s2_y * (p0_x - p2_x)) / (-s2_x * s1_y + s1_x * s2_y); 88 | 89 | if(s >= 0 && s <= 1 && t >= 0 && t <= 1) return true; 90 | 91 | return false; // No collision 92 | } 93 | -------------------------------------------------------------------------------- /Collision_-_LinesegCircleCollide.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | #include 4 | 5 | static bool linecirclecollide(int sx1, int sy1, int sx2, int sy2, int cx, int cy, float cr); 6 | 7 | int main(void) 8 | { 9 | // Initialization 10 | //-------------------------------------------------------------------------------------- 11 | const int screenWidth = 800; 12 | const int screenHeight = 450; 13 | 14 | InitWindow(screenWidth, screenHeight, "raylib example."); 15 | 16 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 17 | //-------------------------------------------------------------------------------------- 18 | 19 | // Main game loop 20 | while (!WindowShouldClose()) // Detect window close button or ESC key 21 | { 22 | // Update 23 | //---------------------------------------------------------------------------------- 24 | 25 | Vector2 linea=(Vector2){GetMouseX(),GetMouseY()}; 26 | Vector2 lineb=(Vector2){linea.x-100,linea.y+50}; 27 | Vector2 circle=(Vector2){400,200}; 28 | float circleradius = 50; 29 | 30 | //---------------------------------------------------------------------------------- 31 | // Draw 32 | //---------------------------------------------------------------------------------- 33 | BeginDrawing(); 34 | 35 | ClearBackground(RAYWHITE); 36 | 37 | DrawLine(linea.x,linea.y,lineb.x,lineb.y,RED); 38 | DrawCircle(circle.x,circle.y,circleradius,YELLOW); 39 | 40 | if(linecirclecollide(linea.x,linea.y,lineb.x,lineb.y,circle.x,circle.y,circleradius)) 41 | DrawText("Something is a foot..",10,10,30,BLUE); 42 | 43 | 44 | EndDrawing(); 45 | //---------------------------------------------------------------------------------- 46 | } 47 | 48 | // De-Initialization 49 | //-------------------------------------------------------------------------------------- 50 | CloseWindow(); // Close window and OpenGL context 51 | //-------------------------------------------------------------------------------------- 52 | 53 | return 0; 54 | 55 | 56 | } 57 | 58 | 59 | //' 60 | //' Line(segment) to Circle Collision// 61 | //' 62 | bool linecirclecollide(int x1, int y1, int x2, int y2, int xc, int yc, float r){ 63 | 64 | float xd = 0.0f; 65 | float yd = 0.0f; 66 | float t = 0.0f; 67 | float d = 0.0f; 68 | float dx = 0.0f; 69 | float dy = 0.0f; 70 | 71 | dx = x2 - x1; 72 | dy = y2 - y1; 73 | 74 | t = ((yc - y1) * dy + (xc - x1) * dx) / (dy * dy + dx * dx); 75 | 76 | if(0 <= t && t <= 1) 77 | { 78 | xd = x1 + t * dx; 79 | yd = y1 + t * dy; 80 | 81 | d = sqrt((xd - xc) * (xd - xc) + (yd - yc) * (yd - yc)); 82 | return d <= r; 83 | } 84 | else 85 | { 86 | d = sqrt((xc - x1) * (xc - x1) + (yc - y1) * (yc - y1)); 87 | if(d <= r) 88 | { 89 | return true; 90 | } 91 | else 92 | { 93 | d = sqrt((xc - x2) * (xc - x2) + (yc - y2) * (yc - y2)); 94 | if(d <= r) 95 | { 96 | return true; 97 | } 98 | else 99 | { 100 | return false; 101 | } 102 | 103 | } 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /Collision_-_rectsoverlap.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | // Our rectsoverlap function. Returns true/false. 5 | static bool rectsoverlap(int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2); 6 | 7 | int main(void) 8 | { 9 | // Initialization 10 | //-------------------------------------------------------------------------------------- 11 | const int screenWidth = 800; 12 | const int screenHeight = 450; 13 | 14 | InitWindow(screenWidth, screenHeight, "raylib example."); 15 | 16 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 17 | //-------------------------------------------------------------------------------------- 18 | 19 | // Main game loop 20 | while (!WindowShouldClose()) // Detect window close button or ESC key 21 | { 22 | // Update 23 | //---------------------------------------------------------------------------------- 24 | int x1 = GetMouseX(); 25 | int y1 = GetMouseY(); 26 | int w1 = 64; 27 | int h1 = 64; 28 | int x2 = 200; 29 | int y2 = 200; 30 | int w2 = 100; 31 | int h2 = 100; 32 | 33 | 34 | //---------------------------------------------------------------------------------- 35 | // Draw 36 | //---------------------------------------------------------------------------------- 37 | BeginDrawing(); 38 | 39 | ClearBackground(RAYWHITE); 40 | 41 | DrawRectangle(x1,y1,w1,h1,YELLOW); 42 | DrawRectangle(x2,y2,w2,h2,RED); 43 | 44 | if(rectsoverlap(x1,y1,w1,h1,x2,y2,w2,h2)){ 45 | DrawText("Collision!",0,20,20,DARKGRAY); 46 | }else{ 47 | DrawText("No Collision!",0,20,20,DARKGRAY); 48 | } 49 | 50 | EndDrawing(); 51 | //---------------------------------------------------------------------------------- 52 | } 53 | 54 | // De-Initialization 55 | //-------------------------------------------------------------------------------------- 56 | CloseWindow(); // Close window and OpenGL context 57 | //-------------------------------------------------------------------------------------- 58 | 59 | return 0; 60 | 61 | 62 | } 63 | 64 | // Rectangles overlap 65 | bool rectsoverlap(int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2){ 66 | if(x1 >= (x2 + w2) || (x1 + w1) <= x2) return false; 67 | if(y1 >= (y2 + h2) || (y1 + h1) <= y2) return false; 68 | return true; 69 | } 70 | -------------------------------------------------------------------------------- /Empty_Template.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | 5 | int main(void) 6 | { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const int screenWidth = 800; 10 | const int screenHeight = 450; 11 | 12 | InitWindow(screenWidth, screenHeight, "raylib example."); 13 | 14 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 15 | //-------------------------------------------------------------------------------------- 16 | 17 | // Main game loop 18 | while (!WindowShouldClose()) // Detect window close button or ESC key 19 | { 20 | // Update 21 | //---------------------------------------------------------------------------------- 22 | 23 | 24 | //---------------------------------------------------------------------------------- 25 | // Draw 26 | //---------------------------------------------------------------------------------- 27 | BeginDrawing(); 28 | 29 | ClearBackground(RAYWHITE); 30 | 31 | 32 | EndDrawing(); 33 | //---------------------------------------------------------------------------------- 34 | } 35 | 36 | // De-Initialization 37 | //-------------------------------------------------------------------------------------- 38 | CloseWindow(); // Close window and OpenGL context 39 | //-------------------------------------------------------------------------------------- 40 | 41 | return 0; 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /Example_-_ArrayToCode-Paste.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | #include 4 | 5 | int main(void) 6 | { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const int screenWidth = 800; 10 | const int screenHeight = 450; 11 | 12 | InitWindow(screenWidth, screenHeight, "raylib example."); 13 | 14 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 15 | //-------------------------------------------------------------------------------------- 16 | int spritewidth = 8; 17 | int spriteheight = 8; 18 | 19 | 20 | int sprite[8][8] = {{1,1,1,1,0,0,0,9}, 21 | {0,1,1,1,0,0,0,0}, 22 | {0,0,1,1,1,2,2,2}, 23 | {0,0,0,1,1,2,2,2}, 24 | {0,0,0,1,1,2,2,2}, 25 | {1,1,1,1,1,2,2,2}, 26 | {0,0,1,1,1,2,2,2}, 27 | {0,0,0,0,0,2,2,2}}; 28 | 29 | // Here we create a copy and paste ready 30 | // text that can be pasted into a code editor. 31 | // It shows how to convert a array into c language code. 32 | char output1[1000] = "int sprite["; 33 | char output2[32]; 34 | sprintf(output2, "%d", spritewidth); 35 | strcat(output1,output2); 36 | strcat(output1,"]["); 37 | sprintf(output2, "%d", spriteheight); 38 | strcat(output1,output2); 39 | strcat(output1,"] = {\n"); 40 | 41 | int x=0;int y=0; 42 | for (y=0;y0)return 1; 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /Example_-_PlayerJumping.c: -------------------------------------------------------------------------------- 1 | #include "raylib.h" 2 | #include "math.h" 3 | 4 | 5 | // our player struct 6 | typedef struct player{ 7 | Vector2 position; 8 | int width; 9 | int height; 10 | float jumpforce; 11 | bool canjump; 12 | }player; 13 | 14 | int main(void) 15 | { 16 | // Initialization 17 | //-------------------------------------------------------------------------------------- 18 | const int screenWidth = 800; 19 | const int screenHeight = 450; 20 | 21 | InitWindow(screenWidth, screenHeight, "raylib example."); 22 | 23 | const float ground = 200.0f; 24 | 25 | player myplayer = {0}; 26 | myplayer.position = (Vector2){400,200}; 27 | myplayer.canjump = true; 28 | myplayer.width = 32; 29 | myplayer.height = 48; 30 | myplayer.jumpforce = 0.0f; 31 | 32 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 33 | //-------------------------------------------------------------------------------------- 34 | 35 | // Main game loop 36 | while (!WindowShouldClose()) // Detect window close button or ESC key 37 | { 38 | // Update 39 | //---------------------------------------------------------------------------------- 40 | 41 | // If we are currently not jumping and if the player presses space. 42 | if(IsKeyDown(KEY_SPACE) && myplayer.canjump){ 43 | myplayer.canjump = false; // We are now jumping. 44 | myplayer.jumpforce = -4.0f; // How high we jump. 45 | } 46 | // If we are currently in a jump. 47 | if(myplayer.canjump==false){ 48 | // Here we update the player y position. 49 | // We want to move 1 pixel at a time. This for collision detection(Not going through tiles.) 50 | for(int i=0;iground){ 55 | myplayer.position.y = ground; 56 | myplayer.canjump = true; 57 | break; 58 | } 59 | } 60 | // Here we add to the jumpforce. It will go from - to +. 61 | myplayer.jumpforce += 0.2f; 62 | } 63 | //---------------------------------------------------------------------------------- 64 | // Draw 65 | //---------------------------------------------------------------------------------- 66 | BeginDrawing(); 67 | 68 | ClearBackground(RAYWHITE); 69 | 70 | DrawText("Press space to Jump.",200,240,40,DARKGRAY); 71 | // Draw our player. 72 | DrawRectangle(myplayer.position.x,myplayer.position.y,myplayer.width,myplayer.height,BLACK); 73 | DrawCircle(myplayer.position.x+4,myplayer.position.y+6,4,WHITE); 74 | DrawCircle(myplayer.position.x+myplayer.width-4,myplayer.position.y+6,4,WHITE); 75 | 76 | EndDrawing(); 77 | //---------------------------------------------------------------------------------- 78 | } 79 | 80 | // De-Initialization 81 | //-------------------------------------------------------------------------------------- 82 | CloseWindow(); // Close window and OpenGL context 83 | //-------------------------------------------------------------------------------------- 84 | 85 | return 0; 86 | 87 | 88 | } 89 | -------------------------------------------------------------------------------- /Example_-_Rainbow_Backgrounds.c: -------------------------------------------------------------------------------- 1 | // 2 | // Rainbows (backgrounds) 3 | // 4 | 5 | #include "raylib.h" 6 | #include 7 | 8 | int main(void) 9 | { 10 | // Initialization 11 | //-------------------------------------------------------------------------------------- 12 | const int screenWidth = 800; 13 | const int screenHeight = 450; 14 | 15 | InitWindow(screenWidth, screenHeight, "raylib example."); 16 | 17 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 18 | //-------------------------------------------------------------------------------------- 19 | float debug=0; 20 | Color col1 = (Color){100,0 ,200,255}; 21 | Color col2 = (Color){255,0 ,100,255}; 22 | float size=1; 23 | int fresh=0; 24 | // Main game loop 25 | while (!WindowShouldClose()) // Detect window close button or ESC key 26 | { 27 | // Update 28 | //---------------------------------------------------------------------------------- 29 | 30 | fresh++; 31 | if(IsKeyPressed(KEY_SPACE)==true || fresh>30){ 32 | fresh=0; 33 | col1 = (Color){GetRandomValue(0,255),GetRandomValue(0,255),GetRandomValue(0,255),255}; 34 | col2 = (Color){GetRandomValue(0,255),GetRandomValue(0,255),GetRandomValue(0,255),255}; 35 | size = GetRandomValue(1,32); 36 | } 37 | // Find the step value between the colors so it flows from color to color. 38 | // We divide it by the screenheight. screenheight is divided by the bar size of each color. 39 | float stepr = abs(col1.r-col2.r)/(float)(screenHeight/size); 40 | float stepg = abs(col1.g-col2.g)/(float)(screenHeight/size); 41 | float stepb = abs(col1.b-col2.b)/(float)(screenHeight/size); 42 | // Make sure the color goes from one value to another(negatives/positives and step values.) 43 | if(col1.r>col2.r)stepr=-stepr; 44 | if(col1.g>col2.g)stepg=-stepg; 45 | if(col1.b>col2.b)stepb=-stepb; 46 | 47 | 48 | //---------------------------------------------------------------------------------- 49 | // Draw 50 | //---------------------------------------------------------------------------------- 51 | BeginDrawing(); 52 | 53 | ClearBackground(RAYWHITE); 54 | 55 | // Here we draw the rainbow... 56 | Color col=col1; 57 | float r=col.r; 58 | float g=col.g; 59 | float b=col.b; 60 | int cnt=0; 61 | for(int i=0;i=size){ 66 | r+=stepr; 67 | g+=stepg; 68 | b+=stepb; 69 | col.r = r; 70 | col.g = g; 71 | col.b = b; 72 | cnt=0; 73 | } 74 | cnt++; 75 | } 76 | 77 | 78 | DrawText("Rainbow Backgrounds..",0,0,20,WHITE); 79 | 80 | EndDrawing(); 81 | //---------------------------------------------------------------------------------- 82 | } 83 | 84 | // De-Initialization 85 | //-------------------------------------------------------------------------------------- 86 | CloseWindow(); // Close window and OpenGL context 87 | //-------------------------------------------------------------------------------------- 88 | 89 | return 0; 90 | 91 | 92 | } 93 | -------------------------------------------------------------------------------- /Example_-_Rayio.c: -------------------------------------------------------------------------------- 1 | // WIP 2 | #include "raylib.h" 3 | 4 | const TILEWIDTH = 64; 5 | const TILEHEIGHT = 48; 6 | 7 | int main(void) 8 | { 9 | // Initialization 10 | //-------------------------------------------------------------------------------------- 11 | const int screenWidth = 800; 12 | const int screenHeight = 450; 13 | 14 | InitWindow(screenWidth, screenHeight, "raylib example."); 15 | 16 | int map[10][40]={ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 17 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 18 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0}, 19 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 20 | {0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,1,0,0}, 21 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 22 | {1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, 23 | {1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, 24 | {1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, 25 | {1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1}}; 26 | 27 | int tilesh = screenWidth/TILEWIDTH; 28 | int tilesv = screenHeight/TILEHEIGHT; 29 | Vector2 camera; 30 | camera.x = 0; 31 | camera.y = 0; 32 | 33 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 34 | //-------------------------------------------------------------------------------------- 35 | 36 | // Main game loop 37 | while (!WindowShouldClose()) // Detect window close button or ESC key 38 | { 39 | // Update 40 | //---------------------------------------------------------------------------------- 41 | for(int i=0;i<3;i++){ 42 | if(IsKeyDown(KEY_RIGHT) && camera.x<(40-(tilesh+3))*TILEWIDTH)camera.x++; 43 | if(IsKeyDown(KEY_LEFT) && camera.x>0)camera.x--; 44 | } 45 | //---------------------------------------------------------------------------------- 46 | // Draw 47 | //---------------------------------------------------------------------------------- 48 | BeginDrawing(); 49 | 50 | ClearBackground(RAYWHITE); 51 | int tx = camera.x / TILEWIDTH; 52 | int offx = tx * TILEWIDTH - camera.x; 53 | for(int y=0;y0 && map[y][x+tx]==1){ 56 | DrawRectangle(x*TILEWIDTH+offx-TILEWIDTH,y*TILEHEIGHT,TILEWIDTH,TILEHEIGHT,GREEN); 57 | } 58 | }} 59 | 60 | EndDrawing(); 61 | //---------------------------------------------------------------------------------- 62 | } 63 | 64 | // De-Initialization 65 | //-------------------------------------------------------------------------------------- 66 | CloseWindow(); // Close window and OpenGL context 67 | //-------------------------------------------------------------------------------------- 68 | 69 | return 0; 70 | 71 | 72 | } 73 | -------------------------------------------------------------------------------- /Example_-_Switch_array_hills.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | void floodit(); 5 | 6 | int main(void) 7 | { 8 | // Initialization 9 | //-------------------------------------------------------------------------------------- 10 | const int screenWidth = 800; 11 | const int screenHeight = 450; 12 | 13 | InitWindow(screenWidth, screenHeight, "raylib example."); 14 | 15 | 16 | int mymap[50][50] = {0}; 17 | 18 | for (int i=0;i<20;i++){ 19 | int y=0; 20 | if (GetRandomValue(0,1) == 1) y=1; 21 | mymap[10+i][25+y] = 1; 22 | 23 | } 24 | 25 | 26 | for (int i=0;i<31550;i++) 27 | { 28 | int x = GetRandomValue(1,49); 29 | int y = GetRandomValue(1,49); 30 | if (mymap[y][x] == 1) 31 | { 32 | switch (GetRandomValue(0,3)) 33 | { 34 | case 0: 35 | mymap[y-1][x]=1; 36 | break; 37 | case 1: 38 | mymap[y+1][x]=1; 39 | break; 40 | case 2: 41 | mymap[y][x-1]=1; 42 | break; 43 | case 3: 44 | mymap[y][x+1]=1; 45 | break; 46 | } 47 | } 48 | 49 | } 50 | 51 | 52 | // Create a Image in memory 53 | RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight); 54 | 55 | // Clear our texture(image) before entering the game loop 56 | BeginTextureMode(target); 57 | ClearBackground(BLUE); 58 | EndTextureMode(); 59 | // Draw something on it. 60 | for (int y=0;y<50;y++) 61 | { 62 | for (int x=0;x<50; x++) 63 | { 64 | if (mymap[y][x]==1) 65 | { 66 | BeginTextureMode(target); 67 | DrawRectangle(x*16,y*8,16,8,BLACK); 68 | EndTextureMode(); 69 | } 70 | } 71 | } 72 | 73 | 74 | 75 | 76 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 77 | //-------------------------------------------------------------------------------------- 78 | 79 | // Main game loop 80 | while (!WindowShouldClose()) // Detect window close button or ESC key 81 | { 82 | // Update 83 | //---------------------------------------------------------------------------------- 84 | 85 | //---------------------------------------------------------------------------------- 86 | // Draw 87 | //---------------------------------------------------------------------------------- 88 | BeginDrawing(); 89 | 90 | ClearBackground(RAYWHITE); 91 | 92 | 93 | // NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom) 94 | DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height }, (Vector2){ 0, 0 }, WHITE); 95 | 96 | 97 | DrawText("Switch/array/hillalgo.", 100, 180, 40, LIGHTGRAY); 98 | 99 | EndDrawing(); 100 | //---------------------------------------------------------------------------------- 101 | } 102 | 103 | // De-Initialization 104 | //-------------------------------------------------------------------------------------- 105 | UnloadRenderTexture(target); // Unload render texture 106 | //-------------------------------------------------------------------------------------- 107 | CloseWindow(); // Close window and OpenGL context 108 | //-------------------------------------------------------------------------------------- 109 | 110 | return 0; 111 | 112 | 113 | } 114 | 115 | -------------------------------------------------------------------------------- /Example_-_Turret_TurnToTarget.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | #include // for cos and sin 4 | 5 | // Return on which side of the line the point is. l-1 0= r=1 6 | // lineback x,y linefront x,y point x,y 7 | int orientation(int ax,int ay,int bx, int by, int cx, int cy); 8 | 9 | typedef struct turret{ 10 | float isactive; 11 | float angle; 12 | Vector2 position; 13 | Vector2 barreltip; // tip of the cannon 14 | Vector2 target; 15 | }turret; 16 | 17 | int main(void) 18 | { 19 | // Initialization 20 | //-------------------------------------------------------------------------------------- 21 | const int screenWidth = 800; 22 | const int screenHeight = 450; 23 | 24 | InitWindow(screenWidth, screenHeight, "raylib example."); 25 | 26 | turret myturret={0}; 27 | myturret.isactive = true; 28 | myturret.angle = 0.0f; 29 | myturret.position = (Vector2){400,200}; 30 | 31 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 32 | //-------------------------------------------------------------------------------------- 33 | 34 | // Main game loop 35 | while (!WindowShouldClose()) // Detect window close button or ESC key 36 | { 37 | // Update 38 | //---------------------------------------------------------------------------------- 39 | 40 | // The turret section. 41 | if(myturret.isactive){ 42 | // Get the target coordinates. 43 | myturret.target = GetMousePosition(); 44 | // Figure out if the target is left or right or center of the barrel. 45 | int o = orientation(myturret.position.x,myturret.position.y,myturret.barreltip.x,myturret.barreltip.y,myturret.target.x,myturret.target.y); 46 | if(o==-1){ // target is left of the barrel so turn left. 47 | myturret.angle-=0.01f; 48 | }else if(o==1){//target is right of the barrel so turn right. 49 | myturret.angle+=0.01f; 50 | }else{ 51 | } 52 | // Keep the angle value between 0..PI*2.0f 53 | if(myturret.angle>PI*2.0f)myturret.angle=0; //needs to be above the line here below.. 54 | if(myturret.angle<0)myturret.angle=PI*2.0f; 55 | 56 | // Get the new barreltip vector. 57 | myturret.barreltip = (Vector2){myturret.position.x+(cos(myturret.angle)*16),myturret.position.y+(sin(myturret.angle)*16)}; 58 | } 59 | 60 | 61 | //---------------------------------------------------------------------------------- 62 | // Draw 63 | //---------------------------------------------------------------------------------- 64 | BeginDrawing(); 65 | 66 | ClearBackground(RAYWHITE); 67 | 68 | //draw the turret. 69 | DrawCircle(myturret.position.x,myturret.position.y,10,DARKGRAY); 70 | DrawLineEx(myturret.position,myturret.barreltip,5,RED); 71 | 72 | DrawText("Move the mouse around the turret to see it turn.",0,0,30,DARKGRAY); 73 | 74 | DrawText(FormatText("Turret Angle : %f",myturret.angle),0,50,30,DARKGRAY); 75 | EndDrawing(); 76 | //---------------------------------------------------------------------------------- 77 | } 78 | 79 | // De-Initialization 80 | //-------------------------------------------------------------------------------------- 81 | CloseWindow(); // Close window and OpenGL context 82 | //-------------------------------------------------------------------------------------- 83 | 84 | return 0; 85 | 86 | 87 | } 88 | 89 | // 90 | // This is the orientation function. It returns -1 if the point is left of the inputted line. 91 | // 0 if on the same and 1 if on the right of the line. 92 | // aa,bb,point 93 | int orientation(int ax,int ay,int bx, int by, int cx, int cy){ 94 | if(((bx-ax)*(cy-ay)-(by-ay)*(cx-ax))<0)return -1; 95 | if(((bx-ax)*(cy-ay)-(by-ay)*(cx-ax))>0)return 1; 96 | return 0; 97 | } 98 | -------------------------------------------------------------------------------- /File_-_ReadAndWrite_Array.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | #include "raylib.h" 7 | 8 | static int spritelibmap[80*4][32][32]; // numspritelib, 9 | 10 | 11 | int main(void) 12 | { 13 | // Initialization 14 | //-------------------------------------------------------------------------------------- 15 | const int screenWidth = 800; 16 | const int screenHeight = 450; 17 | 18 | InitWindow(screenWidth, screenHeight, "raylib example."); 19 | 20 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 21 | //-------------------------------------------------------------------------------------- 22 | 23 | // Put some values in the array. 24 | spritelibmap[0][0][0] = 1; 25 | spritelibmap[20][10][10] = 1; 26 | // Create out file pointer. 27 | FILE *fp; 28 | // Write the array to disk. 29 | fp=fopen("spritedata.spr","w"); 30 | fwrite(spritelibmap,sizeof(spritelibmap),1,fp); /* Write to File */ 31 | fclose(fp); 32 | // Reset the values in the array. 33 | spritelibmap[0][0][0] = 0; 34 | spritelibmap[20][10][10] = 0; 35 | // Read the array from disk.. 36 | fp=fopen("spritedata.spr","r"); 37 | fread(spritelibmap,sizeof(spritelibmap),1,fp); /* read the entire file into the array */ 38 | fclose(fp); 39 | 40 | 41 | // Main game loop 42 | while (!WindowShouldClose()) // Detect window close button or ESC key 43 | { 44 | // Update 45 | //---------------------------------------------------------------------------------- 46 | 47 | 48 | //---------------------------------------------------------------------------------- 49 | // Draw 50 | //---------------------------------------------------------------------------------- 51 | BeginDrawing(); 52 | 53 | ClearBackground(RAYWHITE); 54 | 55 | DrawText(FormatText("%i",spritelibmap[0][0][0]),200,200,20,BLACK); 56 | DrawText(FormatText("%i",spritelibmap[20][10][10]),200,220,20,BLACK); 57 | 58 | EndDrawing(); 59 | //---------------------------------------------------------------------------------- 60 | } 61 | 62 | // De-Initialization 63 | //-------------------------------------------------------------------------------------- 64 | CloseWindow(); // Close window and OpenGL context 65 | //-------------------------------------------------------------------------------------- 66 | 67 | return 0; 68 | 69 | 70 | } 71 | -------------------------------------------------------------------------------- /File_-_ReadDirIntoCharArray.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(void) 9 | { 10 | // Initialization 11 | //-------------------------------------------------------------------------------------- 12 | const int screenWidth = 800; 13 | const int screenHeight = 450; 14 | 15 | InitWindow(screenWidth, screenHeight, "raylib example."); 16 | 17 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 18 | //-------------------------------------------------------------------------------------- 19 | 20 | // Out char where we store the filenames. 21 | char files[10024][PATH_MAX]; 22 | int numfiles=0; 23 | // Here we read the current dir(where this example is run) 24 | // and copy the filename into the files char array. 25 | DIR *d; 26 | struct dirent *dir; 27 | d = opendir("."); 28 | if (d) 29 | { 30 | 31 | while ((dir = readdir(d)) != NULL) 32 | { 33 | strcpy(files[numfiles],dir->d_name); 34 | numfiles++; 35 | } 36 | closedir(d); 37 | } 38 | 39 | // Main game loop 40 | while (!WindowShouldClose()) // Detect window close button or ESC key 41 | { 42 | // Update 43 | //---------------------------------------------------------------------------------- 44 | 45 | 46 | //---------------------------------------------------------------------------------- 47 | // Draw 48 | //---------------------------------------------------------------------------------- 49 | BeginDrawing(); 50 | 51 | ClearBackground(RAYWHITE); 52 | 53 | DrawText(FormatText("Number of files in dir : %i",numfiles),10,10,20,BLACK); 54 | // Draw the first chunk of the dir to the screen. 55 | if(numfiles>0){ 56 | int x=0; 57 | int y=20; 58 | for(int i=0;iscreenHeight-50){ 62 | x+=200; 63 | y=20; 64 | } 65 | } 66 | } 67 | EndDrawing(); 68 | //---------------------------------------------------------------------------------- 69 | } 70 | 71 | // De-Initialization 72 | //-------------------------------------------------------------------------------------- 73 | CloseWindow(); // Close window and OpenGL context 74 | //-------------------------------------------------------------------------------------- 75 | 76 | return 0; 77 | 78 | 79 | } 80 | -------------------------------------------------------------------------------- /File_-_fopen_writefile.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "raylib.h" 5 | 6 | 7 | int main(void) 8 | { 9 | // Initialization 10 | //-------------------------------------------------------------------------------------- 11 | const int screenWidth = 800; 12 | const int screenHeight = 450; 13 | 14 | InitWindow(screenWidth, screenHeight, "raylib example."); 15 | 16 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 17 | //-------------------------------------------------------------------------------------- 18 | 19 | FILE *out = fopen("doissy.txt","w"); 20 | fprintf(out, "%s %s %s", "Welcome", 21 | "to", "GeeksforGeeks"); 22 | fclose(out); 23 | 24 | // Main game loop 25 | while (!WindowShouldClose()) // Detect window close button or ESC key 26 | { 27 | // Update 28 | //---------------------------------------------------------------------------------- 29 | 30 | 31 | 32 | //---------------------------------------------------------------------------------- 33 | // Draw 34 | //---------------------------------------------------------------------------------- 35 | BeginDrawing(); 36 | 37 | ClearBackground(RAYWHITE); 38 | 39 | 40 | EndDrawing(); 41 | //---------------------------------------------------------------------------------- 42 | } 43 | 44 | // De-Initialization 45 | //-------------------------------------------------------------------------------------- 46 | CloseWindow(); // Close window and OpenGL context 47 | //-------------------------------------------------------------------------------------- 48 | 49 | return 0; 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /Function_-_float_random.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | // For rand_float 4 | #include 5 | #include 6 | 7 | float float_rand( float min, float max ); 8 | 9 | int main(void) 10 | { 11 | // Initialization 12 | //-------------------------------------------------------------------------------------- 13 | const int screenWidth = 800; 14 | const int screenHeight = 450; 15 | 16 | InitWindow(screenWidth, screenHeight, "raylib example."); 17 | 18 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 19 | //-------------------------------------------------------------------------------------- 20 | 21 | float set[5][19] = {0.0f}; 22 | for(int x=0;x<5;x++){ 23 | for(int y=0;y<19;y++){ 24 | set[x][y] = float_rand(-1,1); 25 | }} 26 | 27 | // Main game loop 28 | while (!WindowShouldClose()) // Detect window close button or ESC key 29 | { 30 | // Update 31 | //---------------------------------------------------------------------------------- 32 | 33 | 34 | //---------------------------------------------------------------------------------- 35 | // Draw 36 | //---------------------------------------------------------------------------------- 37 | BeginDrawing(); 38 | 39 | ClearBackground(RAYWHITE); 40 | DrawText("rand_float(min, max) function.",0,0,20,BLACK); 41 | for(int x=0;x<5;x++){ 42 | for(int y=0;y<19;y++){ 43 | DrawText(FormatText("%f",set[x][y]),x*150,y*20+40,20,BLACK); 44 | }} 45 | 46 | EndDrawing(); 47 | //---------------------------------------------------------------------------------- 48 | } 49 | 50 | // De-Initialization 51 | //-------------------------------------------------------------------------------------- 52 | CloseWindow(); // Close window and OpenGL context 53 | //-------------------------------------------------------------------------------------- 54 | 55 | return 0; 56 | 57 | 58 | } 59 | float float_rand( float min, float max ){ 60 | float scale = rand() / (float) RAND_MAX; /* [0, 1.0] */ 61 | return min + scale * ( max - min ); /* [min, max] */ 62 | } 63 | -------------------------------------------------------------------------------- /Functions_-_Clamp.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | 5 | // These are the circlerect collision function. The clamp one is needed for the circlerectcollide. 6 | static bool circlerectcollide(int cx,int cy,int cr, int rx, int ry,int rw,int rh); 7 | static float Clamp(float value, float min, float max); 8 | 9 | int main(void) 10 | { 11 | // Initialization 12 | //-------------------------------------------------------------------------------------- 13 | const int screenWidth = 800; 14 | const int screenHeight = 450; 15 | 16 | InitWindow(screenWidth, screenHeight, "raylib example."); 17 | 18 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 19 | //-------------------------------------------------------------------------------------- 20 | 21 | // Main game loop 22 | while (!WindowShouldClose()) // Detect window close button or ESC key 23 | { 24 | // Update 25 | //---------------------------------------------------------------------------------- 26 | 27 | Rectangle r=(Rectangle){GetMouseX(),GetMouseY(),128,64}; 28 | Vector2 c=(Vector2){400,200}; 29 | float cr=50; 30 | //---------------------------------------------------------------------------------- 31 | // Draw 32 | //---------------------------------------------------------------------------------- 33 | BeginDrawing(); 34 | 35 | ClearBackground(RAYWHITE); 36 | 37 | DrawRectangle(r.x,r.y,r.width,r.height,BLACK); 38 | DrawCircle(c.x,c.y,cr,BLUE); 39 | 40 | if(circlerectcollide(c.x,c.y,cr,r.x,r.y,r.width,r.height)){ 41 | DrawText("COLLISION..",20,0,30,RED); 42 | } 43 | 44 | EndDrawing(); 45 | //---------------------------------------------------------------------------------- 46 | } 47 | 48 | // De-Initialization 49 | //-------------------------------------------------------------------------------------- 50 | CloseWindow(); // Close window and OpenGL context 51 | //-------------------------------------------------------------------------------------- 52 | 53 | return 0; 54 | 55 | 56 | } 57 | 58 | bool circlerectcollide(int cx,int cy,int cr, int rx, int ry,int rw,int rh){ 59 | float closestx = Clamp(cx, rx, rx+rw); 60 | float closesty = Clamp(cy, ry, ry+rh); 61 | float distancex = cx - closestx; 62 | float distancey = cy - closesty; 63 | float distancesquared = (distancex * distancex) + (distancey * distancey); 64 | return distancesquared < (cr * cr); 65 | } 66 | 67 | // Clamp float value 68 | float Clamp(float value, float min, float max) 69 | { 70 | const float res = value < min ? min : value; 71 | return res > max ? max : res; 72 | } 73 | -------------------------------------------------------------------------------- /Functions_-_angledifference.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | #include 4 | 5 | static float angledifference(float angle1, float angle2); 6 | 7 | int main(void) 8 | { 9 | // Initialization 10 | //-------------------------------------------------------------------------------------- 11 | const int screenWidth = 800; 12 | const int screenHeight = 450; 13 | 14 | InitWindow(screenWidth, screenHeight, "raylib example."); 15 | 16 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 17 | //-------------------------------------------------------------------------------------- 18 | 19 | // Main game loop 20 | while (!WindowShouldClose()) // Detect window close button or ESC key 21 | { 22 | // Update 23 | //---------------------------------------------------------------------------------- 24 | 25 | 26 | //---------------------------------------------------------------------------------- 27 | // Draw 28 | //---------------------------------------------------------------------------------- 29 | BeginDrawing(); 30 | 31 | ClearBackground(RAYWHITE); 32 | 33 | 34 | EndDrawing(); 35 | //---------------------------------------------------------------------------------- 36 | } 37 | 38 | // De-Initialization 39 | //-------------------------------------------------------------------------------------- 40 | CloseWindow(); // Close window and OpenGL context 41 | //-------------------------------------------------------------------------------------- 42 | 43 | return 0; 44 | 45 | 46 | } 47 | 48 | 49 | // takes radian iput! <0 is left is shorter else right turn is shorter. 50 | // When it outputs >3 you can asume it aligns with the target(2) angle. 51 | float angledifference(float angle1, float angle2){ 52 | float difference = angle1 - angle2; 53 | while (difference < -PI){ 54 | difference += (PI*2); 55 | } 56 | while (difference > PI){ 57 | difference -= (PI*2); 58 | } 59 | return difference; 60 | 61 | } 62 | -------------------------------------------------------------------------------- /Functions_-_distance_EuclMan.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | #include 4 | 5 | static float distance(float x1,float y1,float x2,float y2); 6 | static float edistance(float x1,float y1,float x2,float y2); 7 | 8 | int main(void) 9 | { 10 | // Initialization 11 | //-------------------------------------------------------------------------------------- 12 | const int screenWidth = 800; 13 | const int screenHeight = 450; 14 | 15 | InitWindow(screenWidth, screenHeight, "raylib example."); 16 | 17 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 18 | //-------------------------------------------------------------------------------------- 19 | 20 | // Main game loop 21 | while (!WindowShouldClose()) // Detect window close button or ESC key 22 | { 23 | // Update 24 | //---------------------------------------------------------------------------------- 25 | 26 | int x1 = GetMouseX(); 27 | int y1 = GetMouseY(); 28 | int x2 = 400; 29 | int y2 = 200; 30 | 31 | //---------------------------------------------------------------------------------- 32 | // Draw 33 | //---------------------------------------------------------------------------------- 34 | BeginDrawing(); 35 | 36 | ClearBackground(RAYWHITE); 37 | 38 | DrawLine(x1,y1,x2,y2,RED); 39 | 40 | DrawText(FormatText("Manhattan distance : %f ",distance(x1,y1,x2,y2)),0,0,20,DARKGRAY); 41 | DrawText(FormatText("Euclidean distance : %f ",edistance(x1,y1,x2,y2)),0,20,20,DARKGRAY); 42 | 43 | EndDrawing(); 44 | //---------------------------------------------------------------------------------- 45 | } 46 | 47 | // De-Initialization 48 | //-------------------------------------------------------------------------------------- 49 | CloseWindow(); // Close window and OpenGL context 50 | //-------------------------------------------------------------------------------------- 51 | 52 | return 0; 53 | 54 | 55 | } 56 | 57 | // Manhattan Distance (less precise) 58 | float distance(float x1,float y1,float x2,float y2){ 59 | return (float)abs(x2-x1)+abs(y2-y1); 60 | } 61 | 62 | // Euclidean distance (more precise) 63 | float edistance(float x1,float y1,float x2,float y2){ 64 | return sqrt( (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2) ); 65 | } 66 | -------------------------------------------------------------------------------- /Functions_-_getangle.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | #include 4 | 5 | // Get our angle between two points. 6 | static float getangle(float x1,float y1,float x2,float y2); 7 | 8 | int main(void) 9 | { 10 | // Initialization 11 | //-------------------------------------------------------------------------------------- 12 | const int screenWidth = 800; 13 | const int screenHeight = 450; 14 | 15 | InitWindow(screenWidth, screenHeight, "raylib example."); 16 | 17 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 18 | //-------------------------------------------------------------------------------------- 19 | 20 | // Main game loop 21 | while (!WindowShouldClose()) // Detect window close button or ESC key 22 | { 23 | // Update 24 | //---------------------------------------------------------------------------------- 25 | 26 | int x1 = GetMouseX(); 27 | int y1 = GetMouseY(); 28 | int x2 = screenWidth/2; 29 | int y2 = screenHeight/2; 30 | 31 | //---------------------------------------------------------------------------------- 32 | // Draw 33 | //---------------------------------------------------------------------------------- 34 | BeginDrawing(); 35 | 36 | ClearBackground(RAYWHITE); 37 | 38 | DrawLine(x1,y1,x2,y2,RED); 39 | 40 | DrawText(FormatText("Angle between x1,y1,x2,y2 : %f",getangle(x1,y1,x2,y2)),0,0,20,DARKGRAY); 41 | 42 | EndDrawing(); 43 | //---------------------------------------------------------------------------------- 44 | } 45 | 46 | // De-Initialization 47 | //-------------------------------------------------------------------------------------- 48 | CloseWindow(); // Close window and OpenGL context 49 | //-------------------------------------------------------------------------------------- 50 | 51 | return 0; 52 | 53 | 54 | } 55 | // Return the angle from - to in float 56 | float getangle(float x1,float y1,float x2,float y2){ 57 | return (float)atan2(y2-y1, x2-x1); 58 | } 59 | -------------------------------------------------------------------------------- /ProcGen/GianaRect.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | void c64rectangle(int x, int y, int w, int h,int thick); 5 | 6 | int main(void) 7 | { 8 | // Initialization 9 | //-------------------------------------------------------------------------------------- 10 | const int screenWidth = 800; 11 | const int screenHeight = 450; 12 | 13 | InitWindow(screenWidth, screenHeight, "raylib example."); 14 | 15 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 16 | //-------------------------------------------------------------------------------------- 17 | 18 | // Main game loop 19 | while (!WindowShouldClose()) // Detect window close button or ESC key 20 | { 21 | // Update 22 | //---------------------------------------------------------------------------------- 23 | 24 | 25 | //---------------------------------------------------------------------------------- 26 | // Draw 27 | //---------------------------------------------------------------------------------- 28 | BeginDrawing(); 29 | 30 | ClearBackground(RAYWHITE); 31 | for(int y=0;y0){ 33 | int y1=GetRandomValue(-1,1); 34 | int x1=GetRandomValue(-1,1); 35 | if(map[x+x1][y+y1]==0){ 36 | map[x+x1][y+y1]=z; 37 | } 38 | } 39 | } 40 | // pick random spot. With that value draw a rect there (3*3) (blockize) 41 | for(int i=0;i<100*100*100;i++){ 42 | int x = GetRandomValue(1,99); 43 | int y = GetRandomValue(1,99); 44 | int z = map[x][y]; 45 | if(z>0){ 46 | for(int y1=-1;y1<2;y1++){ 47 | for(int x1=-1;x1<2;x1++){ 48 | if(x+x1<0 || y+y1<0 || x+x1>99 || y+y1>99) continue; 49 | map[x+x1][y+y1]=z; 50 | }} 51 | } 52 | 53 | } 54 | 55 | 56 | // Main game loop 57 | while (!WindowShouldClose()) // Detect window close button or ESC key 58 | { 59 | // Update 60 | //---------------------------------------------------------------------------------- 61 | 62 | 63 | //---------------------------------------------------------------------------------- 64 | // Draw 65 | //---------------------------------------------------------------------------------- 66 | BeginDrawing(); 67 | 68 | ClearBackground(RAYWHITE); 69 | 70 | for(int y=0;y<100;y++){ 71 | for(int x=0;x<100;x++){ 72 | int m=map[x][y]; 73 | float col = (255.0f/(float)numzones)*(float)m; 74 | Color c = (Color){col,col,col,255}; 75 | 76 | DrawRectangle(x*7,y*4,7,4,c); 77 | }} 78 | 79 | EndDrawing(); 80 | //---------------------------------------------------------------------------------- 81 | } 82 | 83 | // De-Initialization 84 | //-------------------------------------------------------------------------------------- 85 | CloseWindow(); // Close window and OpenGL context 86 | //-------------------------------------------------------------------------------------- 87 | 88 | return 0; 89 | 90 | 91 | } 92 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Raylib-Examples ( Learn how to code games by studying examples ) 2 | 3 | My collection of raylib examples. ( https://www.raylib.com/index.html ) 4 | 5 | For Raylib Version of 4 april 2020 ( Notepad++ windows installer version ) 6 | 7 | So far every different file in the repo are standalone. GFX and maybe sound wil be included inside the code files as array data. 8 | 9 | I might end up storing and creating a few hundred game related code examples in this repo over the next couple of years. 10 | 11 |
12 | 13 | Points of interest for me and this repo are : 14 | 15 | *learning C with Raylib
16 | *Learning more about how Rts/Fps/Rpg/Tbs/Shooter/Action/Puzzle games work.
17 | *Tools for eq. Sprite editing(For direct pasting into code)
18 | *Main focus - Minecraft and Civilization 1/2 style games.
19 | 20 | Dotate to author (book and motivation funds) https://www.paypal.me/RudyvanEtten/5 21 | 22 |
23 | 24 | There might be periods where I spend time practising other things like music composition and/or pixelart. Thus there might be a time where I spend less or no time coding. My pixelart blog is : http://pixelart001.blogspot.com/ My music is at : https://soundcloud.com/pakz001 25 | 26 | 27 | 28 |
29 | 30 | How to use these examples : 31 | 32 | Each example in here is a standalone .c file. I myself just copy and paste the one I need into notepad++ and save it as a new .c file and it just works. You should also be able to save this repo as a zip and unzip it and be able to load each example and run it. 33 | 34 | Possibly a .h file like raymath.h sometimes is not found, this happens with certain examples in the official examples. You can copy that .h files from the /src files into the folder with the example that needs it. That seemed to have worked for me. 35 | 36 | The pico8 inspired sprite and map editor in the spriteeditor folder exports the current image as a c array into the clipboard buffer that can then be pasted inside your code. I use this myself. The 'c' key inside the editor is used for this(in the sprite editor section.) (New version should read 8x8 sprite arrays back into the editor with the 'p' key)(save all(f5)loadall(f6)(tab=switch between spriteview and map view.) 37 |
38 | Youtube video's of some of the game projects in the repo here :
39 | 40 |
Video link (youtube) of the Platformer game template(drones)
41 | 42 | Watch the video 43 |
44 |
Video link (youtube) of the Dungeon with dangerous spiders game example.
45 | 46 | Watch the video 47 |
48 | 49 | 50 |

51 | My other hobby : https://soundcloud.com/pakz001 52 |
53 | https://pixelart001.blogspot.com/ 54 | -------------------------------------------------------------------------------- /Scripts/BatchgifToSpriteSheet.c: -------------------------------------------------------------------------------- 1 | // !! needs files 0x.gif to 09.gif in the same folder as this example. 2 | // 3 | 4 | // 5 | // gif to sprite sheet Script (work in progress) 6 | // 7 | // I had some sprites that needed converting. I have a folder filled with 8 | // gif files. Each gif file is a tiny sprite. They are named 01..99+.gif 9 | // I wanted to load each of these gifs and make a sprite sheet of them and then 10 | // save this sheet as a image file. 11 | // 12 | // I was working on doing this but discovered the export function of the 13 | // tool I used had a bug where only the first sprite of a set was saved as 14 | // a gif. I decided not to continue at this point. 15 | 16 | // What I have here is a loader that creates x amount of textures. Then 17 | // the loadtexture command loads the first 10 of these gifs into 18 | // this array. It shows how to create a load function which can load 19 | // procedural generated filenames. 20 | 21 | #include "raylib.h" 22 | #include 23 | 24 | // create the container for the gifs 25 | Texture2D im[150]; 26 | 27 | int main(void) 28 | { 29 | // Initialization 30 | //-------------------------------------------------------------------------------------- 31 | const int screenWidth = 800; 32 | const int screenHeight = 450; 33 | 34 | InitWindow(screenWidth, screenHeight, "raylib example."); 35 | // create our char that wil contain the filename. 36 | char lfn[6]; // '0x.gif' 37 | // create the first set of names 38 | for(int i=1;i<10;i++){ 39 | lfn[0] = 0; 40 | lfn[1] = i; // here we add the number in the filename 41 | lfn[2] = '.'; // gif extension 42 | lfn[3] = 'g'; 43 | lfn[4] = 'i'; 44 | lfn[5] = 'f'; 45 | // load the texture using the FormatText command 46 | im[i] = LoadTexture(FormatText("0%i.gif",i)); 47 | } 48 | //im1 = LoadTexture("01.gif"); // test case 49 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 50 | //-------------------------------------------------------------------------------------- 51 | //im1 = LoadTexture(lfn); 52 | //DrawTexture(im1, 190+i*16, 190, WHITE); 53 | 54 | 55 | 56 | 57 | // Main game loop 58 | while (!WindowShouldClose()) // Detect window close button or ESC key 59 | { 60 | // Update 61 | //---------------------------------------------------------------------------------- 62 | 63 | 64 | //---------------------------------------------------------------------------------- 65 | // Draw 66 | //---------------------------------------------------------------------------------- 67 | BeginDrawing(); 68 | // draw the texture(gifs) on the canvas 69 | int cnt=0; 70 | for(int y=0;y<10;y++){ 71 | for(int x=0;x<20;x++){ 72 | if(cnt<10){ 73 | DrawTexture(im[cnt],x*16,y*16,WHITE); 74 | } 75 | cnt++; 76 | }} 77 | // test case 78 | //DrawText(lfn,100,80,20,BLACK); 79 | //DrawText(FormatText("0%i.gif",i),100,80,20,BLACK); 80 | ClearBackground(RAYWHITE); 81 | 82 | 83 | EndDrawing(); 84 | //---------------------------------------------------------------------------------- 85 | } 86 | for(int i=0;i<50;i++){ 87 | UnloadTexture(im[i]); 88 | } 89 | // De-Initialization 90 | //-------------------------------------------------------------------------------------- 91 | CloseWindow(); // Close window and OpenGL context 92 | //-------------------------------------------------------------------------------------- 93 | 94 | return 0; 95 | 96 | 97 | } 98 | -------------------------------------------------------------------------------- /Space2d/Create_Rotate_ship_center.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | 4 | 5 | int main(void) 6 | { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const int screenWidth = 800; 10 | const int screenHeight = 450; 11 | 12 | InitWindow(screenWidth, screenHeight, "raylib example."); 13 | 14 | // Create a Image in memory 15 | RenderTexture2D player = LoadRenderTexture(16, 16); 16 | 17 | 18 | // Draw our ship.. 19 | BeginTextureMode(player); 20 | ClearBackground(BLANK); 21 | for(int y=player.texture.height;y>0;y--){ 22 | BeginTextureMode(player); 23 | DrawLine(0+y/2,player.texture.height-y,player.texture.width-y/2,player.texture.height-y,WHITE); 24 | EndTextureMode(); 25 | } 26 | 27 | 28 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 29 | //-------------------------------------------------------------------------------------- 30 | 31 | // Several variables we use for ship rotation speed and our current angle. 32 | int shipTurnSpeed=3; 33 | int shipAngle=0; 34 | 35 | // Main game loop 36 | while (!WindowShouldClose()) // Detect window close button or ESC key 37 | { 38 | // Update 39 | //---------------------------------------------------------------------------------- 40 | 41 | for(int i=0;i359)shipAngle=0; 50 | } 51 | //---------------------------------------------------------------------------------- 52 | // Draw 53 | //---------------------------------------------------------------------------------- 54 | BeginDrawing(); 55 | 56 | ClearBackground(BLACK); 57 | DrawText("Use Cursor Left and Right to Rotate Ship - escape to exit.",2,2,20,DARKGRAY); 58 | 59 | // Draw a texture from rectangle to target rectangle. Note we use the - for opengl reasons! 60 | DrawTexturePro(player.texture, (Rectangle){0,0,player.texture.width,-player.texture.height}, 61 | (Rectangle){320,200,player.texture.width,player.texture.height}, 62 | (Vector2){player.texture.width/2,player.texture.height/2},shipAngle,WHITE); 63 | 64 | //(Rectangle){0,0,player.texture.width,-player.texture.height} == << what part of texture to draw 65 | // (Rectangle){320,200,player.texture.width,player.texture.height} == << where to draw it to on the screen 66 | //(Vector2){player.texture.width/2,player.texture.height/2} == << rotation center 67 | //shipAngle == << rotation in degrees 68 | // 69 | 70 | EndDrawing(); 71 | //---------------------------------------------------------------------------------- 72 | } 73 | 74 | // De-Initialization 75 | UnloadRenderTexture(player); // Unload render texture 76 | 77 | //-------------------------------------------------------------------------------------- 78 | CloseWindow(); // Close window and OpenGL context 79 | //-------------------------------------------------------------------------------------- 80 | 81 | return 0; 82 | 83 | 84 | } 85 | -------------------------------------------------------------------------------- /SpriteEditor/grid_rotate_interpolate.c: -------------------------------------------------------------------------------- 1 | // 2 | // Interpolate seems to be like a blur function. Get the avarage color from the surrounding cells if that center cell is unused. 3 | // With palette's take the most present palette from the surrounding cell when cell got lost in rotation(empty) 4 | // 5 | // 6 | 7 | 8 | #include "raylib.h" 9 | #include 10 | 11 | // 12 | // 13 | float angle=0; // radians 14 | int debug=0; 15 | int main(void) 16 | { 17 | // Initialization 18 | //-------------------------------------------------------------------------------------- 19 | const int screenWidth = 800; 20 | const int screenHeight = 450; 21 | 22 | InitWindow(screenWidth, screenHeight, "raylib example."); 23 | 24 | // Put some tiles in the map.. 25 | int map[32][32] = {0}; 26 | 27 | for (int y = 10; y < 32-10; y++) 28 | { 29 | for (int x = 10; x < 32-10; x++) 30 | { 31 | map[x][y]=1; 32 | }} 33 | 34 | 35 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 36 | //-------------------------------------------------------------------------------------- 37 | 38 | // Main game loop 39 | while (!WindowShouldClose()) // Detect window close button or ESC key 40 | { 41 | // Update 42 | //---------------------------------------------------------------------------------- 43 | if(IsKeyDown(KEY_RIGHT)){ 44 | angle+=0.1; 45 | } 46 | if(IsKeyDown(KEY_LEFT)){ 47 | angle-=0.1; 48 | } 49 | //---------------------------------------------------------------------------------- 50 | // Draw 51 | //---------------------------------------------------------------------------------- 52 | BeginDrawing(); 53 | ClearBackground(RAYWHITE); 54 | 55 | int rotated[32][32]={-1}; 56 | for(int y=0;y<32;y++){ 57 | for(int x=0;x<32;x++){ 58 | int x2=floor((cos(angle)*(x-16) - sin(angle)*(y-16)))+16; 59 | int y2=floor((sin(angle)*(x-16) + cos(angle)*(y-16)))+16; 60 | if(x2>-1 && y2>-1 && x2<32 && y2<32){ 61 | if(map[x][y]>0)rotated[x2][y2]=map[x][y]; 62 | } 63 | } 64 | } 65 | // interpolate 66 | for(int y=0;y<32;y++){ 67 | for(int x=0;x<32;x++){ 68 | if(rotated[x][y]==0){ 69 | int cnt=0; 70 | for(int y2=-1;y2<2;y2++){ 71 | for(int x2=-1;x2<2;x2++){ 72 | if(x2+x<0 || x2+x>31 || y2+y<0 || y2+y >31)continue; 73 | if(rotated[x2+x][y2+y]==1)cnt++; 74 | }} 75 | 76 | if(cnt>3){ 77 | rotated[x][y]=1; 78 | debug = 99; 79 | } 80 | } 81 | 82 | }} 83 | 84 | for(int y=0;y<32;y++){ 85 | for(int x=0;x<32;x++){ 86 | if(rotated[x][y]==1){ 87 | DrawRectangle(x*16,y*8,16,8,RED); 88 | } 89 | }} 90 | 91 | DrawText(FormatText("%i",debug),0,0,30,BLACK); 92 | 93 | EndDrawing(); 94 | //---------------------------------------------------------------------------------- 95 | } 96 | 97 | // De-Initialization 98 | //-------------------------------------------------------------------------------------- 99 | CloseWindow(); // Close window and OpenGL context 100 | //-------------------------------------------------------------------------------------- 101 | 102 | return 0; 103 | 104 | 105 | } 106 | -------------------------------------------------------------------------------- /SpriteEditor/gridrotate.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | #include 4 | 5 | // 6 | // 7 | float angle=0; // radians 8 | int debug=0; 9 | int main(void) 10 | { 11 | // Initialization 12 | //-------------------------------------------------------------------------------------- 13 | const int screenWidth = 800; 14 | const int screenHeight = 450; 15 | 16 | InitWindow(screenWidth, screenHeight, "raylib example."); 17 | 18 | // Put some tiles in the map.. 19 | int map[32][32] = {0}; 20 | 21 | for (int y = 10; y < 32-10; y++) 22 | { 23 | for (int x = 10; x < 32-10; x++) 24 | { 25 | map[x][y]=1; 26 | }} 27 | 28 | 29 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 30 | //-------------------------------------------------------------------------------------- 31 | 32 | // Main game loop 33 | while (!WindowShouldClose()) // Detect window close button or ESC key 34 | { 35 | // Update 36 | //---------------------------------------------------------------------------------- 37 | if(IsKeyDown(KEY_RIGHT)){ 38 | angle+=0.1; 39 | } 40 | if(IsKeyDown(KEY_LEFT)){ 41 | angle-=0.1; 42 | } 43 | //---------------------------------------------------------------------------------- 44 | // Draw 45 | //---------------------------------------------------------------------------------- 46 | BeginDrawing(); 47 | ClearBackground(RAYWHITE); 48 | 49 | int rotated[32][32]={0}; 50 | for(int y=0;y<32;y++){ 51 | for(int x=0;x<32;x++){ 52 | int x2=floor((cos(angle)*(x-16) - sin(angle)*(y-16)))+16; 53 | int y2=floor((sin(angle)*(x-16) + cos(angle)*(y-16)))+16; 54 | if(x2>-1 && y2>-1 && x2<32 && y2<32){ 55 | rotated[x][y]=map[x2][y2]; 56 | } 57 | } 58 | } 59 | // interpolate 60 | for(int y=0;y<32;y++){ 61 | for(int x=0;x<32;x++){ 62 | if(rotated[x][y]==0){ 63 | int cnt=0; 64 | for(int y2=-1;y2<2;y2++){ 65 | for(int x2=-1;x2<2;x2++){ 66 | if(x2+x<0 || x2+x>31 || y2+y<0 || y2+y >31)continue; 67 | if(rotated[x2+x][y2+y]==1)cnt++; 68 | }} 69 | 70 | if(cnt>3){ 71 | // rotated[x][y]=1; 72 | // debug = 99; 73 | } 74 | } 75 | 76 | }} 77 | 78 | for(int y=0;y<32;y++){ 79 | for(int x=0;x<32;x++){ 80 | if(rotated[x][y]!=0){ 81 | DrawRectangle(x*16,y*8,16,8,RED); 82 | } 83 | }} 84 | 85 | DrawText(FormatText("%i",debug),0,0,30,BLACK); 86 | 87 | EndDrawing(); 88 | //---------------------------------------------------------------------------------- 89 | } 90 | 91 | // De-Initialization 92 | //-------------------------------------------------------------------------------------- 93 | CloseWindow(); // Close window and OpenGL context 94 | //-------------------------------------------------------------------------------------- 95 | 96 | return 0; 97 | 98 | 99 | } 100 | -------------------------------------------------------------------------------- /ai/SimulateRandomAvoidCollision/README.MD: -------------------------------------------------------------------------------- 1 | 2 | Here a asteroids(game) like simulation. It has a save and load state. It has ai that lets the ship move into a random direction without hitting a asteroid. It saves the state and gives the ship a random angle and thrust value and simulates a x number of steps into the future. If there is no collision then these values are passed into the regular visible onscreen version before(restored) the simulation occured. 3 | 4 | 5 | Forward collision 6 | -------------------------------------------------------------------------------- /ai/SimulateRandomAvoidCollision/resources/spacerocks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakz001/Raylib-Examples/abe00d9bcccf829de94fbc03aa3a5246a3a3a1ad/ai/SimulateRandomAvoidCollision/resources/spacerocks.png -------------------------------------------------------------------------------- /ai/SimulateRandomAvoidCollision/resources/spaceships.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakz001/Raylib-Examples/abe00d9bcccf829de94fbc03aa3a5246a3a3a1ad/ai/SimulateRandomAvoidCollision/resources/spaceships.png -------------------------------------------------------------------------------- /ai/SimulateRandomAvoidCollision/spacesimulate.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakz001/Raylib-Examples/abe00d9bcccf829de94fbc03aa3a5246a3a3a1ad/ai/SimulateRandomAvoidCollision/spacesimulate.exe -------------------------------------------------------------------------------- /ai/SimulateRandomAvoidCollision/spacesimulateMult.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakz001/Raylib-Examples/abe00d9bcccf829de94fbc03aa3a5246a3a3a1ad/ai/SimulateRandomAvoidCollision/spacesimulateMult.exe -------------------------------------------------------------------------------- /ai/Tanks/README.MD: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ai/Tanks/resources/sprites.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakz001/Raylib-Examples/abe00d9bcccf829de94fbc03aa3a5246a3a3a1ad/ai/Tanks/resources/sprites.png -------------------------------------------------------------------------------- /ai/Tanks/resources/tiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakz001/Raylib-Examples/abe00d9bcccf829de94fbc03aa3a5246a3a3a1ad/ai/Tanks/resources/tiles.png -------------------------------------------------------------------------------- /ai/Tanks/tanks.7z: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakz001/Raylib-Examples/abe00d9bcccf829de94fbc03aa3a5246a3a3a1ad/ai/Tanks/tanks.7z -------------------------------------------------------------------------------- /ai/Tanks/tanks.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakz001/Raylib-Examples/abe00d9bcccf829de94fbc03aa3a5246a3a3a1ad/ai/Tanks/tanks.exe -------------------------------------------------------------------------------- /ai/racing/README.MD: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ai/racing/racing.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakz001/Raylib-Examples/abe00d9bcccf829de94fbc03aa3a5246a3a3a1ad/ai/racing/racing.exe -------------------------------------------------------------------------------- /ai/racing/racing_situation1.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakz001/Raylib-Examples/abe00d9bcccf829de94fbc03aa3a5246a3a3a1ad/ai/racing/racing_situation1.exe -------------------------------------------------------------------------------- /effects/ScreenCircleTransitionCLEAN.c: -------------------------------------------------------------------------------- 1 | // 2 | // Circle screen transition effect (CLEAN) 3 | // 4 | // Draw a circle on the screen but draw from the edges of this circle 5 | // to the edges of the screen. 6 | // 7 | // 8 | 9 | #include "raylib.h" 10 | 11 | void circletransition(int r, int screenWidth, int screenHeight, Color col); 12 | 13 | int main(void) 14 | { 15 | // Initialization 16 | //-------------------------------------------------------------------------------------- 17 | const int screenWidth = 800; 18 | const int screenHeight = 450; 19 | 20 | InitWindow(screenWidth, screenHeight, "raylib example."); 21 | 22 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 23 | //-------------------------------------------------------------------------------------- 24 | 25 | int radius = 0; 26 | int state = 0; 27 | 28 | // Main game loop 29 | while (!WindowShouldClose()) // Detect window close button or ESC key 30 | { 31 | // Update 32 | //---------------------------------------------------------------------------------- 33 | 34 | if(state==0 && radius0){ 40 | radius-=10; 41 | }else{ 42 | state = 0; 43 | } 44 | 45 | 46 | //---------------------------------------------------------------------------------- 47 | // Draw 48 | //---------------------------------------------------------------------------------- 49 | BeginDrawing(); 50 | 51 | ClearBackground(RAYWHITE); 52 | 53 | 54 | for(int y=0;y= 0; --x) { 93 | if ((x * x) + (y * y) <= (radius * radius)) { 94 | DrawLine(0,yc-y,xc-x,yc-y,col); 95 | DrawLine(0,yc+y,xc-x,yc+y,col); 96 | DrawLine(xc+x,yc-y,screenWidth,yc-y,col); 97 | DrawLine(xc+x,yc+y,screenWidth,yc+y,col); 98 | largestX = x; 99 | break; // go to next y coordinate 100 | } 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /games/DoubleJointed/README.MD: -------------------------------------------------------------------------------- 1 | Double Dragon Inspired/parody 2 | 3 | Double Jointed(skeletons) 4 | -------------------------------------------------------------------------------- /games/DoubleJointed/doublejointed.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakz001/Raylib-Examples/abe00d9bcccf829de94fbc03aa3a5246a3a3a1ad/games/DoubleJointed/doublejointed.exe -------------------------------------------------------------------------------- /games/DoubleJointed/resources/Mrskelly.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakz001/Raylib-Examples/abe00d9bcccf829de94fbc03aa3a5246a3a3a1ad/games/DoubleJointed/resources/Mrskelly.png -------------------------------------------------------------------------------- /games/DoubleJointed/resources/Onedragon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakz001/Raylib-Examples/abe00d9bcccf829de94fbc03aa3a5246a3a3a1ad/games/DoubleJointed/resources/Onedragon.png -------------------------------------------------------------------------------- /games/DoubleJointed_Step3/README.MD: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /games/DoubleJointed_Step3/doublejointed.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakz001/Raylib-Examples/abe00d9bcccf829de94fbc03aa3a5246a3a3a1ad/games/DoubleJointed_Step3/doublejointed.exe -------------------------------------------------------------------------------- /games/DoubleJointed_Step3/resources/Mrskelly.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakz001/Raylib-Examples/abe00d9bcccf829de94fbc03aa3a5246a3a3a1ad/games/DoubleJointed_Step3/resources/Mrskelly.png -------------------------------------------------------------------------------- /games/DoubleJointed_Step3/resources/Onedragon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakz001/Raylib-Examples/abe00d9bcccf829de94fbc03aa3a5246a3a3a1ad/games/DoubleJointed_Step3/resources/Onedragon.png -------------------------------------------------------------------------------- /games/DoubleJointed_step2/README.MD: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /games/DoubleJointed_step2/doublejointed.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakz001/Raylib-Examples/abe00d9bcccf829de94fbc03aa3a5246a3a3a1ad/games/DoubleJointed_step2/doublejointed.exe -------------------------------------------------------------------------------- /games/DoubleJointed_step2/resources/Mrskelly.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakz001/Raylib-Examples/abe00d9bcccf829de94fbc03aa3a5246a3a3a1ad/games/DoubleJointed_step2/resources/Mrskelly.png -------------------------------------------------------------------------------- /games/DoubleJointed_step2/resources/Onedragon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakz001/Raylib-Examples/abe00d9bcccf829de94fbc03aa3a5246a3a3a1ad/games/DoubleJointed_step2/resources/Onedragon.png -------------------------------------------------------------------------------- /games/blockshooter/block_part1.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | #include 4 | 5 | // Get our angle between two points. 6 | static float getangle(float x1,float y1,float x2,float y2); 7 | 8 | 9 | int main(void) 10 | { 11 | // Initialization 12 | //-------------------------------------------------------------------------------------- 13 | const int screenWidth = 800; 14 | const int screenHeight = 450; 15 | 16 | InitWindow(screenWidth, screenHeight, "raylib example."); 17 | 18 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 19 | //-------------------------------------------------------------------------------------- 20 | 21 | float posx = 320; 22 | float posy = 400; 23 | 24 | // Main game loop 25 | while (!WindowShouldClose()) // Detect window close button or ESC key 26 | { 27 | // Update 28 | //---------------------------------------------------------------------------------- 29 | 30 | 31 | //---------------------------------------------------------------------------------- 32 | // Draw 33 | //---------------------------------------------------------------------------------- 34 | BeginDrawing(); 35 | 36 | ClearBackground(RAYWHITE); 37 | 38 | float x = GetMouseX()/32*32; 39 | float y = GetMouseY()/32*32; 40 | DrawRectangle(x,y,32,32,DARKGRAY); 41 | 42 | float an = getangle(posx,posy,x,y); 43 | 44 | DrawLine(posx,posy,posx+cos(an)*32,posy+sin(an)*32,DARKGRAY); 45 | 46 | 47 | DrawText(FormatText("Angle between x1,y1,x2,y2 : %f",getangle(GetMouseX(),GetMouseY(),posx,posy)),0,0,20,DARKGRAY); 48 | 49 | EndDrawing(); 50 | //---------------------------------------------------------------------------------- 51 | } 52 | 53 | // De-Initialization 54 | //-------------------------------------------------------------------------------------- 55 | CloseWindow(); // Close window and OpenGL context 56 | //-------------------------------------------------------------------------------------- 57 | 58 | return 0; 59 | 60 | 61 | } 62 | // Return the angle from - to in float 63 | float getangle(float x1,float y1,float x2,float y2){ 64 | return (float)atan2(y2-y1, x2-x1); 65 | } 66 | -------------------------------------------------------------------------------- /games/blockshooter/block_part2.c: -------------------------------------------------------------------------------- 1 | 2 | #include "raylib.h" 3 | #include 4 | 5 | int map[100][100] = {0}; 6 | 7 | 8 | 9 | // Get our angle between two points. 10 | static float getangle(float x1,float y1,float x2,float y2); 11 | 12 | 13 | 14 | int main(void) 15 | { 16 | // Initialization 17 | //-------------------------------------------------------------------------------------- 18 | const int screenWidth = 800; 19 | const int screenHeight = 450; 20 | 21 | InitWindow(screenWidth, screenHeight, "raylib example."); 22 | 23 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 24 | //-------------------------------------------------------------------------------------- 25 | 26 | for(int i=0;i<100;i++){ 27 | map[i][0]=1; 28 | } 29 | 30 | float posx = 320; 31 | float posy = 400; 32 | 33 | // Main game loop 34 | while (!WindowShouldClose()) // Detect window close button or ESC key 35 | { 36 | // Update 37 | //---------------------------------------------------------------------------------- 38 | 39 | 40 | //---------------------------------------------------------------------------------- 41 | // Draw 42 | //---------------------------------------------------------------------------------- 43 | BeginDrawing(); 44 | 45 | ClearBackground(RAYWHITE); 46 | 47 | for(int y=0;y<10;y++){ 48 | for(int x=0;x<100;x++){ 49 | if(map[x][y]==1){ 50 | DrawRectangle(x*32,y*32,32,32,RED); 51 | DrawRectangle(x*32+1,y*32+1,32-2,32-2,BLUE); 52 | } 53 | }} 54 | 55 | 56 | float x = GetMouseX()/32; 57 | float y = GetMouseY()/32; 58 | 59 | if(map[(int)x][(int)y]==0){ 60 | if( map[(int)x][(int)y-1]==1 || map[(int)x-1][(int)y]==1 || map[(int)x+1][(int)y]==1){ 61 | DrawRectangle(x*32,y*32,32,32,DARKGRAY); 62 | }} 63 | 64 | float an = getangle(posx,posy,x*32,y*32); 65 | 66 | DrawLine(posx,posy,posx+cos(an)*32,posy+sin(an)*32,DARKGRAY); 67 | 68 | 69 | 70 | 71 | EndDrawing(); 72 | //---------------------------------------------------------------------------------- 73 | } 74 | 75 | // De-Initialization 76 | //-------------------------------------------------------------------------------------- 77 | CloseWindow(); // Close window and OpenGL context 78 | //-------------------------------------------------------------------------------------- 79 | 80 | return 0; 81 | 82 | 83 | } 84 | // Return the angle from - to in float 85 | float getangle(float x1,float y1,float x2,float y2){ 86 | return (float)atan2(y2-y1, x2-x1); 87 | } 88 | -------------------------------------------------------------------------------- /games/wip-DudeSpaceMining.c: -------------------------------------------------------------------------------- 1 | // Based on my old game project "Dude Space Mining " : 2 | // https://github.com/Pakz001/Monkey2examples/blob/master/games/dudespacemining5.monkey27 3 | // (Playable) https://cromdesi.home.xs4all.nl/emscripten/dudespacemining/Main.html 4 | // 5 | // 6 | // Create tilemap system of 20x100by20x100 tiles. Player starts at position 10x10. In the Tilemap struct 7 | // a map is created for this start position(10x10) When the map scrolls near the edge then a new section 8 | // is created. In each map section a minable asteroid is created. 9 | 10 | 11 | #include "raylib.h" 12 | 13 | #define MAX_TILEMAPS 200 14 | 15 | static int map[20][20]; 16 | 17 | typedef struct{ 18 | Vector2 mapPosition; 19 | }Player; 20 | 21 | 22 | typedef struct { 23 | int map[100][100]; //20x100by20x100 tiles. 24 | }Tilemap; 25 | 26 | int main(void) 27 | { 28 | // Initialization 29 | //-------------------------------------------------------------------------------------- 30 | const int screenWidth = 800; 31 | const int screenHeight = 450; 32 | 33 | InitWindow(screenWidth, screenHeight, "raylib example."); 34 | 35 | // Create all the tilemaps, they will be generated when needed. 36 | Tilemap playerMaps[MAX_TILEMAPS] = { 0 }; 37 | 38 | 39 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second 40 | //-------------------------------------------------------------------------------------- 41 | 42 | // Main game loop 43 | while (!WindowShouldClose()) // Detect window close button or ESC key 44 | { 45 | // Update 46 | //---------------------------------------------------------------------------------- 47 | 48 | 49 | //---------------------------------------------------------------------------------- 50 | // Draw 51 | //---------------------------------------------------------------------------------- 52 | BeginDrawing(); 53 | 54 | ClearBackground(RAYWHITE); 55 | 56 | 57 | EndDrawing(); 58 | //---------------------------------------------------------------------------------- 59 | } 60 | 61 | // De-Initialization 62 | //-------------------------------------------------------------------------------------- 63 | CloseWindow(); // Close window and OpenGL context 64 | //-------------------------------------------------------------------------------------- 65 | 66 | return 0; 67 | 68 | 69 | } 70 | --------------------------------------------------------------------------------