AI科技大本营|玩出花儿了!一文教你用 Python 制作吃豆人游戏! | 附代码,Python( 三 )
[-0.5,0,3],[0,-0.5,7],[-0.5,0,3],[0,0.5,7],[-0.5,0,11],[0,-0.5,7],[0.5,0,5]]
self.ghost_sprites.add(player)
elifrole_name=='Clyde':
player=Player(319,259,each)
player.is_move=True
player.tracks=[[-1,0,2],[0,-0.5,4],[0.5,0,5],[0,0.5,7],[-0.5,0,11],[0,-0.5,7],
[-0.5,0,3],[0,0.5,7],[-0.5,0,7],[0,0.5,15],[0.5,0,15],[0,-0.5,3],
[-0.5,0,11],[0,-0.5,7],[0.5,0,3],[0,-0.5,11],[0.5,0,9]]
self.ghost_sprites.add(player)
elifrole_name=='Inky':
player=Player(255,259,each)
player.is_move=True
player.tracks=[[1,0,2],[0,-0.5,4],[0.5,0,10],[0,0.5,7],[0.5,0,3],[0,-0.5,3],
[0.5,0,3],[0,-0.5,15],[-0.5,0,15],[0,0.5,3],[0.5,0,15],[0,0.5,11],
[-0.5,0,3],[0,-0.5,7],[-0.5,0,11],[0,0.5,3],[-0.5,0,11],[0,0.5,7],
[-0.5,0,3],[0,-0.5,3],[-0.5,0,3],[0,-0.5,15],[0.5,0,15],[0,0.5,3],
[-0.5,0,15],[0,0.5,11],[0.5,0,3],[0,-0.5,11],[0.5,0,11],[0,0.5,3],[0.5,0,1]]
self.ghost_sprites.add(player)
elifrole_name=='Pinky':
player=Player(287,259,each)
player.is_move=True
player.tracks=[[0,-1,4],[0.5,0,9],[0,0.5,11],[-0.5,0,23],[0,0.5,7],[0.5,0,3],
[0,-0.5,3],[0.5,0,19],[0,0.5,3],[0.5,0,3],[0,0.5,3],[0.5,0,3],
[0,-0.5,15],[-0.5,0,7],[0,0.5,3],[-0.5,0,19],[0,-0.5,11],[0.5,0,9]]
self.ghost_sprites.add(player)
returnself.hero_sprites,self.ghost_sprites
'''创建食物'''
defsetupFood(self,food_color,bg_color):
self.food_sprites=pygame.sprite.Group
forrowinrange(19):
forcolinrange(19):
if(row==7orrow==8)and(col==8orcol==9orcol==10):
continue
else:
food=Food(30*col+32,30*row+32,4,4,food_color,bg_color)
is_collide=pygame.sprite.spritecollide(food,self.wall_sprites,False)
ifis_collide:
continue
is_collide=pygame.sprite.spritecollide(food,self.hero_sprites,False)
ifis_collide:
continue
self.food_sprites.add(food)
returnself.food_sprites
3、游戏创建:
在通过关卡定义墙等位置后以及精灵自身属性怪物运动、食物定义等后 , 通过调用已经创建好的类达到搭建游戏的目的 。
具体如下可见:
importos
importsys
importpygame
importLevels
'''定义一些必要的参数'''
BLACK=(0,0,0)
WHITE=(255,255,255)
BLUE=(0,0,255)
GREEN=(0,255,0)
RED=(255,0,0)
YELLOW=(255,255,0)
PURPLE=(255,0,255)
SKYBLUE=(0,191,255)
BGMPATH=os.path.join(os.getcwd,'resources/sounds/bg.mp3')
ICONPATH=os.path.join(os.getcwd,'resources/images/icon.png')
FONTPATH=os.path.join(os.getcwd,'resources/font/ALGER.TTF')
HEROPATH=os.path.join(os.getcwd,'resources/images/pacman.png')
BlinkyPATH=os.path.join(os.getcwd,'resources/images/Blinky.png')
ClydePATH=os.path.join(os.getcwd,'resources/images/Clyde.png')
InkyPATH=os.path.join(os.getcwd,'resources/images/Inky.png')
PinkyPATH=os.path.join(os.getcwd,'resources/images/Pinky.png')
'''开始某一关游戏'''
defstartLevelGame(level,screen,font):
clock=pygame.time.Clock
SCORE=0
wall_sprites=level.setupWalls(SKYBLUE)
gate_sprites=level.setupGate(WHITE)
- 科技观察站|被错付了,腾讯与老干妈堪比喜剧电影的“商战”情节:风味豆豉鹅
- 暖日欣欣科技立伟|随便哪一件都值得我们去怀念,热血传奇:盘点盛大经典的装备系列
- 爱辉科技|荣耀赵明点赞,网友:赵总也想去小米?,雷军官宣杨柘加盟小米
- 高科技元素|广东欢太科技有限公司这样建议,小孩沉迷游戏造成误充值
- 心急科技|压力有点大啊,明日之后玩家首次当策划多结局新玩法
- 无边科技|710点券留给钟馗,杨戬改动方案公布司马懿新皮肤被爆料
- 风口科技|中路抢血包,打野我想静静,最怕打野做什么边路抢河蟹
- 云顶之弈▲云顶之弈上分黑科技,只用这一套阵容,轻松上钻2!简直不要太强!
- 电科技|以投屏为主打卖点,索尼这款电视收获数万人好评,携手乐播
- ITheat热点科技|FE12-24mm f2.8已在路上,索尼A7S3全幅微单EVF规格曝光