1. Setting Up the Development Environment
Before we start coding, we need to set up our development environment. In this tutorial, we use VS Code as our code editor, along with the MarsCode extension and AI-assisted coding.
Steps:
- Open VS Code and navigate to File -> Open Folder.
- Select a pre-created folder, such as SuperMarioGame, and click Open Folder.
- Ensure Python and Pygame are installed. If not, install them using:pip install pygame.
- Open the MarsCode extension in VS Code to prepare for AI-assisted coding.
2. Generating Base Game Code with AI
Pygame is a powerful 2D game development library. We can generate the base game code using AI.
Steps:
- In MarsCode, enter the following prompt: Create a Super Mario mini-game using Pygame.
- Select DeepSeek V3 as the AI model and click Send.
- The AI-generated code includes:
– Left and right movement for Mario.
– Jumping functionality.
– A simple gravity system.
– A platform for jumping.
– Basic collision detection. - Click Apply to generate main.py.
3. Running and Fixing Initial Issues
- Right-click main.py and run the script.
- Mario appears as a red block instead of an image.
- Modify the AI prompt: Display Mario as an image instead of a red rectangle.
- AI updates the code, adding:
– Image loading functionality.
– Proper scaling for Mario.
– `screen.blit()` instead of `pygame.draw.rect()`.
4. Adding Character Animations
To improve movement realism:
- Enter this prompt:
Please modify the code. When Mario moves to the left, it should display the animation of walking to the left, and when he moves to the right, it should display the animation of walking to the right. If you don't walk or move, you can display the standing picture in that direction. And I only have the picture facing the left, and the picture facing the right requires the program to generate it itself.
- AI generates a script supporting:
– A standing sprite.
– Walking animations with two frames.
– Auto-flipping the left-facing sprite for right movement.
5. Finalizing and Enhancing
- Save all images in the project folder.
- Run the game again.
- Add background, enemies, and sound effects for more fun!
6. Demo Video
You can watch the following demo video by select the subtitle to your preferred subtitle language.