コード例 #1
0
    os.environ['SDL_VIDEO_CENTERED'] = '1'
    pygame.init()
    pygame.font.init()
    pygame.display.set_caption("Menu Test")
    screen = pygame.display.set_mode(SCREEN_RES)
    eventManager = EventManager()
    dungeon = Dungeon(4)
    camera = Camera(dungeon)

    camera.reticle.setPos( (SCREEN_RES[0]//2,SCREEN_RES[1]//2) )
    eventManager.addGameObject(camera.reticle)
    for room in dungeon.rooms:
        for wall in room.walls.sprites():
            eventManager.addGameObject(wall)

    while running:
        dt = clock.tick(60) / 1000
        running = eventManager.process_input(dt)

        events = pygame.event.get()
        for event in events:
            if event.type == pygame.QUIT:
                running = False

        camera.setCameraPosition(camera.reticle.rect.center)

        screen.fill(pygame.color.THECOLORS['black'])
        camera.draw(screen)
        pygame.display.update()

コード例 #2
0
        tiles.add(Tile(tileSurf, bottomRect))

        if i == 0 or i == int(SCREEN_RES[0] / 32) - 1:
            for j in range(1, int(SCREEN_RES[0] / 32) - 2):
                tiles.add(Tile(tileSurf, pygame.Rect(x, j * 32, 32, 32)))

    screen_rect = window.get_rect()
    clock = pygame.time.Clock()
    running = True
    projectiles = []

    while running:
        dt = clock.tick(60) / 1000

        # Get Player Input and Apply Physics
        running = manager.process_input(dt, True, projectiles)

        # END COLLISION HANDLING

        events = pygame.event.get()
        for event in events:
            if event.type == pygame.QUIT:
                running = False
            elif event.type == pygame.MOUSEBUTTONDOWN:
                if event.button == 1:
                    p = Projectile("test", 20, 10,
                                   (SCREEN_RES[0] >> 1, SCREEN_RES[1] >> 1),
                                   pygame.mouse.get_pos())
                    projectiles.append(p)

        for p in projectiles: