Ejemplo n.º 1
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->running = true;
    this->setFocus();
    setFixedSize(GAME_WIDTH,GAME_HEIGHT);
    ui->backgroundFrame->setFixedSize(GAME_WIDTH,GAME_HEIGHT);
    //inicializacion atributos

    AspectRatioPixmapLabel* labelprueba = new AspectRatioPixmapLabel();
    QPixmap pixPrueba(":/gameElement/assets/spaceship1.png");
    labelprueba->setPixmap(pixPrueba);
    labelprueba->setFixedSize(50,50);
    labelprueba->setParent(this);
    labelprueba->show();
    labelprueba->move(GAME_WIDTH/2,GAME_HEIGHT- 70);
    labelprueba->setScaledContents(true);

    player = newPlayerShip(labelprueba);
    playerBullets = new QList<PlayerBeam*>();
    enemies = new QList<enemy_T*>();
    scoreNumbers = new QList<QLabel*>();
    Lives = new QList<QLabel*>();

    //Inicializacion variables misc
    numbers[0] = ":/miscelanious/assets/numeral0.png";
    numbers[1] = ":/miscelanious/assets/numeral1.png";
    numbers[2] = ":/miscelanious/assets/numeral2.png";
    numbers[3] = ":/miscelanious/assets/numeral3.png";
    numbers[4] = ":/miscelanious/assets/numeral4.png";
    numbers[5] = ":/miscelanious/assets/numeral5.png";
    numbers[6] = ":/miscelanious/assets/numeral6.png";
    numbers[7] = ":/miscelanious/assets/numeral7.png";
    numbers[8] = ":/miscelanious/assets/numeral8.png";
    numbers[9] = ":/miscelanious/assets/numeral9.png";

    //----------------------------------

    //
    generateNextLevel();

    //Asignación de los Threads
    this->gameloop = new GameLoopThread(true);

    //Connects necesarios para el funcionamiento
    connect(gameloop,SIGNAL(gameUpdate()),this,SLOT(gameUpdate()));
    connect(gameloop,SIGNAL(gameRender()),this,SLOT(gameRender()));
    connect(gameloop,SIGNAL(gameDrawn()),this,SLOT(gameDrawn()));

    this->gameloop->start();

}
Ejemplo n.º 2
0
void ballupdate(int k)
{
  if(gameover) return ;
  gameUpdate();
  glutPostRedisplay();
  glutTimerFunc(20,ballupdate,0);
}
Ejemplo n.º 3
0
void GameEngine::GameLoop()
{
	float gameTime = 0.0f;
	clock_t _time;
	float deltaTime = 0.0f;

	while (true)
	{
		_time = clock();

		InputManager::Instance().update(deltaTime);

		FileSystem::Instance().update(deltaTime);

		AssetManager::Instance().update(deltaTime);

		GameObjectManager::Instance().update(deltaTime);

		if (gameUpdate != nullptr)
		{
			gameUpdate(deltaTime);
		}

		RenderSystem::Instance().update(deltaTime);

		_time = clock() - _time;
		deltaTime = ((float)_time) / ((clock_t)1000);
		gameTime += deltaTime;

		LOG("Current Game Time: " << gameTime << " Delta Time: " << deltaTime);
	}
}
Ejemplo n.º 4
0
void Game::mainLoop()
{
	while (window.isOpen())
	{
		sf::Event event;
		while (window.pollEvent(event))
			handleEvent(event);
		if (GameState == mainMenu)
			menuUpdate();
		else if (GameState == inGame)
			gameUpdate();
		else if (GameState == paused)
			pauseUpdate();
		else if (GameState == postGame)
			postUpdate();
		render();
	}
}
Ejemplo n.º 5
0
	void Game::update(const sf::Time& dt)
	{
		gameUpdate(dt);
	}
Ejemplo n.º 6
0
int main(int argc, char** argv) {
    (void) argc;
    (void) argv;
    /*srand(time(NULL));*/
#ifdef WIN32
    {
        LARGE_INTEGER divisor;
        QueryPerformanceFrequency(&divisor);
        clockDivisor = divisor.QuadPart;
    }
#else
    clockDivisor = CLOCKS_PER_SEC;
#endif
    printf("Starting\nClock divisor: %lu\n", clockDivisor);

    struct graphics g = {
#ifdef SHOWKEYS
        .width = 100, .height = 100,
#else
        .width = 1200,
        .height = 900,
#endif
    };
    initiateGraphics(&g, "Test window");

    if(!g.window) goto CLEANUP;
    /*thread t;*/
    /*newThread(test, NULL, &t);*/

    clockType frameStart, frameEnd, gameStart;
    getClockTime(&frameStart);

    initLogic();
    loadEntities();
    loadTileTextures();
    initializeWorld();
    initializeBullets();
    initializeItems();
    initializeItemFunctions();
    luaStart();

    getClockTime(&gameStart);

    while(1){
        cameraTick();
        renderGraphics(&g);

        oldMouseState = mouseState;
        mouseState = SDL_GetMouseState(&mouseX, &mouseY);
        if(oldMouseState != mouseState){
            mouseEvent();
        }
        for(SDL_Event event; SDL_PollEvent(&event);){
            switch(event.type){
            case SDL_QUIT:
                goto CLEANUP;
            case SDL_KEYDOWN:
            case SDL_KEYUP:
                if(event.key.keysym.scancode == 0x14) goto CLEANUP; //TODO
                keyEvent(event.key);
            break;
            }
        }

        getClockTime(&frameEnd);
        frameTime = getDiffClock(frameStart, frameEnd);
        appTime = getDiffClock(gameStart, frameEnd);
        frameStart = frameEnd;
        gameUpdate();
    }
CLEANUP:

    luaEnd();
    uninitializeItems();
    uninitializeItemFunctions();
    uninitializeBullets();
    uninitializeWorld();
    unloadTileTextures();
    unloadEntities();
    destroyGraphics(&g);

    return 0;
}

float normalRandomFloat(){
    return ((float) rand()) / ((float) RAND_MAX);
}

