Ejemplo n.º 1
0
def update():
    g2d.clear_canvas()
    if random.randrange(50) == 0:
        Bullet(arena, random.randrange(arena.size()[0]))
    arena.move_all()
    for a in arena.actors():
        g2d.fill_rect(a.position())
Ejemplo n.º 2
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
Ejemplo n.º 3
0
    def update_buttons(self):
        global solved

        g2d.clear_canvas()
        g2d.set_color((0, 0, 0))
        cols, rows = self._game.cols(), self._game.rows()
        for y in range(1, rows):
            g2d.draw_line((0, y * H), (cols * W, y * H))
        for x in range(1, cols):
            g2d.draw_line((x * W, 0), (x * W, rows * H))
        for y in range(rows):
            for x in range(cols):
                value = self._game.value_at(x, y)

                if '#' not in value:
                    center = x * W + W // 2, y * H + H // 2

                    if '!' in value:
                        g2d.set_color((0, 0, 200))
                        g2d.fill_circle(center, 14)
                        g2d.set_color((255, 255, 255))
                        g2d.fill_circle(center, 12)
                        g2d.set_color((0, 0, 0))
                    g2d.draw_text_centered(value[:-1], center, H // 2)
                else:
                    g2d.fill_rect((x * W, y * H, W, H))
        g2d.update_canvas()

        if self._game.finished() and not solved:
            g2d.alert(self._game.message())
            g2d.close_canvas()
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
Ejemplo n.º 5
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))
Ejemplo n.º 6
0
def tick():
    global x, dx
    ##if g2d.key_pressed("Spacebar"): ...
    ##if x + dx > ARENA_W: ...
    g2d.clear_canvas()             # Draw background
    g2d.draw_image(image, (x, y))  # Draw foreground
    x += dx                        # Update ball's position
Ejemplo n.º 7
0
def update():
    global x, dx
    g2d.clear_canvas()                 # Draw background
    g2d.draw_image(image, (x, y))      # Draw foreground
##    if x + dx < 0 or x + dx + BALL_W > ARENA_W:
##        dx = -dx
    x = (x + dx) % ARENA_W             # Update ball's position
