Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson7_diy1
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
714e0e86
authored
Jun 28, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
2d9a1e42
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
16 deletions
my_game.py
my_game.py
View file @
714e0e86
...
...
@@ -2,6 +2,15 @@ import pygame
from
pygame
import
locals
import
random
pygame
.
init
()
# 初始化
class
Block
(
pygame
.
sprite
.
Sprite
):
# 继承精灵类
def
__init__
(
self
,
image1
,
image2
,
image3
):
super
()
.
__init__
()
self
.
image
=
random
.
choice
([
image1
,
image2
,
image3
])
#random.choice只能循环列表
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
.
x
=
1000
self
.
rect
.
y
=
500
-
self
.
rect
.
height
# 创建一个窗口
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
FPS
=
pygame
.
time
.
Clock
()
# pygame时钟,控制游戏速度(帧数)
...
...
@@ -21,13 +30,7 @@ jumpState = "runing"
y
=
400
t
=
30
roadx
=
0
obstale
=
random
.
choice
([
stone
,
cacti
,
apple
])
rect
=
obstale
.
get_rect
()
# 获取当前的x,y 宽高
print
(
rect
.
height
,
"ssssssssssssssssssssssss"
)
rect
.
x
=
1000
rect
.
y
=
500
-
rect
.
height
obstacle
=
Block
(
stone
,
cacti
,
apple
)
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
...
...
@@ -63,16 +66,14 @@ while True:
screen
.
blit
(
background
,
(
0
,
0
))
if
roadx
<=-
1000
:
roadx
=
0
road
.
x
-=
8
screen
.
blit
(
road
,
(
road
.
x
,
500
))
roadx
-=
8
screen
.
blit
(
road
,
(
roadx
,
500
))
screen
.
blit
(
wukong
,
(
150
,
y
))
if
rect
.
x
<
0
-
rect
.
width
:
obstale
=
random
.
choice
([
stone
,
cacti
,
apple
])
rect
=
obstale
.
get_rect
()
# 获取当前的x,y 宽高
rect
.
x
=
1000
rect
.
y
=
500
-
rect
.
height
rect
.
x
-=
8
screen
.
blit
(
obstale
,(
rect
.
x
,
rect
.
y
))
if
obstacle
.
rect
.
x
<=
0
-
obstacle
.
rect
.
width
:
obstacle
=
Block
(
apple
,
cacti
,
stone
)
obstacle
.
rect
.
x
-=
8
# ++++++++++++++++++++++
screen
.
blit
(
obstacle
.
image
,
(
obstacle
.
rect
.
x
,
obstacle
.
rect
.
y
))
...
...
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