예제 #1
0
def start():
    global playing, state

    playing = True

    init()
    while playing:
        controls.update()
        if state == 0:
            step()
        elif state == 1:
            graphics.drawGameOver()
예제 #2
0
def update():
    from parameters import DAMPING, DO_DAMPING, GRAVITY, SPEED_MULTIPLIER, WALL_DAMPING
    for particle in particles:
        particle.damping(DAMPING if DO_DAMPING else 1)
        particle.gravity(GRAVITY)
        particle.wall_collisions(-WALL_DAMPING if DO_DAMPING else -1)
        particle.move(SPEED_MULTIPLIER)

    # Test inter-particle collisions
    pairs = combinations(range(len(particles)), 2)  # All combinations of particles
    for i, j in pairs:
        p1, p2 = particles[i], particles[j]
        if dist(p1.x, p1.y, p2.x, p2.y, less_than=p1.r + p2.r):  # If they are touching
            particle_bounce_velocities(p1, p2)
            particle_bounce_positions(p1, p2)

    controls.update()
예제 #3
0
def start():
    init()

    while True:
        controls.update()
        graphics.drawCurrentMenu()
예제 #4
0
def main():

    os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (0, 0)
    pygame.init()

    import app
    import controls

    screen = pygame.display.set_mode((app.scr_width, app.scr_height))
    app.font = pygame.font.SysFont('', 16)

    entities.screen = screen

    app.init_gamemap()

    app.init_slot_buttons()

    unit = entities.Unit(None, (100, 100), 0)
    entities.add_entity(unit)
    app.gamemap.drawEntity(unit)

    clock = pygame.time.Clock()
    running = True

    #event loop:
    while (running):

        app.update_rel_mouse_pos()

        #consumes and stores the events in entities.events
        controls.update()

        #check for program quit events:
        if controls.key_released(pygame.K_ESCAPE):
            running = False

        for event in controls.events:
            if event.type == pygame.QUIT:
                running = False

            #check status on control locking
            #scrolling toggles control locking (and minimap display)
            if event.type == pygame.MOUSEBUTTONDOWN:
                if event.button == 5 and controls.locked == False:
                    controls.locked = True
                elif event.button == 4 and controls.locked == True:
                    controls.locked = False
                    app.center_on_mouse_from_minimap()

        #activate minimap if the m key is pressed
        if controls.key_released(pygame.K_m):
            if controls.locked == False:
                controls.locked = True
            elif controls.locked == True:
                controls.locked = False
                app.center_on_mouse_from_minimap()

        #toggle the unit/building slot buttons on when alt key is pressed:
        if controls.key_released(pygame.K_LALT) or controls.key_released(
                pygame.K_RALT):
            if app.slot_buttons == app.unit_slot_buttons:
                app.slot_buttons = app.building_slot_buttons
            else:
                app.slot_buttons = app.unit_slot_buttons

        #Map Scrolling:
        if not controls.locked:
            app.update_map_position()
        ##

        app.update_button_set_animation(app.unit_slot_buttons)
        app.update_button_set_animation(app.entity_options_buttons)

        #clear screen so that the UI and gamemap can be redrawn.
        screen.fill((0, 0, 0))

        screen.blit(app.gamemap.image, app.gamemap.rect.topleft)

        if controls.locked:  #show the mini map if controls are locked
            app.draw_minimap(screen)
            app.gamemap.image.set_alpha(50)
        else:
            if app.gamemap.image.get_alpha() != 255:
                app.gamemap.image.set_alpha(255)
            app.slot_buttons.draw(
                screen
            )  #draws every frame so that animations can properly happen
            if app.entity_options_buttons != None:
                app.entity_options_buttons.draw(screen)

        #display mouse position relative to the game map
        app.draw_mouse_pos_panel(screen)

        #test display on the wood resource icon:
        screen.blit(preloading.wood_resource_image, (app.scr_width - 200, 0))
        screen.blit(preloading.relic_resource_image, (app.scr_width - 120, 0))

        #display the gamemap value on the screen:
        app.draw_gamemap_value(screen)

        #do things with selected entities.
        if controls.mouse_clicked(0):
            app.selection = controls.get_selection(app.gamemap)

            #set up the entity option panel to reflect selection[0]:
            app.draw_info_panel(screen, app.selection)

            #outline transparent borders of entities that are selected:
            app.set_entities_selected(app.selection)

        # call update() method on outdated entities.
        app.update_outdated_entities()

        # set destination for all selected entities.
        if controls.mouse_clicked(2):
            for entity in app.selection:
                entity.set_dest(app.gamemap,
                                (app.rel_mouse_pos[0], app.rel_mouse_pos[1]))
                entities.flag_for_update(entity)

        #update the selection box graphic.
        if pygame.mouse.get_pressed()[0]:
            controls.update_selection_box(screen)

        #flip the display buffer and output everything to screen.
        pygame.display.flip()

        #mouse events need to be processed before this copy:
        controls.last_frame_mouse = pygame.mouse.get_pressed()

        clock.tick(60)

    #cleanup
    pygame.display.quit()
    pygame.quit()