Пример #1
0
def start():  # При старте игры
    global cursor

    pygame.mouse.set_visible(False)  # Скрыть курсор
    Background(general.load_image('background.jpg'), Transform((0, 0)))  # Фон
    Background(general.load_image('background2.png'), Transform((-100, 400)),
               0.1)

    general.load_map()  # Загрузка карты

    player = Pers(Transform((200, 600)))  # Игрок
    general.player = player

    general.camera = Camera(Transform((0, 0), parent=player.transform_),
                            offset=(-900, -540))  # Камера

    player.select_weapon(Weapon('pistol', player.transform_))  # Выбор оружия

    # Разбросанные по карте оружия
    Weapon('ak_47', pos=(2300, 950))
    Weapon('shotgun', pos=(2450, 950))
    Weapon('rifle', pos=(2600, 950))
    Weapon('machine gun', pos=(14800, 1650))
    Weapon('p90', pos=(15000, 1650))
    Weapon('sniper', pos=(15200, 1650))

    cursor = Background(load_image('cursor.png'), Transform(
        (100, 100)))  # курсор мыши
Пример #2
0
def load_calibration(calibration_file):
    with open(calibration_file, 'r') as file:
        line = file.readline().split(' ')
        fx = float(line[1])
        fy = float(line[2])
        cx = float(line[3])
        cy = float(line[4])
        line = file.readline().split(' ')
        width = int(line[0])
        height = int(line[1])

    print("Camera parameters: [{} {}] {} {} {} {}".format(
        width, height, fx, fy, cx, cy))

    cam = Camera(
        fx=fx, fy=fy, cx=cx, cy=cy,
        width=width, height=height,
        frustum_near=0.01, frustum_far=1000.)

    return cam
Пример #3
0
def rpsGame(totalScore=3):
    # --- Init
    camera = Camera()
    rps = RockPaperScissor(totalScore)
    rps.setCImg(1)

    model = load_model("models/model10.h5")

    while rps.carryOn:

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                rps.quit()
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    rps.startTimer(3)

        # --- opencv pImg
        frame_roi = camera.get_frame()
        rps.setPImg(frame_roi)

        if rps.duration == 0 and rps.timer_started:

            # --- cImg
            c_num = random.randint(0, 2)
            rps.setCImg(c_num)

            # model predicts
            x = camera.save_current_frame(frame_roi)
            y = model.predict(x)
            print("[MODEL] Max Probability: " + str(np.max(y)))
            p_num = np.argmax(y, axis=1)[0]
            print("[GAME] Player: " +
                  utils.gestureText[int(np.argmax(y, axis=1))])
            print("[GAME] Computer: {}".format(utils.gestureText[c_num]))
            rps.decideWinner(c_num, p_num)

            rps.stopTimer()

        # --- Drawing background code
        rps.draw_ui()

        # --- updating Timer
        rps.updateTimer()

    rps.quit()
    camera.quit()
Пример #4
0
        dataset = KITTIOdometry(args.path)
    elif args.dataset.lower() == 'euroc':
        params = ParamsEuroc()
        dataset = EuRoCDataset(args.path)

    sptam = SPTAM(params)

    visualize = not args.no_viz
    if visualize:
        from viewer import MapViewer
        viewer = MapViewer(sptam, params)


    cam = Camera(
        dataset.cam.fx, dataset.cam.fy, dataset.cam.cx, dataset.cam.cy, 
        dataset.cam.width, dataset.cam.height, 
        params.frustum_near, params.frustum_far, 
        dataset.cam.baseline)



    durations = []
    for i in range(len(dataset)):
        featurel = ImageFeature(dataset.left[i], params)
        featurer = ImageFeature(dataset.right[i], params)
        timestamp = dataset.timestamps[i]

        time_start = time.time()  

        t = Thread(target=featurer.extract)
        t.start()
