Example #1
0
    def __init__(self, raw_gene, *groups):
        super(Ball, self).__init__(*groups)
        self.done = 0
        if BALL_IMAGE_OPTION == 'random':

            self.color = RGB_gene_gen()
            (R,G,B) = int(self.color[0:8],2), int(self.color[9:17],2), int(self.color[18:26],2)
            self.file_name = path + '!' + hashlib.md5(str((R,G,B))).hexdigest() + '.ball'
            circle_img(32,self.file_name,(R,G,B))

            self.image = pygame.image.load(self.file_name)

            self.rect = pygame.rect.Rect(find_coor(BALL)[0], self.image.get_size())
        if BALL_IMAGE_OPTION == 'ball':
            self.image = pygame.image.load(path + 'ball.png')

            self.rect = pygame.rect.Rect(find_coor(BALL)[0], self.image.get_size())

        #self.raw_gene = gene_gen(random.randint(5,20))
        self.raw_gene = raw_gene
        self.dir_list = dir_gene_dec(self.raw_gene)

        #print self.dir_list

        self.dis_to_fin = None
Example #2
0
    def __init__(self, raw_gene, *groups):
        super(Ball, self).__init__(*groups)
        self.done = 0
        if BALL_IMAGE_OPTION == 'random':

            self.color = RGB_gene_gen()
            (R, G, B) = int(self.color[0:8],
                            2), int(self.color[9:17],
                                    2), int(self.color[18:26], 2)
            self.file_name = path + '!' + hashlib.md5(str(
                (R, G, B))).hexdigest() + '.ball'
            circle_img(32, self.file_name, (R, G, B))

            self.image = pygame.image.load(self.file_name)

            self.rect = pygame.rect.Rect(
                find_coor(BALL)[0], self.image.get_size())
        if BALL_IMAGE_OPTION == 'ball':
            self.image = pygame.image.load(path + 'ball.png')

            self.rect = pygame.rect.Rect(
                find_coor(BALL)[0], self.image.get_size())

        #self.raw_gene = gene_gen(random.randint(5,20))
        self.raw_gene = raw_gene
        self.dir_list = dir_gene_dec(self.raw_gene)

        #print self.dir_list

        self.dis_to_fin = None
Example #3
0
    def main(self, screen):
        clock = pygame.time.Clock()

        background = pygame.image.load(path + 'background.png')
        self.sprites = pygame.sprite.Group()
        self.walls = pygame.sprite.Group()
        self.fins = pygame.sprite.Group()

        self.wall = [Wall(i,self.walls) for i in find_coor(WALL)]
        self.ball = Ball(self.raw_gene, self.sprites)
        self.finish = Finish(find_coor(FINISH)[0], self.fins)

        self.clock1 = time.time()
        while 1:
            dt = clock.tick(30)
            self.clock2 = time.time()


            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    return
                if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                    return

            # Обновляем все группы спрайтов, и переносим всё на экран
            self.sprites.update(dt / 1000., self)
            self.walls.update(dt / 1000.)
            self.fins.update(dt / 1000.)
            screen.blit(background, (0, 0))
            self.walls.draw(screen)
            self.sprites.draw(screen)
            self.fins.draw(screen)
            pygame.display.flip()


            self.ball.dis_to_fin = math.sqrt((self.ball.rect.x - self.finish.rect.x)**2 + (self.ball.rect.y - self.finish.rect.y)**2)
            self.d_clock = self.clock2 - self.clock1

            if self.d_clock > ROUND_TIME:
                print 'Too late!', self.ball.dis_to_fin
                #print self.ball.dis_to_fin
                self.quit = 1
                break

            if self.ball.done:
                print "Tah-dah!", self.d_clock
                #print self.d_clock
                self.quit = 1
                break