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 95c852c0 authored 3 years ago by BellCodeEditor's avatar BellCodeEditor
Browse files
Options
  • Browse Files
  • Download
  • Email Patches
  • Plain Diff

save project

parent acb06362
Hide whitespace changes
Inline Side-by-side
Showing with 26 additions and 5 deletions
  • my_game.py
my_game.py
View file @ 95c852c0
import pygame
from pygame import locals
import random
pygame.init() # 初始化
......@@ -18,10 +19,16 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')]
index = 0
jumpState = "runing"
y = 400
t=30
x=1
a=random.choice([apple,cacti,stone])
rect=a.get_rect()
rect.x=1000
rect.y=500-rect.height
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -31,7 +38,8 @@ while True:
if jumpState=="runing":
if event.key == locals.K_SPACE:
jumpState = "up"
if jumpState == "up": # 起跳
if t>0:
y -= t
......@@ -49,14 +57,26 @@ while True:
wukong = hero[index]
index += 1
if jumpState =="runing":
index += 1
else :
x+=1
if index == 5:
index = 0
# 将背景图画上去
screen.blit(background, (0, 0))
screen.blit(road, (0, 500))
screen.blit(wukong, (150, y))
# 刷新画面
pygame.display.update()
rect.x -= 5
if rect.x>0-rect.width:
screen.blit(a,(rect.x,rect.y))
else:
a=random.choice([apple,cacti,stone])
rect=a.get_rect()
rect.x=1000
rect.y=500-rect.height
pygame.display.update()
FPS.tick(30)
\ 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