Skip to content

Yuvan-1000/Game-dev-using-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Game-dev-using-python

Python Car Simulator — Pygame + NumPy


Overview

This is a lightweight Python simulator for experimenting with car dynamics and collision handling, built using Pygame and NumPy. It provides a simple environment where you can load maps, drive a car around, and test motion, boundary, and obstacle interactions.

The simulator supports:

  • Custom Maps: Load .png or .jpg maps in color or black/white.

    • Color images are automatically converted to grayscale and thresholded into obstacles (black) and free space (white).
  • Collision Handling: The car stops when colliding with obstacles or boundaries.

  • Kinematic Car Model: Includes acceleration, friction, max speed, and steering limits.

  • Built-in Map Generator: If no map is provided, a default test track is created.

  • HUD Display: Shows velocity, angular rate, position, and heading in real-time.


Requirements

Install dependencies with:

pip install pygame numpy

Usage

Run the simulator with:

python main.py

Arguments

  • --map <path> : Path to a map image (.png/.jpg).

    • Color images will be converted to black/white automatically.
    • Black = obstacle, White = free space.
  • --car <path> : Path to the car sprite image (.png). Defaults to player.png.

  • --scale <float> : Scale factor for the input map before rendering.

Example:

python main.py --map track.png --car f1car.png --scale 0.5

Controls

  • Up Arrow → Accelerate forward
  • Down Arrow → Accelerate backward
  • Left Arrow → Steer left
  • Right Arrow → Steer right
  • R → Reset car position
  • Q or Esc → Quit simulator

Features in Action

✅ Load color or black/white maps ✅ Drive the car around obstacles ✅ Real-time physics and collision detection ✅ Reset and re-run experiments quickly


Project Structure

  • main.py — Core simulator loop
  • Car class — Kinematic car dynamics and drawing
  • load_bw_map() — Utility for map loading, grayscale conversion, and thresholding
  • generate_builtin_map() — Creates a default rectangular track

Roadmap

  • Add LiDAR/raycasting sensors
  • Logging & replay tools
  • Multi-car racing support
  • Gym-compatible wrapper for RL training

License

MIT License — free to use and modify.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages