Пример #1
0
def update():
    global tempsDerniereImage, end, deltaMultiplieur, delta
    
    #On calcule le delta:
    t = pygame.time.get_ticks()
    delta = (t - tempsDerniereImage) / 1000.0 * deltaMultiplieur
    tempsDerniereImage = t

    if delta>100000000.05:
        delta = 0.05

    #Regarde s'il y a une event
    for event in pygame.event.get():
        if event.type == QUIT:
            #On quitte la fenêtre
            end = True
    inputs.update()
Пример #2
0
    def run(self):
        while self.playing:
            for event in pygame.event.get():
                self.playing = statemgr.event(event)

                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_F12:
                        # Debug Mode
                        self.debug_mode = not self.debug_mode

                    if event.key == pygame.K_F2:
                        # Save a screenshot.  Simply uses the time stamp with some time removed for file name.
                        timestamp = str(int(time.time()) - 1382496589)
                        pygame.image.save(self.surface, assets.path("screenshots/screenshot" + timestamp + ".png"))

                    #if event.key == pygame.K_ESCAPE:
                        # Escape quits the game
                    #    self.playing = False

                if event.type == pygame.QUIT:
                    # X button
                    self.playing = False

            td = self.clock.tick(metrics.FPS)

            # Don't let frames take longer than 50 milliseconds to prevent objects
            # from falling through floors when dragging window.
            if td > 50:
                td = 50

            inputs.update()
            statemgr.update(td)
            statemgr.draw(self.surface)

            if self.debug_mode:
                statemgr.debug_draw(self.surface)

            # Scale up the screen for nice blocky pixels
            pygame.transform.scale(self.surface, (self.width, self.height), self.display)

            pygame.display.flip()

        pygame.quit()
Пример #3
0
def update(col):
    global tempsDerniereImage, end, deltaMultiplieur, delta

    #On calcule le delta:
    t = pygame.time.get_ticks()
    delta = (t - tempsDerniereImage) / 1000.0 * deltaMultiplieur
    tempsDerniereImage = t

    if delta > 0.05:
        delta = 0.05

    #Regarde s'il y a une event
    for event in pygame.event.get():
        if event.type == QUIT:
            #On quitte la fenêtre
            end = True
    inputs.update()

    #On "nettoie" le contenu de la fenêtre
    pygame.draw.rect(screen, col, (0, 0, w, h), 0)
Пример #4
0
def game_loop(game):
    view = View(game)
    game.start()

    while game.stop_time == 0:
        # Update inputs
        movement = inputs.update()
        # Update game logic
        game.player_relative_move(movement * 360 / game.nb_scenes)
        # Update game state
        if inputs.quit_input:
            break
        # Refresh view
        view.refresh()

        time.sleep(0.01)

    print("Game loop over")
    game.stop()
Пример #5
0
bat1 = Bat(3, 3)
bat2 = Bat(77, 3)
net = Net(int(ceil(constants.COLUMNS / 2)), constants.ROWS)
ball = Ball(40, 6)
score1 = Score(29, 2, 0)
score2 = Score(49, 2, 0)

LEDDisplay.init()
inputs.init()
serialprint.setColor(constants.COLOURS["Reset"])
draw()
if constants.showcountdown:
    LEDDisplay.countdown7seg()  #Three second timer

setup_serve()

while is_winner == False:
    inputarr = [game_state, player_serving]
    inputs.update(bat1, bat2, inputarr)
    game_state = inputarr[0]

    if game_state == constants.STATE_IN_PLAY:
        update_game()
    elif game_state == constants.STATE_SERVE:
        update_serve()

    draw()
    checkWinner()
    LEDDisplay.updateBoard(ball.position.x)
    #time.sleep(0.05)
Пример #6
0
    boulesdefeu.init()
    bonus.init()
    interface.init()

#Boucle principale:
while end is False:

    if pygame.time.get_ticks() > 2400 and not musiquelancee: #On joue la musique 2,4 secondes après le lancement du jeu, si elle n'a pas déjà été lancée
        musique.play()
        musiquelancee = True
    
    #On dessine l'arriere plan sur l'écran pour nettoyer les anciens rendus:
    window.blit(images.arriere[0],(-2,-2))

    #On met à jour les entrées clavier/souris:
    inputs.update()

    #On calcule le delta:
    t = pygame.time.get_ticks()
    delta = (t - tempsDerniereImage) / 1000.0 * deltaMultiplieur
    tempsDerniereImage = t
    #Et on le limite pour éviter d'aller trop vite en cas de problème:
    if delta>0.05: delta = 0.05
    
    for event in pygame.event.get():
        #Si l'utilisateur ferme la fenêtre, on quitte la boucle principale:
        if event.type == QUIT:
            end = True
        

    #On recentre la caméra sur le joueur: