コード例 #1
0
ファイル: entity.py プロジェクト: garred/cuadrados
    def enqueue_shadow(self, screen):
        """Add it's own shadow to the list of shadows that the ground have to
        paint.
        """
        min_depth = int(self.pos[2])-1
        tile_y, tile_x = int(self.pos[0]), int(self.pos[1])

        if (self.pos[0] < 0.0 or self.pos[0] >= len(Ground.pattern[0]) or
            self.pos[1] < 0.0 or self.pos[1] >= len(Ground.pattern[0][0])):
            return

        while min_depth < len(Ground.pattern):
            if not Ground.pattern[min_depth][tile_x][tile_y]:
                min_depth += 1
                continue

            shadow_pos = self.pos[:]
            shadow_pos[2] = len(Ground.pattern) - min_depth + 0.3

            # The shadow behaves different if there is a slope.
            if Ground.pattern[min_depth][tile_x][tile_y]==2:
                shadow_pos[2] += self.pos[0]-tile_y
            elif Ground.pattern[min_depth][tile_x][tile_y]==3:
                shadow_pos[2] += self.pos[1]-tile_x
            elif Ground.pattern[min_depth][tile_x][tile_y]==4:
                shadow_pos[2] -= self.pos[0]-tile_y-1
            elif Ground.pattern[min_depth][tile_x][tile_y]==5:
                shadow_pos[2] -= self.pos[1]-tile_x-1

            Ground.add_shadow(screen, shadow_pos, min_depth, self.radius)

            min_depth += 1
コード例 #2
0
 def startGround(self):
     """ the ground is a 2-D space representing the field where ants wander
     """
     self.Ground = Ground(self, Toric=True)
     self.Ground.scaleX = self.Ground.scaleY = LandSize  # Logical coordinates
     self.Ground.W = self.Ground.H = LandWindowSize  # Physical coordinates
     self.Ground.configure(width=self.Ground.W, height=self.Ground.H)
     self.Ground.pack(expand=Tkinter.YES, fill=Tkinter.BOTH)  # the window shows on the scren
コード例 #3
0
class Ant_Frame(Generic_Main_Frame):

    def __init__(self, Parent,NbAgents):
        #frame with some additional ant capabilities
        Generic_Main_Frame.__init__(self,Parent,self.oneStep,Wtitle='Ants')
        self.startGround()
        self.LastTimeStep = 0
        self.Counter = 0
        #create population of agents
        self.Pop = [Ant('A%d' % IdNb) for IdNb in range(NbAgents)]
        self.PopSize = NbAgents
        self.Moves = 0  # counts the number of times agents have moved
        t = Thread(target=self.redraw)
        t.start()
          
    def startGround(self):
        """ the ground is a 2-D space representing the field where ants wander
        """
        self.Ground = Ground(self, Toric=True)
        self.Ground.scaleX = self.Ground.scaleY = LandSize   # Logical coordinates
        self.Ground.W = self.Ground.H = LandWindowSize      # Physical coordinates
        self.Ground.configure(width=self.Ground.W, height=self.Ground.H)
        self.Ground.pack(expand=Tkinter.YES,fill=Tkinter.BOTH)  # the window shows on the scren
           
    def oneStep(self):
        # this function is called back after each simulation step
        Land.evaporate()
        
        for agent in self.Pop:
            agent.moves()
        
        self.Moves += 1
        return 0
    
    def redraw(self):
        while 1:
            # the landscape is entirely redrawn
            self.Ground.erase() # supposedly destroys all objects on ground
            
            self.displayNodes(Land.Nodes)
            self.displayPheromons(Land.EdgesWithPheromons)
            sleep(1)
    

    def displayPheromons(self, edges):
        for edge in edges:
            coord1 = edge[0]
            coord2 = edge[1]
            self.Ground.create_line(coord1[0], coord1[1], coord2[0],coord2[1], fill="red", dash=(4, 4))

    def displayNodes(self, Nodes):
        for node in Nodes:
            coord = node.Position
            self.Ground.create_rectangle(coord[0]-2, coord[1]-2, coord[0]+2, coord[1]+2,outline='black',fill='gray50')
コード例 #4
0
class Ant_Frame(Generic_Main_Frame):
    def __init__(self, Parent, NbAgents):
        # frame with some additional ant capabilities
        Generic_Main_Frame.__init__(self, Parent, self.oneStep, Wtitle='Ants')
        self.startGround()
        self.LastTimeStep = 0
        self.Counter = 0
        # create population of agents
        self.Pop = [Ant('A%d' % IdNb) for IdNb in range(NbAgents)]
        self.PopSize = NbAgents
        self.Moves = 0  # counts the number of times agents have moved
        t = Thread(target=self.redraw)
        t.start()

    def startGround(self):
        """ the ground is a 2-D space representing the field where ants wander
        """
        self.Ground = Ground(self, Toric=True)
        self.Ground.scaleX = self.Ground.scaleY = LandSize  # Logical coordinates
        self.Ground.W = self.Ground.H = LandWindowSize  # Physical coordinates
        self.Ground.configure(width=self.Ground.W, height=self.Ground.H)
        self.Ground.pack(expand=Tkinter.YES, fill=Tkinter.BOTH)  # the window shows on the scren

    def oneStep(self):
        # this function is called back after each simulation step
        Land.evaporate()

        for agent in self.Pop:
            agent.moves()

        self.Moves += 1
        return 0

    def redraw(self):
        while 1:
            # the landscape is entirely redrawn
            self.Ground.erase()  # supposedly destroys all objects on ground

            self.displayNodes(Land.Nodes)
            self.displayPheromons(Land.EdgesWithPheromons)
            sleep(1)

    def displayPheromons(self, edges):
        for edge in edges:
            coord1 = edge[0]
            coord2 = edge[1]
            self.Ground.create_line(coord1[0], coord1[1], coord2[0], coord2[1], fill="red", dash=(4, 4))

    def displayNodes(self, Nodes):
        for node in Nodes:
            coord = node.Position
            self.Ground.create_rectangle(coord[0] - 2, coord[1] - 2, coord[0] + 2, coord[1] + 2, outline='black',
                                         fill='gray50')
コード例 #5
0
ファイル: Main.py プロジェクト: inconnito3000/Flappy-Bird
    def new(self):
        # Initialise sprite groups.
        self.bird_group = pygame.sprite.Group()
        self.pipes = pygame.sprite.Group()
        self.ground_group = pygame.sprite.Group()
        self.all_sprites = pygame.sprite.Group()

        # Initialise bird.
        self.bird = Bird(self)
        self.bird_group.add(self.bird)
        self.all_sprites.add(self.bird)

        # Initialise ground.
        self.ground = Ground()
        self.ground_group.add(self.ground)
        self.all_sprites.add(self.ground)

        # Initialise bottom pipe.
        self.pipe_down = Bottom_Pipe(self)
        self.pipes.add(self.pipe_down)
        self.all_sprites.add(self.pipe_down)

        # Initialise top pipe.
        self.pipe_up = Top_Pipe(self)
        self.pipes.add(self.pipe_up)
        self.all_sprites.add(self.pipe_up)

        self.run()
コード例 #6
0
    def generate(self, barrier_name):
        self.count += 1

        if barrier_name == "Sky":
            sky = Sky(0,0,WIDTH,SKY_WIDTH)
            if type(sky) is self.dict["Sky"]:
                return sky

        if barrier_name == "Ground":
            ground = Ground(0,HEIGHT-SAND_HEIGHT,WIDTH,SAND_HEIGHT)
            if type(ground) is self.dict["Ground"]:
                return ground

        if barrier_name == "Tube":
            TUBE_HEIGHT = random.randint(20,HEIGHT - SAND_HEIGHT - TUBE_GAP - 20)
            #TUBE_HEIGHT = self.__list_tube_height[self.index]
            self.index += 1

            tubeTop = Tube(WIDTH, 0, TUBE_WIDTH, TUBE_HEIGHT)
            tubeBottom = Tube(WIDTH, TUBE_HEIGHT + TUBE_GAP, TUBE_WIDTH, HEIGHT - SAND_HEIGHT - (TUBE_HEIGHT + TUBE_GAP))

            if type(tubeTop) and type(tubeBottom) is self.dict["Tube"]:
                return tubeTop, tubeBottom

        raise NameError("Wrong factory format")
コード例 #7
0
ファイル: main.py プロジェクト: garred/cuadrados
def draw(screen, background):
    """Draws to the screen the game state.
    """
    screen.blit(background, (0, 0))

    for entity in Entity.collection:
        entity.enqueue_shadow(screen)

    Ground.draw(screen)

    for entity in Entity.collection:
        entity.draw(screen)

    Editor.draw(screen)

    pygame.display.flip()
コード例 #8
0
 def startGround(self):
     """ the ground is a 2-D space representing the field where ants wander
     """
     self.Ground = Ground(self, Toric=True)
     self.Ground.scaleX = self.Ground.scaleY = LandSize   # Logical coordinates
     self.Ground.W = self.Ground.H = LandWindowSize      # Physical coordinates
     self.Ground.configure(width=self.Ground.W, height=self.Ground.H)
     self.Ground.pack(expand=Tkinter.YES,fill=Tkinter.BOTH)  # the window shows on the scren
コード例 #9
0
def play_bird():
    global WIN, GEN
    win = WIN

    bird = Bird.Bird(230, 350, BIRD_IMGS)
    ground = Ground.Ground(730, GROUND_IMG)
    pipes = [Pipe.Pipe(600, PIPE_IMG)]

    clock = pygame.time.Clock()

    score = 0

    run = True
    while run:
        clock.tick(30)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False
                pygame.quit()
                quit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    bird.jump()

        bird.move()

        if ground.collide(bird):
            run = False

        add_pipe = False
        rem = []
        for pipe in pipes:
            if pipe.collide(bird):
                run = False
            if not pipe.passed and pipe.x < bird.x:
                pipe.passed = True
                add_pipe = True

            if pipe.x + pipe.PIPE_TOP.get_width() < 0:
                rem.append(pipe)

            pipe.move()

        if add_pipe:
            score += 1
            pipes.append(Pipe.Pipe(600, PIPE_IMG))

        for r in rem:
            pipes.remove(r)

        ground.move()
        draw_play_window(win, bird, pipes, ground, score)
コード例 #10
0
    def __init__(self):
        self.index = 0
        self.__list_tube_height = []

        for i in range(1,3000):
            self.__list_tube_height.append(random.randint(10,HEIGHT - SAND_HEIGHT - TUBE_GAP- 10))

        self.count = 0

        tube = Tube(0,0,0,0)
        sky = Sky(0,0,0,0)
        ground = Ground(0,0,0,0)

        self.dict = {"Tube": type(tube), "Sky" : type(sky), "Ground": type(ground)}
コード例 #11
0
ファイル: Main.py プロジェクト: MBCook/IttyBittyCity
def main():
    """The main program."""

    # Initialize Pygame

    pygame.init()

    # First we set some stuff up.

    prefs = Preferences.Preferences()
    prefs.loadPreferences()
    video = Video.Video(prefs)
    video.prepareVideo()

    carObject = Car.Car()
    groundObject = Ground.Ground()

    carDir = 0.0

    while 1:

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()

        carDir += 1.0
        if (carDir >= 360.0):
            carDir -= 360.0
        carObject.setAngle(carDir)

        video.prepareNewFrame()
        video.setupCamera()
        video.setupLights()

        # Drawing happens here

        glLoadIdentity()

        drawReference(0.0, 0.0, 0.0, 1.0)

        video.drawSimulationObject(groundObject)
        video.drawSimulationObject(carObject)

        video.finishNewFrame()

        pygame.time.wait(33)
コード例 #12
0
def enter():
    global player, background, ground, hurdle, pet, hurdle_start
    global gaint_sound, collid_sound, jelly_sound, big_collid_sound, hp_sound, result_ok_sound
    #if title_state.time == True:
    hurdle = list()
    player = Player()
    background = Background()
    ground = Ground()
    pet = Pet()
    player.score = converter.player_score
    player.hpsize = converter.player_hpsize

    #Hurdle.__init__()
    ground.__init__()

    Hurdle.Hurdle_Start1 = False
    Hurdle.Hurdle_Start2 = False
    Hurdle.Hurdle_Start3 = False
    Hurdle.Hurdle_Start4 = False
    Hurdle.Hurdle_Start5 = False

    ######사운드 관련#####
    if gaint_sound == None:
        gaint_sound = load_wav('Sound\\i_giant.wav')
        gaint_sound.set_volume(32)

    if collid_sound == None:
        collid_sound = load_wav('Sound\\collide.wav')
        collid_sound.set_volume(16)

    if jelly_sound == None:
        jelly_sound = load_wav('Sound\\g_jelly.wav')
        jelly_sound.set_volume(8)

    if big_collid_sound == None:
        big_collid_sound = load_wav('Sound\\big_hit.wav')
        big_collid_sound.set_volume(32)

    if hp_sound == None:
        hp_sound = load_wav('Sound\\i_large_energy.wav')
        hp_sound.set_volume(32)

    if result_ok_sound == None:
        result_ok_sound = load_wav('Sound\\ui_2.wav')
        result_ok_sound.set_volume(32)

    #for i in range(2):          # 장애물 종류
    #    for j in range(3):      # 물체 개수
    #        hurdle.append(Hurdle(i, j))
    if hurdle_start == None:
        for i in range(len_data['Stage1_Fork']['Len']):
            hurdle.append(Hurdle(len_data['Stage1_Fork']['num'], i))
        for i in range(len_data['Stage1_Fork2']['Len']):
            hurdle.append(Hurdle(len_data['Stage1_Fork2']['num'], i))
        for i in range(len_data['Stage1_thorn']['Len']):
            hurdle.append(Hurdle(len_data['Stage1_thorn']['num'], i))
        for i in range(len_data['big_jelly']['Len']):
            hurdle.append(Hurdle(len_data['big_jelly']['num'], i))
        for i in range(len_data['item_jelly']['Len']):
            hurdle.append(Hurdle(len_data['item_jelly']['num'], i))

##############################################################################

        for i in range(len_data2['Stage1_Fork']['Len']):
            hurdle.append(Hurdle2(len_data2['Stage1_Fork']['num'], i))
        for i in range(len_data2['Stage1_thorn4']['Len']):
            hurdle.append(Hurdle2(len_data2['Stage1_thorn4']['num'], i))
        for i in range(len_data2['Stage1_thorn5']['Len']):
            hurdle.append(Hurdle2(len_data2['Stage1_thorn5']['num'], i))
        for i in range(len_data2['item_jelly']['Len']):
            hurdle.append(Hurdle2(len_data2['item_jelly']['num'], i))

################################################################################

        for i in range(len_data3['Stage1_Fork']['Len']):
            hurdle.append(Hurdle3(len_data3['Stage1_Fork']['num'], i))
        for i in range(len_data3['Stage1_Fork2']['Len']):
            hurdle.append(Hurdle3(len_data3['Stage1_Fork2']['num'], i))
        for i in range(len_data3['Stage1_thorn4']['Len']):
            hurdle.append(Hurdle3(len_data3['Stage1_thorn4']['num'], i))
        for i in range(len_data3['item_jelly']['Len']):
            hurdle.append(Hurdle3(len_data3['item_jelly']['num'], i))


################################################################################

        for i in range(len_data4['Stage1_Fork']['Len']):
            hurdle.append(Hurdle4(len_data4['Stage1_Fork']['num'], i))
        for i in range(len_data4['Stage1_Fork2']['Len']):
            hurdle.append(Hurdle4(len_data4['Stage1_Fork2']['num'], i))
        for i in range(len_data4['Stage1_thorn']['Len']):
            hurdle.append(Hurdle4(len_data4['Stage1_thorn']['num'], i))
        for i in range(len_data4['Stage1_thorn4']['Len']):
            hurdle.append(Hurdle4(len_data4['Stage1_thorn4']['num'], i))
        for i in range(len_data4['Stage1_thorn5']['Len']):
            hurdle.append(Hurdle4(len_data4['Stage1_thorn5']['num'], i))
        for i in range(len_data4['item_jelly']['Len']):
            hurdle.append(Hurdle4(len_data4['item_jelly']['num'], i))

##################################################################################

        for i in range(len_data5['Stage1_Fork']['Len']):
            hurdle.append(Hurdle5(len_data5['Stage1_Fork']['num'], i))
        for i in range(len_data5['Stage1_Fork2']['Len']):
            hurdle.append(Hurdle5(len_data5['Stage1_Fork2']['num'], i))
        for i in range(len_data5['Stage1_thorn4']['Len']):
            hurdle.append(Hurdle5(len_data5['Stage1_thorn4']['num'], i))
        for i in range(len_data5['Stage1_thorn5']['Len']):
            hurdle.append(Hurdle5(len_data5['Stage1_thorn5']['num'], i))
        for i in range(len_data5['item_jelly']['Len']):
            hurdle.append(Hurdle5(len_data5['item_jelly']['num'], i))
        for i in range(len_data5['hp_jelly']['Len']):
            hurdle.append(Hurdle5(len_data5['hp_jelly']['num'], i))
コード例 #13
0
ファイル: MainScene.py プロジェクト: yinweisu/Flappy-Bird
    pipe_height_down = random.randrange(130, 350, 1)

    pipe_x_up = pipe_x_down
    pipe_height_up = 380 - pipe_height_down

    pipe_down = Pipe(pipe_img, pipe_x_down, pipe_height_down, False)
    pipe_up = Pipe(pipe_img, pipe_x_up, pipe_height_up, True)

    return pipe_down, pipe_up


pipe_down, pipe_up = config_pipe(640)
pipe_down2, pipe_up2 = config_pipe(960)

# config ground
ground1 = Ground(ground_img, 0)
ground2 = Ground(ground_img, 336)
ground3 = Ground(ground_img, 672)
ground4 = Ground(ground_img, 1008)

# config timer
frame_passed = 0

running = True

while running:

    collision = (pygame.sprite.collide_rect(
        bird, pipe_down) or pygame.sprite.collide_rect(bird, pipe_up)) or (
            pygame.sprite.collide_rect(bird, pipe_down2)
            or pygame.sprite.collide_rect(bird, pipe_up2)) or bird.y > 360
コード例 #14
0
def loadLevel(lev):
    f = open(lev, "r")
    lines = f.readlines()
    f.close()

    size = 25
    offset = size / 2
    tiles = []
    walls = []
    grounds = []
    dirts = []
    floors = []
    steaks = []
    fallblocks = []
    saltspikels = []
    saltspikers = []
    sidespikes = []
    cobbles = []
    ends = []
    playerPos = []

    newLines = []
    for line in lines:
        newLine = ""
        for c in line:
            if c != "\n":
                newLine += c
        newLines += [newLine]

    lines = newLines

    for y, line in enumerate(lines):
        for x, c in enumerate(line):
            if c == "#":
                tiles += [VineWall([x * size + offset, y * size + offset])]
            if c == "G":
                tiles += [Ground([x * size + offset, y * size + offset])]
            if c == "D":
                tiles += [Dirt([x * size + offset, y * size + offset])]
            if c == "F":
                tiles += [Floor([x * size + offset, y * size + offset])]
            if c == "J":
                tiles += [FallBlock([x * size + offset, y * size + offset])]
            if c == "^":
                tiles += [
                    SaltSpike([x * size + offset, y * size + offset + 4])
                ]
            if c == "<":
                tiles += [SideSpikeL([x * size + offset, y * size + offset])]
            if c == ">":
                tiles += [SideSpikeR([x * size + offset, y * size + offset])]
            if c == "W":
                tiles += [Cobbled([x * size + offset, y * size + offset])]
            if c == "O":
                tiles += [END([x * size + offset, y * size + offset])]
            if c == "S":
                tiles += [Steak([x * size + offset, y * size + offset - 5])]

            if c == "C":
                playerPos += [x * size + offset, y * size + offset]

    return tiles, playerPos
