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
1a9e1d3d
authored
Jul 25, 2024
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
c2d277d1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
10 deletions
1.py
my_game.py
1.py
0 → 100644
View file @
1a9e1d3d
# class Cat():
# def __init__(self):
# self.eye=2
# self.foot=4
# self.color="black"
# def eat(self,food):
# print("今天吃了",food)
# cc=Cat()
# cc.eat("鱼")
# class Dog():
# def __init__(self):
# self.foot=4
# self.color="white"
# def run(self):
# print("狗狗正在快速地跑")
# class Husky(Dog):
# def run(self):
# print("狗狗正在快速地跑")
# Dog().run()
# class Animal():
# def __init__(self):
# self.foot=4
# self.color="white"
# self.weight="10kg"
# class Bird(Animal):
# def __init__(self):
# super().__init__()
# self.foot=2
# self.weight="1kg"
# Bird()
class
Person
():
def
__init__
(
self
,
name
,
age
):
self
.
name
=
name
self
.
age
=
age
class
Teacher
(
Person
):
def
__init__
(
self
,
name
,
age
,
subject
):
super
()
.
__init__
(
name
,
age
)
self
.
subject
=
subject
def
skill
(
self
):
print
(
"老师的教学科目是:"
,
self
.
subject
)
aa
=
Teacher
(
"小贝"
,
14
,
"python"
)
aa
.
skill
()
print
(
aa
.
name
,
aa
.
age
,
aa
.
subject
)
my_game.py
View file @
1a9e1d3d
import
pygame
import
pygame
from
pygame
import
locals
from
pygame
import
locals
pygame
.
init
()
# 初始化
pygame
.
init
()
# 初始化
# 创建一个窗口
# 创建一个窗口
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
...
@@ -22,33 +23,45 @@ y=400
...
@@ -22,33 +23,45 @@ y=400
jumpState
=
"running"
jumpState
=
"running"
t
=
30
t
=
30
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
:
# 接收到退出事件后退出程序
# 接收到退出事件后退出程序
exit
()
exit
()
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_SPACE
:
if
jumpState
==
"running"
:
jumpState
=
"up"
if
event
.
key
==
locals
.
K_SPACE
:
jumpState
=
"up"
if
jumpState
==
"up"
:
if
jumpState
==
"up"
:
if
y
>
150
:
if
t
>
0
:
y
-=
5
y
-=
t
t
-=
2
else
:
else
:
jumpState
=
"down"
jumpState
=
"down"
if
jumpState
==
"down"
:
if
jumpState
==
"down"
:
if
y
<
400
:
if
t
<=
30
:
y
+=
5
y
+=
t
t
+=
2
else
:
else
:
jumpState
=
"running"
jumpState
=
"running"
t
=
30
wukong
=
hero
[
index
]
wukong
=
hero
[
index
]
index
+=
1
if
jumpState
==
"running"
:
if
index
>=
5
:
index
+=
1
index
=
0
if
index
>=
5
:
index
=
0
# 将背景图画上去
# 将背景图画上去
screen
.
blit
(
background
,
(
0
,
0
))
screen
.
blit
(
background
,
(
0
,
0
))
screen
.
blit
(
road
,
(
0
,
500
))
screen
.
blit
(
road
,
(
0
,
500
))
screen
.
blit
(
wukong
,
(
150
,
y
))
screen
.
blit
(
wukong
,
(
150
,
y
))
# 刷新画面
# 刷新画面
if
rect
.
x
<=
0
-
rect
.
width
:
obstacle
=
random
.
cloice
([
brush
,
stone
,
cacti
])
rect
=
obstacle
.
get_rect
()
rect
.
x
=
1000
rect
.
y
=
500
-
rect
.
height
rect
.
x
-=
8
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