{"id":18295259,"url":"https://github.com/andezion/knight","last_synced_at":"2025-08-25T13:17:22.548Z","repository":{"id":235772976,"uuid":"791219533","full_name":"Andezion/Knight","owner":"Andezion","description":"This is a small test project that demonstrates character movement and control using the SDL library. Also, it is pure C :) ","archived":false,"fork":false,"pushed_at":"2025-01-16T22:29:26.000Z","size":5276,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T08:35:28.257Z","etag":null,"topics":["2d-game-engine","c","clion","clion-cmake","game-development","sdl","sdl2-image","sdl2-mixer","sdl2-ttf"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Andezion.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-24T10:06:30.000Z","updated_at":"2025-04-07T18:25:56.000Z","dependencies_parsed_at":"2024-11-05T14:42:58.836Z","dependency_job_id":"1409f310-97c0-4148-8947-f96d034c8b88","html_url":"https://github.com/Andezion/Knight","commit_stats":null,"previous_names":["andezion/knight"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Andezion/Knight","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andezion%2FKnight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andezion%2FKnight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andezion%2FKnight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andezion%2FKnight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Andezion","download_url":"https://codeload.github.com/Andezion/Knight/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andezion%2FKnight/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264321025,"owners_count":23590567,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["2d-game-engine","c","clion","clion-cmake","game-development","sdl","sdl2-image","sdl2-mixer","sdl2-ttf"],"created_at":"2024-11-05T14:34:12.629Z","updated_at":"2025-07-08T18:07:35.236Z","avatar_url":"https://github.com/Andezion.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Knight\nThis is my test game for understanding basics of SDL and game development on C.\n## Table on contents\n* [General info](#general-info)\n* [Gameplay](#gameplay)\n* [Technologies](#technologies)\n* [Setup](#setup)\n\n## General info\nI wanted to write some game using only C, so this is actually my first ever try. I decided to use SDL framework and CLion as compiler. It was pretty hard to understand how to use SDL with CMakefiles, but, thanks to Timur (iltam sumra rashid), i could do it! So, the game shows as some little knight, that should kill some bots from UL. In future I am planning to add levels, different bots, different knight and really much other stuff! \n\nThe main technology implemented in this game is changing frames when you press the keys. I rendered all the frames separately, so that moving, hitting and all other actions of the characters turned out smooth and pleasant (relatively).\nHere's an example of how I implemented frame loading, where fileNames is names of our photos (f.e. photo1.jpg), arraySize is a numbers of our frames and textureArray is our storage: \n```\nint loadTextureArray(SDL_Renderer* renderer, const char** fileNames, int arraySize, SDL_Texture** textureArray)\n{\n    for(int i = 0; i \u003c arraySize; i++)\n    {\n        SDL_Surface* surface = SDL_LoadBMP(fileNames[i]);\n        if (surface == NULL)\n        {\n            printf(\"Error loading image %d: %s\\n\", i, SDL_GetError());\n            SDL_DestroyRenderer(renderer);\n            return 1;\n        }\n        textureArray[i] = SDL_CreateTextureFromSurface(renderer, surface);\n        SDL_FreeSurface(surface);\n        if (textureArray[i] == NULL)\n        {\n            printf(\"Error creating texture for image %d: %s\\n\", i, SDL_GetError());\n            SDL_DestroyRenderer(renderer);\n            return 1;\n        }\n    }\n    return 0;\n}\n```\nHere is my little boy:\n\n![Knight](./Photo/type2.jpg)\n\nI decided to make the number of bots and where they are generated random, that way gameplay will be more varied. Also now I will demonstrate the moment of my knight's strike.\n```\n            else if (event.key.keysym.sym == SDLK_SPACE)\n            {\n                isHitting = 1;\n                \n                if(type_1 == 1)\n                {\n                    if(type_2 == 1)\n                    {\n                        SDL_Rect rect_hit = {posX, posY, WIDTH, HEIGHT};\n                        SDL_RenderCopy(renderer, texture_for_hitting_up[current_hit_up % frames_type_two], NULL, \u0026rect_hit);\n                        current_hit_up = (current_hit_up + 1) % frames_type_two;\n                    }\n                    else\n                    {\n                        SDL_Rect rect_hit = {posX, posY, WIDTH, HEIGHT};\n                        SDL_RenderCopy(renderer, texture_for_hitting_down[current_hit_down % frames_type_two], NULL, \u0026rect_hit);\n                        current_hit_down = (current_hit_down + 1) % frames_type_two;\n                    }\n                }\n                else\n                {\n                    if(type_2 == 1)\n                    {\n                        SDL_Rect rect_hit = {posX, posY, WIDTH, HEIGHT};\n                        SDL_RenderCopy(renderer, texture_for_hitting_in_plus[current_hit_in_plus % frames_type_two], NULL, \u0026rect_hit);\n                        current_hit_in_plus = (current_hit_in_plus + 1) % frames_type_two;\n                    }\n                    else\n                    {\n                        SDL_Rect rect_hit = {posX, posY, WIDTH, HEIGHT};\n                        SDL_RenderCopy(renderer, texture_for_hitting_in_minus[current_hit_in_minus % frames_type_two], NULL, \u0026rect_hit);\n                        current_hit_in_minus = (current_hit_in_minus + 1) % frames_type_two;\n                    }\n                }\n            }\n```\nWhat does that mean? It means that when we press the spacebar we determine the direction of our knight (right or left) and depending on this we load a new array of textures into the renderer for playback!\nFor example, when he hits:\n\n![Hit1](./Photo/type1.jpg)\n\nAnd there is when he just stand: \n\n![Hit2](./Photo/type3.jpg)\n\n## Gameplay\n\nhttps://github.com/Andezion/Knight/assets/115638748/3f3fc47b-fc7f-4eb6-9a32-070ba6883f2d\n\n## Technologies\nProject is created with:\n* SDL, SDL2 and stuff\n* CLion with C lang\n* Photoshop for editing frames\n* Structers, we don't have classes there :)\n* My anal pain\n\n## Setup \nI didn't do release yet, but soon it will appear in this project. Without release it would be pointless to try to download, because CMakefiles is too hard to handle, so...\n\n    \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandezion%2Fknight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandezion%2Fknight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandezion%2Fknight/lists"}