好久之前写的简单易上手小游戏,素材用的我家坤哥的艳照——虽然说好久都没看见哥哥的身影了,可是对于真爱粉而言,哥哥一直都在……
游戏其实就是个换皮的打飞机,刚才打开玩了下,感觉挺喜感,然我感觉到我家哥哥英容犹在。
游戏运行画面如下:
随着游戏运行,那熟悉的音乐响起。
music~
你是不是也像我一样有点热血沸腾了呢。
点击按键:Y、U、I、O还会使用技能,触发哥哥的随机语音。
你干嘛,哎嘿嘿呦~
你是不是也像我一样有点春心荡漾了呢。
下面废话不多说,直接上代码:
import pygame
import sys
import random
import time
#import threading
import math
sys.setrecursionlimit(100000)
pygame.init()
score = 0
font = pygame.font.Font('freesansbold.ttf', 24)
font_0 = pygame.font.Font('freesansbold.ttf', 84)
step = 0
history_score = []
#print(history_score)
screen = pygame.display.set_mode((1440, 811))
pygame.display.set_caption("鸡你太美")
icon = pygame.image.load('icon.jpg')
pygame.display.set_icon(icon)
bg_color = (50, 50, 50)
running = True
#bg_list = ['daoqi.jpg', 'mengde.jpg', 'xueshan.jpg', 'liyue.jpg']
bg_list = ['鸡哥.jpg']
bg_image = pygame.image.load(random.choice(bg_list))
keqing_image = pygame.image.load('蔡徐坤.jpg')
keqing_image_0 = pygame.image.load('2_0.jpg')
#qiuqiu_list = ['daweiqiu.jpg', 'yan.jpg', 'qiuqiuwang.jpg', 'huo.jpg',
# 'mudunqiu.jpg', 'cao.jpg', 'lei.jpg', 'yansaman.jpg']
#boss_list = ['daweiqiu.jpg', 'mudunqiu.jpg', 'yansaman.jpg']
qiuqiu_list = ['chic1.jpg', 'chic2.jpg', 'chic3.jpg']
boss_list = ['chic1.jpg', 'chic2.jpg', 'chic3.jpg']
qiuqiu = random.choice(qiuqiu_list)
qiuqiu_image = pygame.image.load(qiuqiu)
keqing_yuyin = ['keqing_battle_1.mp3', 'keqing_fangsong.mp3', 'keqing_jihui.mp3', 'keqing_meet.mp3']
keqing_battle_sound = ['keqing_battle_1_1.mp3', 'keqing_battle_1_2.mp3',
'keqing_battle_1_3.mp3', 'keqing_battle_1_4.mp3', 'keqing_battle_1_5.mp3']
speed_list = ['1.0', '1.2', '1.5', '1.8', '2.0', '2.4', '2.5', '2.8', '3.0', '3.6', '4.0', '4.1', '4.2', '4.5', '5.0']
init_x = 650
init_y = 630
global init_score
qiuqiu_step = 1
if qiuqiu == 'daweiqiu.jpg':
qiuqiu_step = 1.5
elif qiuqiu == 'yan.jpg':
qiuqiu_step = 1
elif qiuqiu == 'qiuqiuwang.jpg':
qiuqiu_step = 2
qiuqiu_x = random.randint(0, 1300)
qiuqiu_y = random.randint(0, 200)
qiuqiu_num = 25
def moving_keqing():
global init_x
init_x += step
if init_x >= 1290:
init_x = 1290
elif init_x <= 0:
init_x = 0
def show_score():
#global highest_score
global file_name
text = f"SCORE: {score}"
score_render = font.render(text, True, (255, 0, 0))
screen.blit(score_render, (10, 10))
file_name = 'highest_csore.txt'
#with open(file_name, 'w+') as fp:
#fp.write(str(score))
#if int(init_score) <= score:
highest_score = score
#else:
#highest_score = init_score
#设置最高分这边有点问题,在于历史分数列表元素与返回值不匹配
text_0 = f"HIGHEST HISTORY SCORE: {highest_score}"
score_render_0 = font.render(text_0, True, (255, 0, 0))
screen.blit(score_render_0, (10, 50))
def max_score(history_score):
max_0 = 0
for s in history_score:
if int(s) > max_0:
max_0 = int(s)
return max_0
def check_event():
global step
for event in pygame.event.get():
if event.type == pygame.QUIT:
history_score.append(str(score))
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
step = 3
elif event.key == pygame.K_LEFT:
step = -3
elif event.key == pygame.K_q:
history_score.append(str(score))
sys.exit()
elif event.key == pygame.K_e:
sound_1 = pygame.mixer.Sound(random.choice(keqing_battle_sound))
sound_1.play()
time.sleep(0.1)
for qiuqiu in qiuqius:
Qiuqiu.reset_qiuqiu(qiuqiu)
elif event.key == pygame.K_j:
sound_2 = pygame.mixer.Sound('keqing_jihui.mp3')
sound_2.play()
elif event.key == pygame.K_k:
sound_3 = pygame.mixer.Sound('keqing_fangsong.mp3')
sound_3.play()
elif event.key == pygame.K_l:
sound_4 = pygame.mixer.Sound('keqing_meet.mp3')
sound_4.play()
elif event.key == pygame.K_SPACE:
if len(bullets) <= 4:
bullets.append(Bullet())
elif event.type == pygame.KEYUP:
if event.key == pygame.K_RIGHT:
step = 0
elif event.key == pygame.K_LEFT:
step = 0
class Qiuqiu():
def __init__(self):
self.img = pygame.image.load(random.choice(qiuqiu_list))
self.x = random.randint(0, 1300)
self.y = random.randint(0, 200)
self.step = float(random.choice(speed_list))
def reset_qiuqiu(self):
self.x = random.randint(0, 1300)
self.y = random.randint(-400, -200)
self.step += 2
qiuqius = []
for i in range(qiuqiu_num):
qiuqius.append(Qiuqiu())
#print(qiuqius)
class Bullet():
def __init__(self):
self.img = pygame.image.load('篮球.jpg')
self.x = init_x + 140
self.y = init_y - 45
self.step = 2
def hit_qiuqiu(self):
global score
global history_score
global highest_score
for e in qiuqius:
if distance(self.x, self.y, e.x, e.y) < 50 and self.y > 10:
#判断碰撞有问题,会意外闪退,在于两处删除子弹有矛盾
bullets.remove(self)
e.reset_qiuqiu()
if e.step >= 3:
score += 5
elif 2 <= e.step < 3:
score += 2
else:
score += 1
highest_score = score
#history_score.append(str(score)) 先不用列表储存
bullets = []
bullet_num = 4
def show_qiuqiu():
for qiuqiu in qiuqius:
screen.blit(qiuqiu.img, (qiuqiu.x, qiuqiu.y))
qiuqiu.x += qiuqiu.step
if qiuqiu.x > 1350 or qiuqiu.x < 0:
qiuqiu.step *= -1
qiuqiu.y += 80
def check_game():
for e in qiuqius:
if e.y > 820:
sound_ = pygame.mixer.Sound('keqing_jihui.mp3')
sound_.play()
text = 'Game Over!'
game_over = font_0.render(text, True, (255, 0, 0))
screen.blit(game_over, (500, 360))
pygame.display.update()
time.sleep(10)
sys.exit()
def distance(bx, by, qx, qy):
a = bx - qx
b = by - qy
return math.sqrt(a * a + b * b)
def show_bullets():
for b in bullets:
#if len(bullets) <= bullet_num:
screen.blit(b.img, (b.x, b.y))
b.hit_qiuqiu()
b.y -= b.step
if b.y < 0:
bullets.remove(b)
if not qiuqius:
show_qiuqiu()
def run_game():
#with open(file_name, 'r') as fp_0:
#init_score = fp_0.readline()
while True:
screen.blit(bg_image, (0, 0))
check_event()
show_qiuqiu()
show_score()
screen.blit(keqing_image, (init_x, init_y - 80))
moving_keqing()
show_bullets()
check_game()
pygame.display.update()
def yuyin():
while True:
pygame.mixer.music.load(random.choice(keqing_yuyin))
pygame.mixer.music.play(1)
time.sleep(30)
pygame.mixer.music.load('鸡你太美.mp3')
pygame.mixer.music.play(-1)
try:
run_game()
except ValueError:
print("\n\n运载负荷过大意外退出!!!")
然后以下是我使用的素材:
注意手上的🏀,哪去了?
为了避免侵犯我家哥哥的肖像权,特地对面部特征进行了模糊化处理~(或者直接没有脸)
没错,这正是我家哥哥用的篮球,所以这么……
喜欢的小伙伴还请多多点赞,加个关注~
(音频好像传不了?)