コード例 #15
0
def eval_genome(genomes, config):
    global WIN, GEN
    win = WIN
    GEN += 1

    nets = []
    ge = []
    birds = []

    for _, g in genomes:
        net = neat.nn.FeedForwardNetwork.create(g, config)
        nets.append(net)
        birds.append(Bird.Bird(230, 350, BIRD_IMGS))
        g.fitness = 0
        ge.append(g)

    ground = Ground.Ground(730, GROUND_IMG)
    pipes = [Pipe.Pipe(600, PIPE_IMG)]

    clock = pygame.time.Clock()

    score = 0

    run = True
    while run:
        clock.tick(30)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False
                pygame.quit()
                quit()

        pipe_index = 0
        if len(birds) > 0:
            if len(pipes) > 1 and birds[
                    0].x > pipes[0].x + pipes[0].PIPE_TOP.get_width():
                pipe_index = 1
        else:
            run = False
            break

        for x, bird in enumerate(birds):
            bird.move()
            ge[x].fitness += 0.1

            output = nets[x].activate(
                (bird.y, abs(bird.y - pipes[pipe_index].height),
                 abs(bird.y - pipes[pipe_index].bottom),
                 abs(pipes[pipe_index].x)))

            if output[0] > 0.5:
                bird.jump()

        add_pipe = False
        rem = []
        for pipe in pipes:
            for x, bird in enumerate(birds):
                if pipe.collide(bird):
                    ge[x].fitness -= 2
                    birds.pop(x)
                    nets.pop(x)
                    ge.pop(x)

                if not pipe.passed and pipe.x < bird.x:
                    pipe.passed = True
                    add_pipe = True

            if pipe.x + pipe.PIPE_TOP.get_width() < 0:
                rem.append(pipe)

            pipe.move()

        if add_pipe:
            score += 1
            for g in ge:
                g.fitness += 5
            pipes.append(Pipe.Pipe(600, PIPE_IMG))

        for r in rem:
            pipes.remove(r)

        for x, bird in enumerate(birds):
            if bird.y + bird.img.get_height() >= 730 or bird.y < 0:
                birds.pop(x)
                nets.pop(x)
                ge.pop(x)

        if score >= 15:
            print("score: ", score)
            run = False

        ground.move()
        draw_train_window(win, birds, pipes, ground, score, GEN)
コード例 #16
0
def verse_bird():
    global WIN, GEN
    win = WIN

    print("in here")
    with open('best_bird.obj', 'rb') as best_bird:
        net = pickle.load(best_bird)

    ai_bird = Bird.Bird(230, 350, BIRD_IMGS)
    player_bird = Bird.Bird(230, 350, PLAYER_BIRD_IMGS)
    ground = Ground.Ground(730, GROUND_IMG)
    pipes = [Pipe.Pipe(600, PIPE_IMG)]

    clock = pygame.time.Clock()

    player_win = False
    ai_win = False
    score = 0

    run = True
    while run:
        clock.tick(30)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False
                pygame.quit()
                quit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    player_bird.jump()

        pipe_index = 0

        if len(pipes) > 1 and ai_bird.x > pipes[0].x + pipes[
                0].PIPE_TOP.get_width():
            pipe_index = 1

        ai_bird.move()
        player_bird.move()

        output = net.activate(
            (ai_bird.y, abs(ai_bird.y - pipes[pipe_index].height),
             abs(ai_bird.y - pipes[pipe_index].bottom),
             abs(pipes[pipe_index].x)))

        if output[0] > 0.5:
            ai_bird.jump()

        add_pipe = False
        rem = []
        for pipe in pipes:

            if pipe.collide(ai_bird):
                player_win = True
                run = False
            if pipe.collide(player_bird):
                ai_win = True
                run = False

            if not pipe.passed and pipe.x < ai_bird.x:
                pipe.passed = True
                add_pipe = True

            if pipe.x + pipe.PIPE_TOP.get_width() < 0:
                rem.append(pipe)

            pipe.move()

        if add_pipe:
            score += 1
            pipes.append(Pipe.Pipe(600, PIPE_IMG))

        for r in rem:
            pipes.remove(r)

        if ai_bird.y + ai_bird.img.get_height() >= 730 or ai_bird.y < 0:
            player_win = True
            run = False
        if player_bird.y + player_bird.img.get_height(
        ) >= 730 or player_bird.y < 0:
            ai_win = True
            run = False

        if score >= 50:
            run = False

        ground.move()
        draw_verse_window(win, ai_bird, player_bird, pipes, ground, score)
コード例 #17
0
from Item import*
from Runner import*
from Collector import*
pygame.init()
pygame.key.set_repeat(1,1)
pygame.mixer.music.load("music.mp3")
pygame.mixer.music.play(-1)
screen = pygame.display.set_mode((800,600))
background = pygame.Surface((800,600))
points=0
timeleft=60
maxcoins=5
ctime=0
defeat=False
victory=False
grass = Ground()
grass.draw(background)
money=Coins()
changedrecs = []
guy = Person(50,50)
guy.cinterval=5000
guy.cs=0
guy.maxcs=5
pyramid=Pyramid(650,30)
pbase=Base(650,88)
#oldman= OldMan(random.randint(0,783),random.randint(0,577))
oldman = OldMan(100,200)
clerk = Clerk(200,100)
collector= Collector(200,200)
runner= Runner(400,400)
font = pygame.font.Font(None, 36)
コード例 #18
0
        if (isinstance(sceneObject, Firework)):
            if(sceneObject.decayed):
                deadFireworks.append(sceneObject)
    for deadFirework in deadFireworks:
        sceneObjects.remove(deadFirework)


pygame.init()
RenderEngine.init(640, 480)
camera = Camera(-9, 4, -26, 70)
physicsSimulator = PhysicsSimulator()
physicsSimulator.simulate = True
isControlCar = False

sceneObjects = []
ground = Ground()
sceneObjects.append(ground)
sceneObjects.extend(generateNeighborhood())
car = Car(positionZ=20, rotationY=0)
car.mass = 15
sceneObjects.append(car)
car2 = Car(positionZ=40, positionX=-20, steeringAngle=10)
sceneObjects.append(car2)
car3 = Car(positionZ=11, positionX=-40, driveAcceleration=0.06)
car3.mass = 15
sceneObjects.append(car3)
car4 = Car(positionZ=11, positionX=40, rotationY=180, driveAcceleration=0.06)
sceneObjects.append(car4)
speed = 1

done = False
コード例 #19
0
def main(genomes, config):

    nets = []
    ge = []
    score = 0
    birds = []
    
    #set up neural Network
    for _, g in genomes:
        net = neat.nn.FeedForwardNetwork.create(g,config)
        nets.append(net)
        birds.append(Bird.Bird(230, 350))
        g.fitness = 0
        ge.append(g)

    base = Ground.Base(730)
    pipes = [Pipe(600)]
    win = pygame.display.set_mode((WIN_WIDTH, WIN_HEIGHT))
    clock = pygame.time.Clock()


    run = True

    while run:
        clock.tick(30)
        for event in pygame.event.get():
            #click red x button
            if event.type == pygame.QUIT :
                run = False
                pygame.quit()
                quit()
        base.move()


        pipe_ind = 0
        if len(birds) > 0:
            if len(pipes) > 1 and birds[0].x > pipes[0].x + pipes[0].PIPE_TOP.get_width():
                pipe_ind = 1
        else:
            run = False
            break

        for x, bird in enumerate(birds):
            bird.move()
            ge[x].fitness += 0.1

            output = nets[x].activate((bird.y, abs(bird.y - pipes[pipe_ind].height), abs(bird.y - pipes[pipe_ind].bottom)))
            
            if output[0] > 0.5:
                bird.jump()

        add_pipe = False
        rem = []
        for pipe in pipes:
            for x, bird in enumerate(birds):
                if pipe.collide(bird):
                    ge[x].fitness -= 1

                    #remove from existence
                    birds.pop(x)
                    nets.pop(x)
                    ge.pop(x)

                if not pipe.passed and pipe.x < bird.x:
                    pipe.passed = True
                    add_pipe = True
            if pipe.x + pipe.PIPE_TOP.get_width() < 0:
                rem.append(pipe)
        
            
            pipe.move()

        #add pipe if distance good
        if add_pipe:
            score += 1
            #add 5 fitness to remaining birds
            for g in ge:
                g.fitness += 5
            pipes.append(Pipe(600))

        #remove pipes that have been passed
        for r in rem:
            pipes.remove(r)


    
        #if bird hits ground / goes off screen
        for x, bird in enumerate(birds):
            if bird.y + bird.img.get_height() >= 730 or bird.y < 0:
                birds.pop(x)
                nets.pop(x)
                ge.pop(x)

        draw_window(win, birds, pipes, base, score)
コード例 #20
0
ファイル: initialization.py プロジェクト: garred/cuadrados
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((255,255,255))

fps = 60.0
ifps = 1.0 / fps


# Initializing objects

import Ground   #"singleton" (not a class, only globals and functions).

# Creating the map

if len(sys.argv) == 2:
    Ground.load_map(sys.argv[1])
elif len(sys.argv) == 5:
    Ground.new_map(
        sys.argv[1],
        int(sys.argv[2]), int(sys.argv[3]), int(sys.argv[4])
        )
else:
    print("""
Usage:
- python main.py [path to existing map]
- python main.py [new map name] [levels] [rows] [columns]
        """)
    sys.exit()

Ground.tile_size = 152.0
Ground.tile_separation = 150.0