コード例 #1
0
void ScoreOrb::update(double deltaT, double prevDeltaT)
{
    if (rot < 360) {
        rot += 30 * deltaT;
    }
    else {
        rot = 0;
    }

    setTraMat(mb1, posX, posY, 0.0);
    setRotMat(mb2, M_PI*rot / 180.0, 2);
    MultMat(mb1, mb2, mb);
    for (int i = 0; i<4; ++i)MultMatPre2DPoint(mb, &objectPoly.vert[i], &objectPolyN.vert[i]);
}
コード例 #2
0
void EnemyType3::update(double deltaT, double prevDeltaT, double playerX, double playerY)
{
	double rotRads = atan2(posY - playerY, posX - playerX); //trig function for angle of zombie
	rot = rotRads * (180.0 / M_PI); // convert to deg

	double playerDirSin = sin(rotRads); //calculates direction for y
	double playerDirCos = cos(rotRads); //calculates direction for x

	posX -= playerDirCos * speed * deltaT;
	posY -= playerDirSin * speed * deltaT;

	setTraMat(mb1, posX, posY, 0.0);
	setRotMat(mb2, M_PI*rot / 180.0, 2);
	MultMat(mb1, mb2, mb);
	for (int i = 0; i < 4; ++i){
		MultMatPre2DPoint(mb, &enemyPoly.vert[i], &enemyPolyN.vert[i]);
	}
}
コード例 #3
0
void PlayerShip::update(double deltaT, double prevDeltaT, InputState *inputState)
{
	double playerDirSin = sin(DEG_2_RAD(-rotateZ));
	double playerDirCos = cos(DEG_2_RAD(-rotateZ));

	if (inputState->isKeyPressed('W') || inputState->isKeyPressed('UP'))
	{
		if (currentSpeed > 0) 
		{
			if (currentSpeed < maxSpeed) {
				currentSpeed += acceleration;
			}
			if (rocketFlamesScaleY < 1.0)
			{
				rocketFlamesScaleY += 0.006;
			}
			if (rocketFlamesScaleX < 1.0)
			{
				rocketFlamesScaleX += 0.006;
			}
		}
		else
		{
			if (currentSpeed < maxSpeed) {
				currentSpeed += directionChangeSpeed;
			}
			if (rocketFlamesScaleY < 1.0)
			{
				rocketFlamesScaleY += 0.006;
			}
			if (rocketFlamesScaleX < 1.0)
			{
				rocketFlamesScaleX += 0.006;
			}
		}
	}

	else if(inputState->isKeyPressed('S'))
	{
		if (currentSpeed > -maxSpeed) {
			if (currentSpeed < 0) {
				currentSpeed -= acceleration;
			}
			else{
				currentSpeed -= 0.1;
			}
		}
		if (rocketFlamesScaleY > 0.0)
		{
			rocketFlamesScaleY -= 0.006;
		}
		if (rocketFlamesScaleX > 0.0)
		{
			rocketFlamesScaleX -= 0.006;
		}
	}
	else
	{
		if (currentSpeed > 0)
		{
			currentSpeed -= decceleration;
			if (currentSpeed < 0)
			{
				currentSpeed = 0;
			}
		}
		else if (currentSpeed <= 0)
		{
			currentSpeed += decceleration;
			if (currentSpeed > 0)
			{
				currentSpeed = 0;
			}
		}
		if (rocketFlamesScaleY > 0.0)
		{
			rocketFlamesScaleY -= 0.006;
		}
		if (rocketFlamesScaleX > 0.0)
		{
			rocketFlamesScaleX -= 0.006;
		}
	}

	playerX += playerDirSin * PLAYER_MOVEMENT_SPEED * deltaT * currentSpeed;
	playerY += playerDirCos * PLAYER_MOVEMENT_SPEED * deltaT * currentSpeed;

	if(inputState->isKeyPressed('D'))
	{
		booster1X = 0.8;
		booster2X = -0.5;
		rotateZ -= rotationSpeed * deltaT;
		spriteX = 1;
		booster1Y = -2.4;

	}
	 else if(inputState->isKeyPressed('A'))
	{
		rotateZ += rotationSpeed * deltaT;
		spriteX = 0.666666;
		booster1X = -0.9;
		booster2X = 0.3;
		booster1Y = -2.4;
	}
	 else {
		 booster1X = -0.7;
		 booster2X = 0.5;
		 spriteX = 0.33333333333;
		 booster1Y = booster2Y = -2.6;
	 }
	//**************************************ATTACK AND BOOST
	if (boostOn == true) {
		maxSpeed = boostSpeed;
	}

	if (boostOn == false) {
		maxSpeed = defaultMaxSpeed;

		if (currentSpeed > maxSpeed) {
			currentSpeed -= 0.1;
		}
	}

	//***************************************JUMPING
	if (inputState->isKeyPressed('J'))
	{
		jump = true;
	}
	if ( jump == true) //is jumping
	{
		if ( jumpStage < JUMP_HEIGHT) //is before apex
		{
			if (falling == false) //is going up
			{
				jumpStage = jumpStage + 0.002 + (1 * deltaT);
				if ( jumpStage  > JUMP_HEIGHT - 0.5)
				{
					falling = true;
				}
			}
			
			else if (falling == true) //is coming back down
			{
				jumpStage = jumpStage - 0.003 - (1 * deltaT);
				if ( jumpStage < 1.001 ) 
				{
					jumpStage = 1;
					jump = false;
					falling = false;
				}
			}
		} 
	}

	//*****************************************************POWER UPS
	if (shieldOn == true)
	{
		if (shieldTimeLength < shieldTimeMax)
		{
			shieldTimeLength += 0.01;
		}
		else {
			shieldOn = false;
			shieldTimeLength = 0;
		}	
	}

	if(powerORBOn == true) {
		powerORBRotate += (ROTATION_SPIKE_BALL_SPEED * deltaT);
		if (powerORBSize < powerORBMaxSize) {
			powerORBSize += 0.001 + (1 * deltaT);
		}
	}
	else if(powerORBOn == false) {
		if (powerORBSize > 0.0) {
			powerORBSize -= 0.001 + (1 * deltaT);
		}
		if (powerORBSize == 0.0) {
			powerORBRotate = 0.0;
		}
	}
	
	shieldTime += (SHIELD_OSCILATION_SPEED * deltaT );

	if (shieldOn == true) {
		if (shieldScale < 1.0) {
			shieldScale += SHIELD_GROWTH_RATE * deltaT;
			if (shieldScale > 1.0) {
				shieldScale = 1.0;
			}
		}
	}
	else {
		if (shieldScale > 0.0) {
			shieldScale -= SHIELD_GROWTH_RATE * deltaT;
			if (shieldScale < 0.0) {
				shieldScale = 0.0;
			}
		}
	}

	//****************************************RESPAWN/DEATH STATE
	if (respawnState == true || damageState == true) {
		respawnTimer += 0.05;
		if (respawnTimer > RESPAWN_STATE_TIME) {
			respawnState = false;
			damageState = false;
			respawnTimer = 0.0;
			respawnstateOpacity = 1.0;
		}
		else {
			respawnstateOpacity = 0.4;
		}
	}

	if (playerX > wallMaxX) {
		playerX = wallMaxX;
	}
	else if (playerX < wallMinX) {
		playerX = wallMinX;
	}

	if (playerY > wallMaxY) {
		playerY = wallMaxY;
	}
	else if (playerY < wallMinY) {
		playerY = wallMinY;
	}


	//****************************************MATRIX COLLISION
	setTraMat(mb1, playerX, playerY, 0.0);
	setRotMat(mb2, M_PI*rotateZ / 180.0, 2);
	MultMat(mb1, mb2, mb);
	for (int i = 0; i < 4; ++i) {
		MultMatPre2DPoint(mb, &playerPoly.vert[i], &playerPolyN.vert[i]);
	}
}
コード例 #4
0
int main(void)

{
    short Tab1[MAX_COL][MAX_COL] ,Tab2[MAX_COL][MAX_COL] ,Tab3[MAX_COL][MAX_COL]={0} 
          ,Vect[MAX_COL]={0},n,val;
    char choix,retour='O';
    
    srand(time(NULL));
    Init(&Tab1[0][0],&Tab2[0][0],&n);
    printf("\n Matrice 1: \n");
    printf(" ----------\n");
    Affiche(&Tab1[0][0],n,n);
    printf("\n");
    printf(" Matrice 2: \n");
    printf(" ----------\n");
    Affiche(&Tab2[0][0],n,n);
    printf("\n");
    system("pause");
    system("cls");
    
    while((retour=='O')||(retour=='o'))
    {
        Menu(&choix);

        switch(choix)
        {
        
            case '1':
                     printf("Valeur du nombre a ajouter a la premiere matrice : ");
                     scanf("%hd",&val);
                     AddVal(&Tab1[0][0],&Tab3[0][0],n,val);
                     printf("\n Resultat : \n");
                     printf(" -----------\n");
                     Affiche(&Tab3[0][0],n,n);
                     printf("\n");
                 break;
                 
            case '2':
                     AddMat(&Tab1[0][0],&Tab2[0][0],&Tab3[0][0],n);
                     printf("\n Resultat : \n");
                     printf(" -----------\n");
                     Affiche(&Tab3[0][0],n,n);
                     printf("\n");
                 break;    
                     
            case '3':
                     printf("Valeur du nombre a soustraire a la premiere matrice : ");
                     scanf("%hd",&val);
                     SousVal(&Tab1[0][0],&Tab3[0][0],n,val);
                     printf("\n Resultat : \n");
                     printf(" -----------\n");
                     Affiche(&Tab3[0][0],n,n);
                     printf("\n");
                 break;
                 
            case '4':
                     SousMat(&Tab1[0][0],&Tab2[0][0],&Tab3[0][0],n);
                     printf("\n Resultat : \n");
                     printf(" -----------\n");
                     Affiche(&Tab3[0][0],n,n);
                     printf("\n");
                 break;
                  
            case '5':
                     printf("Valeur du nombre a multiplier a la premiere matrice : ");
                     scanf("%hd",&val);
                     MultVal(&Tab1[0][0],&Tab3[0][0],n,val);
                     printf("\n Resultat : \n");
                     printf(" -----------\n");
                     Affiche(&Tab3[0][0],n,n);
                     printf("\n");
                 break;
                 
            case '6':
                     MultMat(&Tab1[0][0],&Tab2[0][0],&Vect[0],n);
                     printf("\n Matrice 1 : \n");
                     printf(" -----------\n");
                     Affiche(&Tab1[0][0],n,n);
                     printf("\n");
                     printf("\n Matrice 2 : \n");
                     printf(" -----------\n");
                     Affiche(&Tab2[0][0],n,n);
                     printf("\n Vecteur : \n");
                     printf(" -----------\n");
                     Affiche(&Vect[0],n,1);
                 break;
            case '7': ;
             
        }
        
        if (choix!='7')
        {
            printf("\n\nRetour au menu ? [O/N] \n");
            fflush(stdin);
            scanf("%c",&retour);
            system("cls");
        }
        else
        {
            retour='n';
        }
        
    }
    
    system("pause");
    return(0);               
}
コード例 #5
0
ファイル: MatrizV1.cpp プロジェクト: JaumNetto/C
main()
{
	int mat[3][3], matB[3][3], matS[3][3], matM[3][3], somaDP, somaDS, maior, pares, op, idnt, op2;
	char resp;
	
	//Ler Matrizes inicial
		printf("Primeira Matriz!\n\n");
		lermat(mat);
		printf("\n\nSegunda Matriz!\n\n");
		lermat(matB);
	
	while(1)
	{
	
	//Switch escolha procedimento
		puts("**********MENU**********");
		puts("1- Somar Matrizes");
		puts("2- Multiplicar Matrizes");
		puts("3- Soma da Diagonal Principal");
		puts("4- Soma da Diagonal Secundaria");
		puts("5- Maior Valor da Matriz");
		puts("6- Quantidade de Pares na Matriz");
		puts("7- Verificar Identidade");
		puts("8- Exibir Matriz");
		puts("9- Inserir novas matrizes");
		
		printf("Digite a opcao:");
		scanf("%d", &op);
			if(op<1 || op>9)
				{
					puts("Opcao Invalida!0");
					printf("Digite sua opcao:");
					scanf("%d", &op);
				}
		
		switch(op)
		{
			case 1://Soma Matriz
				SomaMat(mat, matB, matS);
				exibemat(matS);
				break;
				
			case 2://Multiplica matriz
				MultMat(mat, matB, matM);
				exibemat(matM);
				break;
				
			case 3://Soma diagonal principal
				printf("\n\n-A soma da diagonal principal da matriz 1 eh: %d\n\n", diagP(mat));
				printf("\n\n-A soma da diagonal principal da matriz 2 eh: %d\n\n", diagP(matB));
				break;
				
			case 4://Soma diagonal secundaria
				printf("\n\n-A soma da diagonal secundaria da matriz 1 eh: %d\n\n", diagS(mat));
				printf("\n\n-A soma da diagonal secundaria da matriz 2 eh: %d\n\n", diagS(matB));
				break;
				
			case 5://Maior valor da matriz
				printf("\n\n-O maior valor da matriz 1 eh: %d\n\n", MaiorV(mat));
				printf("\n\n-O maior valor da matriz 2 eh: %d\n\n", MaiorV(matB));
				break;
				
			case 6://Pares na matriz
				printf("\n\n-Ha %d pares na matriz 1\n\n", ParesMat(mat));
				printf("\n\n-Ha %d pares na matriz 2\n\n", ParesMat(matB));
				break;
				
			case 7://Identidade
				idnt=IdentMat(mat);
					if(idnt==1)
						printf("\n\n-A matriz 1 eh identidade!!\n\n");
					else
						printf("\n\n-A matriz 1 nao eh identidade!!\n\n");
				
				idnt=IdentMat(matB);
					if(idnt==1)
						printf("\n\n-A matriz 2 eh identidade!!\n\n");
					else
						printf("\n\n-A matriz 2 nao eh identidade!!\n\n");
					break;
					
			case 8://Exibir matriz
				printf("\n\n\n");
				puts("1- Matriz 1");
				puts("2- Matriz 2");
				puts("3- Matriz Soma");
				puts("4- Matriz Multiplicacao");
				printf("\n\n\n");	
				
				printf("Digite qual exibir:");
				scanf("%d", &op2);
					
					if(op2==1)
						exibemat(mat);
						else if(op2==2)
								exibemat(matB);
								else if(op2==3)
										exibemat(matS);
										else
											exibemat(matM);
					break;
					
			case 9://Ler matriz
					printf("\n\nPrimeira Matriz!\n");
						lermat(mat);
					printf("\n\nSegunda Matriz!!\n");
						lermat(matB);
					break;
					
			default:
				printf("Nenhuma Opcao escolhida!");
				break;
		}
		
		printf("Deseja continuar?:(s/n):");
		fflush(stdin);
		scanf("%c", &resp);
			if(resp=='n')
				break;
		
	}
		
}//Fim do programa!