コード例 #1
0
 def tick(self):
     if g2d.key_pressed("LeftButton"):
         self._downtime = time()
     elif g2d.key_released("LeftButton"):
         mouse = g2d.mouse_position()
         x, y = mouse[0] // W, mouse[1] // H
         if time() - self._downtime > LONG_PRESS:
             self._game.flag_at(x, y)
         else:
             self._game.play_at(x, y)
         self.update_buttons()
コード例 #2
0
ファイル: boardgamegui.py プロジェクト: GiorCocc/3-in-a-row
 def tick(self):
     if g2d.key_pressed("LeftButton"):
         self._downtime = time()
     elif g2d.key_released("LeftButton"):
         mouse = g2d.mouse_position()
         x, y = mouse[0] // W, mouse[1] // H
         if time() - self._downtime > LONG_PRESS:
             self._game.flag_at(x, y)
         else:
             self._game.play_at(x, y)
         self.update_buttons()
     elif g2d.key_pressed("a"):
         self._game.auto_line()
         self._game.auto_terna()
         self.update_buttons()
     elif g2d.key_pressed("u"):
         self._game.unsolvable()
         if self._game.unsolvable():
             g2d.alert("Error!!!")
         else:
             g2d.alert("All right, for now...")
     elif g2d.key_pressed("h"):
         self._game.solve(0)
         self.update_buttons()
コード例 #3
0
ファイル: bounce.py プロジェクト: giorgiabenassi/fondinfo
def tick():
    if g2d.key_pressed("ArrowUp"):
        turtle.go_up(True)
    elif g2d.key_released("ArrowUp"):
        turtle.go_up(False)
    if g2d.key_pressed("ArrowRight"):
        turtle.go_right(True)
    elif g2d.key_released("ArrowRight"):
        turtle.go_right(False)
    if g2d.key_pressed("ArrowDown"):
        turtle.go_down(True)
    elif g2d.key_released("ArrowDown"):
        turtle.go_down(False)
    if g2d.key_pressed("ArrowLeft"):
        turtle.go_left(True)
    elif g2d.key_released("ArrowLeft"):
        turtle.go_left(False)

    arena.move_all()  # Game logic

    g2d.clear_canvas()
    for a in arena.actors():
        sym, pos = a.symbol(), a.position()
        g2d.draw_image_clip(sprites, a.symbol(), a.position())
コード例 #4
0
    def tick(self):
        global CONT_STEP, DECISION, DIRECTION

        # controlli da tastiera separati per ogni giocatore e con gestione della direzione per la bolla. A destra ←→↑↓ ; a sinistra WASD
        if g2d.key_pressed("ArrowUp"):
            self._game.hero1().go_up()
        elif g2d.key_pressed("ArrowRight"):
            self._game.hero1().go_right()
            DIRECTION = 1
        elif g2d.key_pressed("ArrowLeft"):
            self._game.hero1().go_left()
            DIRECTION = 0
        elif (g2d.key_released("ArrowLeft") or g2d.key_released("ArrowRight")):
            self._game.hero1().stay()
        elif g2d.key_pressed("ArrowDown"):
            dragon_x, dragon_y, dragon_w, dragon_h = self._game.hero1(
            ).position()
            if DIRECTION == 0:
                dragon_dimension = dragon_x - dragon_w
                speed = -SPEED
            elif DIRECTION == 1:
                dragon_dimension = dragon_x + dragon_w
                speed = SPEED
            self._game.bubble().append(
                Bubble(self._game.arena(), (dragon_dimension, dragon_y),
                       speed))

        if g2d.key_pressed('w'):
            self._game.hero().go_up()
        elif g2d.key_pressed("d"):
            self._game.hero().go_right()
            DIRECTION = 1
        elif g2d.key_pressed("a"):
            self._game.hero().go_left()
            DIRECTION = 0
        elif (g2d.key_released("a") or g2d.key_released("d")):
            self._game.hero().stay()
        elif g2d.key_pressed("s"):
            dragon_x, dragon_y, dragon_w, dragon_h = self._game.hero(
            ).position()
            if DIRECTION == 0:
                dragon_dimension = dragon_x - dragon_w
                speed = -SPEED
            elif DIRECTION == 1:
                dragon_dimension = dragon_x + dragon_w
                speed = SPEED
            self._game.bubble().append(
                Bubble(self._game.arena(), (dragon_dimension, dragon_y),
                       speed))

        # decisione del movimento per il nemico aggiornando il numero di passi con il tick
        CONT_STEP += 1
        if CONT_STEP == STEP_DIR_FRAME:
            for enemy in self._game.enemy():
                DECISION = randint(1, 3)
                enemy.decision(DECISION)
            CONT_STEP = 0
        else:
            for enemy in self._game.enemy():
                enemy.decision(DECISION)

        # controllo se il giocatore è vivo e nel caso lo rimuov0 e lo riaggiungo nel punto di origine
        if self._game.hero().lives() == 0:
            self._game.arena().remove(self._game.hero())
            g2d.alert("Sei stato eliminato!")
            self._game.hero().restore()

        if self._game.hero1().lives() == 0:
            self._game.arena().remove(self._game.hero1())
            g2d.alert("Sei stato eliminato!")
            self._game.hero1().restore()

        self._game.arena().move_all()  # Game logic

        # disegno degli elementi grafici
        g2d.clear_canvas()

        for i in self._game.platform():
            i.fill()

        for a in self._game.arena().actors():
            if a.symbol() != (0, 0, 0, 0):
                g2d.draw_image_clip(self._sprites, a.symbol(), a.position())
            else:
                g2d.fill_rect(a.position())

        # gestione delle vite, dei punti e del tempo nell'interfaccia
        lives_player = "Player1 Lives: " + str(self._game.hero().lives())
        lives_player1 = "Player2 Lives: " + str(self._game.hero1().lives())
        points = "Points: " + str(self._game.hero().points() +
                                  self._game.hero1().points())
        toplay = "Time: " + str(self._game.remaining_time())

        g2d.draw_text(lives_player + "    " + toplay + "    " + points, (0, 0),
                      24)
        g2d.draw_text(lives_player1, (0, 24), 24)

        # creazione degli alert per il termine del gioco
        if self._game.game_over():
            g2d.alert("Game over")
            g2d.close_canvas()

        elif self._game.game_won():
            g2d.alert("Game won")
            g2d.close_canvas()