Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson7_diy4
This project
Loading...
Sign in
Toggle navigation
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
22f5efe7
authored
Jun 04, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
5a0c6e2e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
14 deletions
my_game.py
my_game.py
View file @
22f5efe7
...
@@ -2,6 +2,13 @@ import pygame
...
@@ -2,6 +2,13 @@ import pygame
from
pygame
import
locals
from
pygame
import
locals
import
random
import
random
pygame
.
init
()
# 初始化
pygame
.
init
()
# 初始化
class
Books
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
image1
,
image2
,
image3
):
super
()
.
__init__
()
self
.
image
=
random
.
choice
([
image1
,
image2
,
image3
])
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
.
x
=
1000
self
.
rect
.
y
=
500
-
self
.
rect
.
height
# 创建一个窗口
# 创建一个窗口
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
pygame
.
display
.
set_caption
(
"悟空跑酷"
)
pygame
.
display
.
set_caption
(
"悟空跑酷"
)
...
@@ -17,18 +24,16 @@ hero = [pygame.image.load('hero1.png'),
...
@@ -17,18 +24,16 @@ 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'
)]
class
Books
(
pygame
.
sprite
.
sprite
):
index
=
0
index
=
0
y
=
400
y
=
400
t
=
35
t
=
35
road_x
=
0
road_x
=
0
beijing_x
=
0
beijing_x
=
0
jump
=
"running"
jump
=
"running"
rect
=
cacti
.
get_rect
()
#
rect = cacti.get_rect()
rect
.
x
=
1000
#
rect.x = 1000
rect
.
y
=
455
-
rect
.
width
#
rect.y = 455 - rect.width
obstacle
=
random
.
choice
([
stone
,
cacti
,
apple
]
)
obstacle
=
Books
(
stone
,
cacti
,
apple
)
while
True
:
while
True
:
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
if
event
.
type
==
locals
.
QUIT
:
...
@@ -52,29 +57,30 @@ while True:
...
@@ -52,29 +57,30 @@ while True:
else
:
else
:
jump
=
"running"
jump
=
"running"
t
=
35
t
=
35
wukong
=
hero
[
index
]
wukong
=
hero
[
index
]
if
jump
==
"running"
:
if
jump
==
"running"
:
index
+=
1
index
+=
1
if
index
==
5
:
if
index
==
5
:
index
=
0
index
=
0
# 将背景图画上去
# 将背景图画上去
beijing_x
-=
4
beijing_x
-=
4
if
beijing_x
<=
-
1000
:
if
beijing_x
<=
-
1000
:
beijing_x
=
0
beijing_x
=
0
screen
.
blit
(
background
,
(
beijing_x
,
0
))
screen
.
blit
(
background
,(
beijing_x
,
0
))
#路
road_x
-=
8
road_x
-=
8
if
road_x
<=
-
1000
:
if
road_x
<=
-
1000
:
road_x
=
0
road_x
=
0
screen
.
blit
(
road
,
(
road_x
,
500
))
screen
.
blit
(
road
,
(
road_x
,
500
))
screen
.
blit
(
wukong
,
(
150
,
y
))
screen
.
blit
(
wukong
,
(
150
,
y
))
if
rect
.
x
<
0
-
rect
.
width
:
#障碍物
obstacle
=
random
.
choice
([
stone
,
cacti
,
apple
])
if
obstacle
.
rect
.
x
<
0
-
obstacle
.
rect
.
width
:
rect
=
cacti
.
get_rect
()
obstacle
=
Books
(
stone
,
cacti
,
apple
)
rect
.
x
=
1000
rect
.
y
=
455
-
rect
.
width
else
:
else
:
rect
.
x
-=
8
obstacle
.
rect
.
x
-=
8
screen
.
blit
(
obstacle
,(
rect
.
x
,
rect
.
y
))
screen
.
blit
(
obstacle
.
image
,(
obstacle
.
rect
.
x
,
obstacle
.
rect
.
y
))
# 刷新画面
# 刷新画面
pygame
.
display
.
update
()
pygame
.
display
.
update
()
FPS
.
tick
(
60
)
FPS
.
tick
(
60
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment