前言
嘿,有没有想我?
栗子驾着七彩祥云来给大家敲代码啦!
所有文章完整的素材+源码都在👇👇
☀☀☀☀☀☀
每天00:00 或早上🕘 或晚上🕔不定时更新。请记得打开手机,查收今日份的小源码哦~
每天都会出超有趣的内容,不要忘记我啦!
如果你无聊,你睡不着失眠, 那可以尝试下这款无聊中的战斗机——今天给大家介绍一款
超级佛系休闲游戏《Flight敏捷鸟》打击飞鸟小游戏。
不要走开,跟着我一起燥起来叭!
正文
一、运行环境
1)环境安装👇
Python3、 Pycharm 、Pygame模块部分自带模块就不展示啦。
(如需安装包、激活码等直接 私信我即可安装问题解答都可以的哈~)
第三方库的安装:pip install pygame 或者 带镜像源 pip install -i https://pypi.douban.com/simple/ +模块名
2)素材(图片、音乐等)
游戏没音乐🎵就没有灵魂啦~
二、代码展示
主程序👇
import pygame,os,random
from pygame.locals import *
from pygame.sprite import Sprite,Group,groupcollide
def load_image(name):
fullname=os.path.join(os.path.join(os.path.split(os.path.abspath(__file__))[0],"filedata"),name)
image=pygame.image.load(fullname)
return image
def load_sound(name):
fullname=os.path.join(os.path.join(os.path.split(os.path.abspath(__file__))[0],"filedata"),name)
sound=pygame.mixer.Sound(fullname)
return sound
class Bow:
def __init__(self,screen):
self.screen=screen
self.image=load_image("bow.png")
self.rect=self.image.get_rect()
self.rect.midbottom=self.screen.get_rect().midbottom
def update(self):
pos=pygame.mouse.get_pos()
self.rect.center=pos
def blit(self):
self.screen.blit(self.image,self.rect)
class Arrow(Sprite):
def __init__(self,screen,bow):
super(Arrow,self).__init__()
self.screen=screen
self.bow=bow
self.speed=13
self.image=load_image("arrow.png")
self.rect=self.image.get_rect()
self.rect.midbottom=self.bow.rect.midbottom
def update(self):
self.rect.centery-=self.speed
if self.rect.bottom<0:
self.kill()
def blit(self):
self.screen.blit(self.image,self.rect)
class Bird(Sprite):
def __init__(self,screen):
super(Bird,self).__init__()
self.screen=screen
self.screenrect=screen.get_rect()
self.now=0
self.loadlist=["bird1.png","bird1.png","bird1.png","bird1.png",
"bird2.png","bird2.png","bird2.png","bird2.png",
"bird3.png","bird3.png","bird3.png","bird3.png",
"bird4.png","bird4.png","bird5.png","bird4.png",
"bird5.png","bird5.png","bird5.png","bird5.png",
"bird6.png","bird6.png","bird6.png","bird6.png",
"bird7.png","bird7.png","bird7.png","bird7.png",
"bird8.png","bird8.png","bird8.png","bird8.png"]
self.image=load_image(self.loadlist[self.now])
self.rect=self.image.get_rect()
self.rectat=random.choice(["top","left","right"])
self._updatespeed()
def _updatespeed(self):
self.xspeed=round(random.uniform(1,3),2)
self.yspeed=round(random.uniform(1,3),2)
if self.rectat=="top":
self.rect.center=(random.randint(0,WIDTH-200),0)
elif self.rectat=="left":
self.rect.center=(0,random.randint(0,HEIGHT-450))
elif self.rectat=="right":
self.rect.center=(WIDTH,random.randint(0,HEIGHT-450))
def update(self):
self.now+=1
if self.now>23:
self.now=0
self.rect.centerx+=self.xspeed
self.rect.centery+=self.yspeed
self.image=load_image(self.loadlist[self.now])
if self.rect.top>self.screenrect.height or self.rect.bottom<0:
self.kill()
elif self.rect.left>self.screenrect.width or self.rect.right<0:
self.kill()
def blit(self):
self.screen.blit(self.image,self.rect)
WIDTH=700
HEIGHT=650
def initmain():
pygame.init()
screen=pygame.display.set_mode((WIDTH,HEIGHT))
pygame.display.set_caption("Bow & Arrow - KILL Birds")
fpstime=pygame.time.Clock()
surface=Bow(screen)
arrows=Group()
birds=Group()
rates=0
score=0
gameFont=pygame.font.SysFont("黑体",26,True)
hurtsound=load_sound("birdhurt.mp3")
arrowsound=load_sound("arrowgo.mp3")
pygame.mouse.set_visible(False)
while True:
fpstime.tick(100)
screen.fill((128,255,255))
surface.blit()
surface.update()
arrows.update()
arrows.draw(screen)
birds.update()
birds.draw(screen)
screen.blit(gameFont.render("Kill: "+str(score),True,(0,0,0)),(2,2))
if groupcollide(arrows,birds,False,True):
score+=1
if score%2==0 and score!=0:
hurtsound.play()
if rates%30==0:
newbird=Bird(screen)
birds.add(newbird)
rates+=1
for event in pygame.event.get():
if event.type==QUIT:
pygame.quit()
__import__("sys").exit()
elif event.type==MOUSEBUTTONDOWN:
if event.button==1:
pygame.event.set_grab(True)
newarrow=Arrow(screen,surface)
arrows.add(newarrow)
arrowsound.play()
elif event.button!=1:
pygame.event.set_grab(False)
elif event.type==KEYDOWN:
pygame.event.set_grab(False)
pygame.display.flip()
if __name__=="__main__":
initmain()
三、效果展示
游戏玩法:
是一款弓箭佛系射鸟玩法的休闲小游戏,通过射箭可以赚钱
**怎么射箭:**手指按住屏幕拉动弓弦,瞄准时机在指针对准中心点时,松开手指即可射出。
总结
嘻嘻,老规矩的啦!源码免费、素材白嫖。就问你喜不喜欢,喜欢就好,不喜欢下次接着更新
更新游戏嘛?!不喜欢的喜欢的可以给个三联嘛,下次一定让大家满意嘿嘿.jpg
💖免费的源码基地——
你们的支持是我最大的动力!!记得三连哦~mua 欢迎大家阅读往期的文章哦~
😘往期推荐阅读——
项目1.6 【Pygame小游戏】斗地主我见多了,BUT 这款开源欢乐斗地主,最让人服气~
项目3.1 【Pygame实战】如果你是赛车爱好者:这款新赛车游戏分分钟让你上瘾(超跑又是谁的梦想?)
项目3.2 【Pygame小游戏】炸裂全场、超级炸弹人“爆炸”登场,这是你的童年嘛?
项目2.2【Pygame小游戏】扫雷游戏50多岁了,但这款我能玩一年~(三个版本集合)
项目2.3 战疫互动|宅家防疫,“消灭新冠病毒”小游戏火爆上线啦~(附完整源码)
🎁文章汇总——
Python文章合集 | (入门到实战、游戏、Turtle、案例等)
(文章汇总还有更多你案例等你来学习啦~源码找我即可免费!)
🎄文章汇总——
项目1.0 Python—2021 |已有文章汇总 | 持续更新,直接看这篇就够了
(更多内容+源码都在文章汇总哦!!欢迎阅读~)