def tick(self):
        global solved

        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()
        if g2d.key_pressed("a"):
            self._game.mark_auto()
        elif g2d.key_released("a"):
            self.update_buttons()
        if g2d.key_pressed("h"):
            self._game.user_helper()
        elif g2d.key_released("h"):
            self.update_buttons()
        if g2d.key_pressed("r"):
            if not solved:
                while not solved:
                    solved = self._game.solve_recursive(0)
            else:
                solved = False
                self._game.clear_board()
        elif g2d.key_released("r"):
            self.update_buttons()
Esempio n. 2
0
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, (sym.x, sym.y, sym.w, sym.h),
                            (pos.x, pos.y, pos.w, pos.h))
def tick():
    global x,y, dy, dx, s        

    g2d.clear_canvas()             # Draw background
    g2d.draw_image(image, (x, y))  # Draw foreground
    

    if g2d.key_pressed("w"):
        s=1
        # y-=dy
    elif g2d.key_pressed("a"):
        s=2
        # x-=dx
    elif g2d.key_pressed("s"):
        s=3
        # y+=dy
    elif g2d.key_pressed("d"):
        s=4
        # x+=dx
    
    if s==1:
        y-=dy
    elif s==2:
        x-=dx
    elif s==3:
        y+=dy
    elif s==4:
        x+=dx
Esempio n. 4
0
def tick():
    if g2d.key_pressed("1"):
        b1.start()
    if g2d.key_pressed("2"):
        b2.start()
    g2d.clear_canvas()  # BG
    b1.move()
    b2.move()
    g2d.fill_rect(b1.position())  # FG
    g2d.fill_rect(b2.position())  # FG
Esempio n. 5
0
def tick():
    if g2d.key_pressed("ArrowLeft"):
        b1.go()
    elif g2d.key_pressed("ArrowRight"):
        b2.go()
    g2d.clear_canvas()  # BG
    b1.move()
    b2.move()
    g2d.draw_image(img, b1.position())  # FG
    g2d.draw_image(img, b2.position())  # FG
Esempio n. 6
0
def tick():
    if g2d.key_pressed("ArrowUp"):
        frog.jump_up()
    elif g2d.key_pressed("ArrowRight"):
        frog.jump_right()
    elif g2d.key_pressed("ArrowDown"):
        frog.jump_down()
    elif g2d.key_pressed("ArrowLeft"):
        frog.jump_left()

    g2d.clear_canvas()
    arena.move_all()
    for a in arena.actors():
        g2d.fill_rect(a.position())
def tick():
    g2d.clear_canvas()  # BG

    if g2d.key_pressed("w"):
        b1.go_up()
    if g2d.key_pressed("a"):
        b1.go_left()
    if g2d.key_pressed("s"):
        b1.go_down()
    if g2d.key_pressed("d"):
        b1.go_right()

    b1.move()
    g2d.fill_rect(b1.position())  # FG
Esempio n. 8
0
def tick():
    if g2d.key_pressed("Spacebar"):
        turtle.jump()
    elif g2d.key_pressed("ArrowLeft"):
        turtle.go_left()
    elif g2d.key_pressed("ArrowRight"):
        turtle.go_right()
    elif g2d.key_released("ArrowLeft") or g2d.key_released("ArrowRight"):
        turtle.stay()

    arena.move_all()  # Game logic

    g2d.clear_canvas()
    for a in arena.actors():
        g2d.draw_image_clip(sprites, a.symbol(), a.position())
Esempio n. 9
0
def update():
    terrenoval = B - 100
    global contatore, contatore2, contatore3
    if g2d.key_pressed("ArrowUp"):
        turtle.go_up()
    elif g2d.key_pressed("ArrowRight"):
        turtle.go_right()
    elif g2d.key_pressed("ArrowDown"):
        turtle.go_down()
    elif g2d.key_pressed("ArrowLeft"):
        turtle.go_left()
    elif (
            g2d.key_released("ArrowRight") or
            g2d.key_released("ArrowDown") or
            g2d.key_released("ArrowLeft")):
        turtle.stay()

    arena.move_all()
    g2d.clear_canvas()

    # -------------------------------------Sfondo-----------------------------------------------------------
    '''Disegno 2 volte l'immagine, di cui una volta fuori dallo schermo, quando il decremento è uguale al totale del canvas lo ripristino in modo
        che il movimento sembri continuo'''
    g2d.draw_image_clip(image, (0, 0, 512, 128), (0, 0, A, B))

    g2d.draw_image_clip(image, (0, 258, 512, 128), (0 - contatore3 // 2, (B - 75) // 3, A, B - (B - 75) // 3))
    g2d.draw_image_clip(image, (0, 258, 512, 128), (A - contatore3 // 2, (B - 75) // 3, A, B - (B - 75) // 3))

    g2d.draw_image_clip(image, (0, 386, 512, 128), (0 - contatore, terrenoval - 90, A, B - (terrenoval - 90)))
    g2d.draw_image_clip(image, (0, 386, 512, 128), (A - contatore, terrenoval - 90, A, B - (terrenoval - 90)))

    g2d.draw_image_clip(image, (0, 513, 512, 128), (0 - contatore2 * 2, terrenoval, A, 100))
    g2d.draw_image_clip(image, (0, 513, 512, 128), (A - contatore2 * 2, terrenoval, A, 100))
    if contatore == A:
        contatore = 0
    if contatore2 == A // 2:
        contatore2 = 0
    if contatore3 == A * 2:
        contatore3 = 0

    for a in arena.actors():
        if a.symbol() != (0, 0, 0, 0):
            g2d.draw_image_clip(sprites, a.symbol(), a.position())
        else:
            g2d.fill_rect(a.position())
    contatore += 1
    contatore2 += 1
    contatore3 += 1
Esempio n. 10
0
def update():
    global x, dx  # posizione pallina (globale)
    if g2d.key_pressed("Spacebar"):  # inversione movimento
        dx = -dx
    g2d.clear_canvas()  # background
    g2d.draw_image(image, (x, 50))  # disegna immagine posizione(x,y)
    x = (x + dx) % 320  # modifica ascissa immagine
Esempio n. 11
0
def tick():
    global x, dx
    if g2d.key_pressed("Enter"):
        dx = -dx
    g2d.clear_canvas()  # Draw background
    g2d.draw_image(image, (x, y))  # Draw foreground
    x = (x + dx) % ARENA_W  # Update ball's position
Esempio n. 12
0
def tick():
    if g2d.key_pressed("LeftButton"):
        x, y = g2d.mouse_position()
        g2d.set_color((randrange(256), randrange(256), randrange(256)))
        if x <= 25 and y <= 25 and g2d.confirm("Exit?"):
            g2d.close_canvas()
        else:
            g2d.fill_circle((x, y), 25)
Esempio n. 13
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 0<=mouse[0]<=W*self._game.cols() and 0<=mouse[1]<=H*self._game.rows():
             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("h"):
         if g2d.confirm("Are You Sure? The autocompletion may not complete it (for wrong moves at the beginning). Are you sure you want to continue?"):
             self._game.help()
             #self._game.help_cirle()
             #self._game.help_square()
             self.update_buttons()
Esempio n. 14
0
def tick():
    if g2d.key_pressed("ArrowUp"):
        hero.jump()
    elif g2d.key_pressed("ArrowRight"):
        hero.go_right()
    elif g2d.key_pressed("ArrowLeft"):
        hero.go_left()
    elif (g2d.key_released("ArrowLeft") or g2d.key_released("ArrowRight")):
        hero.stay()

    arena.move_all()  # Game logic

    g2d.clear_canvas()
    for a in arena.actors():
        if a.symbol() != (0, 0, 0, 0):
            g2d.draw_image_clip(sprites, a.symbol(), a.position())
        else:
            g2d.fill_rect(a.position())
Esempio n. 15
0
def tick():
    if g2d.key_pressed("Spacebar"):
        mario.jump()
    elif g2d.key_pressed("ArrowLeft"):
        mario.go_left()
    elif g2d.key_pressed("ArrowRight"):
        mario.go_right()
    elif (g2d.key_released("ArrowLeft") or g2d.key_released("ArrowRight")):
        mario.stay()

    arena.move_all()  # Game logic

    g2d.clear_canvas()
    for a in arena.actors():
        if isinstance(a, Wall):
            g2d.fill_rect(a.position())
        else:
            g2d.draw_image_clip(sprites, a.symbol(), a.position())
Esempio n. 16
0
 def handle_keyboard(self):
     hero = self._game.hero()
     if g2d.key_pressed("ArrowUp"):
         hero.go_up(True)
     elif g2d.key_released("ArrowUp"):
         hero.go_up(False)
     if g2d.key_pressed("ArrowRight"):
         hero.go_right(True)
     elif g2d.key_released("ArrowRight"):
         hero.go_right(False)
     if g2d.key_pressed("ArrowDown"):
         hero.go_down(True)
     elif g2d.key_released("ArrowDown"):
         hero.go_down(False)
     if g2d.key_pressed("ArrowLeft"):
         hero.go_left(True)
     elif g2d.key_released("ArrowLeft"):
         hero.go_left(False)
Esempio n. 17
0
def tick():
    global x, y, count
    if g2d.key_pressed("Enter") and count == 5:
        count = 0
    g2d.clear_canvas()             # Draw background
    g2d.draw_image(image, (x, y))  # Draw foreground
    if count < 5:
        x = (x + dx) % ARENA_W     # Update ball's position
        y = (y + dy) % ARENA_H     # Update ball's position
        count += 1
Esempio n. 18
0
def tick():
    global view_x, view_y
    arena_w, arena_h = arena.size()
    if g2d.key_pressed("ArrowUp"):
        view_y = max(view_y - 10, 0)
    elif g2d.key_pressed("ArrowRight"):
        view_x = min(view_x + 10, arena_w - view_w)
    elif g2d.key_pressed("ArrowDown"):
        view_y = min(view_y + 10, arena_h - view_h)
    elif g2d.key_pressed("ArrowLeft"):
        view_x = max(view_x - 10, 0)

    g2d.draw_image_clip(background,
                        (view_x, view_y, view_w, view_h),
                        (0, 0, view_w, view_h))  # BG
    arena.move_all()
    for a in arena.actors():
        x, y, w, h = a.position()
        g2d.fill_rect((x - view_x, y - view_y, w, h))  # FG
Esempio n. 19
0
    def move(self):
        self._timer += 1  # Timer per le animazioni
        self._shootimer += 1  # Timer per il cannone
        if self._timer == self._maxtimer:
            self._timer = 0  # Resetta il timer
        if g2d.key_pressed(self._btnj):
            if self._y == self._ground:  # Se a terra, il rover salta
                self._dy = -20
            else:  # Se in aria, il rover decresce gradualmente la salita
                self._dy += 2
        else:
            if self._y != self._ground:  # Se il tasto non è premuto ma il rover è in aria, continua il salto
                self._dy += 2
            else:  # Altrimenti il rover non si muove sull'asse Y
                self._dy = 0

        if g2d.key_pressed(self._btnl):
            if self._x + self._dx > self._arena._w // 10 and self._y == self._ground:
                self._dx = -4  # Se a terra e nel limite impostato, il rover si muove
            elif self._y != self._ground:
                pass  # Se il rover è in aria, l'input dell'utente è ignorato finchè il rover non tocca terra
            else:
                self._dx = 0  # Se il rover raggiunge il limite impostato, non prosegue oltre

        elif g2d.key_pressed(
                self._btnr):  # Codice identico per il movimento a destra
            if self._x + self._w + self._dx < self._arena._w - self._arena._w // 10 and self._y == self._ground:
                self._dx = 4
            elif self._y != self._ground:
                pass
            else:
                self._dx = 0

        elif g2d.key_pressed(self._btnl) and g2d.key_pressed(self._btnr):
            self._dx = 0  # Se entrambi i pulsanti sono premuti, il rover non si muove orizzontalmente

        elif g2d.key_released(self._btnl) or g2d.key_released(self._btnr):
            if self._y == self._ground or self._x + self._dx < self._arena._w // 10 or \
                    self._x + self._w + self._dx > self._arena._w - self._arena._w // 10:
                self._dx = 0  # Se uno dei pulsanti è rilasciato, e il rover è a terra o fuori dai limiti
                # del canvas, esso si ferma, altrimenti l'input dell'utente viene ignorato

        else:  # Se nessun pulsante ha cambiato stato, il rover continua quello che stava facendo
            if self._x + self._dx < self._arena._w // 10 or self._x + self._w + self._dx > self._arena._w - self._arena._w // 10:
                self._dx = 0  # Il rover in questo caso si ferma solo se fuori dai limiti del canvas

        if g2d.key_pressed(self._btns1):
            Bullet(arena, self._x + self._offx1, self._y + self._offy1, 0, -10,
                   4, self._playernum - 1)

        if g2d.key_pressed(self._btns2) and self._shootimer > 30:
            Bullet(arena, self._x + self._offx2, self._y + self._offy2,
                   self._dx + 5, 0, 5, self._playernum - 1)
            self._shootimer = 0

        self._y += self._dy  # Applica i cambiamenti
        self._x += self._dx
Esempio n. 20
0
def tick():
    global x, dx
    if g2d.key_pressed("Enter"):
        dx = -dx
    if x + dx < -MARGIN:
        x = ARENA_W + MARGIN
    if x + dx > ARENA_W + MARGIN:
        x = -MARGIN
    g2d.clear_canvas()  # Draw background
    g2d.draw_image(image, (x, y))  # Draw foreground
    x += dx  # Update ball's position
Esempio n. 21
0
 def tick(self):
     if g2d.key_pressed("LeftButton"):
         self._downtime = time()
     elif g2d.key_released("LeftButton"):
         pos = g2d.mouse_position()
         x, y = pos[0] // W, pos[1] // H
         if time() - self._downtime > LONG_PRESS:
             self._game.flag_at(x, y)
         else:
             self._game.play_at(x, y)
         self.update_buttons()
def tick():
    global x, y, dy, dx
    if g2d.key_pressed("w"):
        dx = 0
        dy = -5
    elif g2d.key_pressed("a"):
        dy = 0
        dx = -5
    elif g2d.key_pressed("s"):
        dx = 0
        dy = 5
    elif g2d.key_pressed("d"):
        dy = 0
        dx = 5

    g2d.clear_canvas()  # Draw background
    g2d.draw_image(image, (x, y))  # Draw foreground

    x += dx  # Update ball's position
    y += dy
Esempio n. 23
0
def update():
    if g2d.key_pressed("ArrowUp"):
        turtle.go_up()
    elif g2d.key_pressed("ArrowRight"):
        turtle.go_right()
    elif g2d.key_pressed("ArrowDown"):
        turtle.go_down()
    elif g2d.key_pressed("ArrowLeft"):
        turtle.go_left()
    elif (g2d.key_released("ArrowRight") or g2d.key_released("ArrowDown")
          or g2d.key_released("ArrowLeft")):
        turtle.stay()

    arena.move_all()
    g2d.clear_canvas()
    for a in arena.actors():
        if a.symbol() != (0, 0, 0, 0):
            print(a.symbol())
            g2d.draw_image_clip(sprites, a.symbol(), a.position())
        else:
            g2d.fill_rect(a.position())
Esempio n. 24
0
def tick():
    global x, dx, count
    g2d.clear_canvas()  # Draw background
    g2d.draw_image(image, (x, y))  # Draw foreground
    if g2d.key_pressed("Enter"):
        count = 5
    if count > 0:
        count -= 1
        if x + dx < -MARGIN:
            x = ARENA_W + MARGIN
        if x + dx > ARENA_W + MARGIN:
            x = -MARGIN
        x += dx  # Update ball's position
    def handle_keyboard(self):
        # Hero 1
        if g2d.key_pressed("ArrowUp") or self._hero[0].get_state() != "ground":
            if self._hero[0].get_state() == "ground":
                self._hero[0].set_offset(-6)
                self._hero[0].set_state("jumping_up")
            else:
                self._hero[0].jump()
        elif g2d.key_released("ArrowUp"):
            self._hero[0].stay()
        if g2d.key_pressed("ArrowRight"):
            self._game.ground_boost()
        elif g2d.key_released("ArrowRight"):
            self._game.ground_release_boost()
        elif g2d.key_pressed("ArrowLeft"):
            self._hero[0].go_left()
        elif g2d.key_released("ArrowLeft"):
            self._hero[0].stay()
        elif g2d.key_pressed("Spacebar"):
            self._game.hero_shoot_straight(0)
            self._game.hero_shoot_up(0)
        elif g2d.key_released('Spacebar'):
            self._hero[0].stay()

        # Hero 2
        if self._settings['mode'] == 'co-op':
            if g2d.key_pressed("w") or self._hero[1].get_state() != "ground":
                if self._hero[1].get_state() == "ground":
                    self._hero[1].set_offset(-6)
                    self._hero[1].set_state("jumping_up")
                else:
                    self._hero[1].jump()
            elif g2d.key_released("w"):
                self._hero[1].stay()
            if g2d.key_pressed("d"):
                self._game.ground_boost()
            elif g2d.key_released("d"):
                self._game.ground_release_boost()
            elif g2d.key_pressed("a"):
                self._hero[1].go_left()
            elif g2d.key_released("a"):
                self._hero[1].stay()
            elif g2d.key_pressed("s"):
                self._game.hero_shoot_straight(1)
                self._game.hero_shoot_up(1)
            elif g2d.key_released('s'):
                self._hero[1].stay()
Esempio n. 26
0
def tick():
    if g2d.key_pressed("Enter"):
        b.uturn()
    g2d.clear_canvas()
    b.move()
    g2d.fill_rect(b.position())
Esempio n. 27
0
    def movement(self):
        player1 = self._game.player1()
        player2 = self._game.player2()

        if g2d.key_pressed("w"):
            player1.go_up()

        if g2d.key_pressed("d"):
            player1.go_right(True)
        elif g2d.key_released("d"):
            player1.go_right(False)

        if g2d.key_pressed("a"):
            player1.go_left(True)
        elif g2d.key_released("a"):
            player1.go_left(False)

        if g2d.key_pressed("q"):
            player1.attack()

        if g2d.key_pressed("ArrowUp"):
            player2.go_up()

        if g2d.key_pressed("ArrowRight"):
            player2.go_right(True)
        elif g2d.key_released("ArrowRight"):
            player2.go_right(False)

        if g2d.key_pressed("ArrowLeft"):
            player2.go_left(True)
        elif g2d.key_released("ArrowLeft"):
            player2.go_left(False)

        if g2d.key_pressed("Spacebar"):
            player2.attack()

        if self._current_level == 0:
            if g2d.key_pressed(
                    "q"
            ):  #il giocatore 1 viene evidenziato pronto o non pronto quando viene premuto il tasto
                self._player1_ready = not self._player1_ready

            if g2d.key_pressed(
                    "Spacebar"
            ):  #il giocatore 2 viene evidenziato pronto o non pronto quando viene premuto il tasto
                self._player2_ready = not self._player2_ready

            if self._player1_ready or self._player2_ready:  #invoca il metodo che cambia livello, se almeno un giocatore è pronto
                if g2d.key_pressed("Enter"):
                    self._current_level = 1
                    self._game.levels(self._current_level, self._player1_ready,
                                      self._player2_ready)
Esempio n. 28
0
def update():
    terrenoval = B - 100
    global players
    g2d.clear_canvas()
    global bucacont, boh, rocciacont, rover2
    if arena.stop() is False:
        if g2d.key_pressed("ArrowUp"):
            rover.go_up()
        elif g2d.key_pressed("ArrowDown"):
            rover.go_down()
        elif g2d.key_pressed("Spacebar"):
            x, y, w, h = rover.position()
            Proiettile(arena, x + (w / 4), y, 0, -5)
            Proiettile(arena, x + w, y + (h / 2), 5, 0)
        elif g2d.key_pressed("ArrowRight"):
            rover.go_right()
        elif g2d.key_pressed("ArrowLeft"):
            rover.go_left()
        elif (
                g2d.key_released("ArrowUp") or g2d.key_released("ArrowRight") or g2d.key_released("ArrowLeft")):
            rover.stay()
        if players:
            if g2d.key_pressed("w"):
                rover2.go_up()
            elif g2d.key_pressed("s"):
                rover2.go_down()
            elif g2d.key_pressed("LeftButton"):
                x, y, w, h = rover2.position()
                Proiettile(arena, x + (w / 4), y, 0, -5)
                Proiettile(arena, x + w, y + (h / 2), 5, 0)
            elif g2d.key_pressed("d"):
                rover2.go_right()
            elif g2d.key_pressed("a"):
                rover2.go_left()
            elif (
                    g2d.key_released("w") or g2d.key_released("d") or g2d.key_released("a")):
                rover2.stay()

    arena.move_all()
    g2d.draw_image_clip(image, (0, 0, 512, 128), (0, 0, A, B))
    if random.randint(0, 50) == 0 and \
            bucacont >= 30 and \
            arena.stop() is False and rocciacont >= 30:
        Buca(arena, A)
        bucacont = 0
    if random.randint(0, 50) == 0 and \
            rocciacont >= 30 and \
            arena.stop() is False and bucacont >= 30:
        choice = bool(random.getrandbits(1))
        if choice:
            Roccia(arena, A, terrenoval - 16, choice)
        else:
            Roccia(arena, A, terrenoval - 36, choice)
        rocciacont = 0

    for a in arena.actors():
        if a.symbol() != (0, 0, 0, 0):
            if isinstance(a,
                          Sfondo):  # il discriminante tra gli sfondi e tutto il resto è l'immagine da cui prendere le porzioni symbol
                g2d.draw_image_clip(image, a.symbol(), a.position())
            else:
                g2d.draw_image_clip(sprites, a.symbol(), a.position())
        else:
            g2d.fill_rect(a.position())
    bucacont += 1
    rocciacont += 1