Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

Administrator / pygame_lesson7_diy4

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Commit a15af8f7 authored 2 years ago by BellCodeEditor's avatar BellCodeEditor
Browse files
Options
  • Browse Files
  • Download
  • Email Patches
  • Plain Diff

save project

parent ca8a8ed3
Hide whitespace changes
Inline Side-by-side
Showing with 17 additions and 3 deletions
  • my_game.py
my_game.py
View file @ a15af8f7
import pygame import pygame
from pygame import locals from pygame import locals
import random
pygame.init() # 初始化 pygame.init() # 初始化
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
...@@ -16,6 +16,11 @@ hero = [pygame.image.load('hero1.png'), ...@@ -16,6 +16,11 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero3.png'), pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'), pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')] pygame.image.load('hero5.png')]
stones=random.choice([stone,cacti,apple])
rect=stones.get_rect()
stones_x=1000;
stones_y=500-rect[3]
pygame.display.set_caption('悟空酷跑') pygame.display.set_caption('悟空酷跑')
index = 0 index = 0
sport='running' sport='running'
...@@ -49,9 +54,18 @@ while True: ...@@ -49,9 +54,18 @@ while True:
if index>=len(hero): if index>=len(hero):
index=0 index=0
# 将背景图画上去 # 将背景图画上去
if stones_x + rect[2] < 0:
stones=random.choice([stone,cacti,apple])
rect=stones.get_rect()
stones_x=1000;
stones_y=500-rect[3]
else:
stones_x -= 2
rect = stones.get_rect()
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
screen.blit(road, (0, 500)) screen.blit(road, (0, 500))
screen.blit(hero[index], (150, y)) screen.blit(hero[index], (150, y))
screen.blit(stones, (stones_x, stones_y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(6 FPS.tick(60)
\ No newline at end of file \ No newline at end of file
This diff is collapsed. Click to expand it.
  • Write
  • Preview
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment