[Python Game] A Dino Rush game based on pygame implemented | Attached is the source code

Preface

halo, good evening, buns
I haven’t updated for a long time, mainly because the editor has been a little busy recently
I will give you one today< /span> Come and play with your friends I’ve arranged this for everyone! ! ! It is a relatively classic mini-game. I still remember that it can be used on Google Chrome to pass the time even if there is no Internet connection. Little gamesDino Rush is a mini-game for baby dinosaurs


Related documents

Follow the editor and send a private message to the editor to get it!
Of course, don’t forget one thing~~
Public account: Python log

development tools

Python version: 3.7.8
Related modules:
pygame module;
random module; and some python built-in modules. time module;
sqlite3 module;

Environment setup

Install Python and add it to the environment variables, and pip to install the required relevant modules.

main feature

  • Use simple operations (space bar or up key to jump, down key to crouch) to control the dinosaur's movements
  • Randomly generate clouds, cacti and pterosaurs as obstacles
  • Update scores and top scores in real time, and provide corresponding sound effect prompts
  • Interface elements such as dinosaurs were redrawn using the open source pixel painting software Asprite
  • Character elements are rendered using the classic pixel style arcade game font Joystix Monospace
  • Use Python's integrated SQLite to store the UNIX timestamp and score information at the end of each game

How to run the game

  1. Make sure you have the Python and Pygame libraries installed
  2. Clone or download the code files of this repository
  3. In a terminal or command line interface, go to the directory where the code files are located
  4. Start the game by running the following command:

python Game.py

Game operation instructions

  • Press Spacebar or Up Arrow: Dinosaur Jump
  • Hold down key: dinosaur squats
  • Release the down key: the dinosaur returns to standing state

Show results

Start interface

Insert image description here

in the game

Insert image description here

game over

Insert image description here

Partial code display

Import module

import core
import sys
import time
import random
import pygame
import sqlite3
from modules import *

other codes

def main(highest_score):
    pygame.init()
    screen = pygame.display.set_mode(core.SCREENSIZE)
    pygame.display.set_caption('Dino Rush 源码领取+Q群:494958217 领取  公众号:Python日志')

    sounds = {
   
    
    }
    for key, value in core.AUDIO_PATHS.items():
        sounds[key] = pygame.mixer.Sound(value)

    GameStartInterface(screen, sounds, core)

    score = 0
    highest_score = highest_score
    dino = Dinosaur(core.IMAGE_PATHS['dino'])
    ground = Ground(core.IMAGE_PATHS['ground'], position=(0, core.SCREENSIZE[1] * 0.93))
    cloud_sprites_group = pygame

Guess you like

Origin blog.csdn.net/Gtieguo/article/details/130568599