早爆娱闻 玩出花儿了!一文教你用 Python 制作吃豆人游戏!| 附代,Python( 二 )
2、游戏关卡定义:
在这里设置好了关卡一 。 关卡的定义必须包括墙的位置 , 不同关卡墙的位置和怪物的位置不同 。 更多关卡可以参照设置
对应代码如下:
importpygamefromSpritesimport*NUMLEVELS=1'''关卡一'''classLevel1:def__init__(self):self.info='level1''''创建墙'''defsetupWalls(self,wall_color):self.wall_sprites=pygame.sprite.Groupwall_positions=[[0,0,6,600],[0,0,600,6],[0,600,606,6],[600,0,6,606],[300,0,6,66],[60,60,186,6],[360,60,186,6],[60,120,66,6],[60,120,6,126],[180,120,246,6],[300,120,6,66],[480,120,66,6],[540,120,6,126],[120,180,126,6],[120,180,6,126],[360,180,126,6],[480,180,6,126],[180,240,6,126],[180,360,246,6],[420,240,6,126],[240,240,42,6],[324,240,42,6],[240,240,6,66],[240,300,126,6],[360,240,6,66],[0,300,66,6],[540,300,66,6],[60,360,66,6],[60,360,6,186],[480,360,66,6],[540,360,6,186],[120,420,366,6],[120,420,6,66],[480,420,6,66],[180,480,246,6],[300,480,6,66],[120,540,126,6],[360,540,126,6]]forwall_positioninwall_positions:wall=Wall(*wall_position,wall_color)self.wall_sprites.add(wall)returnself.wall_sprites'''创建门'''defsetupGate(self,gate_color):self.gate_sprites=pygame.sprite.Groupself.gate_sprites.add(Wall(282,242,42,2,gate_color))returnself.gate_sprites'''创建角色'''defsetupPlayers(self,hero_image_path,ghost_images_path):self.hero_sprites=pygame.sprite.Groupself.ghost_sprites=pygame.sprite.Groupself.hero_sprites.add(Player(287,439,hero_image_path))foreachinghost_images_path:role_name=each.split('/')[-1].split('.')[0]ifrole_name=='Blinky':player=Player(287,199,each)player.is_move=Trueplayer.tracks=[[0,-0.5,4],[0.5,0,9],[0,0.5,11],[0.5,0,3],[0,0.5,7],[-0.5,0,11],[0,0.5,3],[0.5,0,15],[0,-0.5,15],[0.5,0,3],[0,-0.5,11],[-0.5,0,3],[0,-0.5,11],[-0.5,0,3],[0,-0.5,3],[-0.5,0,7],[0,-0.5,3],[0.5,0,15],[0,0.5,15],[-0.5,0,3],[0,0.5,3],[-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=Trueplayer.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=Trueplayer.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=Trueplayer.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.Groupforrowinrange(19):forcolinrange(19):if(row==7orrow==8)and(col==8orcol==9orcol==10):continueelse: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:continueis_collide=pygame.sprite.spritecollide(food,self.hero_sprites,False)ifis_collide:continueself.food_sprites.add(food)returnself.food_sprites
- “龙吟”也就算了,散布“恐怖假信息”玩出格了
- 秀水镇|“龙吟”也就算了,散布“恐怖假信息”玩出格了
- 早爆娱闻 17分钟充满4000mAh,网友:就这?,小米的100W快充或将量产
- 早爆娱闻 国产“芯”即将到来,成功打破技术垄断:国产22nm光刻机研发成功
- 小鸡游戏官方|玩个游戏,玩出“帕金森”老人病?
- 小匪娱闻|出手阔绰!TVB“御用宫女”36岁生日送自己绝版手表,价值超70万
- 早爆娱闻|你说了算,做汽车服务加盟连锁还是自己干?看完以后
- 618 Battle名场面,好爸爸居然以一波"捣蛋"玩出圈了!
- 娱闻坊|虞书欣疑似参加《中餐厅4》,被老板推掉,粉丝气愤
- 幸福一箩筐|去年被吐槽全是竖排镜头设计,小米今年火力全开,后盖设计玩出花