Beispiel #1
0
void BladeRunnerEngine::gameLoop() {
	_gameIsRunning = true;
	do {
		/* TODO: check player death */
		gameTick();
	} while (_gameIsRunning);
}
Beispiel #2
0
void Game::finishLoad(){
    if(m_cc->isError()){
        qDebug() << "Error loading: " << m_cc->errors();
        return;
    }
    m_currentMap = qobject_cast<Map*>(m_cc->create(qmlContext(m_gameArea)));
    if(!m_currentMap){
        qDebug() << "Error loading map.";
        return;
    }
    m_currentMap->setParentItem(m_gameArea);
    m_players = m_currentMap->m_players;//Yes, we share references.
    qDebug() << "Loading Map" << m_currentMap << m_players;
    playersChanged(m_players);

    m_gameOver = false;
    //HQs (must be unit[0])
    bool hqsBuilt = true;
    for(int i=0; i<m_players.size(); i++)
        hqsBuilt = build(m_players[i]->startPos().x(), m_players[i]->startPos().y(), m_players[i]->hq(), i) && hqsBuilt;
    Q_ASSERT(hqsBuilt);//TODO: Nicer error handling, this was just a QML error
    //Other starting units
    recursiveLoadStartState(m_currentMap);
    //Sentinel Waypoints
    m_players[0]->m_waypoints << new Waypoint(m_players[0], m_players[1]->m_units[0], m_currentMap);
    m_players[1]->m_waypoints << new Waypoint(m_players[1], m_players[0]->m_units[0], m_currentMap);
    debugPrint("Map Loaded: " + QString::number(m_currentMap->width()) + "," + QString::number(m_currentMap->height()));
    QTimer::singleShot(16, this, SLOT(gameTick()));
}
Beispiel #3
0
static void gameSingleLoop( void )
{
	LJ_engineTick();
	gameTick();
	LJ_engineStartRendering();
	LJ_engineRender();
	LJ_engineFinishRendering();
}
Beispiel #4
0
void GameScreen::update(float delta)
{
	// Check for pausing because polling events blow
	if(sf::Keyboard::isKeyPressed(sf::Keyboard::P))
	{
		if(mPauseReleased)
		{
			if(mState == GameState::PAUSED || mState == GameState::PLAYING)
			{
				mState = (mState == GameState::PAUSED)?GameState::PLAYING:GameState::PAUSED;
			}
		}
		mPauseReleased = false;
	}
	else
	{
		mPauseReleased = true;
	}

	switch (mState)
	{
	case PAUSED:
		break;
	case PLAYING:
		gameTick(delta);
		break;
	case LANDING:
		landingTick(delta);
		break;
	case GAMEOVER:
		deathTick(delta);
		break;
	case SAVED:
		savedTick(delta);
		break;
	case NEXTLEVEL:
		nextLevelTick(delta);
		break;
	default:
		break;
	}
	
	// Update the debug data
	DEBUGLABELS[DBG_FALLSPEED].second = mFallSpeed;
	DEBUGLABELS[DBG_TRAVELED].second = mLevelTraveled;
	DEBUGLABELS[DBG_PLAYER_YVEL].second = player->velocity.y;

	std::string dbgResult = "";
	for(int i = 0; i < 3; ++i)
	{
		dbgResult += DEBUGLABELS[i].first + std::to_string(DEBUGLABELS[i].second) + "\n";
	}
	DEBUGTEXT.setString(dbgResult);
}
Beispiel #5
0
void BladeRunnerEngine::loopActorSpeaking() {
	if (!_audioSpeech->isPlaying()) {
		return;
	}

	playerLosesControl();

	do {
		gameTick();
	} while (_gameIsRunning && _audioSpeech->isPlaying());

	playerGainsControl();
}
Beispiel #6
0
AppWindow::AppWindow() : game(10, 20) {
  setWindowTitle("488 Tetrominoes on the Wall");

  gameTicker = new QTimer(this);
  connect(gameTicker, SIGNAL(timeout()), this, SLOT(gameTick()));
  gameTicker->start(SLOW_MS);

  QGLFormat glFormat;
  glFormat.setVersion(3, 3);
  glFormat.setProfile(QGLFormat::CoreProfile);
  glFormat.setSampleBuffers(true);

  QVBoxLayout *layout = new QVBoxLayout;
  m_viewer = new Viewer(glFormat, this);
  layout->addWidget(m_viewer);
  setCentralWidget(new QWidget);
  centralWidget()->setLayout(layout);

  m_viewer->viewGame(&game);
  m_viewer->show();

  createActions();
  createMenu();
}
Beispiel #7
0
int main(void) {
	GLFWwindow* window;

	glfwSetErrorCallback(error_callback);

	if (!glfwInit())
		exit(EXIT_FAILURE);

	window = glfwCreateWindow(800, 600, "Simple example", NULL, NULL);
	if (!window) {
		glfwTerminate();
		exit(EXIT_FAILURE);
	}

	glfwMakeContextCurrent(window);

	glfwSetKeyCallback(window, key_callback);

	std::cout << "Drawing a window." << std::endl;

	Tank tan = Tank();
	tan.state.x = 50;
	tan.state.y = 50;

	long curTicks = 0;
	float tps = 25.0f;
	while (!glfwWindowShouldClose(window)) {
		float ratio;
		int width, height;

		for (; curTicks < (float) glfwGetTime() * tps; curTicks++) {
			gameTick(tan);
		}

		glfwGetFramebufferSize(window, &width, &height);
		ratio = width / (float) height;

		glViewport(0, 0, width, height);
		glClear(GL_COLOR_BUFFER_BIT);

		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		//glOrtho(-ratio, ratio, -1.f, 1.f, -10, 10);
		glOrtho(0, width/2, 0, height/2, -10, 10);
		glMatrixMode(GL_MODELVIEW);

		glLoadIdentity();
		//glRotatef((float) glfwGetTime() * 10.f, 0.f, 0.f, 1.f);
		//glTranslatef((float) glfwGetTime() * 20.f, 0.f, 0.f);
		//tan.state.h = (float) glfwGetTime() * -10.f;
		//tan.state.turretH = (float) glfwGetTime() * 10.f;

		//drawCube(0, 0, 0);
		//drawTri();
		//glLineWidth(2.f);
		tan.draw();

		glfwSwapBuffers(window);
		glfwPollEvents();
	}

	glfwDestroyWindow(window);

	glfwTerminate();
	std::cout << "Byebye" << std::endl;
	exit(EXIT_SUCCESS);
}