Commit 9282d2d8 by BellCodeEditor

auto save

parent c075cadc
...@@ -11,52 +11,59 @@ stop_img = pygame.image.load('stop.png') # 暂停按钮 ...@@ -11,52 +11,59 @@ stop_img = pygame.image.load('stop.png') # 暂停按钮
last_img = pygame.image.load('last.png') # 上一曲按钮 last_img = pygame.image.load('last.png') # 上一曲按钮
next_img = pygame.image.load('next.png') # 下一曲按钮 next_img = pygame.image.load('next.png') # 下一曲按钮
logo_img = pygame.image.load('logo.png') # 中间logo 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: play = stop_img #播放/暂停图标状态初始化
for event in pygame.event.get(): volume = 0 #音量初始化
if event.type == locals.QUIT: click = 0.0 #点击次数初始化
exit() pygame.mixer.music.set_volume(volume) #音量
volume = 0.2 pygame.mixer.music.play() #播放
pygame.mixer.music.set_volume(volume)
start = stop_img
click = 0
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_UP: if event.key == locals.K_UP:
volume += 0.1 volume += 0.1
if volume < 0 or volume==0: if volume > 1:
volume = 0 volume = 1.0
print("volume" + str(volume))
pygame.mixer.music.set_volume(volume) pygame.mixer.music.set_volume(volume)
if event.key == locals.K_DOWN: if event.key == locals.K_DOWN:
volume -= 0.1 volume -= 0.1
if volume < 0 <or volume==0: if volume < 0:
volume = 0 volume = 0.0
print("volume" + str(volume))
pygame.mixer.music.set_volume(volume) pygame.mixer.music.set_volume(volume)
#播放/暂停
if event.type == locals.MOUSEBUTTONDOWN: if event.type == locals.MOUSEBUTTONDOWN:
click += 1 if event.button == 1:
if click%2 == 0: click += 1
pygame.mixer.music.unpause() print("click" + str(click))
start = stop_img if click%2 == 0:
else: pygame.mixer.music.unpause()
pygame.mixer.music.pause() play = stop_img
start = play_img if pygame.mixer.music.get_busy() == False:
pygame.mixer.music.play()
else:
play = play_img
pygame.mixer.music.pause()
if volume <=0:
volume = 0
if pygame.mixer.music.get_busy() == False:
pygame.mixer.music.play()
# 绘制画面 # 绘制画面
screen.blit(bg_img, (0, 0)) # 填充背景 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(logo_img, (170, 60)) # 中间logo图
screen.blit(last_img, (120, 350)) # 上一曲 screen.blit(last_img, (120, 350)) # 上一曲
screen.blit(next_img, (420, 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() pygame.display.update()
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment