Skip to content

suhasdas/first-pygame-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

This Pygame code is for a game titled "Hopeless Death From Dropping Hazards." Let's break down the key parts of the code:

Pygame Code Explanation

Imports and Initialization

  • Pygame: The main library used for creating the game.
  • Time: Used for tracking the elapsed time.
  • Random: To generate random positions for the falling stars.

Game Setup

  • Window Settings: Sets up the game window with a specific width and height, and loads a background image.
  • Player and Star Attributes: Defines dimensions and velocities for the player and falling stars.
  • Fonts: Defines two different fonts for displaying text in the game.

draw Function

  • Purpose: This function is responsible for drawing the game's state on the screen each frame.
  • Implementation: It draws the background, the time survived, the player (as a red rectangle), and the falling stars (as purple rectangles).

main Function

  • Game Loop: This is where the game logic is implemented. The game runs inside a while loop (run = True).
  • Player Movement: Handles player movement using arrow keys or WASD. The player can move left, right, and jump.
  • Gravity: Simulates gravity by incrementally increasing the player's downward velocity (yvel).
  • Star Generation: New stars are generated at random x-coordinates and fall from the top of the screen.
  • Collision Detection: Checks if any star collides with the player. If there's a collision, the game ends.
  • Star Removal: Stars that fall off the bottom of the screen are removed from the list of stars.
  • Game Over: If the player is hit by a star, a "You Lost" message is displayed, and the game ends after a delay.

Execution

  • The game is started by calling main() if the script is the main program (if __name__ == "__main__": main()).

Gameplay Summary

  • The player controls a character that can move horizontally and jump.
  • Stars fall from the top of the screen at increasing rates.
  • The player needs to avoid being hit by the stars.
  • The elapsed time is displayed, and the game ends when the player is hit by a star.

thats it

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages