Anyone could lend me a quick hand?
I just ported a quick version of Pong (the game) for windows. However, this was all done on a virtual machine (win 2000) on Linux. So I can't be sure if it works on Win XP and Win Vista. Thus:
If you have a spare minute, and your machine is Win XP or Win Vista, could you quickly test if the game runs?
I will send the executable via email (so you will either have to PM me it, or post your email here).
Thanks in advance! [Smile]
I'd be happy to test in on XP and Server 2003, on one condition - post your source code for review so we can all be sure you're not doing anything devious [wink]
Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]
I have VMs setup for both XP and Win7, so I can see if it runs on those if you want to send me a copy.
-----OpenEndedAdventure.com - The Adventure that Anyone Can Edit.
Here is the source code:
And I wouldn't even dare to do anything devious. I am as sick of Trojans/Worms/Viruses/Malicious Software as everyone else here. [smile]
Please send me your email address via PM or post it here (I recommend PM, less chance of bots harvesting it). Thanks again for your help guys!
#include <iostream>#include <cmath>#include <SDL.h>#include <SDL_image.h>#include "bgeffect.cpp"//Namespaces...using namespace std;//Screen...const int SCREEN_WIDTH = 800;const int SCREEN_HEIGHT = 600;const int SCREEN_BPP = 16;const int FRAMES_PER_SECOND = 50;//Physics...const double FRICTION = .2;//Scoresint p1Score = 0;int p2Score = 0;//Player...const int PLAYER_SPEED_MAX = 20;const int PLAYER_SPEED_INCREASE = 3;const int PLAYER_BAT_HEIGHT = 80;double p1YVel = 0;double p1YPos = SCREEN_HEIGHT/2-PLAYER_BAT_HEIGHT/2;bool upPressed = false;bool downPressed = false;//p2double p2YVel = 0;double p2YPos = SCREEN_HEIGHT/2-PLAYER_BAT_HEIGHT/2;//Ball...const int BALL_MAXSPEED = 20;const int BALL_DIAMETER = 35;const double BALL_SPEED_INCREASE = 1;int BALL_FRAME = 0;const int BALL_MAXFRAME = 4;double ballXVel = 5;double ballYVel = 0;double ballXPos = SCREEN_WIDTH/2;double ballYPos = SCREEN_HEIGHT/2;int ballFrame = 0;//Borderconst int BORDER_THICKNESS = 40;//Surfaces...SDL_Surface *screen;SDL_Surface *background;SDL_Surface *border;SDL_Surface *ball;SDL_Surface *p1;SDL_Surface *p2;//Rectangles...SDL_Rect bgRect;SDL_Rect borderRect;SDL_Rect p1Rect;SDL_Rect p2Rect;SDL_Rect ballRect;SDL_Rect ballRectAnimation[5];//Events...SDL_Event event;//Functions...void loadImages();void render();void logic();void events();void startFPS();void endFPS();void startGame();void updateMovement();void AI();int ballCheckCollision();void resetBall();bool hitTest();void traceScores();void createAnimationRect();SDL_Surface *bgEffect1;SDL_Surface *bgEffect2;SDL_Surface *bgEffect3;SDL_Surface *bgEffect4;SDL_Surface *bgEffect5;class bgEffect { private: SDL_Rect bgEffectRect; bool effect1, effect2, effect3, effect4, effect5; int effect1Alpha, effect2Alpha, effect3Alpha, effect4Alpha, effect5Alpha; public: bool hit; int alphaIncreaseNumber, alphaDone; bool random(int); void show(); void play();};void bgEffect::show() { int randomNumber = (rand()%5)+1; switch(randomNumber) { /*case 1: SDL_BlitSurface(bgEffect1, NULL, screen, &bgEffectRect); break; case 2: SDL_BlitSurface(bgEffect2, NULL, screen, &bgEffectRect); break; case 3: SDL_BlitSurface(bgEffect3, NULL, screen, &bgEffectRect); break; case 4: SDL_BlitSurface(bgEffect4, NULL, screen, &bgEffectRect); break; case 5: SDL_BlitSurface(bgEffect5, NULL, screen, &bgEffectRect); break; */ case 1: effect1 = true; effect1Alpha = SDL_ALPHA_TRANSPARENT; break; case 2: effect2 = true; effect2Alpha = SDL_ALPHA_TRANSPARENT; break; case 3: effect3 = true; effect3Alpha = SDL_ALPHA_TRANSPARENT; break; case 4: effect4 = true; effect4Alpha = SDL_ALPHA_TRANSPARENT; break; case 5: effect5 = true; effect5Alpha = SDL_ALPHA_TRANSPARENT; break; default: break; }}void bgEffect::play() { alphaIncreaseNumber = 10; alphaDone = 100; if (effect1 == true) { if (effect1Alpha >= alphaDone) { effect1 = false; } else { effect1Alpha += alphaIncreaseNumber; SDL_SetAlpha(bgEffect1, SDL_SRCALPHA, effect1Alpha); SDL_BlitSurface(bgEffect1, NULL, screen, &bgEffectRect); } } if (effect2 == true) { if (effect2Alpha >= alphaDone) { effect2 = false; } else { effect2Alpha += alphaIncreaseNumber; SDL_SetAlpha(bgEffect2, SDL_SRCALPHA, effect2Alpha); SDL_BlitSurface(bgEffect2, NULL, screen, &bgEffectRect); } } if (effect3 == true) { if (effect3Alpha >= alphaDone) { effect3 = false; } else { effect3Alpha += alphaIncreaseNumber; SDL_SetAlpha(bgEffect3, SDL_SRCALPHA, effect3Alpha); SDL_BlitSurface(bgEffect3, NULL, screen, &bgEffectRect); } } if (effect4 == true) { if (effect4Alpha >= alphaDone) { effect4 = false; } else { effect4Alpha += alphaIncreaseNumber; SDL_SetAlpha(bgEffect4, SDL_SRCALPHA, effect4Alpha); SDL_BlitSurface(bgEffect4, NULL, screen, &bgEffectRect); } } if (effect5 == true) { if (effect5Alpha >= alphaDone) { effect5 = false; } else { effect5Alpha += alphaIncreaseNumber; SDL_SetAlpha(bgEffect5, SDL_SRCALPHA, effect5Alpha); SDL_BlitSurface(bgEffect5, NULL, screen, &bgEffectRect); } }}bgEffect bgEffectHandler;int main(int args, char* argv[]) { SDL_Init(SDL_INIT_VIDEO); SDL_WM_SetCaption("Pong", NULL); screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE); loadImages(); createAnimationRect(); startGame(); //Main Game loop... bool running = true; while (running) { events(); if (event.type == SDL_QUIT) { return 0; } logic(); render(); } return 0;}void startGame() { p1Rect.x = 20; p1YPos = SCREEN_HEIGHT / 2; p2Rect.x = SCREEN_WIDTH - 60; p2YPos = SCREEN_HEIGHT / 2; ballXPos = SCREEN_WIDTH/2; ballYPos = SCREEN_HEIGHT/2;}void loadImages() { background = IMG_Load("gfx/background/backgroundstatic.png"); border = IMG_Load("gfx/border.png"); ball = IMG_Load("gfx/ball/ball.png"); p1 = IMG_Load("gfx/p1.png"); p2 = IMG_Load("gfx/p2.png"); bgEffect1 = IMG_Load("gfx/background/frame1.png"); bgEffect2 = IMG_Load("gfx/background/frame2.png"); bgEffect3 = IMG_Load("gfx/background/frame3.png"); bgEffect4 = IMG_Load("gfx/background/frame4.png"); bgEffect5 = IMG_Load("gfx/background/frame5.png"); p1 = SDL_DisplayFormatAlpha(p1); ball = SDL_DisplayFormatAlpha(ball); bgEffect1 = SDL_DisplayFormat(bgEffect1); bgEffect2 = SDL_DisplayFormat(bgEffect2); bgEffect3 = SDL_DisplayFormat(bgEffect3); bgEffect4 = SDL_DisplayFormat(bgEffect4); bgEffect5 = SDL_DisplayFormat(bgEffect5);}void events() { while (SDL_PollEvent(&event)) { if (event.type == SDL_KEYDOWN) { switch (event.key.keysym.sym) { case SDLK_UP: upPressed = true; break; case SDLK_DOWN: downPressed = true; break; default: break; } } else if (event.type == SDL_KEYUP) { switch (event.key.keysym.sym) { case SDLK_UP: upPressed = false; break; case SDLK_DOWN: downPressed = false; break; default: break; } } }}void logic() { //Player Movement if (upPressed == true) { p1YVel -= PLAYER_SPEED_INCREASE; } if (downPressed == true) { p1YVel += PLAYER_SPEED_INCREASE; } //Check Maxspeeds... if (p1YVel > PLAYER_SPEED_MAX) { p1YVel = PLAYER_SPEED_MAX; } else if (p1YVel < -PLAYER_SPEED_MAX) { p1YVel = -PLAYER_SPEED_MAX; } if (p2YVel > PLAYER_SPEED_MAX) { p2YVel = PLAYER_SPEED_MAX; } else if (p2YVel < -PLAYER_SPEED_MAX) { p2YVel = -PLAYER_SPEED_MAX; } if (ballXVel > BALL_MAXSPEED) { ballXVel = BALL_MAXSPEED; } else if (ballXVel < -BALL_MAXSPEED) { ballXVel = -BALL_MAXSPEED; } if (ballYVel > BALL_MAXSPEED/2) { ballYVel = BALL_MAXSPEED/2; } else if (ballYVel < -BALL_MAXSPEED/2) { ballYVel = -BALL_MAXSPEED/2; } //movement ends updateMovement(); //AI AI(); //Collsion checks ballCheckCollision();}void AI() { if ((p2YPos + PLAYER_BAT_HEIGHT/2) < ballYPos-10) { p2YVel += PLAYER_SPEED_INCREASE; } if ((p2YPos + PLAYER_BAT_HEIGHT/2) > ballYPos+10) { p2YVel -= PLAYER_SPEED_INCREASE; }}void updateMovement() { //Player 1 p1YPos += p1YVel; p1Rect.y = floor(p1YPos+.5); //Player 2 p2YPos += p2YVel; p2Rect.y = floor(p2YPos+.5); //Ball ballXPos += ballXVel; ballYPos += ballYVel; ballRect.x = floor(ballXPos+.5); ballRect.y = floor(ballYPos+.5); //Friction p1YVel *= (1-FRICTION); if (p1YVel < .5 && p1YVel > -.5) { p1YVel = 0; } p2YVel *= (1-FRICTION); if (p2YVel < .5 && p2YVel > -.5) { p2YVel = 0; }}void render() { SDL_FillRect(screen, NULL, 0); SDL_BlitSurface(background, NULL, screen, &bgRect); if (bgEffectHandler.hit == true) { bgEffectHandler.show(); bgEffectHandler.hit = false; } bgEffectHandler.play(); SDL_BlitSurface(border, NULL, screen, &borderRect); SDL_BlitSurface(p1, NULL, screen, &p1Rect); SDL_BlitSurface(p2, NULL, screen, &p2Rect); SDL_BlitSurface(ball, &ballRectAnimation[BALL_FRAME], screen, &ballRect); BALL_FRAME++; if (BALL_FRAME > BALL_MAXFRAME) { BALL_FRAME = 0; } SDL_Flip(screen);}bool hitTest(SDL_Rect A, SDL_Rect B) { int leftA, leftB; int rightA, rightB; int topA, topB; int bottomA, bottomB; leftA = A.x; rightA = A.x + A.w; topA = A.y; bottomA = A.y + A.h; leftB = B.x; rightB = B.x + B.w; topB = B.y; bottomB = B.y + B.h; if( bottomA <= topB ) { return false; } if( topA >= bottomB ) { return false; } if( rightA <= leftB ) { return false; } if( leftA >= rightB ) { return false; } return true;}int ballCheckCollision() { //Check if we are hitting the top & bottom wall if (ballYPos > SCREEN_HEIGHT-BORDER_THICKNESS-BALL_DIAMETER) { ballYPos -= ballYVel; ballYVel = -ballYVel; } else if (ballYPos < BORDER_THICKNESS) { ballYPos -= ballYVel; ballYVel = -ballYVel; } //Check if we are out of the screen if (ballXPos < 0 || ballXPos > SCREEN_WIDTH) { resetBall(); } if (ballRect.x < SCREEN_WIDTH - 150 && ballRect.x > 150) { return 0; } if (ballRect.x > SCREEN_WIDTH/2) { if (hitTest(ballRect, p2Rect) == true) { ballXPos -= ballXVel; ballXVel += BALL_SPEED_INCREASE; ballXVel = -ballXVel; ballYVel += ((ballYPos + BALL_DIAMETER/2) - (p2YPos + PLAYER_BAT_HEIGHT/2))/10; bgEffectHandler.hit = true; } } else { if (hitTest(ballRect, p1Rect) == true) { ballXPos -= ballXVel; ballXVel -= BALL_SPEED_INCREASE; ballXVel = -ballXVel; ballYVel += ((ballYPos + BALL_DIAMETER/2) - (p1YPos + PLAYER_BAT_HEIGHT/2))/10; bgEffectHandler.hit = true; } } return 0;}void resetBall() { if (ballXPos > SCREEN_WIDTH/2) { p1Score++; } else { p2Score++; } traceScores(); ballXPos = SCREEN_WIDTH/2; ballYPos = SCREEN_HEIGHT/2; ballXVel = (random()%BALL_MAXSPEED)-BALL_MAXSPEED/2; ballYVel = (random()%(BALL_MAXSPEED/2))-BALL_MAXSPEED/4; while (ballXVel > -5 && ballXVel < 5) { ballXVel = (random()%(BALL_MAXSPEED*2))-BALL_MAXSPEED; }}void traceScores() { cout << "*** P1 SCORE: " << p1Score << " ***" << endl; cout << "*** P2 Score: " << p2Score << " ***" << endl << endl;}void createAnimationRect() { for (int i = 0; i < 5; i++) { ballRectAnimation.y = 0; ballRectAnimation.x = 40*i; ballRectAnimation.w = 40; ballRectAnimation.h = 40; }}
And I wouldn't even dare to do anything devious. I am as sick of Trojans/Worms/Viruses/Malicious Software as everyone else here. [smile]
Please send me your email address via PM or post it here (I recommend PM, less chance of bots harvesting it). Thanks again for your help guys!
Quote: Original post by pseudobot
Please send me your email address via PM or post it here (I recommend PM, less chance of bots harvesting it). Thanks again for your help guys!
Why not just post a link to the game so we can just download it???
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement