예제 #1
0
int mainLoop()
{   
    wchar_t ch = 0;
    int running = 1;
    int roundEnd = 0;

    int i = 0;
    while(running)
    {
        ch = getChar();
        if(ch == 27)
           break;

        /*
         * Rotates specified lines the
         * specified amount (in radians
         */
        rotateLine(line1,M_PI/1000);
        rotateLine(line2,M_PI/900);
        rotateLine(line3,-M_PI/900);

        /*
         * Firethruster handles input
         */
        fireThruster(ch);
        moveLander();

        /*
         * Time to sleep between frames
         */
        usleep(1000);

        if(roundEnd)
        {
            roundEnd = 0;
            clearPrintScreen();
            usleep(1000000);
            if(fuel < 0)
                running = 0;
        }

        /*
         * Convert fuel int to string 
         * and add to textVector
         */
        char fuelstr[7];
        sprintf(fuelstr,"%d",fuel_int);
        changeText(fuel,fuelstr);
        char scorestr[7];
        sprintf(scorestr,"%d",score_int);
        changeText(score,scorestr);

        draw();

        switch(detectWin(platform1,platform2))
        {
            case 0:
                break;
            case 1:
                printToScreen("Crashed!");
                draw();
                resetLander();
                roundEnd = 1;
                break;
            case 21:
                printToScreen("Landed too hard :( -100 fuel");
                score_int += 50;
                fuel_int -= 100;
                draw();
                resetLander();
                roundEnd = 1;
                break;
            case 22:
                printToScreen("Landed too hard :( -100 fuel");
                score_int += 75;
                fuel_int -= 100;
                draw();
                resetLander();
                roundEnd = 1;
                break;
            case 31:
                printToScreen("PERFECT LANDING!");
                score_int += 300;
                draw();
                resetLander();
                roundEnd = 1;
                break;
            case 32:
                printToScreen("PERFECT LANDING!");
                score_int += 200;
                draw();
                resetLander();
                roundEnd = 1;
                break;
            case 4:
                printToScreen("Out of fuel!");
                draw();
                resetLander();
                roundEnd = 1;
        }

    }
    exitVect();
    return 0;
}
예제 #2
0
int main(int argc, char *argv[])
{
	SDL_Init(SDL_INIT_VIDEO);
	displayWindow = SDL_CreateWindow("My Game", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_OPENGL);
	SDL_GLContext context = SDL_GL_CreateContext(displayWindow);
	SDL_GL_MakeCurrent(displayWindow, context);
	#ifdef _WINDOWS
		glewInit();
	#endif

	glViewport(0, 0, 1280, 720);

	ShaderProgram program(RESOURCE_FOLDER"vertex.glsl", RESOURCE_FOLDER"fragment.glsl");

	Entity rightpaddle(program);
	rightpaddle.moveRight(1.50);

	Entity ball(program);

	Entity leftpaddle(program);
	leftpaddle.moveLeft(1.50);

	Time counter;
	float elapsed;

	float paddleVertex[] = { -0.025, -0.175,
		0.025, -0.175,
		0.025, 0.175,
		-0.025, -0.175,
		0.025, 0.175,
		-0.025, 0.175
	};

	float ballVertex[] = { -0.035, -0.035,
		0.035, -0.035,
		0.035, 0.035,
		-0.035, -0.035,
		0.035, 0.035,
		-0.035, 0.035
	};

	SDL_Event event;
	bool done = false;
	while (!done) {
		while (SDL_PollEvent(&event)) {
			if (event.type == SDL_QUIT || event.type == SDL_WINDOWEVENT_CLOSE) {
				done = true;
			}
		}
		glClear(GL_COLOR_BUFFER_BIT);

		elapsed = counter.getTime();

		rightpaddle.setMatrix();
		rightpaddle.Draw(paddleVertex);

		ball.setMatrix();
		ball.Draw(ballVertex);

		leftpaddle.setMatrix();
		leftpaddle.Draw(paddleVertex);

		detectCollision(ball, leftpaddle, rightpaddle, elapsed);
		
		movePaddles(leftpaddle, rightpaddle, elapsed);
		moveBall(ball, elapsed);

		detectWin(ball, elapsed);

		SDL_GL_SwapWindow(displayWindow);// keep at bottom
	}

	SDL_Quit();
	return 0;
}
예제 #3
0
void singlePlayer(void){
    // declarations
    unsigned char keepGoing, nextRow, nextCol, playerTurn;
    char nextMove[BUF_SIZE];

    unsigned char win = 0; // 1 for player got three in a row, 0 otherwise
    unsigned char turnNum = 0; // 1 to n^2 for total turns
    
    unsigned char ticTacToeTable[N][N];
    
    // intialize and display ticTacToe array
    clearTwoDimArray(ticTacToeTable);
    printTwoDimArray(ticTacToeTable);
    
    // first, randomly decide who is going first, human or player
    srand(time(NULL));
    playerTurn = rand() % 2;

    // loop until a player wins or maximum amount of turns reached
    while(!win && turnNum++ < N*N)
    {
        // alternate between players
        switch(playerTurn)
        {
            case 0: // computer turn
                printf("Computer's Turn %d\n", turnNum);

                // calculate next best position to move
                AIplace(ticTacToeTable, nextMove);
 
             // set to player's turn
                playerTurn = 1;
                break;
            case 1:
                printf("Player's Turn %d\n", turnNum);
	do{
                    // accept user input for row and column
                    printf("Enter a row and column (1 to 3) to place, in that\n");
                    printf("order, with a dash in between the two numbers.\n");

                    scanf("%s", nextMove);
                    
                    // validate input
                    keepGoing = !validInput(nextMove, ticTacToeTable, turnNum);
                } while(keepGoing);


                // set to computer's turn
                playerTurn = 0;
                break;
            default:
                break;
        }

        nextRow = nextMove[0] - '1';
        nextCol = nextMove[2] - '1';

        // update tic tac toe table
        ticTacToeTable[nextRow][nextCol] = turnNum;

        // check for win
        win = detectWin(ticTacToeTable);
        // print tic tac toe table
        printTwoDimArray(ticTacToeTable);
    }

    if(win)
        printf("WINNER WINNER CHICKEN DINNER!!\n");
    else
        printf("NO WINNER!!\n"); 
}