Ejemplo n.º 1
0
void player_Frame(float lag)
{
    updatePlayerPosition(lag);
    collectItems();

    if(player->sclass != newAnimation)
        snge_SwitchAnim(player, newAnimation);

    float oldy = viewportPos.y;

    float gY = (float)((_BRICK_HEIGHT * (mapHeight + _INTER_ROW_COUNT - 1) * level) + (_BRICK_HEIGHT * vy)) + voff;
    float gX = (float)(_BRICK_WIDTH * vx) + hoff;

    viewportPos.x = - _MAP_OFFSET_X;
    viewportPos.y = - _MAP_OFFSET_Y + gY;

    bcg_Move(&bcg, oldy - viewportPos.y);

    snge_MoveViewport(viewportPos);

    player->x = gX - _PLAYER_WIDTH2 - _PLAYER_SPRITE_PADDING_X + _MAP_OFFSET_X;

    air -= _AIR_DECREASE_SPEED * lag;
    if(air < 0.0)
        air = 0.0;
    depth = (mapHeight * level) + vy;
    hud_SetDepth(depth);
    hud_SetPoints(points);
    hud_SetAir(air);
}
Ejemplo n.º 2
0
void Player::process()
{
	//the process functions is called by the SimulationMain each renderloop to move the player and camera
	//velo 0, -0.01f, 0 für schwerkraft
	if (flying)
		velo = velo + glm::vec3(0.0f, -0.01f, 0.0f);
	else
		velo = velo + glm::vec3(0.0f, -0.0f, 0.0f);
	glm::vec3 tmp = camera->getPosition();
	//camera->translate(velo);
	tmp = tmp + camera->getMoveForwarBackwardOrientation() * velo;
	AABB testAABB;
	testAABB.createAABB(tmp.x + dx, tmp.y + dy, tmp.z + dz, tmp.x - dx, tmp.y - dy, tmp.z - dz);
	//updatePlayerPosition(camera->getPosition());
	if (simulation->testPlayerCollision(testAABB))
	{
//		camera->translate(camera->getPosition() - tmp);
//		updatePlayerPosition(camera->getPosition());
		velo = glm::vec3(0.0f, 0.0f, 0.0f);
		midAir = false;
	}
	else
	{
		camera->translate(velo);
		updatePlayerPosition(camera->getPosition());
		midAir = true;
	}
	prevCameraPosition = camera->getCenterPoint();
}
Ejemplo n.º 3
0
void Player::translate(glm::vec3 translation)
{
	glm::vec3 tmp = camera->getPosition();
	tmp = tmp + camera->getMoveForwarBackwardOrientation() * translation;
 	AABB testAABB;
	testAABB.createAABB(tmp.x + dx, tmp.y + dy, tmp.z + dz, tmp.x - dx, tmp.y - dy, tmp.z - dz);
	if (simulation->testPlayerCollision(testAABB))
	{
//		camera->translate(camera->getPosition()-tmp);
//		updatePlayerPosition(camera->getPosition());
	}
	else
	{
		camera->translate(translation);
		updatePlayerPosition(camera->getPosition());
	}
}
Ejemplo n.º 4
0
void MazeGameView::handlePlayerMove(MazeGameModel::Move move)
{
    if (model().movePlayer(move)) {
        //qDebug() << "wut?";
        updatePlayerPosition();
        model().moveEnemy(solveEnemyMove());
        updateEnemyPosition();
    }

    if (model().isGameOver()) {
        //qDebug() << "Game Over";
        if (model().hasPlayerWon()) {
            //qDebug() << "Player Won";
            emit playerWon();
        }
        else {
            //qDebug() << "Player Lost";
            emit playerLost();
        }
    }
}
Ejemplo n.º 5
0
void MazeEditorView::clickReceived(int x)
{
    QPoint clickedPos(model().data()->translate(x));

    //qDebug() << "Clicked " << clickedPos.x() << clickedPos.y() << " (" << x << ") (MazeEditorView)";

    if ((model().data()->playerPosition() == clickedPos)) {
        //qDebug() << "1";
        model_m.setEnemyPosition(clickedPos);
    }
    else if ((model().data()->enemyPosition() == clickedPos)) {
        //qDebug() << "2";
        model_m.setPortalPosition(clickedPos);
    }
    else if ((model().data()->portalPosition() == clickedPos)) {
        //qDebug() << "3";
        model_m.setObstacleAt(clickedPos, false);
        model_m.setPortalPosition(model_m.previousPortalPosition());
    }
    else if (!(model().data()->isObstacleAt(clickedPos))) {
        //qDebug() << "4";
        model_m.setObstacleAt(clickedPos, true);
    }
    else {
        //qDebug() << "5";
        model_m.setPlayerPosition(clickedPos);
    }

    updatePlayerPosition();
    updateEnemyPosition();
    updatePortalPosition();
    updateTileGraphicsAt(clickedPos);

    MazeView::clickReceived(x);
    setFocus();
}
Ejemplo n.º 6
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    m_fileMenu(new QMenu(tr("&File"), this)),
    m_viewMenu(new QMenu(tr("&View"), this)),
    m_playbackMenu(new QMenu(tr("&Playback"), this)),
    m_transfersMenu(new QMenu(tr("&Downloads"), this)),
    m_editMenu(new QMenu(tr("&Edit"), this)),
    m_helpMenu(new QMenu(tr("&About"), this)),
    m_openFilesAction(new QAction(QIcon::fromTheme("document-open"), tr("&Open files"), this)),
    m_openUrlAction(new QAction(QIcon::fromTheme("folder-remote"), tr("Open &URL"), this)),
    m_addFilesAction(new QAction(QIcon::fromTheme("list-add"), tr("&Add files"), this)),
    m_addUrlAction(new QAction(QIcon::fromTheme("folder-remote"), tr("Add &URL"), this)),
    m_searchAction(new QAction(QIcon::fromTheme("edit-find"), tr("&Search"), this)),
    m_pluginsAction(new QAction(QIcon::fromTheme("view-refresh"), tr("Load &plugins"), this)),
    m_quitAction(new QAction(QIcon::fromTheme("application-exit"), tr("&Quit"), this)),
    m_showPlaybackQueueAction(new QAction(QIcon::fromTheme("music-library"), tr("Show &playback queue"), this)),
    m_showTransfersAction(new QAction(QIcon::fromTheme("folder-publicshare"), tr("Show &transfers"), this)),
    m_reloadAction(new QAction(QIcon::fromTheme("view-refresh"), tr("&Reload current tab"), this)),
    m_closeAction(new QAction(QIcon::fromTheme("list-remove"), tr("&Close current tab"), this)),
    m_playPauseAction(new QAction(QIcon::fromTheme("media-playback-start"), tr("&Play"), this)),
    m_stopAction(new QAction(QIcon::fromTheme("media-playback-stop"), tr("&Stop"), this)),
    m_previousAction(new QAction(QIcon::fromTheme("media-skip-backward"), tr("&Previous"), this)),
    m_nextAction(new QAction(QIcon::fromTheme("media-skip-forward"), tr("&Next"), this)),
    m_repeatAction(new QAction(QIcon::fromTheme("media-playlist-repeat"), tr("&Repeat"), this)),
    m_shuffleAction(new QAction(QIcon::fromTheme("media-playlist-shuffle"), tr("&Shuffle"), this)),
    m_stopAfterCurrentAction(new QAction(tr("Stop &after current track"), this)),
    m_clearAction(new QAction(QIcon::fromTheme("list-remove"), tr("&Clear playback queue"), this)),
    m_startTransfersAction(new QAction(QIcon::fromTheme("media-playback-start"), tr("&Start transfers"), this)),
    m_pauseTransfersAction(new QAction(QIcon::fromTheme("media-playback-pause"), tr("&Pause transfers"), this)),
    m_settingsAction(new QAction(QIcon::fromTheme("preferences-desktop"), tr("&Preferences"), this)),
    m_aboutAction(new QAction(QIcon::fromTheme("help-about"), tr("&About"), this)),
    m_positionSpacer(new QWidget(this)),
    m_positionSpacerAction(0),
    m_positionSlider(new QSlider(Qt::Horizontal, this)),
    m_positionSliderAction(0),
    m_positionLabel(new QLabel(this)),
    m_positionLabelAction(0),
    m_toolBar(new QToolBar(this)),
    m_widget(new QWidget(this)),
    m_tabWidget(new QTabWidget(m_widget)),
    m_nowPlayingMetaData(new ItemMetaData(m_widget)),
    m_layout(new QVBoxLayout(m_widget))
{
    setWindowTitle("MusiKloud2");
    
    // Initialise status bar
    statusBar();
    
    // Add menus
    menuBar()->addMenu(m_fileMenu);
    menuBar()->addMenu(m_viewMenu);
    menuBar()->addMenu(m_playbackMenu);
    menuBar()->addMenu(m_transfersMenu);
    menuBar()->addMenu(m_editMenu);
    menuBar()->addMenu(m_helpMenu);
    
    // Setup file menu
    m_fileMenu->addAction(m_openFilesAction);
    m_fileMenu->addAction(m_openUrlAction);
    m_fileMenu->addAction(m_addFilesAction);
    m_fileMenu->addAction(m_addUrlAction);
    m_fileMenu->addAction(m_searchAction);
    m_fileMenu->addSeparator();
    m_fileMenu->addAction(m_pluginsAction);
    m_fileMenu->addAction(m_quitAction);
    
    // Setup file menu actions
    m_openFilesAction->setShortcut(tr("Ctrl+O"));
    m_openUrlAction->setShortcut(tr("Ctrl+U"));
    m_addFilesAction->setShortcut(tr("Ctrl+Shift+O"));
    m_addUrlAction->setShortcut(tr("Ctrl+Shift+U"));
    m_searchAction->setShortcut(tr("Ctrl+Y"));
    m_pluginsAction->setShortcut(tr("Ctrl+L"));
    m_quitAction->setShortcut(tr("Ctrl+Q"));
    
    // Setup view menu
    m_viewMenu->addAction(m_showPlaybackQueueAction);
    m_viewMenu->addAction(m_showTransfersAction);
    m_viewMenu->addSeparator();
    m_viewMenu->addAction(m_reloadAction);
    m_viewMenu->addAction(m_closeAction);
    
    // Setup view menu actions
    m_reloadAction->setEnabled(false);
    m_closeAction->setShortcut(tr("Ctrl+W"));
    m_closeAction->setEnabled(false);
    
    // Setup playback menu
    m_playbackMenu->addAction(m_playPauseAction);
    m_playbackMenu->addAction(m_stopAction);
    m_playbackMenu->addAction(m_previousAction);
    m_playbackMenu->addAction(m_nextAction);
    m_playbackMenu->addSeparator();
    m_playbackMenu->addAction(m_repeatAction);
    m_playbackMenu->addAction(m_shuffleAction);
    m_playbackMenu->addAction(m_stopAfterCurrentAction);
    m_playbackMenu->addSeparator();
    m_playbackMenu->addAction(m_clearAction);
    
    // Setup playback menu actions
    m_playPauseAction->setShortcut(tr("Ctrl+Return"));
    m_stopAction->setShortcut(tr("Ctrl+."));
    m_previousAction->setShortcut(tr("Alt+Up"));
    m_nextAction->setShortcut(tr("Alt+Down"));
    m_repeatAction->setCheckable(true);
    m_repeatAction->setShortcut(tr("Ctrl+R"));
    m_repeatAction->setToolTip(tr("Toggle repeat playback mode"));
    m_shuffleAction->setCheckable(true);
    m_shuffleAction->setShortcut(tr("Ctrl+S"));
    m_shuffleAction->setToolTip(tr("Toggle shuffle playback mode"));
    m_stopAfterCurrentAction->setCheckable(true);
    m_clearAction->setShortcut(tr("Ctrl+Shift+X"));
    
    // Setup transfers menu
    m_transfersMenu->addAction(m_startTransfersAction);
    m_transfersMenu->addAction(m_pauseTransfersAction);
    
    // Setup edit menu
    m_editMenu->addAction(m_settingsAction);
    
    // Setup edit menu actions
    m_settingsAction->setShortcut(tr("Ctrl+P"));
    
    // Setup help menu
    m_helpMenu->addAction(m_aboutAction);

    // Setup toolbar
    m_toolBar->setObjectName("mainToolBar");
    m_toolBar->setWindowTitle(tr("Main toolbar"));
    m_toolBar->setMovable(false);
    m_toolBar->setAllowedAreas(Qt::TopToolBarArea);
    m_toolBar->addAction(m_openFilesAction);
    m_toolBar->addAction(m_addFilesAction);
    m_toolBar->addAction(m_searchAction);
    m_toolBar->addAction(m_previousAction);
    m_toolBar->addAction(m_nextAction);
    m_toolBar->addAction(m_playPauseAction);
    m_toolBar->addAction(m_stopAction);
    m_positionSpacerAction = m_toolBar->addWidget(m_positionSpacer);
    m_positionSliderAction = m_toolBar->addWidget(m_positionSlider);
    m_positionLabelAction = m_toolBar->addWidget(m_positionLabel);
    m_toolBar->addAction(m_repeatAction);
    m_toolBar->addAction(m_shuffleAction);
    addToolBar(Qt::TopToolBarArea, m_toolBar);
    
    // Setup position spacer, slider and label
    m_positionSpacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    m_positionSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    m_positionSliderAction->setVisible(false);
    m_positionLabel->setFixedWidth(m_positionLabel->fontMetrics().width("000:00 / 000:00"));
    m_positionLabel->setAlignment(Qt::AlignCenter);
    m_positionLabelAction->setVisible(false);
    
    // Setup tab widget
    m_tabWidget->setTabsClosable(true);
    m_tabWidget->tabBar()->setSelectionBehaviorOnRemove(QTabBar::SelectLeftTab);
    m_tabWidget->tabBar()->setExpanding(false);
    
    // Setup now playing metadata
    m_nowPlayingMetaData->setStyleSheet("font-weight: bold");
    m_nowPlayingMetaData->setThumbnailSize(QSize(96, 96));
    m_nowPlayingMetaData->hide();
    
    // Setup layout
    m_layout->addWidget(m_tabWidget);
    m_layout->addWidget(m_nowPlayingMetaData);
    m_layout->setContentsMargins(0, 0, 0, 0);
    setCentralWidget(m_widget);
    
    // Restore window geometry/state
    restoreGeometry(Settings::mainWindowGeometry());
    restoreState(Settings::mainWindowState());
    
    // Connect signals and slots
    connect(AudioPlayer::instance(), SIGNAL(durationChanged(qint64)), this, SLOT(onPlayerDurationChanged(qint64)));
    connect(AudioPlayer::instance(), SIGNAL(metaDataChanged()), this, SLOT(updateNowPlayingMetaData()));
    connect(AudioPlayer::instance(), SIGNAL(positionChanged(qint64)), this, SLOT(onPlayerPositionChanged(qint64)));
    connect(AudioPlayer::instance(), SIGNAL(seekableChanged(bool)), this, SLOT(onPlayerSeekableChanged(bool)));
    connect(AudioPlayer::instance(), SIGNAL(statusChanged(AudioPlayer::Status)),
            this, SLOT(onPlayerStatusChanged(AudioPlayer::Status)));
    connect(m_openFilesAction, SIGNAL(triggered()), this, SLOT(openFiles()));
    connect(m_openUrlAction, SIGNAL(triggered()), this, SLOT(openUrl()));
    connect(m_addFilesAction, SIGNAL(triggered()), this, SLOT(addFiles()));
    connect(m_addUrlAction, SIGNAL(triggered()), this, SLOT(addUrl()));
    connect(m_searchAction, SIGNAL(triggered()), this, SLOT(search()));
    connect(m_pluginsAction, SIGNAL(triggered()), this, SLOT(loadPlugins()));
    connect(m_quitAction, SIGNAL(triggered()), this, SLOT(close()));
    connect(m_showPlaybackQueueAction, SIGNAL(triggered()), this, SLOT(showPlaybackQueue()));
    connect(m_showTransfersAction, SIGNAL(triggered()), this, SLOT(showTransfers()));
    connect(m_reloadAction, SIGNAL(triggered()), this, SLOT(reloadCurrentTab()));
    connect(m_closeAction, SIGNAL(triggered()), this, SLOT(closeCurrentTab()));
    connect(m_playPauseAction, SIGNAL(triggered()), AudioPlayer::instance(), SLOT(togglePlaying()));
    connect(m_stopAction, SIGNAL(triggered()), AudioPlayer::instance(), SLOT(stop()));
    connect(m_previousAction, SIGNAL(triggered()), AudioPlayer::instance(), SLOT(previous()));
    connect(m_nextAction, SIGNAL(triggered()), AudioPlayer::instance(), SLOT(next()));
    connect(m_repeatAction, SIGNAL(triggered(bool)), AudioPlayer::instance(), SLOT(setRepeatEnabled(bool)));
    connect(m_shuffleAction, SIGNAL(triggered(bool)), AudioPlayer::instance(), SLOT(setShuffleEnabled(bool)));
    connect(m_stopAfterCurrentAction, SIGNAL(triggered(bool)),
            AudioPlayer::instance(), SLOT(setStopAfterCurrentTrack(bool)));
    connect(m_clearAction, SIGNAL(triggered()), AudioPlayer::instance(), SLOT(clearQueue()));
    connect(m_startTransfersAction, SIGNAL(triggered()), Transfers::instance(), SLOT(start()));
    connect(m_pauseTransfersAction, SIGNAL(triggered()), Transfers::instance(), SLOT(pause()));
    connect(m_settingsAction, SIGNAL(triggered()), this, SLOT(showSettingsDialog()));
    connect(m_aboutAction, SIGNAL(triggered()), this, SLOT(showAboutDialog()));
    connect(m_positionSlider, SIGNAL(sliderReleased()), this, SLOT(updatePlayerPosition()));
    connect(m_positionSlider, SIGNAL(valueChanged(int)), this, SLOT(onSliderValueChanged(int)));
    connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(onTabStatusChanged()));
    connect(m_tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
}
Ejemplo n.º 7
0
void Player::reset()
{
	camera->setPosition(glm::vec3(0.0f, 0.0f, 0.0f));
	updatePlayerPosition(glm::vec3(0.0f, 0.0f, 0.0f));
}