Python Mini-Game Collection with Source Code Tutorials
This article presents a series of Python mini-game tutorials, including code for coin-collecting, ping-pong, skiing, space shooter, whack-a-mole, dinosaur runner, match-3, Tetris, snake, 24-point puzzle, alien invasion, tic-tac-toe, and more, offering complete source files and gameplay explanations.
This article provides a collection of Python mini‑game tutorials, each with full source code and brief explanations, covering a variety of classic arcade‑style games.
1. Coin Collecting – A pygame program where the player moves a hero to collect gold coins while avoiding obstacles. The code demonstrates initializing pygame, loading images and sounds, handling keyboard input, updating the game state, and recording high scores.
<code>import os
import cfg
import sys
import pygame
def initGame():
pygame.init()
screen = pygame.display.set_mode(cfg.SCREENSIZE)
pygame.display.set_caption('吃金币 —— 九歌')
# load assets, main loop, event handling, etc.
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
# update, draw, flip
</code>2. Ping‑Pong – Implements a two‑player table tennis game with paddle control, ball physics, and scoring. The source shows how to manage multiple sprites, detect collisions, and render the game loop.
<code>def startInterface(screen):
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
# draw paddles, ball, scores
pygame.display.update()
clock.tick(60)
</code>Additional games include a skiing runner, a space‑shooter, a whack‑a‑mole, a dinosaur runner, a match‑3 puzzle, a Tetris clone using PyQt5, the classic Snake, a 24‑point arithmetic puzzle, an alien invasion shooter, and a tic‑tac‑toe implementation. Each section follows the same structure: asset loading, main loop, event handling, collision detection, and end‑game interface.
The article concludes with promotional information for a free Python public course and links to further reading.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.