Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson04_diy
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
9282d2d8
authored
Nov 26, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
c075cadc
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
122 additions
and
21 deletions
HOYO-MiX - Dream Aria (Genshin Impact Main Theme Var.) 梦之咏叹.mp3
HOYO-MiX - Genshin Impact Main Theme 原神.mp3
HOYO-MiX - 神女劈观·唤情 Devastation and Redemption.mp3
my_music.py
snake.py
HOYO-MiX - Dream Aria (Genshin Impact Main Theme Var.) 梦之咏叹.mp3
0 → 100644
View file @
9282d2d8
File added
HOYO-MiX - Genshin Impact Main Theme 原神.mp3
0 → 100644
View file @
9282d2d8
File added
HOYO-MiX - 神女劈观·唤情 Devastation and Redemption.mp3
0 → 100644
View file @
9282d2d8
File added
my_music.py
View file @
9282d2d8
...
...
@@ -11,52 +11,59 @@ stop_img = pygame.image.load('stop.png') # 暂停按钮
last_img
=
pygame
.
image
.
load
(
'last.png'
)
# 上一曲按钮
next_img
=
pygame
.
image
.
load
(
'next.png'
)
# 下一曲按钮
logo_img
=
pygame
.
image
.
load
(
'logo.png'
)
# 中间logo
pygame
.
mixer
.
music
.
load
(
'歌曲4.ogg'
)
pygame
.
mixer
.
music
.
load
(
'HOYO-MiX - Genshin Impact Main Theme 原神.mp3'
)
#载入音乐
pygame
.
mixer
.
music
.
load
(
'HOYO-MiX - Dream Aria (Genshin Impact Main Theme Var.) 梦之咏叹.mp3'
)
pygame
.
mixer
.
music
.
load
(
'HOYO-MiX - 神女劈观·唤情 Devastation and Redemption.mp3'
)
my_font
=
pygame
.
font
.
Font
(
'neuropol.ttf'
,
18
)
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
exit
()
volume
=
0.2
pygame
.
mixer
.
music
.
set_volume
(
volume
)
play
=
stop_img
#播放/暂停图标状态初始化
volume
=
0
#音量初始化
click
=
0.0
#点击次数初始化
pygame
.
mixer
.
music
.
set_volume
(
volume
)
#音量
pygame
.
mixer
.
music
.
play
()
#播放
start
=
stop_img
click
=
0
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
exit
()
#音量调节
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_UP
:
volume
+=
0.1
if
volume
<
0
or
volume
==
0
:
volume
=
0
if
volume
>
1
:
volume
=
1.0
print
(
"volume"
+
str
(
volume
))
pygame
.
mixer
.
music
.
set_volume
(
volume
)
if
event
.
key
==
locals
.
K_DOWN
:
volume
-=
0.1
if
volume
<
0
<
or
volume
==
0
:
volume
=
0
if
volume
<
0
:
volume
=
0.0
print
(
"volume"
+
str
(
volume
))
pygame
.
mixer
.
music
.
set_volume
(
volume
)
#播放/暂停
if
event
.
type
==
locals
.
MOUSEBUTTONDOWN
:
if
event
.
button
==
1
:
click
+=
1
print
(
"click"
+
str
(
click
))
if
click
%
2
==
0
:
pygame
.
mixer
.
music
.
unpause
()
start
=
stop_img
else
:
pygame
.
mixer
.
music
.
pause
()
start
=
play_img
if
volume
<=
0
:
volume
=
0
play
=
stop_img
if
pygame
.
mixer
.
music
.
get_busy
()
==
False
:
pygame
.
mixer
.
music
.
play
()
else
:
play
=
play_img
pygame
.
mixer
.
music
.
pause
()
# 绘制画面
screen
.
blit
(
bg_img
,
(
0
,
0
))
# 填充背景
screen
.
blit
(
start
,
(
270
,
330
))
# 暂停按钮
screen
.
blit
(
play
,
(
270
,
330
))
# 暂停按钮
screen
.
blit
(
logo_img
,
(
170
,
60
))
# 中间logo图
screen
.
blit
(
last_img
,
(
120
,
350
))
# 上一曲
screen
.
blit
(
next_img
,
(
420
,
350
))
# 下一曲
#绘制音量
info
=
"Volume"
+
str
(
volume
)
text
=
my_font
.
render
(
info
,
True
,(
0
,
0
,
0
))
screen
.
blit
(
text
,(
508
,
10
))
# 刷新画面
pygame
.
display
.
update
()
snake.py
0 → 100644
View file @
9282d2d8
import
pygame
from
pygame
import
locals
import
random
# 初始化pygame,为使用硬件做准备
pygame
.
init
()
# 创建一个窗口
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
FPSCLOCK
=
pygame
.
time
.
Clock
()
# pygame时钟,控制游戏速度(帧数)
# 背景
background
=
pygame
.
image
.
load
(
'bg.png'
)
right
=
pygame
.
image
.
load
(
'right.png'
)
# 头 朝右
food
=
pygame
.
image
.
load
(
'apple.png'
)
# 食物 苹果
body
=
pygame
.
image
.
load
(
'body.png'
)
# 身体
left
=
pygame
.
image
.
load
(
'left.png'
)
# 头 朝左
up
=
pygame
.
image
.
load
(
'up.png'
)
# 头 朝上
down
=
pygame
.
image
.
load
(
'down.png'
)
# 头 朝下
my_font
=
pygame
.
font
.
Font
(
'neuropol.ttf'
,
18
)
x
,
y
=
240
,
120
position
=
[(
180
,
90
),
(
180
,
120
),
(
210
,
120
),
(
x
,
y
)]
apple_x
,
apple_y
=
300
,
300
score
=
0
setheading
=
"right"
snake_head
=
right
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
# 接收到退出事件后退出程序
exit
()
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_RIGHT
and
setheading
!=
"left"
:
setheading
=
'right'
snake_head
=
right
if
event
.
key
==
locals
.
K_LEFT
and
setheading
!=
"right"
:
setheading
=
'left'
snake_head
=
left
if
event
.
key
==
locals
.
K_UP
and
setheading
!=
"down"
:
setheading
=
'up'
snake_head
=
up
if
event
.
key
==
locals
.
K_DOWN
and
setheading
!=
"up"
:
setheading
=
'down'
snake_head
=
down
# 设置贪吃蛇的头部坐标
if
setheading
==
"right"
:
x
+=
30
elif
setheading
==
"left"
:
x
-=
30
elif
setheading
==
"up"
:
y
-=
30
else
:
y
+=
30
position
.
append
((
x
,
y
))
if
x
==
apple_x
and
y
==
apple_y
:
num1
=
random
.
randint
(
1
,
22
)
num2
=
random
.
randint
(
1
,
16
)
apple_x
=
30
*
num1
-
30
apple_y
=
30
*
num2
-
30
score
+=
1
else
:
position
.
pop
(
0
)
#撞墙检测
if
x
<
30
:
x
=
660
if
x
>
630
:
x
=
-
30
if
y
<
0
:
y
=
480
if
y
>
480
:
y
=
-
30
# 将背景图画上去
screen
.
blit
(
background
,
(
0
,
0
))
# 将贪吃蛇的头画上去
screen
.
blit
(
snake_head
,
position
[
-
1
])
# 将贪吃蛇的身体画上去
for
i
in
range
(
len
(
position
)
-
1
):
screen
.
blit
(
body
,
position
[
i
])
# 将果实画上去
screen
.
blit
(
food
,
(
apple_x
,
apple_y
))
#绘制分数
info
=
"Score"
+
str
(
score
)
text
=
my_font
.
render
(
info
,
True
,(
0
,
0
,
0
))
screen
.
blit
(
text
,(
540
,
10
))
# 刷新画面
pygame
.
display
.
update
()
FPSCLOCK
.
tick
(
6
)
\ 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