Ejemplo n.º 8
0
 def update_buttons(self):
     g2d.clear_canvas()
     g2d.set_color((0, 0, 0))
     cols, rows = self._game.cols(), self._game.rows()
     for y in range(1, rows):
         g2d.draw_line((0, y * H), (cols * W, y * H))
     for x in range(1, cols):
         g2d.draw_line((x * W, 0), (x * W, rows * H))
     for y in range(rows):
         for x in range(cols):
             g2d.set_color((0,0,0))
             value = self._game.value_at(x, y)
             if self._game.checkblack(x,y):
                 g2d.fill_rect((x * W, y * H, W, H))
             center = x * W + W//2, y * H + H // 2
             if self._game.checkcircle(x,y):
                 g2d.fill_circle((center), W // 2)
                 g2d.set_color((255,255,255))
                 g2d.fill_circle((center), W // 2 - 1)
             g2d.set_color((0,0,0))
             g2d.draw_text_centered(value, center, H//2)
     g2d.update_canvas()
     if self._game.finished():
         g2d.alert(self._game.message())
         g2d.close_canvas()
Ejemplo n.º 9
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
Ejemplo n.º 10
0
def update():
    global dx, dy, x, y
    g2d.clear_canvas()  # Clear background
    g2d.fill_circle((x, y), 20)  # Draw foreground
    x += dx
    y += dy

    if x >= A - distance:  # angolo in alto a destra
        dx = 0
        dy = 5

    if y >= A - distance:  # angolo in basso a destra
        dx = -5
        dy = 0
    '''
            nei primi due if posso anche inserire gli and come negli ultimi due ottenendo lo stesso risultato. 
            Non l'ho messo semplicemente per ottimizzare il codice
            '''
    if x <= 0 + distance and y >= A - distance:  # angolo in basso a sinistra
        dx = 0
        dy = -5

    if y <= 0 + distance and x <= 0 + distance:  # angolo in alto a sinistra
        dx = 5
        dy = 0
Ejemplo n.º 11
0
def tick():
    g2d.clear_canvas()
    if random.randrange(50) == 0:
        Bullet(arena, random.randrange(arena.size()[0]))
    arena.move_all()
    for a in arena.actors():
        g2d.fill_rect(a.position())
Ejemplo n.º 12
0
def update():
    ''' 
	modifica il canvas
	'''
    global x  # posizione pallina (globale)
    g2d.clear_canvas()  # pulisce background
    g2d.draw_image(image, (x, 50))  # disegna immagine posizione(x,y)
    x = (x + dx) % 320  # modifica ascissa immagine
Ejemplo n.º 13
0
def update():
    global balls
    g2d.clear_canvas()  # Clear background

    for b in balls:
        g2d.set_color((b.color()))
        g2d.fill_circle((b.val()), 20)  # Draw foreground
        b.move()
Ejemplo n.º 14
0
def tick():
    global i
    x = int(300 + i * math.cos(i * math.pi / 32))
    y = int(300 + i * math.sin(i * math.pi / 32))
    g2d.clear_canvas()
    g2d.set_color((255 - i, 0, i))
    g2d.fill_circle((x, y), i // 2)
    i = (i + 1) % n
Ejemplo n.º 15
0
def update():
    global i
    x = int(300 + i * math.cos(i * math.pi / 32))
    y = int(300 + i * math.sin(i * math.pi / 32))
    g2d.clear_canvas()
    g2d.set_color((255 - i, 0, i))
    g2d.fill_circle((x, y), i // 2)
    i = (i + 1) % n
Ejemplo n.º 16
0
def update():
    global raggio
    x = int(centro + raggio * math.cos(raggio * math.pi / 32))
    y = int(centro + raggio * math.sin(raggio * math.pi / 32))
    g2d.clear_canvas()
    g2d.set_color((255 - raggio, 0, raggio))
    g2d.fill_circle((x, y), int(raggio / 2))
    raggio = (raggio + 1) % n
Ejemplo n.º 17
0
def update():
    global x, y, count
    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
Ejemplo n.º 18
0
def update():
    g2d.clear_canvas()  # BG
    b1.move()
    b2.move()
    g2d.set_color((0, 0, 255))
    g2d.fill_rect(b1.position())  # FG
    g2d.set_color((0, 255, 0))
    g2d.fill_rect(b2.position())  # FG
Ejemplo n.º 19
0
def update():
    global x1, y1, dx1, dy1
    global x2, y2, dx2, dy2
    g2d.clear_canvas()               # Draw background
    g2d.draw_image(image, (x1, y1))  # Draw foreground
    g2d.draw_image(image, (x2, y2))  # Draw foreground
    x1, y1, dx1, dy1 = move_ball(x1, y1, dx1, dy1)
    x2, y2, dx2, dy2 = move_ball(x2, y2, dx2, dy2)
Ejemplo n.º 20
0
def tick():
    global x1, y1, dx1, dy1
    global x2, y2, dx2, dy2
    g2d.clear_canvas()  # Draw background
    g2d.draw_image(image, (x1, y1))  # Draw foreground
    g2d.draw_image(image, (x2, y2))  # Draw foreground
    x1, y1, dx1, dy1 = move_ball(x1, y1, dx1, dy1)
    x2, y2, dx2, dy2 = move_ball(x2, y2, dx2, dy2)
Ejemplo n.º 21
0
def update():
    global x, y, dx
    g2d.clear_canvas()
    g2d.draw_image(image, (x, y))
    if x + dx < 0 or x + dx + 20 > 320:
        y += 5
        dx = -dx
    else:
        x = x + dx
Ejemplo n.º 22
0
def tick():
    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())
Ejemplo n.º 23
0
def tick():
    global x, y, dx
    g2d.clear_canvas()
    g2d.draw_image(image, (x, y))
    if x + dx < 0 or x + dx + 20 > 320:
        y += 5
        dx = -dx
    else:
        x = x + dx
Ejemplo n.º 24
0
def update():
    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())
Ejemplo n.º 25
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
Ejemplo n.º 26
0
def update():
    global b, i
    i += 1
    g2d.clear_canvas()  # Clear background
    g2d.fill_circle(
        (b.val()),
        20)  # chiamo il metodo di b per avere le coordinate del centro
    b.move(i)
    if i == 40:
        i = 0
Ejemplo n.º 27
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
Ejemplo n.º 28
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
Ejemplo n.º 29
0
def draw_frame():
    center_x, center_y = canvas_w // 2, canvas_h // 2
    g2d.clear_canvas()
    g2d.set_color((255, 255, 0))
    g2d.fill_circle((center_x, center_y), 30)
    for p in planets:
        p.move()
        x, y = p.pos()
        radius = p.diameter() // 2
        g2d.set_color(p.color())
        g2d.fill_circle((center_x + x, center_y + y), radius)
def tick():
    global x, y, dx, dy
    if x + dx < 0 or x + dx + BALL_W > ARENA_W:
        dx = -dx
    if y + dy < 0 or y + dy + BALL_H > ARENA_H:
        dy = -dy
    g2d.clear_canvas()
    g2d.draw_image(image, (x, y))
    x += dx
    dy += g
    y += dy
Ejemplo n.º 31
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
Ejemplo n.º 32
0
def tick():
    center_x, center_y = canvas_w // 2, canvas_h // 2
    g2d.clear_canvas()
    g2d.set_color((255, 255, 0))
    g2d.fill_circle((center_x, center_y), 30)
    for p in planets:
        p.move()
        x, y = p.pos()
        radius = p.diameter() // 2
        g2d.set_color(p.color())
        g2d.fill_circle((center_x + x, center_y + y), radius)
Ejemplo n.º 33
0
def update():
    global b, b1
    g2d.clear_canvas()  # Clear background

    g2d.set_color((b.color()))
    g2d.fill_circle((b.val()), 20)  # Draw foreground

    g2d.set_color((b1.color()))
    g2d.fill_circle((b1.val()), 20)

    b.move()
    b1.move()
Ejemplo n.º 34
0
def update():
    ''' 
	modifica il canvas
	'''
    global x, dx  # posizione pallina (globale)
    g2d.clear_canvas()  # pulizia background
    g2d.draw_image(image, (x, 50))  # disegna immagine posizione(x,y)
    x = x + dx  # modifica ascissa immagine
    largImm = 20  # larghezza (e altezza immagine)
    if x < 0 or x > (320 - largImm):
        dx = -dx
        x = x + dx
Ejemplo n.º 35
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
Ejemplo n.º 36
0
def update():
	''' 
	modifica il canvas
	'''
	global x,dx,y						# posizione pallina (globale)
	if y>240:
		x = y = 0						# ritorno posizione iniziale
	g2d.clear_canvas()					# background vuoto   
	g2d.draw_image(image, (x, y))		# disegna immagine posizione(x,y)
	x = x + dx	 						# modifica ascissa immagine
	if x<0 or x>(320-largImm):
		dx = -dx						# inversione orizzontale
		y = y + dy						# discesa
Ejemplo n.º 37
0
def tick():
    arena.move_all()  # Game logic

    g2d.clear_canvas()
    for a in arena.actors():
        if isinstance(a, Background):
            ax, ay, aw, ah = a.position()
            g2d.draw_image_clip(bg, a.symbol(), (ax, ay, aw, ah))
            g2d.draw_image_clip(bg, a.symbol(), (ax + aw, ay, aw, ah))
        elif a.symbol() != (0, 0, 0, 0):
            g2d.draw_image_clip(sprites, a.symbol(), a.position())
        else:
            g2d.fill_rect(a.position())
Ejemplo n.º 38
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())
Ejemplo n.º 39
0
 def update_buttons(self):
     g2d.clear_canvas()
     g2d.set_color((0, 0, 0))
     rows, cols = self._game.rows(), self._game.cols()
     for y in range(1, rows):
         g2d.draw_line((0, y * H), (cols * W, y * H))
     for x in range(1, cols):
         g2d.draw_line((x * W, 0), (x * W, rows * H))
     for y in range(rows):
         for x in range(cols):
             value = self._game.value_at(x, y)
             center = x * W + W//2, y * H + H//2
             g2d.draw_text_centered(value, center, H//2)
     g2d.update_canvas()
     if self._game.finished():
         g2d.alert(self._game.message())
         g2d.close_canvas()
Ejemplo n.º 40
0
def update():
    g2d.clear_canvas()  # BG
    b1.move()
    b2.move()
    g2d.draw_image(img, b1.position())  # FG
    g2d.draw_image(img, b2.position())  # FG
Ejemplo n.º 41
0
def update():
    arena.move_all()  # Game logic

    g2d.clear_canvas()
    for a in arena.actors():
        g2d.draw_image_clip(sprites, vals(a.symbol()), vals(a.position()))
Ejemplo n.º 42
0
def update():
    g2d.clear_canvas()  # BG
    b1.move()
    b2.move()
    g2d.fill_rect(b1.position())  # FG
    g2d.fill_rect(b2.position())  # FG
Ejemplo n.º 43
0
def update():
    g2d.clear_canvas()  # BG
    for b in balls:
        b.move()
        g2d.fill_rect(b.position())  # FG
Ejemplo n.º 44
0
def update():
    g2d.clear_canvas()
    for a in aliens:
        a.move()
        g2d.fill_rect(a.position())
Ejemplo n.º 45
0
def update():
    g2d.clear_canvas()
    b.move()
    g2d.fill_rect(b.position())
Ejemplo n.º 46
0
def update():
    g2d.clear_canvas()
    a.move()
    g2d.set_color(a.color())
    g2d.fill_circle(a.center(), a.radius())