float randomFloat(float a, float b){
    float diff = b - a;
    return a + normalRandomFloat() * diff;
}
Ejemplo n.º 7
0
int main(void){
	int i = 0;
	//Score set
	score = 0;
	PLL_Init();
	//Sound init
	DAC_Init();
	Timer0A_Init(Sound_Update, 1000000/11025);
//	Timer0B_Init(updateXAxis, 1000000/11025);
//	Timer1B_Init(updateYAxis, 1000000/11025);
	//Input
	ADC_Init();
	portD_Init();
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
												GPIOPinTypeGPIOInput(GPIO_PORTG_BASE,
												(GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7));
												GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_2);
												GPIOPadConfigSet(GPIO_PORTG_BASE,
												(GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7),
												GPIO_STRENGTH_2MA,
												GPIO_PIN_TYPE_STD_WPU);
	SysTick_Init(50000000/400);
	Output_Init();
	Output_Color(15);
	SysTick_IntEnable();
	EnableInterrupts();
	//Set flags
	gFlags = 0;
	HWREGBITW(&gFlags, TITLE_SCREEN) = True;	
	//Math rand set seed
	while(HWREGBITW(&gFlags, SELECT_DOWN) == 0 &&
				((GPIO_PORTG_DATA_R & 0x80) != 0)) { }
	while(HWREGBITW(&gFlags, SELECT_DOWN) == 1 ||
				((GPIO_PORTG_DATA_R & 0x80) == 0)) { }
	setSeed(NVIC_ST_CURRENT_R);
	//Game set
	setGraphics(1);//the lm3s can't handle more than 2 rocks at graphics level 3.
	gameInit();
	gameSet(0);
	while(1) {
		//Only draw to buffer when it has been output to the screen
		if(HWREGBITW(&gFlags, FRAME_BUFFER_READY) == False) {
			/*if(gameLevel == -2) {
				drawString(myMsgs[1], makePoint(50, 40));
				while ((GPIO_PORTG_DATA_R & 0x80) != 0 &&
							 HWREGBITW(&gFlags, SELECT_DOWN) == False) { }
				while ((GPIO_PORTG_DATA_R & 0x80) == 0 &&
							 HWREGBITW(&gFlags, SELECT_DOWN) == True) { }
				//Reset game
			*/
			//Check for level completion, aka all rocks and enemies are 
			//TODO: enemies
			if(HWREGBITW(&gFlags, LEVEL_COMPLETE) == True) { gameSet(++gameLevel); }
			//Redraw the screen from scratch.
			clearBuffer();
			//Draw the player.
			if(gPlayer.status == ALIVE) {
				drawPlayer(makePoint((int)gPlayer.x, (int)gPlayer.y),
									 gPlayer.angle, gPlayer.exhaustOn);
			}
			for(i = 0; i < MAX_ROCKS; i++) {
				if(gRocks[i].status == ALIVE) {
					drawRock(makePoint(gRocks[i].x, gRocks[i].y),
									 gRocks[i].rockType, gRocks[i].rockSize);
				}
			}
			//Draw allied bullets.
			for(i = 0; i < MAX_PLAYER_BULLETS; i++) {
				if(gPlayerBullets[i].status == ALIVE) {
					drawBullet(makePoint(gPlayerBullets[i].x, gPlayerBullets[i].y));
				}
			}
			//Draw enemy bullets.
			for(i = 0; i < MAX_ENEMY_BULLETS; i++) {
				if(gEnemyBullets[i].status == ALIVE) {
					drawBullet(makePoint(gEnemyBullets[i].x, gEnemyBullets[i].y));
				}
			}
			//Draw explosions.
			for(i = 0; i < MAX_EXPLOSIONS; i++) {
				if(gExplosions[i].status == ALIVE) {
					drawExplosion(gExplosions[i].pos, gExplosions[i].current);
				}
			}
			
			//
			drawNumber(score, makePoint(2,2));
			drawNumber(gameLevel, makePoint(128/2-6,2));
			
			if(HWREGBITW(&gFlags, GAME_OVER) == True) {
				drawString("GAME OVER", makePoint(40, 38));
				if((GPIO_PORTG_DATA_R & 0x80)) {
					//reset game
				}
				gameUpdate();
			} else if(HWREGBITW(&gFlags, TITLE_SCREEN) == True) {
				drawString("ASTEROIDS", makePoint(40, 38));
				gameLevel = 0;
			}
			updateXAxis();
			gameUpdate();
			HWREGBITW(&gFlags, FRAME_BUFFER_READY) = True;
		}
	}
}
Ejemplo n.º 8
0
void Title::update()
{
    if (c_Easing::isEnd(color_b)) {
        update_count++;
        if (update_count == 1) {
            end_flag = false;
            next_count = 0;
            ui.setup();
            ui.titleSetup();

            gameSetup();
            ui.player = entities.getObject<Player>();
            ui.enemyholder = entities.getObject<EnemyHolder>();
            if (SoundGet.find("TitleBGM")->isEnabled())
                SoundGet.find("TitleBGM")->stop();
            else
                SoundGet.find("TitleBGM")->start();
            SoundGet.find("TitleBGM")->setLoopEnabled(true);
        }
        ui.titleUpdate();
        gameUpdate();
        //bool set1
        //bool set2
        //bool set3
        //↓のif文の中で引数をtrueにする
        if (ui.getTutoFirtsFlag()) {
            if (LEAPHANDS.GetHandCenterPosToRatio().y >= 0.14f
                    || env.isPress(KeyEvent::KEY_0)) {
                tutorial_flag[0] = true;
            }
        }
        if (tutorial_flag[1] == false)
            if (ui.getTutoSecondFlag()) {
                if (player->isCharaDashing())
                {
                    tutorial_flag[1] = true;

                }
            }
        if (ui.getTutoThirdFlag())
        {
            if (enemyholder->remainingEnemy() < 4)
            {
                tutorial_flag[2] = true;
            }
        }
    }

    if (end_flag == true &&
            end_count == 1) {
        ui.ui_data["黒板"]->Active();
        ui.ui_data["黒板"]->setEnd();
    }



    if (tutorial) {

        ui.tuto1(tutorial_flag[0]);

        if (tutorial_flag[0]) {
            ui.tuto2(tutorial_flag[1]);
        }
        if (tutorial_flag[1]) {
            ui.tuto3(tutorial_flag[2]);
        }
        if (tutorial_flag[2]) {
            ui.tuto4(end_flag);
        }
    }
    if (env.isPush(KeyEvent::KEY_BACKSPACE)) {
        SoundGet.find("TitleBGM")->stop();
        SoundGet.find("Start")->start();
        end_flag = true;
    }

}
Ejemplo n.º 9
0
void gui_tetris_draw(){
  gameUpdate(game);
}