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
582e005b
authored
Sep 03, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
eddc54b8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
56 deletions
1.py
my_game.py
1.py
View file @
582e005b
import
turtle
# 和你的小伙伴用列表讲讲桃园结义的故事,并说说这其中运用了哪些列表知识:
pen
=
turtle
.
Pen
()
# 来,我给你起个头~
pen
.
write
(
"诺依, turtle真好用, 我会在画布上写字啦!"
,
font
=
(
"Times"
,
30
,
"normal"
))
# 从前啊,有三个bro,分别是:刘备、关羽、张飞...
turtle
.
done
()
bro1
=
"关羽"
\ No newline at end of file
bro2
=
"刘备"
bro3
=
"张飞"
bros
=
[
"刘备"
,
"关羽"
,
"张飞"
]
bro1
=
[
"关羽"
,
160
,
8.5
]
bro2
=
[
"刘备"
,
161
,
9.1
]
bro3
=
[
"张飞"
,
166
,
8.3
]
bros
[
0
]
=
"关羽"
bros
[
1
]
=
"刘备"
print
(
bros
)
\ No newline at end of file
my_game.py
View file @
582e005b
...
@@ -11,7 +11,13 @@ class Block(pygame.sprite.Sprite):
...
@@ -11,7 +11,13 @@ class Block(pygame.sprite.Sprite):
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
.
x
=
1000
self
.
rect
.
x
=
1000
self
.
rect
.
y
=
500
-
self
.
rect
.
height
self
.
rect
.
y
=
500
-
self
.
rect
.
height
class
Player
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
image
):
super
()
.
__init__
()
self
.
image
=
image
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
.
x
=
150
self
.
rect
.
y
=
400
# 创建一个窗口
# 创建一个窗口
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
FPS
=
pygame
.
time
.
Clock
()
# pygame时钟,控制游戏速度(帧数)
FPS
=
pygame
.
time
.
Clock
()
# pygame时钟,控制游戏速度(帧数)
...
@@ -34,7 +40,8 @@ t = 30
...
@@ -34,7 +40,8 @@ t = 30
# +++++++++++++++++++++++
# +++++++++++++++++++++++
bg_x
=
0
bg_x
=
0
road_x
=
0
road_x
=
0
time
=
0
time
=
0
gamestate
=
True
# +++++++++++++++++++++++
# +++++++++++++++++++++++
#obstacle = Block(bush, stone, cacti)
#obstacle = Block(bush, stone, cacti)
block_list
=
pygame
.
sprite
.
Group
()
block_list
=
pygame
.
sprite
.
Group
()
...
@@ -47,51 +54,55 @@ while True:
...
@@ -47,51 +54,55 @@ while True:
if
jumpState
==
"runing"
:
if
jumpState
==
"runing"
:
if
event
.
key
==
locals
.
K_SPACE
:
if
event
.
key
==
locals
.
K_SPACE
:
jumpState
=
"up"
jumpState
=
"up"
if
gamestate
==
True
if
jumpState
==
"up"
:
# 起跳状态
if
jumpState
==
"up"
:
# 起跳状态
if
t
>
0
:
if
t
>
0
:
y
-=
t
y
-=
t
t
-=
2
t
-=
2
else
:
else
:
jumpState
=
"down"
jumpState
=
"down"
if
jumpState
==
"down"
:
# 降落状态
if
jumpState
==
"down"
:
# 降落状态
if
t
<=
30
:
if
t
<=
30
:
y
+=
t
y
+=
t
t
+=
2
t
+=
2
else
:
else
:
jumpState
=
"runing"
jumpState
=
"runing"
t
=
30
t
=
30
# 悟空造型
# 悟空造型
wukong
=
hero
[
index
]
wukong
=
Player
(
hero
[
index
])
if
jumpState
==
"runing"
:
# 跑步状态下
if
jumpState
==
"runing"
:
# 跑步状态下
index
+=
1
index
+=
1
if
index
>=
5
:
if
index
>=
5
:
index
=
0
index
=
0
# 将背景图画上去
# 将背景图画上去
# +++++++++++++++++++++++
# +++++++++++++++++++++++
bg_x
-=
1
bg_x
-=
1
if
bg_x
<=-
1000
:
if
bg_x
<=-
1000
:
bg_x
=
0
bg_x
=
0
screen
.
blit
(
background
,
(
bg_x
,
0
))
screen
.
blit
(
background
,
(
bg_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
.
image
,
(
150
,
y
))
# 悟空
time
+=
1
time
+=
1
if
time
>=
60
:
if
time
>=
60
:
time
=
0
time
=
0
num
=
random
.
randint
(
0
,
50
)
num
=
random
.
randint
(
0
,
50
)
if
num
>
20
:
if
num
>
20
:
obstacle
=
Block
(
bush
,
stone
,
cacti
)
obstacle
=
Block
(
bush
,
stone
,
cacti
)
block_list
.
add
(
obstacle
)
block_list
.
add
(
obstacle
)
for
sprite
in
block_list
:
for
sprite
in
block_list
:
sprite
.
rect
.
x
-=
8
sprite
.
rect
.
x
-=
8
screen
.
blit
(
sprite
.
image
,
(
sprite
.
rect
.
x
,
sprite
.
rect
.
y
))
screen
.
blit
(
sprite
.
image
,
(
sprite
.
rect
.
x
,
sprite
.
rect
.
y
))
if
sprite
.
rect
.
x
<=
0
-
sprite
.
rect
.
x
:
if
sprite
.
rect
.
x
<=
0
-
sprite
.
rect
.
x
:
sprite
.
kill
()
sprite
.
kill
()
# 刷新画面
if
pygame
.
sprite
.
collide_rect
(
wukong
,
sprite
):
pygame
.
display
.
update
()
gameover
=
pygame
.
image
.
load
(
'gameover.png'
)
FPS
.
tick
(
30
)
screen
.
blit
(
gameover
,(
400
,
200
))
\ No newline at end of file
gameover
=
False
# 刷新画面
pygame
.
display
.
update
()
FPS
.
tick
(
30
)
\ 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