Code Monkey home page Code Monkey logo

anishvedant / snake-game Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 9.07 MB

This project is a modern take on the classic Snake game, built using Python and Pygame. It features custom graphics, engaging sound effects, and a highscore tracking system. Enjoy playing the game while exploring the code to learn more about game development with Pygame.

License: MIT License

Python 100.00%
highscore pygame python snakegame apple classic-game educational-project game game-development games

snake-game's Introduction

Snake Game with Python and Pygame

This is a classic Snake game implemented in Python using the Pygame library. The game features end-to-end functionality with graphical elements, sound effects, and a highscore tracking system.

Features

  • Classic Snake Gameplay: Move the snake to collect apples and grow longer.
  • Graphics: Custom graphics for the snake's head, body, and tail, as well as the apple.
  • Sound Effects: Background music and sound effects for eating apples and crashing.
  • Highscore Tracking: Keeps track of the highest score achieved.
  • Pause and Resume: Pause the game with the spacebar and resume it at any time.
  • Game Over Screen: Displays the player's score when the game ends.

Installation

  1. Clone the Repository:

    git clone https://github.com/anishvedant/snake-game.git
    cd snake-game
  2. Install Dependencies: Ensure you have Python and Pygame installed. You can install Pygame using pip:

    pip install pygame
  3. Add Game Assets: Place the required graphic and sound files in the appropriate directories:

    • Graphics/head_up.png
    • Graphics/head_down.png
    • Graphics/head_right.png
    • Graphics/head_left.png
    • Graphics/tail_up.png
    • Graphics/tail_down.png
    • Graphics/tail_right.png
    • Graphics/tail_left.png
    • Graphics/body_vertical.png
    • Graphics/body_horizontal.png
    • Graphics/body_tr.png
    • Graphics/body_tl.png
    • Graphics/body_br.png
    • Graphics/body_bl.png
    • Graphics/apple.png
    • Sound/crunch.wav
    • Sound/crash.mp3
    • Sound/music.mp3
    • Font/PoetsenOne-Regular.ttf

Usage

  1. Run the Game:

    python3 snake.py
  2. Gameplay Instructions:

    • Use the arrow keys to control the direction of the snake.
    • Press SPACE to pause and resume the game.
    • Press ESC to quit the game.

Game Mechanics

Snake Movement

The snake is controlled using the arrow keys:

  • UP: Moves the snake up (if it's not currently moving down).
  • RIGHT: Moves the snake right (if it's not currently moving left).
  • DOWN: Moves the snake down (if it's not currently moving up).
  • LEFT: Moves the snake left (if it's not currently moving right).

Growing the Snake

When the snake eats an apple, it grows by one block. The position of the next apple is randomized within the game grid.

Collision Detection

The game ends if:

  • The snake collides with the walls (edges of the game window).
  • The snake collides with itself.

Highscore Tracking

The game tracks the highest score achieved and displays it on the screen. The highscore is saved in a highscore.txt file.

Sound Effects

  • Background Music: Loops continuously during the game.
  • Crunch Sound: Plays when the snake eats an apple.
  • Crash Sound: Plays when the game ends due to a collision.

Code Structure

  • snake.py: Main game file containing all the game logic and functions.
  • Graphics/: Directory containing the image assets for the game.
  • Sound/: Directory containing the sound effects and background music.
  • Font/: Directory containing the font file used in the game.

Future Improvements

  • Add more levels with increasing difficulty.
  • Implement different game modes (e.g., time attack, endless mode).
  • Enhance graphics and animations.
  • Add more sound effects and background music tracks.

Contributing

Contributions are welcome! Feel free to fork the repository and submit pull requests with your improvements and bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Disclaimer

This game is for educational purposes and personal enjoyment. Ensure you have the appropriate rights to use the graphic and sound assets included in the game.


snake-game's People

Contributors

anishvedant avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.