Chasing-Enemy: Dynamic Obstacles & Items
A survival game built with Pygame, where you must outmaneuver a sword-wielding enemy while navigating dynamic obstacles, collecting coins, and avoiding bombs. The goal is simple: survive as long as possible while maximizing your score.
🎮 Gameplay Overview
You play as a terrified character constantly chased by a dangerous enemy.
Use arrow keys (or WASD) to move around the screen.
Survive as long as you can while dodging:
Obstacles that spawn dynamically and block paths.
A relentless enemy wielding a sword.
Bombs that penalize your score if collected.
Collect coins for bonus points.
The longer you survive, the higher your survival score.
✨ Features Player
Smooth movement with collision detection.
Always confined within the game window.
Enemy
Constantly pursues the player using a basic AI.
Adjusts pathfinding slightly when blocked by obstacles.
Sword animation dynamically points toward the player.
Items
Coins (+5 points): Spawn randomly, despawn after 15s.
Bombs (-5 points): Trap items that decrease your score.
Smart spawn system ensures items don’t appear too close to the player or inside obstacles.
Obstacles
Dynamic rectangular blocks appear randomly.
Despawn after 10s.
Maximum of 8 obstacles at any time.
Carefully placed to avoid unfair spawns on top of the player.
Scoring System
Survival Time: 1 point per second survived.
Item Score: Collect coins and avoid bombs.
Total Score = Survival Time × Multiplier + Item Score.
Visual & UI
Clean, minimal UI showing:
Survival time.
Item score.
Total score.
Obstacle count.
Pulsating Game Over screen effect.
Restart with SPACEBAR.
Exit with ESC.
🕹️ Controls Key Action Arrow Keys / WASD Move Player SPACEBAR Restart (after Game Over) ESC Quit Game ⚙️ Installation & Setup
Install Python 3.8+
Install dependencies:
pip install pygame
Run the game:
python chasing_monster.py
🧩 Code Structure
Player Class: Handles movement, collision, and drawing.
Enemy Class: AI movement, sword animation, and collision logic.
Item Class: Defines coins and bombs with lifespan/despawn mechanics.
Obstacle Class: Spawning, despawning, and collision detection.
Utility Functions:
collides_with_obstacles() – Detects collision with obstacles.
check_collision() – Player vs enemy detection.
check_item_collection() – Player-item overlap.
spawn_obstacle() / generate_initial_obstacles() – Spawns new obstacles fairly.
pulsating_color() – Creates dynamic text coloring for the Game Over screen.
main(): Core game loop managing events, updates, and rendering.
🚀 Future Improvements
Add sound effects for coins, bombs, and Game Over.
Implement multiple enemy types with different behaviors.
Add power-ups (e.g., speed boost, shield).
Introduce difficulty scaling over time.