Пример #5
0
        return frame

    frames = []
    for j in range(rows):
        for i in range(columns):
            frame_location = (rect.w * i, rect.h * j)
            frames.append(
                sheet.subsurface(pygame.Rect(frame_location, rect.size)))

    return frames


weapons = cut_sheet(load_image('Weapons.png'), 1, 8)  # Спрайты оружии
bullets = cut_sheet(load_image('Bullets.png'), 1, 3)  # Спрайты патронов

camera = Camera(Transform((0, 0)))
player = None

# Все враги
ENEMIES = [{
    'weapon': 'pistol',
    'animator': 'Enem4',
    'hp': 100,
    'radius': 200
}, {
    'weapon': 'ak_47',
    'animator': 'Enem2',
    'hp': 300,
    'radius': 100
}, {
    'weapon': 'shotgun',
Пример #6
0
    if 'tum' in args.dataset.lower():
        dataset = TUMRGBDDataset(args.path)
    elif 'icl' in args.dataset.lower():
        dataset = ICLNUIMDataset(args.path)

    params = Params()
    ptam = RGBDPTAM(params)

    if not args.no_viz:
        from viewer import MapViewer
        viewer = MapViewer(ptam, params)

    height, width = dataset.rgb.shape[:2]
    cam = Camera(dataset.cam.fx, dataset.cam.fy, dataset.cam.cx,
                 dataset.cam.cy, width, height, dataset.cam.scale,
                 params.virtual_baseline, params.depth_near, params.depth_far,
                 params.frustum_near, params.frustum_far)

    durations = []
    for i in range(len(dataset))[:]:
        feature = ImageFeature(dataset.rgb[i], params)
        depth = dataset.depth[i]
        if dataset.timestamps is None:
            timestamp = i / 20.
        else:
            timestamp = dataset.timestamps[i]

        time_start = time.time()
        feature.extract()

        frame = RGBDFrame(i,
Пример #7
0
playerposition = (0, 0)

pygame.init()
pygame.display.set_caption('~ R I K \' S   G A M E ~')
pygame.display.set_icon(pygame.image.load('icon.png'))
clock = pygame.time.Clock()

w = World(size=1024, tilesize=32)
s = Screen(800, 800)

gs = GraphicsSystem()
cs = ControlSystem()
ss = SpriteSystem()

p = Entity(w)
p.camera = Camera(0, 0, 800, 800, track=True, entitytotrack=p)
p.position = Position(0, 0, 32, 32, 2)
p.control = Control(pygame.K_UP, pygame.K_DOWN, pygame.K_LEFT, pygame.K_RIGHT)
p.state = State()

p.sprite = Sprite()
p.sprite.sprites['idle'] = [
    pygame.image.load('images/player/idle.png'),
    pygame.image.load('images/player/idle2.png'),
    pygame.image.load('images/player/idle3.png')
]
p.sprite.animate = True

running = True

while running:
Пример #8
0
        params = ParamsKITTI()
        dataset = KITTIOdometry(args.path)
    elif args.dataset.lower() == 'euroc':
        params = ParamsEuroc()
        dataset = EuRoCDataset(args.path)

    sptam = SPTAM(params)

    visualize = not args.no_viz
    if visualize:
        from viewer import MapViewer
        viewer = MapViewer(sptam, params)

    cam = Camera(
        dataset.cam.fx, dataset.cam.fy, dataset.cam.cx, dataset.cam.cy,
        dataset.cam.width, dataset.cam.height, params.frustum_near,
        params.frustum_far, dataset.cam.baseline
    )  # Initialize camera object with focal lenghts, image center, width,
    # height, etc

    durations = []

    # Loop over images, why 100??
    for i in range(len(dataset))[:100]:
        featurel = ImageFeature(dataset.left[i], params)
        featurer = ImageFeature(dataset.right[i], params)
        timestamp = dataset.timestamps[i]

        time_start = time.time()

        t = Thread(target=featurer.extract)