當前位置: 首頁>>代碼示例>>Python>>正文


Python Background.init方法代碼示例

本文整理匯總了Python中background.Background.init方法的典型用法代碼示例。如果您正苦於以下問題:Python Background.init方法的具體用法?Python Background.init怎麽用?Python Background.init使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在background.Background的用法示例。


在下文中一共展示了Background.init方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TheApp

# 需要導入模塊: from background import Background [as 別名]
# 或者: from background.Background import init [as 別名]
class TheApp(cocos.layer.Layer):
    # If you want that your layer receives events
    # you must set this variable to 'True',
    # otherwise it won't receive any event.
    is_event_handler = True

    def __init__(self):
        super(TheApp, self).__init__()

        self.image = pyglet.resource.image('terrain_4.png')
        self._background = Background()
        self._objects = []
        enemy = Enemy()
        self._objects.append(enemy)
        self._player = Player()
        self._objects.append(self._player)
        # call the "step" method every frame when the layer is active
        self.schedule(self.step)

    def on_enter(self):
        super(TheApp, self).on_enter()
        self._background.init()
        for ob in self._objects:
            ob.init()

    def draw(self):
        super(TheApp, self).draw()
        self._background.draw()
        for ob in self._objects:
            ob.draw()

    def step(self, dt):
        for ob in self._objects:
            ob.update(dt)

    def on_key_press(self, symbol, modifiers):
        if symbol == key.RIGHT:
            self._player.setXVelocity(10)
        if symbol == key.LEFT:
            self._player.setXVelocity(-10)

    def on_key_release(self, key, modifiers):
        self._player.setXVelocity(0)
開發者ID:CoderDojoZH,項目名稱:workshops,代碼行數:45,代碼來源:the_app.py

示例2: handle_speed

# 需要導入模塊: from background import Background [as 別名]
# 或者: from background.Background import init [as 別名]
def handle_speed():
    global actualLevel

    time = pygame.time.get_ticks() // 1000
    steep = time // gameConfigs["timeToIncreaseSpeed"]
    print(steep)
    if steep > actualLevel:
        actualLevel += 1
        if (Ship.speed <= gameConfigs["maxSpeed"]):
            Ship.speedUp()
            Enemy.speedUp()
            Projectile.speedUp()

player = Player(screen)
EnemiesList.randomSpawn(screen)
Background.init(screen)
while run:
    clock.tick(60)
    screen.fill((0, 0, 0))

    if len(EnemiesList.enemies)<=0:
        screen.blit(fontLarge.render("Venceu!", True, (255,255,255)), (gameConfigs["width"]/2 - 240, gameConfigs["height"]/2  - 100))
    
    elif player.lifes<=0:
        pygame.mixer.music.load("assets/audios/gunshot2.ogg")
        pygame.mixer.music.play()
        screen.blit(fontLarge.render("Perdeu!", True, (255,255,255)), (gameConfigs["width"]/2 - 240, gameConfigs["height"]/2  - 100))
    
    else:        

        Background.update(screen)
開發者ID:mateusKoppe,項目名稱:space-battle,代碼行數:33,代碼來源:spaceBattle.py


注:本文中的background.Background.init方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。