Skip to content

param20h/space-invade

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI-Powered Space Invaders with Python and Pygame This repository contains the source code for the "Space Invaders" style game featured in our blog post on building games with Generative AI. The project demonstrates how to use an AI coding assistant (like Amazon Q Developer) to progressively build a complete and playable game from simple text prompts.

🚀 About The Project The goal of this project is to showcase how modern AI tools can democratize game development. By following the prompts outlined in our tutorial, you can generate this entire game, from basic player movement to a fully functional arcade shooter with enemies, scoring, and player lives.

This repository serves as the final reference code, allowing you to see the complete project and compare it with the code you generate.

Key Features Player Control: Smooth left-right movement for the player's spaceship.

Invader Swarm: A grid of enemies that moves horizontally, drops down, and reverses direction.

Shooting Mechanics: Fire lasers to destroy invaders and score points.

Collision Detection: Lasers destroy invaders, and enemy lasers can destroy the player.

Scoring System: Gain points for each invader destroyed.

Game State: Win and lose conditions to create a complete gameplay loop.

🛠️ Technologies Used This project is built with a few simple, powerful, and free tools:

Python - A versatile and beginner-friendly programming language.

Pygame - A cross-platform set of Python modules designed for writing video games.

🔧 Getting Started To get a local copy up and running, follow these simple steps.

Prerequisites Make sure you have Python and pip installed on your system. This project was built using Python 3.9, but any recent version of Python 3 should work.

Python 3.9+

python --version

pip (Python Package Installer)

pip --version

Installation Clone the repository

git clone

Navigate to the project directory

cd ai-space-invaders

Install Pygame

pip install pygame

Running the Game

Desktop Version: Execute the main Python script to start the game.

python space_invaders.py

Web Version: The game is automatically deployed to GitHub Pages when you push to the main branch. You can play it online at: https://[your-username].github.io/[repository-name]/

Two deployment options are available:

  1. HTML5 Version (recommended): A native JavaScript/HTML5 implementation that runs smoothly in any modern browser
  2. Pygame Web Version: Uses pygbag to convert the Python/Pygame code to run in browsers

🌐 Online Deployment

This repository includes GitHub Actions workflows that automatically deploy the game to GitHub Pages:

  • deploy-html5.yml: Creates a native HTML5/JavaScript version of the game
  • deploy-game.yml: Converts the Python/Pygame code to run in browsers using pygbag

To enable GitHub Pages deployment:

  1. Go to your repository Settings
  2. Navigate to Pages section
  3. Set Source to "GitHub Actions"
  4. Push to main branch to trigger deployment

🎮 How to Play The controls are simple and classic!

Move Left: Left Arrow Key

Move Right: Right Arrow Key

Shoot Laser: Spacebar

Your mission is to destroy all the invaders before they reach the bottom of the screen. Avoid their lasers and aim for the high score!

📖 Blog Post This code was created as part of our step-by-step tutorial on building games with AI. For the full context, prompts, and detailed explanations, please read the original article:

🤝 Contributing Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".

Fork the Project

Create your Feature Branch (git checkout -b feature/AmazingFeature)

Commit your Changes (git commit -m 'Add some AmazingFeature')

Push to the Branch (git push origin feature/AmazingFeature)

Open a Pull Requestu

📄 License Distributed under the MIT License. See LICENSE file for more information.

About

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors