void GameObjMap::onEnter()
{
    Node::onEnter();
    
	InitBackGround();
	AddStar();
	InitMapItem();

    state = 0;
}
Example #2
0
void MatrixManager::UpdateMatrix()
{
    int i, j;
    //
    if ((rand() % 4) == 0)
        AddStar();
    //
    for (i = 0; i < MAX_STARS; i++)
    {
        starfield[i].UpdateStar();
    }
    //
    /*
    for (i = 0; i < MATRIX_W; i++)
    {
        for (j = 0; j < MATRIX_H; j++)
        {
            // decrease intensity for existing chars
            if (((matrix_keep_text[i][j] != 0) || (matrix_keep_intensity[i][j] != 0)) &&
                (matrix_intensity[i][j] == MAX_INTENSITY))
            {
                // matrix_intensity[i][j] = MAX_INTENSITY;
            }
            else
            {
                if (matrix_intensity[i][j] >= 2)
                {
                    matrix_intensity[i][j] -= 2;
                }
                else
                {
                    matrix_intensity[i][j] = 0;
                }
            }
        }
        //
        if (anim_point[i] == 0)
        {
            // animation on hold
            if (anim_start[i] > 0)
            {
                // if delay is still on, decrease delay
                anim_start[i]--;
            }
            else
            {
                // if delay is elapsed, start animation
                anim_point[i]++;
            }
        }
        else
        {
            // animation in progress
            if (matrix_keep_text[i][anim_point[i] - 1] != 0)
            {
                matrix_chars[i][anim_point[i] - 1] = matrix_keep_text[i][anim_point[i] - 1];
            }
            else
            {
                matrix_chars[i][anim_point[i] - 1] = (rand() % 0xfe) + 1;
            }
            matrix_intensity[i][anim_point[i] - 1] = MAX_INTENSITY / 2;
            //
            if (anim_point[i] >= MATRIX_H)
            {
                // stop animation, allocate delay
                anim_point[i] = 0;
                anim_start[i] = (rand() % MAX_FRAME_DELAY);
            }
            else
            {
                anim_point[i]++;
            }
        }
    }
    */
}
Example #3
0
void DisplayHandler () // display callback function
{
	if (bRotate) 
	{
		fCameraAngle[0] += 1.0 ;
		fCameraAngle[2] += 1.0 ;
	}
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;
	glLoadIdentity() ;

	SetCamera() ;

	if (!bPause)
	{
		GLfloat fTempX = GLfloat(iLastMouseX) / GLfloat(iWinWidth) ;
		GLfloat fTempY = GLfloat(iLastMouseY) / GLfloat(iWinHeight) ;
		GLfloat fFixedX = (Player.ptLocation.dX - 8.65) / -17.3 ;
		GLfloat fFixedZ = (Player.ptLocation.dZ - 8.65) / -17.3 ;
		if (bRightMouseDown)
		{
			if (!(fFixedX + 0.02 > fTempX && fFixedX - 0.02 < fTempX))
			{
				if (fFixedX > fTempX)
				{
					Player.ptLocation.dX += 0.1 ;
					if (Player.ptAngle.dZ > -20) 
						Player.ptAngle.dZ -= 5.0 ;
				} else
				{
					Player.ptLocation.dX -= 0.1 ;
					if (Player.ptAngle.dZ < 20) 
						Player.ptAngle.dZ += 5.0 ;
				}
			} else
			{
				if (Player.ptAngle.dZ < 0) Player.ptAngle.dZ += 5.0 ;
				else if (Player.ptAngle.dZ > 0)	Player.ptAngle.dZ -= 5.0 ;
			}
			if (!(fFixedZ + 0.1 > fTempY && fFixedZ - 0.02 < fTempY))
			{
				if (fFixedZ > fTempY)
				{
					Player.ptLocation.dZ += 0.1 ;
				} else 
				{
					Player.ptLocation.dZ -= 0.1 ;
				}
			}
		} else Player.ptAngle.dZ = 0 ;

		if (randp() > 0.98) AddPlanet() ;
		AddStar() ;
		AddStar() ;
		AddStar() ;
		AddStar() ;
		AddStar() ;
		AddStar() ;

		if (/*!bExplode && */iCount % 15 == 0) SpawnEnemy() ;

		if (!bExplode && bAutofire && iCount % 4 == 0) FireShot(&Player, pPlayerShots) ;

		iCount ++ ;

	}
	
	DisplayStars() ;
	DisplayPlanets() ;
	DisplayEnemies() ;

	DisplayShots(pPlayerShots) ;
	DisplayShots(pEnemyShots) ;

	if (bExplode && !bPause)
	{
		if (iCount == 0) 
		{
			printf("Game over\n") ;
			MakeExplosion(Player.ptLocation, 1000) ;
		}
	} else 
	{
		if (iCount % 4)
		{
			Particle *pNew = new Particle ;
			pNew->ptLocation.dX = Player.ptLocation.dX + randp() * 0.5 - 0.25;
			pNew->ptLocation.dY = Player.ptLocation.dY + 0.3 * randp() ;
			pNew->ptLocation.dZ = Player.ptLocation.dZ - 1.5 + 0.2 * randp() ;
			pNew->ptVelocity.dX = 0 ;
			pNew->ptVelocity.dY = 0 ;
			pNew->ptVelocity.dZ = -0.2 ;
			pNew->ptColor.dX = 0.98 ;
			pNew->ptColor.dY = 0.59 + 0.3 * randp() - 0.15 ;
			pNew->ptColor.dZ = 0.01 ;
			pNew->dAlpha = 0.7 ;
			pNew->dMass = 1 ;
			pNew->dLife = 7 * randp() + 3 ;
			pNew->ptAcceleration = 0 ;
			Particles.AddBack(pNew) ;
		}

		Player.Display() ;
	}

	LinkedListNode<Particle> *pTravParticles = Particles.pHead ;
	LinkedListNode<Particle> *pTempParticle ;
	
	while (pTravParticles != 0)
	{
		pTravParticles->pValue->dLife -- ;
		if (pTravParticles->pValue->dLife <= 0)
		{
			pTempParticle = pTravParticles ;
			pTravParticles = pTravParticles->pNext ;
			Particles.Remove(pTempParticle, true) ;
		} else
		{
			pTravParticles->pValue->Apply(0.9) ;
			
			DisplayParticle(pTravParticles->pValue) ;
			
			pTravParticles = pTravParticles->pNext ;
		}
	}
	
		
	glFinish() ;
	glutSwapBuffers() ;
	glutPostRedisplay() ;
}