Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SDL_App.cpp : Defines the entry point for our Project
- //
- //#include "stdafx.h"
- #include <Windows.h>
- #include "GL_Functions.h"
- #include "pctimer.h"
- #include <string>
- #include <cmath>
- #include <iostream>
- #include <crtdbg.h>
- #include "Game.h"
- #include "Ball.h"
- //#include "AIECollision.h"
- //#include "DLLInclude.h"
- //#include "Vector2.h"
- using namespace std;
- //Prototype / Lets main see gameloop as defined below
- void GameLoop();
- int main(int argc, char* argv[])
- {
- //Lets open the window and initialise opengl
- //Using NOT magic numbers to define the size....
- InitGL(SCREEN_WIDTH,SCREEN_HEIGHT);
- do
- {
- //Clear the screen, so previous frames don't build up
- ClearScreen();
- //run gameloop until i say otherwise!
- GameLoop();
- break;
- //Stop it from running too fast! Sleep ZZzzz
- //Sleep(5);
- } while (FrameworkUpdate()); //Do some secret stuff,
- //Close down
- CloseDown();
- _CrtDumpMemoryLeaks();
- //Quit!
- return 0;
- }
- void GameLoop()
- {
- //Define Declarations
- float fScoreX = 64;
- float fScoreY = 64;
- const float fSpeed = 0.3f;
- bool bWin = false;
- bool bGameOver = false;
- int bgtex = LoadTexture("./images/Bg.png");
- int menutex = LoadTexture("./images/Menu.png");
- int balltex = LoadTexture("./images/BrainBall.png");
- int cursortex = LoadTexture("./images/Cursor.png");
- int paddletex = LoadTexture("./images/RightPaddle.png");
- int howtoplaytex = LoadTexture("./images/HowtoPlay.png");
- int player1win = LoadTexture("./images/Player1Win.png");
- int player2win = LoadTexture("./images/Player2Win.png");
- //numbers for scores
- int iScore0 = LoadTexture("./images/Score0.png");
- int iScore1 = LoadTexture("./images/Score1.png");
- int iScore2 = LoadTexture("./images/Score2.png");
- int iScore3 = LoadTexture("./images/Score3.png");
- int iScore4 = LoadTexture("./images/Score4.png");
- int iScore5 = LoadTexture("./images/Score5.png");
- int iScore6 = LoadTexture("./images/Score6.png");
- //score array
- //int iScore = 0;
- int iScoreL = 0;
- int iScoreR = 0;
- int iScoreLeft[] = {iScore0, iScore1, iScore2, iScore3, iScore4, iScore5, iScore6};
- int iScoreRight[] = {iScore0, iScore1, iScore2, iScore3, iScore4, iScore5, iScore6};
- //defines the structs for use in gameloop
- sScreen screen = {SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, SCREEN_WIDTH , SCREEN_HEIGHT, bgtex};
- sScore score1 = {SCREEN_WIDTH / 3, SCREEN_HEIGHT / 7, fScoreX, fScoreY, iScoreLeft[iScoreL]};
- sScore score2 = {(SCREEN_WIDTH / 3 * 2), SCREEN_HEIGHT / 7, fScoreX, fScoreY, iScoreRight[iScoreR]};
- sBall ball = {SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 + 75, 0.5, 0.5, 16, fSpeed, balltex};
- sPaddle paddle1 = {100, SCREEN_HEIGHT / 2 + 75, 96, 24, fSpeed, 'w', 's', paddletex};
- sPaddle paddle2 = {924, SCREEN_HEIGHT / 2 + 75, 96, 24, fSpeed, KEY_UP, KEY_DOWN, paddletex};
- //sScreen screen = {0, 0, SCREEN_WIDTH , SCREEN_HEIGHT, LoadTexture("./images/Bg.png")};
- //End Define
- do
- {
- //Clear the screen, so previous frames don't build up
- //ClearScreen();
- //Logic
- //the escape key ends the gameloop
- if (IsKeyDown(KEY_ESCAPE))
- {
- break;
- }
- //function for paddle behaviour and ball movement/collision
- PaddleMove(paddle1);
- PaddleMove(paddle2);
- BallCollide(paddle1, paddle2, ball);
- BallAct(ball);
- //int iScoreL = 0;
- //int iScoreR = 0;
- if ( bWin == false )
- {
- if ( iScoreL < 6 && iScoreR < 6)
- {
- //Score left on screen exit
- if ( ball.fPosX <= BORDER_SIDE)
- {
- score2.iSprite = iScoreLeft[++iScoreL];
- ball.fPosX = (SCREEN_WIDTH / 2);
- ball.fPosY = (SCREEN_HEIGHT / 2 + 75);
- ball.fDirX *= -1;
- Sleep(500);
- }
- //Score right on screen exit
- if ( ball.fPosX >= SCREEN_WIDTH - BORDER_SIDE)
- {
- score1.iSprite = iScoreRight[++iScoreR];
- ball.fPosX = (SCREEN_WIDTH / 2);
- ball.fPosY = (SCREEN_HEIGHT / 2 + 75);
- ball.fDirX *= -1;
- Sleep(500);
- }
- //break;
- }
- if ( iScoreL >= 6 || iScoreR >= 6 )
- {
- bWin = true;
- }
- }
- //End Logic
- //Draw on screen
- //draws the screen, ball and paddles
- DrawSpriteRotated(screen.iSprite, screen.x, screen.y, screen.fWidth, screen.fHeight, 0);
- DrawSpriteRotated(score1.iSprite, score1.x, score1.y, score1.fWidth, score1.fHeight, 0);
- DrawSpriteRotated(score2.iSprite, score2.x, score2.y, score2.fWidth, score2.fHeight, 0);
- DrawSpriteRotated(ball.iSprite, ball.fPosX, ball.fPosY, ball.fDiameter, ball.fDiameter, 0);
- DrawSpriteRotated(paddle1.iSprite, paddle1.fPosX, paddle1.fPosY, paddle1.fWidth, paddle1.fHeight, 0);
- DrawSpriteRotated(paddle2.iSprite, paddle2.fPosX, paddle2.fPosY, paddle2.fWidth, paddle2.fHeight, 0);
- if (bWin == true && bGameOver == false)
- {
- if ( iScoreL == 6 )
- {
- //Clear the screen, to show win
- //ClearScreen();
- DrawSpriteRotated(player2win, screen.x, screen.y, screen.fWidth, screen.fHeight, 0);
- FrameworkUpdate();
- Sleep(5000);
- bGameOver = true;
- }
- if ( iScoreR == 6 )
- {
- //Clear the screen, to show win
- //ClearScreen();
- DrawSpriteRotated(player1win, screen.x, screen.y, screen.fWidth, screen.fHeight, 0);
- FrameworkUpdate();
- Sleep(5000);
- bGameOver = true;
- }
- //system ("Pause");
- //break;
- }
- if ( bGameOver == true )
- {
- ClearScreen();
- int iScoreL = 0;
- int iScoreR = 0;
- bGameOver = false;
- GameLoop();
- //break;
- }
- //End Draw on screen
- //Stop it from running too fast! Sleep ZZzzz
- //Sleep(25);
- } while (FrameworkUpdate()); //Do some secret stuff,
- //free textures from memory
- FreeTexture(bgtex);
- FreeTexture(menutex);
- FreeTexture(balltex);
- FreeTexture(paddletex);
- FreeTexture(iScore0);
- FreeTexture(iScore1);
- FreeTexture(iScore2);
- FreeTexture(iScore3);
- FreeTexture(iScore4);
- FreeTexture(iScore5);
- FreeTexture(iScore6);
- FreeTexture(player1win);
- FreeTexture(player2win);
- FreeTexture(cursortex);
- FreeTexture(howtoplaytex);
- }
Add Comment
Please, Sign In to add comment