Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson10_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
2f992d82
authored
Jun 12, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
16cf30b9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
5 deletions
my_Tetris.py
my_Tetris.py
View file @
2f992d82
import
pygame
import
pygame
from
pygame
import
locals
from
pygame
import
locals
import
random
pygame
.
init
()
# 初始化
pygame
.
init
()
# 初始化
score
=
0
score
=
0
grid_size
=
20
# 格子大小
grid_size
=
20
# 格子大小
...
@@ -16,6 +16,18 @@ clock = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
...
@@ -16,6 +16,18 @@ 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
=
[
2
,
8
]
center
=
[
2
,
8
]
current_T
=
[(
0
,
1
),(
0
,
0
),(
0
,
-
1
),(
-
1
,
0
)]
current_O
=
[(
0
,
0
),(
0
,
1
),(
-
1
,
0
),(
-
1
,
1
)]
current_J
=
[(
1
,
0
),(
2
,
0
),(
0
,
0
),(
2
,
-
1
)]
current_I
=
[(
1
,
0
),(
2
,
0
),(
0
,
0
),(
3
,
0
)]
#[(0,-1),(-1,0),(0,1)],[(0,-2),(-2,0),(0,2)],[(0,-3),(-3,0),()]
current_L
=
[(
1
,
0
),(
2
,
0
),(
0
,
0
),(
2
,
1
)]
current_S
=
[(
0
,
-
1
),(
0
,
0
),(
-
1
,
0
),(
-
1
,
1
)]
current_Z
=
[(
-
1
,
-
1
),(
-
1
,
0
),(
0
,
0
),(
0
,
1
)]
current_all
=
[
current_T
,
current_O
,
current_J
,
current_I
,
current_L
,
current_S
,
current_Z
]
color_1
=
random
.
randint
(
0
,
255
)
color_2
=
random
.
randint
(
0
,
255
)
color_3
=
random
.
randint
(
0
,
255
)
k
=
random
.
choice
(
current_all
)
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
:
...
@@ -30,12 +42,19 @@ while True:
...
@@ -30,12 +42,19 @@ while True:
if
event
.
key
==
locals
.
K_DOWN
:
if
event
.
key
==
locals
.
K_DOWN
:
if
center
[
0
]
<
25
:
if
center
[
0
]
<
25
:
center
[
0
]
+=
1
#行数增加(向下)
center
[
0
]
+=
1
#行数增加(向下)
#if event.key == locals.K_UP:
screen
.
blit
(
background
,(
0
,
0
))
# 将背景图画上去
screen
.
blit
(
background
,(
0
,
0
))
# 将背景图画上去
pygame
.
draw
.
rect
(
screen
,(
255
,
0
,
0
),(
center
[
1
]
*
20
-
20
,
center
[
0
]
*
20
-
20
,
20
,
20
),
0
)
#画出小方块
current_pos
=
[]
pygame
.
draw
.
rect
(
screen
,(
255
,
255
,
255
),(
center
[
1
]
*
20
-
20
,
center
[
0
]
*
20
-
20
,
20
,
20
),
1
)
#画出小方块的边框
for
cube
in
k
:
#图形
# ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ↖
pos
=
(
cube
[
0
]
+
center
[
0
],
cube
[
1
]
+
center
[
1
])
# 对象 / 颜色 / x坐标 / y坐标 / 方块高/ 宽 /是否填充(0填充,1不填充)
current_pos
.
append
(
pos
)
for
cube
in
current_pos
:
pygame
.
draw
.
rect
(
screen
,(
color_1
,
color_2
,
color_3
),(
cube
[
1
]
*
20
-
20
,
cube
[
0
]
*
20
-
20
,
20
,
20
),
0
)
#画出小方块
pygame
.
draw
.
rect
(
screen
,(
color_3
+
10
,
color_1
+
10
,
color_2
+
10
),(
cube
[
1
]
*
20
-
20
,
cube
[
0
]
*
20
-
20
,
20
,
20
),
1
)
#画出小方块的边框
# # ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ↖
# # 对象 / 颜色 / x坐标 / y坐标 / 方块高/ 宽 /线宽(0没有线)
# 得分:
# 得分:
MyFont
=
font
.
render
(
str
(
score
),
True
,(
0
,
0
,
0
))
#设置字体
MyFont
=
font
.
render
(
str
(
score
),
True
,(
0
,
0
,
0
))
#设置字体
screen
.
blit
(
MyFont
,(
350
,
70
))
#渲染字体
screen
.
blit
(
MyFont
,(
350
,
70
))
#渲染字体
...
...
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