Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson6-1
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
548e87f4
authored
Jul 11, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
e3f412dc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
199 additions
and
11 deletions
diy.py
lllllll.py
pk.py
diy.py
View file @
548e87f4
# 和你的小伙伴用列表讲讲桃园结义的故事,并说说这其中运用了哪些列表知识:
# 和你的小伙伴用列表讲讲桃园结义的故事,并说说这其中运用了哪些列表知识:
# 来,我给你起个头~
# 来,我给你起个头~
# 从前啊,有三个bro,分别是:刘备、
关羽、张飞.
..
# 从前啊,有三个bro,分别是:刘备、
刘备、关羽
..
bro1
=
"
关羽
"
bro1
=
"
刘备
"
bro2
=
"
刘备
"
bro2
=
"
关羽
"
bro3
=
"张飞"
bro3
=
"张飞"
bros
=
[
"刘备"
,
"关羽"
,
"张飞"
]
bro4
=
[
"刘备"
,
161
,
9.1
]
bro1
=
[
"关羽"
,
160
,
8.5
]
bro5
=
[
"关羽"
,
160
,
8.5
]
bro2
=
[
"刘备"
,
161
,
9.1
]
bro6
=
[
"张飞"
,
166
,
8
,
3
]
bro3
=
[
"张飞"
,
166
,
8.3
]
bro7
=
[
"刘备"
,
"关羽"
,
"张飞"
]
bros
[
0
]
=
"关羽"
bro7
[
0
]
=
"关羽"
bros
[
1
]
=
"刘备"
bro7
[
1
]
=
"刘备"
print
(
bros
)
print
(
bro7
)
\ No newline at end of file
lllllll.py
0 → 100644
View file @
548e87f4
import
pygame
class
Floor
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
image
,
position
,
width
=
3
,
**
kwargs
):
pygame
.
sprite
.
Sprite
.
__init__
(
self
)
self
.
image
=
image
self
.
rect
=
self
.
image
.
get_rect
()
self
.
mask
=
pygame
.
mask
.
from_surface
(
self
.
image
)
self
.
rect
.
left
,
self
.
rect
.
top
=
position
self
.
rect
.
width
=
self
.
rect
.
width
*
width
self
.
move_speed
=
5
self
.
width
=
width
def
update
(
self
):
self
.
rect
.
left
-=
self
.
move_speed
if
self
.
rect
.
right
<
0
:
return
True
return
False
def
draw
(
self
,
screen
):
for
i
in
range
(
self
.
width
):
screen
.
blit
(
self
.
image
,
(
self
.
rect
.
left
+
self
.
image
.
get_width
()
*
i
,
self
.
rect
.
top
,
self
.
rect
.
width
,
self
.
rect
.
height
))
# update函数是地板往左移的逻辑,随着游戏时间的增加可以更改地板移动的速度,来增加游戏难度。
# 地板资源是一张图片,在定义变量里边的定义基础高度即图片上边缘据屏幕底部的距离,地板间隙宽度即两个地板图片间的距离, 地板高度间隙即两个地板图片间的高度差。
# FLOOR_LIST
FLOOR_HEIGHT
=
100
FLOOR_GAP_WIDTH
=
150
FLOOR_GAP_HEIGHT
=
30
BASE_HEIGHT
=
SCREEN_HEIGHT
-
FLOOR_HEIGHT
floor_width_level
,
floor_height_level
,
floor_gap_level
FLOOR_LIST
=
[(
6
,
0
,
1
),
(
2
,
-
1
,
2
),
(
3
,
0
,
1
),
(
2
,
1
,
1
)]
*
10
\ No newline at end of file
pk.py
0 → 100644
View file @
548e87f4
import
pygame
class
Floor
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
image
,
position
,
width
=
3
,
**
kwargs
):
pygame
.
sprite
.
Sprite
.
__init__
(
self
)
self
.
image
=
image
self
.
rect
=
self
.
image
.
get_rect
()
self
.
mask
=
pygame
.
mask
.
from_surface
(
self
.
image
)
self
.
rect
.
left
,
self
.
rect
.
top
=
position
self
.
rect
.
width
=
self
.
rect
.
width
*
width
self
.
move_speed
=
5
self
.
width
=
width
def
update
(
self
):
self
.
rect
.
left
-=
self
.
move_speed
if
self
.
rect
.
right
<
0
:
return
True
return
False
def
draw
(
self
,
screen
):
for
i
in
range
(
self
.
width
):
screen
.
blit
(
self
.
image
,
(
self
.
rect
.
left
+
self
.
image
.
get_width
()
*
i
,
self
.
rect
.
top
,
self
.
rect
.
width
,
self
.
rect
.
height
))
FLOOR_HEIGHT
=
100
FLOOR_GAP_WIDTH
=
150
FLOOR_GAP_HEIGHT
=
30
# floor_width_level, floor_height_level, floor_gap_level
FLOOR_LIST
=
[(
6
,
0
,
1
),
(
2
,
-
1
,
2
),
(
3
,
0
,
1
),
(
2
,
1
,
1
)]
*
10
from
abc
import
abstractmethod
class
Scene
():
def
__init__
(
self
):
self
.
start_time
=
0.0
self
.
current_time
=
0.0
self
.
done
=
False
self
.
next_scene
=
None
self
.
next_loading_time
=
0
self
.
persist
=
{}
self
.
bgm
=
None
self
.
bg_image
=
None
self
.
key_press
=
{}
@abstractmethod
def
startup
(
self
,
current_time
,
persist
,
sources
):
'''abstract method'''
def
cleanup
(
self
):
self
.
done
=
False
return
self
.
persist
@abstractmethod
def
update
(
self
,
screen
,
event
,
current_time
):
'''abstract method'''
@abstractmethod
def
set_sources
(
self
,
sources
):
'''abstract method'''
import
pygame
import
consts
as
cfg
from
modules.interface.loadRes
import
load_resouces
class
Control
:
def
__init__
(
self
):
self
.
done
=
False
self
.
screen
,
self
.
clock
=
self
.
init_game
()
self
.
sources
=
load_resouces
()
self
.
init_event
()
self
.
scene
=
None
self
.
scene_dict
=
{}
self
.
scene_name
=
None
self
.
current_time
=
0.0
def
init_game
(
self
):
# 初始化游戏
pygame
.
init
()
screen
=
pygame
.
display
.
set_mode
((
cfg
.
SCREEN_WIDTH
,
cfg
.
SCREEN_HEIGHT
))
pygame
.
display
.
set_caption
(
cfg
.
ORIGINAL_CAPTION
)
clock
=
pygame
.
time
.
Clock
()
return
screen
,
clock
def
setup_scene
(
self
,
scene_dict
,
start_scene
):
# 设置场景
self
.
scene_dict
=
scene_dict
self
.
scene_name
=
start_scene
self
.
scene
=
self
.
scene_dict
[
self
.
scene_name
]
self
.
game_info
=
{
'current_time'
:
0.0
,
'previous_scene'
:
None
,
'current_scene'
:
self
.
scene_name
,
'next_scene'
:
None
,
'next_loading_time'
:
0
}
self
.
scene
.
startup
(
self
.
current_time
,
self
.
game_info
,
self
.
sources
)
def
update
(
self
):
# udpate
self
.
current_time
=
pygame
.
time
.
get_ticks
()
if
self
.
scene
:
if
self
.
scene
.
done
:
self
.
flip_scene
()
self
.
scene
.
update
(
self
.
current_time
,
self
.
screen
,
self
.
event
)
def
flip_scene
(
self
):
# 切换场景
previous
,
self
.
scene_name
=
self
.
scene_name
,
self
.
scene
.
next_scene
persist
=
self
.
scene
.
cleanup
()
if
persist
.
get
(
'next_loading_time'
,
0
)
>
0
:
self
.
scene_name
=
'loading'
self
.
scene
=
self
.
scene_dict
[
self
.
scene_name
]
self
.
scene
.
startup
(
self
.
current_time
,
persist
,
self
.
sources
)
def
event_loop
(
self
):
# 监控按键与鼠标
self
.
init_event
()
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
pygame
.
QUIT
:
self
.
done
=
True
elif
event
.
type
==
pygame
.
KEYDOWN
:
if
event
.
key
==
pygame
.
K_ESCAPE
:
self
.
done
=
True
else
:
self
.
event
[
'key_press'
][
event
.
key
]
=
True
elif
event
.
type
==
pygame
.
KEYUP
:
self
.
event
[
'key_up'
][
event
.
key
]
=
True
elif
event
.
type
==
pygame
.
MOUSEBUTTONDOWN
:
self
.
event
[
'mouse_pos'
]
=
pygame
.
mouse
.
get_pos
()
self
.
event
[
'mouse_click'
]
=
pygame
.
mouse
.
get_pressed
()
def
init_event
(
self
):
self
.
event
=
{
'key_press'
:
{},
'key_up'
:
{},
'mouse_pos'
:
None
,
'mouse_click'
:
(
0
,
0
,
0
),
}
def
main
(
self
):
while
not
self
.
done
:
self
.
event_loop
()
self
.
update
()
pygame
.
display
.
update
()
self
.
clock
.
tick
(
cfg
.
FPS
)
print
(
'game exit'
)
\ 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