• 大小: 67KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-08
  • 语言: 其他
  • 标签: python  pygame  

资源简介

一个小孩子在上方左右移动,不断地往下面扔香蕉皮和糖果,下面有一个小孩子由玩家操作来接糖果

资源截图

代码片段和文件信息

“““This program is made up of four characters: Me Partner Candy and Rubbish.
    Partner moves to left or right on the top of the screen dropping candies and rubbshes.
    Me can move to up down right and left controlled by the mouse.
    If Me get a candy score increases.
    If Me get a rubbish score decreases and lives decrease.
    The game will end when live is zero.
    Attention: ‘lives‘ here is equal to ‘chances‘ ‘score‘ is equal to ‘candies‘
    Xuelai Zhang
    2012/7/3“““
    
#initialize and import
import pygamecharacters random
pygame.init()
#display
screen = pygame.display.set_mode((640480))
pygame.display.set_caption(“Catch the candies“)

#functions
#game
def game():
    #entites
    #bachground
    background = pygame.Surface(screen.get_size())
    background = background.convert()
    background.fill((000))
    screen.blit(background(00))
    #partner
    partner = characters.Partner()
    “““
    #candies
    candy1 = characters.Candy(partner.rect.centerx)
    candy2 = characters.Candy(partner.rect.centerx)
    candy3 = characters.Candy(partner.rect.centerx)
    #rubbishes
    rubbish1 = characters.Rubbish(partner.rect.centerx)
    rubbish2 = characters.Rubbish(partner.rect.centerx)
    rubbish3 = characters.Rubbish(partner.rect.centerx)
    “““
    #candies
    candies = []
    #rubbishes
    rubbishes = []
    #me
    me = characters.Me()
    #score
    scoreboard = characters.Scoreboard()
    
    #define groups
    #friendSprites including Me Partner
    friendSprites = pygame.sprite.Group(me partner)
    #candySprites including Candy
    candySprites = pygame.sprite.Group()
    #rubbishSprites including Rubbish
    rubbishSprites = pygame.sprite.Group()
    #scoreSprites including scoreboard
    scoreSprites = pygame.sprite.Group(scoreboard)
    
    #time
    clock = pygame.time.Clock()
    #assign
    keepgoing = True
    #set a counter to drop something every 0.1 second
    counter = 0
    #Act
    while keepgoing:
        #set tick
        clock.tick(30)
        pygame.mouse.set_visible(False)
        #set a flag whether to drop something
        drop = random.randint(01)
        #set up a flag whether to drop candy or rubbish
        drpCandy = random.randint(0 1)
        #decide whether to drop candy rubbish or nothing
        if counter == 6:
            counter =0
            if drop == 1:
                #add a new rubbish in rubbishSprites
                if drpCandy == 0:
                    rubbish = characters.Rubbish(partner.rect.centerx)
                    rubbishSprites.add(rubbish)
                #add a new candy in candySprites
                else:
                    candy = characters.Candy(partner.rect.centerx)
                    candySprites.add(candy)
        counter += 1
        #check if it ends by user
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                keepgoing = False
        
        #check collision
        #collision 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2012-07-04 00:09  catchCandy\
     文件       10144  2012-07-04 00:03  catchCandy\ao.ogg
     文件        3782  2012-07-03 23:46  catchCandy\candy.png
     文件        7834  2012-07-04 03:11  catchCandy\catchCandy.py
     文件        7807  2012-07-04 03:09  catchCandy\catchCandy.py.bak
     文件        5447  2012-07-04 03:11  catchCandy\characters.py
     文件        5531  2012-07-04 02:56  catchCandy\characters.py.bak
     文件        6391  2012-07-04 03:12  catchCandy\characters.pyc
     文件       10897  2012-07-03 23:55  catchCandy\me.png
     文件       12156  2012-07-04 00:05  catchCandy\ohno.ogg
     文件       11325  2012-07-03 23:58  catchCandy\partner.png
     文件        3126  2012-07-03 23:48  catchCandy\rubbish.png
     文件        9304  2012-07-04 00:02  catchCandy\yohoo.ogg

评论

共有 条评论