{"id":24382056,"url":"https://github.com/tanner-davison/asteroid-destroyer-sdl","last_synced_at":"2025-12-26T06:46:54.697Z","repository":{"id":270628884,"uuid":"910968495","full_name":"Tanner-Davison/asteroid-destroyer-sdl","owner":"Tanner-Davison","description":"Asteroid Destroyer made from scratch using C++ and SDL subsystems","archived":false,"fork":false,"pushed_at":"2025-07-29T08:53:27.000Z","size":43570,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-29T09:38:41.695Z","etag":null,"topics":["cmake","cmakel","cpp","cpp23","dll","sdl2","sdl2-library"],"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/Tanner-Davison.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,"zenodo":null}},"created_at":"2025-01-01T23:45:25.000Z","updated_at":"2025-07-29T08:53:31.000Z","dependencies_parsed_at":"2025-01-16T09:26:19.567Z","dependency_job_id":"888ade36-0c29-4e7d-8a52-73983524bb72","html_url":"https://github.com/Tanner-Davison/asteroid-destroyer-sdl","commit_stats":null,"previous_names":["tanner-davison/sdl-window","tanner-davison/cpp-sdl-game","tanner-davison/asteroid-destroyer-sdl"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Tanner-Davison/asteroid-destroyer-sdl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tanner-Davison%2Fasteroid-destroyer-sdl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tanner-Davison%2Fasteroid-destroyer-sdl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tanner-Davison%2Fasteroid-destroyer-sdl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tanner-Davison%2Fasteroid-destroyer-sdl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tanner-Davison","download_url":"https://codeload.github.com/Tanner-Davison/asteroid-destroyer-sdl/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tanner-Davison%2Fasteroid-destroyer-sdl/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28047809,"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","status":"online","status_checked_at":"2025-12-26T02:00:06.189Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["cmake","cmakel","cpp","cpp23","dll","sdl2","sdl2-library"],"created_at":"2025-01-19T09:16:21.625Z","updated_at":"2025-12-26T06:46:54.681Z","avatar_url":"https://github.com/Tanner-Davison.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e Asteroids Destroyer an SDL Game. \u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e Welcome, This is my first Game Project using SDL's Subsystem and my best first attempt at creating a 2D game! \u003c/p\u003e\n\u003cp align=\"center\"\u003eCreated By: Tanner Davison\u003c/p\u003e\n\u003cp align=\"center\" \u003etanner.davison95@gmail.com\u003c/p\u003e\n\u003cp align=\"center\"\u003e\u003cem\u003eNow compatible on Mac and or Windows Desktop!\u003c/em\u003e\u003c/p\u003e\n\u003cbr/\u003e\n\u003cp\u003ePlease email me if you know any patterns that could assist in this project or if you would like to share any tips and tricks I could use to improve my SDL compatibility\u003c/p\u003e\n\u003c/br\u003e\n\n# Steps Of Rendering In Game Objects\n\n#### _or even better send a pr with your changes!_\n\n### Step 1: Create Surface\n\n````cpp\ncppCopySDL_Surface* surface = TTF_RenderText_Solid(font, \"Text\", color);\n// or\nSDL_Surface* surface = IMG_Load(\"image.png\");\n\n### Step 2: Create Texture from Surface\n\n```cpp\ncppCopySDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);\n````\n\n### Define the Destination Rectangle (where to render)\n\n```cpp\ncppCopySDL_Rect destRect = { x, y, width, height };\n```\n\n### Step 3: Render to Screen\n\n```cpp\ncppCopySDL_RenderCopy(renderer, texture, NULL, \u0026destRect);\n```\n\n### Cleanup to Prevent Memory Leaks\n\n```cpp\nSDL_DestroyTexture(texture);      // Then destroy texture\n```\n\n## Updating Player Position functions(quite a lot)\n\n```cpp\n//main() -\u003e\n    //...\n\n    while (accumulator \u003e= FIXED_TIME_STEP) {\n      for (auto \u0026player : players) {\n        player-\u003ehandlePlayerInputAndPosition(keyState); //HERE!\n      }\n\n    //...\n```\n\n### handlePlayerInputAndPosition\n\n````cpp\nvoid Player::handlePlayerInputAndPosition(const Uint8 *keyState) {\n  handleInput(keyState[SDL_SCANCODE_W] || keyState[SDL_SCANCODE_UP],\n              keyState[SDL_SCANCODE_S] || keyState[SDL_SCANCODE_DOWN],\n              keyState[SDL_SCANCODE_A] || keyState[SDL_SCANCODE_LEFT],\n              keyState[SDL_SCANCODE_D] || keyState[SDL_SCANCODE_RIGHT],\n              keyState[SDL_SCANCODE_SPACE], keyState[SDL_SCANCODE_LSHIFT]);\n}\n\n```cpp\nvoid Player::handlePlayerInputAndPosition(const Uint8 *keyState) {\n  const bool up = keyState[SDL_SCANCODE_W] || keyState[SDL_SCANCODE_UP],\n             down = keyState[SDL_SCANCODE_S] || keyState[SDL_SCANCODE_DOWN],\n             left = keyState[SDL_SCANCODE_A] || keyState[SDL_SCANCODE_LEFT],\n             right = keyState[SDL_SCANCODE_D] || keyState[SDL_SCANCODE_RIGHT],\n             boost = keyState[SDL_SCANCODE_LSHIFT],\n             isShooting = keyState[SDL_SCANCODE_SPACE];\n\n  ACCELERATION = boost ? BOOST_ACCELERATION : BASE_ACCELERATION;\n  float CurrentMaxVelocity = boost ? MAX_VELOCITY * 1.5f : MAX_VELOCITY;\n\n  // Movement handling\n  if (right) {\n    velocityX = std::min(velocityX + ACCELERATION, CurrentMaxVelocity);\n  } else if (left) {\n    velocityX = std::max(velocityX - ACCELERATION, -CurrentMaxVelocity);\n  } else {\n    velocityX *= DECELERATION;\n    if (abs(velocityX) \u003c 0.3f) {\n      velocityX = 0;\n    }\n  }\n\n  if (down) {\n    velocityY = std::min(velocityY + ACCELERATION, CurrentMaxVelocity);\n  } else if (up) {\n    velocityY = std::max(velocityY - ACCELERATION, -CurrentMaxVelocity);\n  } else {\n    velocityY *= DECELERATION;\n    if (abs(velocityY) \u003c 0.3f) {\n      velocityY = 0;\n    }\n  }\n\n  if (isShooting) {\n    weapon.shoot();\n  }\n\n  float nextX = rectXf + velocityX;\n  float nextY = rectYf + velocityY;\n    //THIS GETS CALLED NEXT\n  handleBoundsAndUpdatePosition(nextX, nextY);\n}\n````\n\n### handleBoundsAndUpdatePosition(nextX, nextY);\n\n```cpp\nvoid Player::handleBoundsAndUpdatePosition(float nextX, float nextY) {\n  const bool hitLeftWall = nextX \u003c= 0,\n             hitRightWall = nextX \u003e= SCREEN_WIDTH - rectWidth,\n             hitTopWall = nextY \u003c= 0,\n             hitBottomWall = nextY \u003e= SCREEN_HEIGHT - rectHeight;\n\n  if (hitLeftWall) {\n    rectXf = 0.0f;\n    velocityX = -velocityX * 1.8f;\n\n  } else if (hitRightWall) {\n    rectXf = SCREEN_WIDTH - rectWidth;\n    velocityX = -velocityX * 1.8f;\n  } else {\n    rectXf = nextX;\n  }\n\n  if (hitTopWall) {\n    rectYf = 0.0f;\n    velocityY = -velocityY * 1.8f;\n\n  } else if (hitBottomWall) {\n    rectYf = SCREEN_HEIGHT - rectHeight;\n    velocityY = -velocityY * 1.8f;\n\n  } else {\n    rectYf = nextY;\n  }\n\n  // update Position\n  rectX = static_cast\u003cint\u003e(rectXf);\n  rectY = static_cast\u003cint\u003e(rectYf);\n}\n```\n\n## Specific vars description to position\n\nx: Players x-coordinets\ny: Players y-coordinates\n\nvelocityX: Players speed along the x-axis\nvelocityY: Players speed along the y-axis\n\nP(x) = centerX + (i - (n/2)) _ spacing\nP(y) = bottomY - |i - (n/2)| _ vertical_offset\nWhere:\n\n**n** is the total count of players\n**i** is the current player index (0 to n-1)\n| | represents absolute value\n\nThis is essentially a linear function for x-coordinates combined with an absolute value function for y-coordinates,\ncentered around the middle index. It creates a symmetric V shape because the absolute value function creates the same y-offset for positions equidistant from the center,\nwhile the x-coordinates spread outward linearly.\n\n## MOVEMENT\n\nspeed: the base speed of the player\n\nacceleration: How quick the player can change speed\n\nmaxSpeed: the max speed the player can reach\n\nisMoving: A boolean variable to track whether the player is currently moving\n\nfacingDirection: A variable to track the direction the player is facing, can be an angle, a vector, or a enum for representing\n\ndirections like \"Up\" , \"Down\", \"Left\" and \"Right\".\n\nangle: current rotation angle in degrees\n\nrotationSpeed: degrees per frame\n\n# Used with Neovim\n\nThis project is a basic C++ game setup using SDL2 for graphics, input handling, and window management. The project is configured with CMake for building and g++ for compiling on Windows.\n\n# Compilation Notes for Self\n\nclang looks for compilation databases in this order:\n\n1. compile_commands.json\n2. compile_flags.txt\n3. .clangd\\ configuration file\n\n## Prerequisites\n\nBefore you can build and run this project, you need to have the following installed:\n\n- **SDL2** library:\n  - Download SDL2 from [SDL2 Downloads](https://www.libsdl.org/download-2.0.php) or use a package manager to install it (e.g., vcpkg, or brew on macOS).\n  - SDL2.dll must be placed in the `bin` directory for the project to run properly.\n\n## How\n\n## Setup\n\n### Clone the Repository\n\nFirst, clone the repository to your local machine:\n\n```bash\ngit clone https://github.com/Tanner-Davison/sdl-first-game.git\ncd sdl-first-game\nInstall SDL2\n```\n\nMake sure that you have the SDL2 library installed. You can download it from the official SDL2 website. [or here](https://github.com/libsdl-org/SDL/releases)\n\nIf you are using vcpkg to manage dependencies, you can install SDL2 with the following command:\n\n```bash\nvcpkg install sdl2\nMake sure to link the SDL2 include and lib directories properly in your project if you're not using a package manager.\n```\n\nBuild the Project\nGenerate CMake build files:\n\nOpen the project folder in your terminal and run:\n\n```bash\ncmake -S . -B build\n```\n\nBuild the project:\n\nAfter generating the build files, run:\n\n```bash\ncmake --build build\n```\n\nThis will compile your project using Visual Studio's build system.\n\nRunning the Project\nAfter building the project, you can run the executable. Depending on your setup, run the following command in your terminal:\n\nOn Windows (using Visual Studio):\n\n```bash\n.\\build\\Debug\\sdl-first-game.exe\n```\n\n```bash\n# On Linux/macOS (or a Unix-like system):\n./build/sdl-first-game\n```\n\nEnsure that the SDL2.dll file is in the same folder as the executable on Windows, or ensure that the necessary SDL2 shared libraries are available on Unix-like systems.\n\nCode Structure\n\n**CMakeLists.txt:** CMake build configuration.\n\n**src/main.cpp:** The main C++ entry point of the application.\n\n**include/:** Folder where header files (if any) are placed.\n\n**lib/:** Folder containing the SDL2 libraries.\n\n**bin/:** Folder where SDL2.dll is placed for runtime.\n\nThe project is configured to use SDL2 with the C++ standard set to C++23.\nThe #define **SDL_MAIN_HANDLED** is used to prevent SDL2 from overriding the main function.\nPLEASE PUT THIS ON TOP TO NOT DRIVE YOURSELF CRAZY DURING COMPILATION\nLicense\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanner-davison%2Fasteroid-destroyer-sdl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftanner-davison%2Fasteroid-destroyer-sdl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanner-davison%2Fasteroid-destroyer-sdl/lists"}