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
b001879f
authored
Dec 25, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
9e6e518e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
9 deletions
my_game.py
my_game.py
View file @
b001879f
import
pygame
from
pygame
import
locals
import
random
import
random
pygame
.
init
()
# 初始化
pygame
.
init
()
# 初始化
class
Java
(
pygame
.
sprite
.
Sprite
):
class
Java
(
pygame
.
sprite
.
Sprite
):
...
@@ -9,6 +7,8 @@ class Java(pygame.sprite.Sprite):
...
@@ -9,6 +7,8 @@ class Java(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
u
(
pygame
.
sprite
.
Sprite
):
def
__init__
()
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
FPS
=
pygame
.
time
.
Clock
()
# pygame时钟,控制游戏速度(帧数)
FPS
=
pygame
.
time
.
Clock
()
# pygame时钟,控制游戏速度(帧数)
pygame
.
display
.
set_caption
(
"Minecraft"
)
pygame
.
display
.
set_caption
(
"Minecraft"
)
...
@@ -26,10 +26,13 @@ index = 0
...
@@ -26,10 +26,13 @@ index = 0
y
=
400
y
=
400
jumpState
=
"runing"
jumpState
=
"runing"
t
=
30
t
=
30
obstacle
=
Java
(
bush
,
stone
,
cacti
)
obstacle_list
=
pygame
.
sprite
.
Group
()
#obstacle = Java(bush, stone, cacti)
road_x
=
0
road_x
=
0
background_x
=
0
background_x
=
0
ed
=
8
ed
=
8
e
=
60
time
=
0
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
:
...
@@ -90,9 +93,21 @@ while True:
...
@@ -90,9 +93,21 @@ while True:
road_x
=
0
road_x
=
0
if
background_x
<
-
1000
:
if
background_x
<
-
1000
:
background_x
=
0
background_x
=
0
if
obstacle
.
rect
.
x
<=
0
-
obstacle
.
rect
.
width
:
# 障碍物消失
time
+=
1
obstacle
=
Java
(
bush
,
stone
,
cacti
)
if
time
>=
60
:
obstacle
.
rect
.
x
-=
ed
time
=
0
screen
.
blit
(
obstacle
.
image
,
(
obstacle
.
rect
.
x
,
obstacle
.
rect
.
y
))
num
=
random
.
randint
(
0
,
50
)
if
num
>
20
:
obstacle
=
Java
(
bush
,
stone
,
cacti
)
obstacle_list
.
add
(
obstacle
)
for
o
in
obstacle_list
:
o
.
rect
.
x
-=
ed
screen
.
blit
(
o
.
image
,
(
o
.
rect
.
x
,
o
.
rect
.
y
))
if
o
.
rect
.
x
<=
0
-
o
.
rect
.
width
:
o
.
kill
()
# 障碍物消失
if
pygame
.
sprite
.
collide_rect
(
wuk
,
o
):
e
=
0
#obstacle = Java(bush,stone,cacti)
#obstacle.rect.x -= ed
pygame
.
display
.
update
()
pygame
.
display
.
update
()
FPS
.
tick
(
60
)
FPS
.
tick
(
e
)
\ No newline at end of file
\ 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