{"id":20514814,"url":"https://github.com/pgvalle/spaceinvadersclone","last_synced_at":"2025-10-27T18:11:30.119Z","repository":{"id":64837783,"uuid":"576012223","full_name":"pgvalle/SpaceInvadersClone","owner":"pgvalle","description":"Yet another Space Invaders clone coded in C","archived":false,"fork":false,"pushed_at":"2024-10-19T13:05:51.000Z","size":1172,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T00:15:11.606Z","etag":null,"topics":["c","gamedev","jesus","jesus-christ","jesus-is-da-lord-n-savior","sdl2","space-invaders"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pgvalle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-08T20:06:41.000Z","updated_at":"2024-10-19T13:05:54.000Z","dependencies_parsed_at":"2024-05-22T15:00:52.818Z","dependency_job_id":null,"html_url":"https://github.com/pgvalle/SpaceInvadersClone","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgvalle%2FSpaceInvadersClone","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgvalle%2FSpaceInvadersClone/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgvalle%2FSpaceInvadersClone/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgvalle%2FSpaceInvadersClone/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pgvalle","download_url":"https://codeload.github.com/pgvalle/SpaceInvadersClone/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248799953,"owners_count":21163404,"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":["c","gamedev","jesus","jesus-christ","jesus-is-da-lord-n-savior","sdl2","space-invaders"],"created_at":"2024-11-15T21:18:22.909Z","updated_at":"2025-10-27T18:11:30.053Z","avatar_url":"https://github.com/pgvalle.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Space Invaders Clone\r\n\r\nThis readme is dated. :v\r\n\r\nThis game, as the name suggests, is yet another\r\n[SpaceInvaders](https://en.wikipedia.org/wiki/Space_Invaders)' clone.\r\nObviously It's not 100% the same as the original one.\r\nBut I guarantee it's good enough to be called Space Invaders Clone.\r\n\r\n# Build instructions\r\n## Linux\r\n\r\nTo start, you must install sdl2 and sdl2-mixer (in the future, when I add audio effects).\r\nIf you don't know how to install those libraries, here are the commands to install them in debian,\r\narch and fedora based distros with some extra stuff you need but might not have already installed:\r\n\r\n1. `$ sudo apt install make gcc git libsdl2-dev libsdl2-mixer-dev`\r\n2. `$ sudo pacman -S make gcc git sdl2 sdl2_ttf sdl2_mixer`\r\n3. `$ sudo dnf install make gcc git-all SDL2-devel SDL2_mixer-devel`\r\n\r\nUsing make should produce an executable called space_invaders.out inside the repo root folder\r\nAnd you're done. You should be able to execute the game now.\r\n\r\n## Windows\r\n\r\nTo be documented...\r\n\r\n# Concepts\r\n## Table of Contents\r\n\r\n1.  [Finite State Machines (at least two)](#finite-state-machines)\r\n2.  [Event Loop](#event-loop)\r\n3.  Animations\r\n4.  Keyboard and/or Mouse events\r\n5.  Timers\r\n6.  Collisions\r\n7.  Text and Images\r\n8.  [Dynamic collections (at least one)](#dynamic-collections)\r\n9.  [Something else...](#something-else)\r\n10. [Problems](#problems)\r\n11. [The good thing](#the-good-thing)\r\n\r\n## Finite State Machines\r\n\r\nThere's a total of 8 state machines that you can find in the code.\r\nHere's the diagram for each one of them:\r\n\r\n### Screens\r\n![screens](readme/fsm/screens.png \"screens\")\r\n### Menu\r\n![menu](readme/fsm/menu.png \"menu\")\r\n### Play\r\n![play](readme/fsm/play.png \"play\")\r\n### Pause\r\n![pause](readme/fsm/pause.png \"pause\")\r\n### Game Over\r\n![over](readme/fsm/over.png \"over\")\r\n\r\n## Event Loop\r\n\r\nHere's how I have my event loop:\r\n```\r\nvoid run_app_loop()\r\n{\r\n    const Uint32 FPS = 60;\r\n    Uint32 start = 0, delta = 0, event_start = 0, event_wait = 1000 / FPS;\r\n\r\n    while (screen != SCREEN_EXIT) {\r\n        SDL_Event event;\r\n        if (SDL_WaitEventTimeout(\u0026event, event_wait)) {\r\n            process_app_events(\u0026event);\r\n\r\n            const Uint32 event_delta = SDL_GetTicks() - event_start;\r\n            event_start += event_delta;\r\n            // wait less next time\r\n            event_wait -= event_delta \u003c event_wait ? event_delta : event_wait;\r\n        } else {\r\n            update_app(delta);\r\n            render_app();\r\n        \r\n            delta = SDL_GetTicks() - start;\r\n            start += delta;\r\n            // reset event timing\r\n            event_start = start;\r\n            event_wait = 1000 / FPS;\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n## Dynamic collections\r\n\r\nFirst of all, a quick shout to [nothings](https://github.com/nothings).\r\nI used two of their libraries: [stb_ds.h](https://github.com/nothings/stb/blob/master/stb_ds.h)\r\nand [stb_image.h](https://github.com/nothings/stb/blob/master/stb_image.h).\r\nReally good pieces of software, btw! Saved me so much hours I can't even count.\r\nThere are three dynamic collections in the game: explosions, invaders and shots.\r\n\r\n## Something Else...\r\n\r\nI was supposed to implement an algorithm, data structure or effect in my game\r\nthat would make it more than just an example application implemented using all the concepts required.\r\nI came up with a technique to render texts which basically consisted in rendering ascii characters\r\nusing sdl-ttf once and saving the output as a png. Then, as the font picked is ~~almost~~ monospaced,\r\nit became easier to map a character, say 'A', to a section of the image that contains 'A'.\r\nIt helped me rendering dynamic ui elements like the score counter.\r\n\r\n## Problems\r\n\r\n1. I couldn't figure out how to organize my code in a satisfactory way.\r\nIt Probably has something to do with either my \"it's not good enough\" thing or my lack of knowledge on clean coding.\r\n2. Audio effects aren't implemented yet and obviously we got some annoying bugs as well.\r\n\r\n## The good thing\r\n\r\nEven with a lot of defects, this project helped me improve myself as a programmer and as a person.\r\nI tried so hard in the past to code simple games like pong and snake but failed. Those previous experiences\r\nmade me stop thinking of game programming. However, recently I had classes on event-oriented programming with games.\r\nThose classes helped me realize I can't just start coding whatever. I need to have a goal and study on how I can\r\nreach that goal before before kicking the ball. And the bigger the project, the bigger the planning.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgvalle%2Fspaceinvadersclone","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpgvalle%2Fspaceinvadersclone","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgvalle%2Fspaceinvadersclone/lists"}