Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson10_diy01
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
a729e9d0
authored
Dec 25, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
85a888fd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
3 deletions
my_Tetris.py
my_Tetris.py
View file @
a729e9d0
...
@@ -16,15 +16,40 @@ clock = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
...
@@ -16,15 +16,40 @@ clock = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
background
=
pygame
.
image
.
load
(
'bg.png'
)
background
=
pygame
.
image
.
load
(
'bg.png'
)
font
=
pygame
.
font
.
Font
(
'STKAITI.TTF'
,
60
)
# 字体
font
=
pygame
.
font
.
Font
(
'STKAITI.TTF'
,
60
)
# 字体
center
=
[
1
,
6
]
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
.
key
==
locals
.
K_LEFT
:
#小方块向左走,列改变了,列越来越小,当列等于0就不能移动了,列大于0就可以继续移动
if
center
[
1
]
>
0
:
center
[
1
]
-=
1
if
event
.
key
==
locals
.
K_RIGHT
:
#共有15列 0 --- 14
#小方块向右走,列改变了,列越来越大,当列等于14就不能移动了,列小于14就可以继续移动
if
center
[
1
]
<
14
:
center
[
1
]
+=
1
if
event
.
key
==
locals
.
K_DOWN
:
#共有25行 0 --- 24
#小方块向下走,行改变了,行越来越大,当行等于24就不能移动了,行小于24就可以继续移动
if
center
[
0
]
<
24
:
center
[
0
]
+=
1
# 将背景图画上去
# 将背景图画上去
???
screen
.
blit
(
background
,(
0
,
0
))
#绘制小方块pygame.draw.rect(窗口,(R,G,B),(x,y,宽度,高度),线宽)
pygame
.
draw
.
rect
(
screen
,(
255
,
0
,
0
),(
center
[
1
]
*
20
,
center
[
0
]
*
20
,
20
,
20
),
0
)
#红色
pygame
.
draw
.
rect
(
screen
,(
255
,
255
,
255
),(
center
[
1
]
*
20
,
center
[
0
]
*
20
,
20
,
20
),
1
)
#白色边框
# 得分
# 得分
???
#先 生成可渲染文字对象 字体对象.render(文字内容,是否抗锯齿,颜色)
text
=
font
.
render
(
str
(
score
),
True
,(
0
,
0
,
0
))
#将文字渲染
screen
.
blit
(
text
,(
350
,
70
))
# 刷新画面
# 刷新画面
pygame
.
display
.
update
()
pygame
.
display
.
update
()
clock
.
tick
(
FPS
)
clock
.
tick
(
FPS
)
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