int main()
{
	// Set display options.
	// DCNT_MODE0 sets mode 0, which provides four tiled backgrounds.
	// DCNT_OBJ enables objects.
	// DCNT_OBJ_1D make object tiles mapped in 1D (which makes life easier).
	REG_DISPCNT = DCNT_MODE0 | DCNT_BG0 | DCNT_BG1 | DCNT_BG2 | DCNT_OBJ;
	
	REG_BG0CNT = BG_CBB(0) | BG_SBB(30) | BG_8BPP | BG_REG_32x32 | BG_PRIO(0);
	
	REG_BG1CNT = BG_CBB(0) | BG_SBB(29) | BG_8BPP | BG_REG_32x32 | BG_PRIO(1);
	
	REG_BG2CNT = BG_CBB(0) | BG_SBB(25) | BG_8BPP | BG_REG_64x64 | BG_PRIO(2);
	REG_BG2HOFS = 0;
	REG_BG2VOFS = 0;
	
	ClearObjects();
	
	SetPaletteBG(1, RGB(31, 31, 31)); // white
	
	//Load each tile in font_bold into it's corresponding position in charblock 0
	for (int i = 0; i < 128; i++)
	{
		LoadTile8(0, i, font_bold[i]);
	}
	
	DrawText(5, (SCREEN_HEIGHT / 16) - 2, "DECEPTIVE DIMENSIONS");
	DrawText(5, (SCREEN_HEIGHT / 16), "Press start to begin");
	
	Buttons buttons;
	int framecounter = 0;
	
	//Title screen (under construction)
	while (true)
	{
		buttons.Update();
		
		if (buttons.StartJustPressed())
		{
			break;
		}
		
		WaitVSync();	
	}
	
	while (true)
	{
		//Load Custom spritesheet
		LoadPaletteObjData(0, spritesheet4Pal, sizeof spritesheet4Pal);
		LoadPaletteBGData(0, backgroundnewnewPal, sizeof backgroundnewnewPal);
		LoadTileData(4, 0, spritesheet4Tiles, sizeof spritesheet4Tiles);
		LoadTileData(0, 0, backgroundnewnewTiles, sizeof backgroundnewnewTiles);
		
		int levelnumber = 1;
		
		Level level(levelnumber);
		
		for (int screenblock = 21; screenblock < 31; screenblock++)
		{
			level.FillScreenblock(screenblock, 0);
		}
		
		level.DrawBackground(level.curdimension);
		
		bool gamerunning = true;
		
		//Main game loop
		while (gamerunning)
		{
			buttons.Update();
			
			gamerunning = level.CheckIfLevelComplete();
			level.TakeInput(buttons);
			level.MoveObjects();
			level.Draw();
			level.UpdateLevelObjects(framecounter);

			framecounter++;
			
			WaitVSync();
			FlipBuffers();
		}
		
		//Reload each tile in font_bold into it's corresponding position in charblock 0
		for (int i = 0; i < 128; i++)
		{
			LoadTile8(0, i, font_bold[i]);
		}
		
		SetPaletteBG(0, RGB(0, 0, 0)); // black
		SetPaletteBG(1, RGB(31, 31, 31)); // white		
		
		for (int screenblock = 25; screenblock < 31; screenblock++)
		{
			for (int y = 0; y < 32; y++)
			{
				for (int x = 0; x < 32; x++)
				{
					SetTile(screenblock, x, y, 0);
				}
			}
		}
		
		level.player.drawx = SCREEN_WIDTH;
		
		SetObject(level.player.GetObjNum(),
		  ATTR0_SHAPE(2) | ATTR0_8BPP | ATTR0_HIDE,
		  ATTR1_SIZE(2) | ATTR1_X(level.player.drawx),
		  ATTR2_ID8(0) | ATTR2_PRIO(2));
		
		UpdateObjects();
		
		DrawText(6, (SCREEN_HEIGHT / 16) - 2, "That's all folks!!");
		DrawText(3, (SCREEN_HEIGHT / 16), "Press start to try again");
		
		while (true)
		{
			buttons.Update();
			
			if (buttons.StartJustPressed())
			{
				break;
			}
			
			WaitVSync();
		}
	}
}
Exemple #2
0
//						Update game5
void update( ESContext* ctx, float deltaTime )
{
    if(getKeyState(KeyCodes::KEY_ESCAPE))
    {
        deinit(ctx);
        exit(0);
    }

    if(player.isHeJumping == true)
    {
        PlayHop();
    }

    int number = button1.Update(deltaTime);



    switch(gameState)
    {
    case 0:
        menu.background->setPosition(0,0);
        insertText.background->setPosition(400,400);
        dead.background->setPosition(400,400);
        //gameState = 1;
        button1.buttons->setPosition(-6, 1);
        switch (number)
        {
        case 1:
            gameState = 1;
            break;
        case 2:
            break;
        case 3:
            break;
        }
        break;
    case 1:

        switch (letterState)
        {
        case 0:
            insertText.background->setPosition(0,0.35f);
            button1.buttons->setPosition(-400, 400);
            insertText.background->setPosition(0,0.35f);
            score->m_nameText1->setText( to_string(score->letters[score->lindex]));
            score->nameText1->setPosition(-0.5f,0);
            break;
        case 1:
            score->m_nameText2->setText( to_string(score->letters[score->lindex]));
            score->nameText2->setPosition(0,0);
            break;
        case 2:
            score->m_nameText3->setText( to_string(score->letters[score->lindex]));
            score->nameText3->setPosition(0.5f,0);
            break;
        case 3:
            //gameState = 2;
            //button1.buttons->setPosition(4, 4);
            if(getKeyState(KeyCodes::KEY_RETURN))
            {
                menu.background->setPosition(400,400);
                insertText.background->setPosition(400,400);
                score->nameText1->setPosition(-0.5f,-5);
                score->nameText2->setPosition(0,-5);
                score->nameText3->setPosition(0.5f,-5);

                gameState = 2;
            }

            break;
        }

        if(isButtonPressed == false)
        {
            if(getKeyState(KeyCodes::KEY_DOWN))
            {
                score->lindex++;
                isButtonPressed = true;
                if (score->lindex > 25)
                {
                    score->lindex = 25;
                }
            }

            if(getKeyState(KeyCodes::KEY_UP))
            {
                score->lindex--;
                isButtonPressed = true;
                if (score->lindex < 0)
                {
                    score->lindex = 0;
                }
            }

            if(getKeyState(KeyCodes::KEY_RETURN))
            {
                letterState++;
                scoreList.push_back(score->letters[score->lindex]);
                isButtonPressed = true;
            }
        }
        else if(!getKeyState(KeyCodes::KEY_DOWN) && !getKeyState(KeyCodes::KEY_UP) && !getKeyState(KeyCodes::KEY_RETURN))
        {
            isButtonPressed = false;
        }
        break;
    case 2:
        count++;

        button1.buttons->setPosition(400, 400);

        dangers[0].speed = 8.5f * (1 + score->highscore/20000);
        dangers[1].speed = 3.5f * (1 + score->highscore/20000);
        dangers[2].speed = 15.5f * (1 + score->highscore/20000);

        player.Update(deltaTime);
        enemy.Update(deltaTime);
        health.Update(deltaTime);
        score->update(deltaTime);
        notDanger.Update(deltaTime);
        apple.Update(deltaTime);
        banana.Update(deltaTime);
        map->update(deltaTime);

        score->highscore += backgrounds[0].boost/10;

        if(player.isHeDead == true)
        {
            if(isPlayerScreamed == false)
            {
                PlayNoo();
            }
        }

        for (size_t i = 0; i < backgrounds.size(); i++)
        {
            backgrounds[i].Update(deltaTime);
        }

        for (size_t i = 0; i < dangers.size(); i++)
        {

            dangers[i].Update(deltaTime);
            //	Collision between player and danger
            if ((player.hitx > dangers[i].hitx - 0.6f && player.hitx < dangers[i].hitx + 0.8f
                    && player.hity > dangers[i].hity - 0.5f
                    && player.hity -1.3f < dangers[i].hity + 0.5f) && player.isHeBlinking == false)
            {
                if(player.isHeDead == false)
                {
                    PlayAuts();
                    //engine->play2D("ouch.wav", false);
                }
                dangers[i].Respawn();
                player.DangerHit();
                player.Blink();

                // spark effect
                spark1.Hit();
                spark1.spark->setPosition((float)dangers[i].hitx,(float)dangers[i].hity);
                // slow effect
                for (int i = 0; i < 6; i++)
                {
                    backgrounds[i].Slow();
                }
                // player slow effect
                player.Slow();
            }

            // Player pickups a bonus
            if (notDanger.danger->collidesTo(player.player))
            {
                PlayNom();
                //engine->play2D("pickup1.wav", false);
                notDanger.Respawn();
                health.Medkit();
                score->strawberry();
            }
            // Player pickups a bonus
            if (banana.danger->collidesTo(player.player))
            {
                PlayNom();
                //engine->play2D("pickup1.wav", false);
                banana.Respawn();
                //health.Medkit();
                score->banaani();
            }
            // Player pickups a bonus
            if (apple.danger->collidesTo(player.player))
            {
                PlayNom();
                //engine->play2D("pickup1.wav", false);
                apple.Respawn();
                //health.Medkit();
                score->omena();
            }
        }
        // Hit hippo
        if (player.hitx <= -6.0f)
        {
            //health.hp = 0;
            //player.Death();
            PlayAuts();
            player.Blink();
            player.HippoHit();
            if(player.isHeDead == true)
            {
                if(isPlayerScreamed == false)
                {
                    PlayNoo();
                }
            }
        }

        if (player.hity >= 40.0f)
        {
            dangers[0].Respawn();
            dangers[1].Respawn();
            dangers[2].Respawn();
            notDanger.Respawn();
            player.die = 0;
            engine->play2D("deathscreen.wav", false);
            health.newGame();
            gameState = 3;
            dead.background->setPosition(0,2);
        }
        break;
    case 3:
        if (isScoresRead == false)
        {
            writeHighScores(ceil(score->highscore));
            sqlite3_exec(db, "select * FROM scores ORDER BY score DESC LIMIT 0, 5;", callback, NULL, NULL);
            isScoresRead = true;
        }

        for (size_t i = 0; i < score->scoreTexts.size(); i++)
        {
            score->scoreTextObjects[i]->setPosition(vec2(7,-4.5f + i*0.5f));
        }

        if(getKeyState(KeyCodes::KEY_R))
        {
            gameState = 2;
            player.player->setPosition(-1,2.5);
            score->highscore = 0;
            isPlayerScreamed = false;
            isScoresRead = false;
            dindex = 0;
            dead.background->setPosition(400,400);

            for (int i = 0; i < 5; i++)
            {
                score->scoreTextObjects[i]->setPosition(vec2(-15,0));
            }
        }
        break;
    }
}