Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson8_diy3
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
3bb0855a
authored
Oct 24, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
96e09b00
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
5 deletions
my_game.py
my_game.py
View file @
3bb0855a
import
pygame
,
random
from
pygame
import
locals
pygame
.
init
()
# 初始化
class
Player
(
pygame
.
sprite
.
Sprite
):
...
...
@@ -10,7 +9,7 @@ class Player(pygame.sprite.Sprite):
self
.
image
=
image
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
.
x
=
150
self
.
rect
.
y
=
5
00
self
.
rect
.
y
=
400
# 应该是4
00
...
...
@@ -49,8 +48,9 @@ bg_x = 0
time
=
0
gamestate
=
True
obstacle
=
Block
(
bush
,
stone
,
cacti
)
# 障碍物列表, 随机一个对象
#
obstacle = Block(bush,stone,cacti) # 障碍物列表, 随机一个对象
block_list
=
pygame
.
sprite
.
Group
()
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
...
...
@@ -60,10 +60,11 @@ while True:
if
jumpState
==
"runing"
:
if
event
.
key
==
locals
.
K_SPACE
:
jumpState
=
"up"
wukong
=
Player
(
hero
[
index
])
wukong
=
Player
(
hero
[
index
])
if
jumpState
==
"runing"
:
index
+=
1
if
index
==
5
:
if
index
>=
5
:
# 出错 >= 不是 ==
index
=
0
if
gamestate
==
True
:
...
...
@@ -92,6 +93,7 @@ while True:
if
bg_x
<=
-
1000
:
bg_x
=
0
screen
.
blit
(
background
,
(
bg_x
,
0
))
road_x
-=
8
# 道路移动
if
road_x
<=
-
1000
:
road_x
=
0
...
...
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