Exemplo n.º 1
0
    def __init__(self, game):
        Sprite.__init__(self, game)

        self.image_left = [
            PhotoImage(file="figure-L1.gif"),
            PhotoImage(file="figure-L2.gif"),
            PhotoImage(file="figure-L3.gif")
        ]
        self.image_right = [
            PhotoImage(file="figure-R1.gif"),
            PhotoImage(file="figure-R2.gif"),
            PhotoImage(file="figure-R3.gif")
        ]

        self.image = game.canvas.create_image(200,
                                              470,
                                              image=self.image_left[0],
                                              anchor='nw')

        self.speed_x = 0
        self.speed_y = 0
        self.current_image = 0  #   индекс текущего изображения 0, 1 и 2 для трех стадий бега человечка
        self.current_image_add = 1  #  число которое  прибавить к индексу хранящемуся в свойстве current_image, чтобы получить индекс следующего изображения

        self.last_time = time.time(
        )  #  будет хранить время последней смены кадров фигурки. сейчас записано текущее время с помощью функции time из модуля time.

        self.coordinates = coords_rectangle.Coords()

        game.canvas.bind_all('<KeyPress-Left>', self.turn_left)
        game.canvas.bind_all('<KeyPress-Right>', self.turn_right)
        game.canvas.bind_all('<space>', self.jump)
        game.canvas.bind_all('<KeyRelease-Left>', self.stop_left)
        game.canvas.bind_all('<KeyRelease-Right>', self.stop_right)
Exemplo n.º 2
0
 def test_within_x_true(self):
     co1 = coords_rectangle.Coords(x1=7, y1=1, x2=9, y2=3)
     co2 = coords_rectangle.Coords(x1=4, y1=4, x2=10, y2=6)
     self.assertTrue(coords_rectangle.within_x(co1, co2))
Exemplo n.º 3
0
 def test_collided_top_false_side(self):
     co1 = coords_rectangle.Coords(x1=12, y1=5, x2=14, y2=7)
     co2 = coords_rectangle.Coords(x1=4, y1=4, x2=10, y2=6)
     self.assertFalse(coords_rectangle.collided_top(co1, co2))
Exemplo n.º 4
0
 def test_collided_top_true(self):
     co1 = coords_rectangle.Coords(x1=6, y1=5, x2=8, y2=7)
     co2 = coords_rectangle.Coords(x1=4, y1=4, x2=10, y2=6)
     self.assertTrue(coords_rectangle.collided_top(co1, co2))
Exemplo n.º 5
0
 def test_collided_right_false_inleftside(self):
     co1 = coords_rectangle.Coords(x1=10, y1=2, x2=12, y2=5)
     co2 = coords_rectangle.Coords(x1=4, y1=4, x2=10, y2=6)
     self.assertFalse(coords_rectangle.collided_right(co1, co2))
Exemplo n.º 6
0
 def test_collided_right_false_up(self):
     co1 = coords_rectangle.Coords(x1=7, y1=1, x2=9, y2=3)
     co2 = coords_rectangle.Coords(x1=4, y1=4, x2=10, y2=6)
     self.assertFalse(coords_rectangle.collided_right(co1, co2))
Exemplo n.º 7
0
 def test_collided_left_false_side(self):
     co1 = coords_rectangle.Coords(x1=13, y1=2, x2=15, y2=5)
     co2 = coords_rectangle.Coords(x1=4, y1=4, x2=10, y2=6)
     self.assertFalse(coords_rectangle.collided_left(co1, co2))
Exemplo n.º 8
0
 def test_collided_right_true(self):
     co1 = coords_rectangle.Coords(x1=2, y1=2, x2=4, y2=5)
     co2 = coords_rectangle.Coords(x1=4, y1=4, x2=10, y2=6)
     self.assertTrue(coords_rectangle.collided_right(co1, co2))
Exemplo n.º 9
0
 def test_within_y_false(self):
     co1 = coords_rectangle.Coords(x1=7, y1=1, x2=9, y2=3)
     co2 = coords_rectangle.Coords(x1=4, y1=4, x2=10, y2=6)
     self.assertFalse(coords_rectangle.within_y(co1, co2))
Exemplo n.º 10
0
 def test_within_y_true(self):
     co1 = coords_rectangle.Coords(x1=13, y1=2, x2=15, y2=5)
     co2 = coords_rectangle.Coords(x1=4, y1=4, x2=10, y2=6)
     self.assertTrue(coords_rectangle.within_y(co1, co2))
Exemplo n.º 11
0
 def test_within_x_false(self):
     co1 = coords_rectangle.Coords(x1=13, y1=2, x2=15, y2=5)
     co2 = coords_rectangle.Coords(x1=4, y1=4, x2=10, y2=6)
     self.assertFalse(coords_rectangle.within_x(co1, co2))
Exemplo n.º 12
0
 def __init__(self, game, photo_image, x, y, width, height):
     Sprite.__init__(self, game)
     self.photo_image = photo_image
     self.image = game.canvas.create_image(x, y, image=self.photo_image, anchor='nw')
     self.coordinates = coords_rectangle.Coords(x, y, x + width, y + height)