Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) PokeVolley source code (version 2.0)

 

PokeVolley version 2.0 source code.

 

Operating system: Windows XP

IDE: C++ Builder 6.0 Enterprise Edition

Project type: GUI application

Compiler: supplied with C++ Builder 6.0 Enterprise Edition

Libraries used:

 

 

 

 

 

ProjectPokeVolley.cpp

 

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("UnitFormMain.cpp", FormMain);
USEFORM("UnitFormSprites.cpp", FormSprites);
USEFORM("UnitFormMenu.cpp", FormMenu);
USEFORM("UnitFormAbout.cpp", FormAbout);
USEFORM("UnitFormWhatsNew.cpp", FormWhatsNew);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
  try
  {
     Application->Initialize();
     Application->Title = "PokeVolley";
     Application->CreateForm(__classid(TFormMenu), &FormMenu);
                 Application->CreateForm(__classid(TFormSprites), &FormSprites);
                 Application->Run();
  }
  catch (Exception &exception)
  {
     Application->ShowException(&exception);
  }
  catch (...)
  {
     try
     {
       throw Exception("");
     }
     catch (Exception &exception)
     {
       Application->ShowException(&exception);
     }
  }
  return 0;
}
//---------------------------------------------------------------------------

 

 

 

 

 

UnitFormAbout.cpp

 

//---------------------------------------------------------------------------
/*
  PokeVolley, Pokemon volleyball game
  Copyright (C) 2005  Richel Bilderbeek

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include <boost/scoped_ptr.hpp>
#include "UnitFormAbout.h"
#include "UnitFormWhatsNew.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormAbout *FormAbout;
//---------------------------------------------------------------------------
__fastcall TFormAbout::TFormAbout(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFormAbout::ButtonWhatsNewClick(TObject *Sender)
{
  boost::scoped_ptr<TFormWhatsNew> f(new TFormWhatsNew(0));
  f->ShowModal();
}
//---------------------------------------------------------------------------

 

 

 

 

 

UnitFormAbout.h

 

//---------------------------------------------------------------------------
/*
  PokeVolley, Pokemon volleyball game
  Copyright (C) 2005  Richel Bilderbeek

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#ifndef UnitFormAboutH
#define UnitFormAboutH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
class TFormAbout : public TForm
{
__published: // IDE-managed Components
        TImage *Image1;
        TImage *Image2;
        TImage *Image3;
        TImage *Image4;
        TImage *Image5;
        TImage *Image6;
        TRichEdit *RichEdit1;
        TButton *ButtonWhatsNew;
        TImage *ImageBallR;
        TImage *ImageBallG;
        TImage *ImageBallB;
        TImage *Image7;
        TImage *Image8;
        void __fastcall ButtonWhatsNewClick(TObject *Sender);
private: // User declarations
public: // User declarations
        __fastcall TFormAbout(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormAbout *FormAbout;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormMain.cpp

 

//---------------------------------------------------------------------------
/*
  PokeVolley, Pokemon volleyball game
  Copyright (C) 2005  Richel Bilderbeek

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <cassert>
#include "UnitFormMain.h"
#include "UnitFormSprites.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormMain *FormMain;
//---------------------------------------------------------------------------
#include <algorithm>
//---------------------------------------------------------------------------
__fastcall TFormMain::TFormMain(TComponent* Owner)
  : TForm(Owner),
  mKeyA(false),
  mKeyD(false),
  mKeyW(false),
  mKeyLeft(false),
  mKeyRight(false),
  mKeyUp(false),
  mScoreLeft(0),
  mScoreRight(0),
  mPlayerLeftJumps(false),
  mPlayerRightJumps(false),
  mPlayerLeftX(0),
  mPlayerLeftY(ClientHeight - ImagePlayer1->Height),
  mPlayerRightX(ClientWidth - ImagePlayer2->Width),
  mPlayerRightY(ClientHeight - ImagePlayer2->Height),
  mPlayerLeftSpeedY(0.0),
  mPlayerRightSpeedY(0.0)
{
  assert(FormSprites);

  //Load all images
  ImageBasket1->Picture = FormSprites->ImageBasket1_0->Picture;
  ImageBasket2->Picture = FormSprites->ImageBasket2_0->Picture;
  ImageBackground->Picture = FormSprites->ImageBackground->Picture;
  ImageBuffer->Picture = FormSprites->ImageBackground->Picture;
  ImagePlayer1->Picture = FormSprites->ImagePlayer1->Picture;
  ImagePlayer2->Picture = FormSprites->ImagePlayer2->Picture;
  ImageBall->Picture = FormSprites->ImageBallR->Picture;

  resetCoordinats();



}
//---------------------------------------------------------------------------
void TFormMain::resetCoordinats()
{
  //Set coordinats
  mBallX = (ClientWidth / 2) - (ImageBall->Width / 2);
  mBallY = 0.0;
  mBallSpeedX = (static_cast<double>(rand()%100)/10.0)-5.0;
  mBallSpeedY = 0.0;

  ImageBasket1->Left = 0;
  ImageBasket1->Top = (ClientHeight / 2) - (ImageBasket1->Height / 2);
  ImageBasket2->Left = ClientWidth - ImageBasket2->Width;
  ImageBasket2->Top = (ClientHeight / 2) - (ImageBasket2->Height / 2);

  Caption = "PokeVolley (C) 2005 Richel Bilderbeek: " + IntToStr(mScoreLeft) + " : " + IntToStr(mScoreRight);
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::FormKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
  switch(Key)
  {
    case 65: //A: Left
      mKeyA = true; mKeyD = false; break;
    case 87: //W: Up
      mKeyW = true; mKeyS = false; break;
    case 68: //D: Right
      mKeyD = true; mKeyA = false; break;
    case 83: //S: Down
      mKeyS = true; mKeyW = false; break;
    case VK_LEFT:
      mKeyLeft = true; mKeyRight = false; break;
    case VK_UP:
      mKeyUp = true; mKeyDown = false; break;
    case VK_RIGHT:
      mKeyRight = true; mKeyLeft = false; break;
    case VK_DOWN:
      mKeyDown = true; mKeyUp = false; break;
  }
}
//---------------------------------------------------------------------------
void TFormMain::processKeys()
{
  if (mKeyA == true)
  {
    mPlayerLeftSpeedX -= 1.0;
  }
  if (mKeyD == true)
  {
    mPlayerLeftSpeedX += 1.0;
  }
  if (mKeyW == true)
  {
    if (mPlayerLeftJumps==false)
    {
      mPlayerLeftJumps = true;
      ImagePlayer1->Picture = FormSprites->ImagePlayer1Jump->Picture;
      mPlayerLeftY -=50;
      mPlayerLeftSpeedY = -20.0;
    }
  }
  if (mKeyS == true)
  {
    if (mPlayerLeftJumps==true) mPlayerLeftSpeedY += 0.5;
  }
  if (mKeyLeft == true)
  {
    mPlayerRightSpeedX -= 1.0;
  }
  if (mKeyRight == true)
  {
    mPlayerRightSpeedX += 1.0;
  }
  if (mKeyUp == true)
  {
    if (mPlayerRightJumps==false)
    {
      mPlayerRightJumps = true;
      ImagePlayer2->Picture = FormSprites->ImagePlayer2Jump->Picture;
      mPlayerRightY -=50;
      mPlayerRightSpeedY = -20.0;
    }
  }
  if (mKeyDown == true)
  {
    if (mPlayerRightJumps==true) mPlayerRightSpeedY += 0.5;
  }


}
//---------------------------------------------------------------------------
void TFormMain::moveBall()
{
  mBallX += mBallSpeedX;
  mBallY += mBallSpeedY;
  mBallSpeedY += 0.5;

  if (mBallX < 0)
  {
    mBallSpeedX = -mBallSpeedX;
    mBallX = 0.0;
  }
  if (mBallY < 0)
  {
    mBallSpeedY = -mBallSpeedY;
    mBallY = 0.0;
  }
  if (mBallX + ImageBall->Width > ClientWidth)
  {
    mBallSpeedX = -mBallSpeedX;
    mBallX = ClientWidth - ImageBall->Width;
  }
  if (mBallY + ImageBall->Height > ClientHeight)
  {
    mBallSpeedY = -mBallSpeedY;
    mBallY = ClientHeight - ImageBall->Height;
  }

  ImageBall->Left = mBallX;
  ImageBall->Top = mBallY;
}
//---------------------------------------------------------------------------
void TFormMain::movePlayers()
{
  //Friction
  mPlayerLeftSpeedX *=0.95;
  mPlayerRightSpeedX *=0.95;

  //Gravity
  if (mPlayerLeftJumps == true) mPlayerLeftSpeedY +=0.5;
  if (mPlayerRightJumps == true) mPlayerRightSpeedY +=0.5;

  mPlayerLeftX  += mPlayerLeftSpeedX;
  mPlayerRightX += mPlayerRightSpeedX;
  mPlayerLeftY  += mPlayerLeftSpeedY;
  mPlayerRightY += mPlayerRightSpeedY;

  if (mPlayerLeftX < 0)
  {  //Player left leaves screen on left side
    mPlayerLeftX = 0;
    mPlayerLeftSpeedX = ( mPlayerLeftSpeedX < 0 ? -mPlayerLeftSpeedX : mPlayerLeftSpeedX);
  }

  if (mPlayerRightX < 0)
  {  //Player right leaves screen on left side
    mPlayerRightX = 0;
    mPlayerRightSpeedX = ( mPlayerRightSpeedX < 0 ? -mPlayerRightSpeedX : mPlayerRightSpeedX);
  }

  if (mPlayerLeftX + ImagePlayer1->Width > ClientWidth)
  {  //Player left leaves screen on right side
    mPlayerLeftX = ClientWidth - ImagePlayer1->Width;
    mPlayerLeftSpeedX = ( mPlayerLeftSpeedX > 0 ? -mPlayerLeftSpeedX : mPlayerLeftSpeedX);
  }

  if (mPlayerRightX + ImagePlayer2->Width > ClientWidth)
  {  //Player right leaves screen on right side
    mPlayerRightX = ClientWidth - ImagePlayer2->Width;
    mPlayerRightSpeedX = ( mPlayerRightSpeedX > 0 ? -mPlayerRightSpeedX : mPlayerRightSpeedX);
  }


  if (mPlayerLeftY < 0)
  { //Player left leaves screen with head
    mPlayerLeftSpeedY = -mPlayerLeftSpeedY;
    mPlayerLeftY = 0.0;
  }
  if (mPlayerRightY < 0)
  { //Player right leaves screen with head
    mPlayerRightSpeedY = -mPlayerRightSpeedY;
    mPlayerRightY = 0.0;
  }
  if (mPlayerLeftY + ImagePlayer1->Height > ClientHeight)
  { //Player left leaves screen with feet
    mPlayerLeftSpeedY = 0.0;
    mPlayerLeftJumps = false;
    ImagePlayer1->Picture = FormSprites->ImagePlayer1->Picture;
    mPlayerLeftY = ClientHeight - ImagePlayer1->Height;
  }
  if (mPlayerRightY + ImagePlayer2->Height > ClientHeight)
  { //Player right leaves screen with feet
    mPlayerRightSpeedY = 0.0;
    mPlayerRightJumps = false;
    ImagePlayer2->Picture = FormSprites->ImagePlayer2->Picture;
    mPlayerRightY = ClientHeight - ImagePlayer2->Height;
  }

  ImagePlayer1->Left  = mPlayerLeftX;
  ImagePlayer2->Left = mPlayerRightX;
  ImagePlayer1->Top  = mPlayerLeftY;
  ImagePlayer2->Top = mPlayerRightY;

}
//---------------------------------------------------------------------------
void TFormMain::detectCollision()
{
  TRect rect;

  //Check collision of player left and ball
  IntersectRect(rect,ImageBall->BoundsRect, ImagePlayer1->BoundsRect);
  if (IsRectEmpty(rect)==false)
  {
    //Change the direction
    if (rect.Width() > rect.Height())
    { //Vertical collision
      if (mPlayerLeftSpeedY==0.0)
      { //Bounce on head
        mBallSpeedY = -mBallSpeedY;
      }
      else
      {
        std::swap(mBallSpeedY,mPlayerLeftSpeedY);

      }
      //Bounce ball
      //mBallSpeedY = -mBallSpeedY;
      mBallSpeedX += random(3)-1;
      //Bounce player
      //mPlayerLeftSpeedY = -mPlayerLeftSpeedY;
    }
    else
    { //Horizontal collision
      std::swap(mBallSpeedX,mPlayerLeftSpeedX);
      if (mBallSpeedX > 0 && mPlayerLeftSpeedX > 0) mPlayerLeftSpeedX = -mPlayerLeftSpeedX;
      if (mBallSpeedX < 0 && mPlayerLeftSpeedX < 0) mPlayerLeftSpeedX = -mPlayerLeftSpeedX;
      //Bounce ball
      //mBallSpeedX = -mBallSpeedX;
      mBallSpeedY += random(3)-1;
      //Push player
      ImagePlayer1->Left += ( ImageBall->Left < ImagePlayer1->Left ? 10 : -10);
    }
    //Move the ball
    mBallX += mBallSpeedX; mBallY += mBallSpeedY;
  }

  //Check collision of player right and ball
  IntersectRect(rect,ImageBall->BoundsRect, ImagePlayer2->BoundsRect);
  if (IsRectEmpty(rect)==false)
  {
    //Change the direction
    if (rect.Width() > rect.Height())
    { //Vertical collision
      if (mPlayerRightSpeedY==0.0)
      { //Bounce on head
        mBallSpeedY = -mBallSpeedY;
      }
      else
      {
        std::swap(mBallSpeedY,mPlayerRightSpeedY);
      }
      //mBallSpeedY = -mBallSpeedY;
      mBallSpeedX += random(3)-1;
      //Bounce player
      //mPlayerRightSpeedY = -mPlayerRightSpeedY;
    }
    else
    { //Horizonal collision
      std::swap(mBallSpeedX,mPlayerRightSpeedX);
      if (mBallSpeedX > 0 && mPlayerRightSpeedX > 0) mPlayerRightSpeedX = -mPlayerRightSpeedX;
      if (mBallSpeedX < 0 && mPlayerRightSpeedX < 0) mPlayerRightSpeedX = -mPlayerRightSpeedX;
      //mBallSpeedX = -mBallSpeedX;
      mBallSpeedY += random(3)-1;
      //Push the player
      ImagePlayer2->Left += ( ImageBall->Left < ImagePlayer2->Left ? 10 : -10);
    }
    //Move the ball
    mBallX += mBallSpeedX; mBallY += mBallSpeedY;
  }

  //Check collision of basket left and ball
  IntersectRect(rect,ImageBasket1->BoundsRect, ImageBall->BoundsRect);
  if (IsRectEmpty(rect)==false)
  { //Right player has scored
    ++mScoreRight;
    resetCoordinats();
  }
  IntersectRect(rect,ImageBasket2->BoundsRect, ImageBall->BoundsRect);
  if (IsRectEmpty(rect)==false)
  { //Right player has scored
    ++mScoreLeft;
    resetCoordinats();
  }

}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormKeyUp(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
  switch(Key)
  {
    case 65: mKeyA = false; break;
    case 68: mKeyD = false; break;
    case 83: mKeyS = false; break;
    case 87: mKeyW = false; break;
    case VK_LEFT: mKeyLeft = false; break;
    case VK_RIGHT: mKeyRight = false; break;
    case VK_UP: mKeyUp = false; break;
    case VK_DOWN: mKeyDown = false; break;
  }

}
//---------------------------------------------------------------------------
void __fastcall TFormMain::Timer1Timer(TObject *Sender)
{
  moveBall();
  processKeys();
  movePlayers();
  detectCollision();

  //Draw ImageBackground on ImageBuffer
  ImageBuffer->Canvas->Draw(0,0,ImageBackground->Picture->Graphic);
  //Draw Baskets on ImageBuffer
  ImageBuffer->Canvas->Draw(ImageBasket1->Left,ImageBasket1->Top,GetRandomBasket1()->Picture->Graphic);
  ImageBuffer->Canvas->Draw(ImageBasket2->Left,ImageBasket2->Top,GetRandomBasket2()->Picture->Graphic);
  //Draw Squirtles and ball on ImageBuffer
  ImageBuffer->Canvas->Draw(ImagePlayer1->Left, ImagePlayer1->Top,ImagePlayer1->Picture->Graphic);
  ImageBuffer->Canvas->Draw(ImagePlayer2->Left, ImagePlayer2->Top,ImagePlayer2->Picture->Graphic);
  ImageBuffer->Canvas->Draw(ImageBall->Left, ImageBall->Top, ImageBall->Picture->Graphic);
  //Draw ImageBuffer on Form
  Canvas->Draw(0,0,ImageBuffer->Picture->Graphic);
        
}
//---------------------------------------------------------------------------
const Extctrls::TImage * TFormMain::GetRandomBasket1() const
{
  switch (std::rand() % 3)
  {
    case 0: return FormSprites->ImageBasket1_0;
    case 1: return FormSprites->ImageBasket1_1;
    case 2: return FormSprites->ImageBasket1_2;
  }
  assert(!"Should not get here");
  return 0;
}
//---------------------------------------------------------------------------
const Extctrls::TImage * TFormMain::GetRandomBasket2() const
{
  switch (std::rand() % 3)
  {
    case 0: return FormSprites->ImageBasket2_0;
    case 1: return FormSprites->ImageBasket2_1;
    case 2: return FormSprites->ImageBasket2_2;
  }
  assert(!"Should not get here");
  return 0;
}
//---------------------------------------------------------------------------




 

 

 

 

 

UnitFormMain.h

 

//---------------------------------------------------------------------------
/*
  PokeVolley, Pokemon volleyball game
  Copyright (C) 2005  Richel Bilderbeek

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#ifndef UnitFormMainH
#define UnitFormMainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
#include <AppEvnts.hpp>
#include <ImgList.hpp>
//---------------------------------------------------------------------------
class TFormMain : public TForm
{
__published: // IDE-managed Components
        TImage *ImagePlayer2;
        TImage *ImageBall;
        TImage *ImagePlayer1;
        TImage *ImageBackground;
        TImage *ImageBuffer;
        TImage *ImageBasket1;
        TImage *ImageBasket2;
        TTimer *Timer1;
  void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
  void __fastcall FormKeyUp(TObject *Sender, WORD &Key, TShiftState Shift);
        void __fastcall Timer1Timer(TObject *Sender);
private: // User declarations
  bool mKeyA, mKeyD, mKeyLeft, mKeyRight, mKeyW, mKeyUp, mKeyS, mKeyDown;

  double mBallX, mBallY;
  double mBallSpeedX, mBallSpeedY;

  double mPlayerLeftX, mPlayerLeftY;
  double mPlayerRightX, mPlayerRightY;
  double mPlayerLeftSpeedX, mPlayerLeftSpeedY;
  double mPlayerRightSpeedX, mPlayerRightSpeedY;
  bool mPlayerLeftJumps, mPlayerRightJumps;

  int mScoreLeft, mScoreRight;
  void resetCoordinats();
  void moveBall();
  void movePlayers();
  void detectCollision();
  void processKeys();
  const Extctrls::TImage * GetRandomBasket1() const;
  const Extctrls::TImage * GetRandomBasket2() const;
public: // User declarations
  __fastcall TFormMain(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormMain *FormMain;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormMenu.cpp

 

//---------------------------------------------------------------------------
/*
  PokeVolley, Pokemon volleyball game
  Copyright (C) 2005  Richel Bilderbeek

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include <boost/scoped_ptr.hpp>
#include "UnitFormMenu.h"
#include "UnitFormMain.h"
#include "UnitFormAbout.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormMenu *FormMenu;
//---------------------------------------------------------------------------
__fastcall TFormMenu::TFormMenu(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFormMenu::OnStartClick(TObject *Sender)
{
  boost::scoped_ptr<TFormMain> f(new TFormMain(0));
  f->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TFormMenu::OnAboutClick(TObject *Sender)
{
  boost::scoped_ptr<TFormAbout> f(new TFormAbout(0));
  f->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TFormMenu::Image8Click(TObject *Sender)
{
  Close();        
}
//---------------------------------------------------------------------------

 

 

 

 

 

UnitFormMenu.h

 

//---------------------------------------------------------------------------
/*
  PokeVolley, Pokemon volleyball game
  Copyright (C) 2005  Richel Bilderbeek

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#ifndef UnitFormMenuH
#define UnitFormMenuH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
class TFormMenu : public TForm
{
__published: // IDE-managed Components
        TImage *Image3;
        TImage *Image5;
        TImage *Image6;
        TImage *Image7;
        TImage *Image8;
        TImage *Image1;
        TImage *Image2;
        void __fastcall OnStartClick(TObject *Sender);
        void __fastcall OnAboutClick(TObject *Sender);
        void __fastcall Image8Click(TObject *Sender);
private: // User declarations
public: // User declarations
        __fastcall TFormMenu(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormMenu *FormMenu;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormSprites.cpp

 

//---------------------------------------------------------------------------
/*
  PokeVolley, Pokemon volleyball game
  Copyright (C) 2005  Richel Bilderbeek

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "UnitFormSprites.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormSprites *FormSprites;
//---------------------------------------------------------------------------
__fastcall TFormSprites::TFormSprites(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

 

 

 

 

 

UnitFormSprites.h

 

//---------------------------------------------------------------------------
/*
  PokeVolley, Pokemon volleyball game
  Copyright (C) 2005  Richel Bilderbeek

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#ifndef UnitFormSpritesH
#define UnitFormSpritesH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
class TFormSprites : public TForm
{
__published: // IDE-managed Components
        TImage *ImageBallR;
        TImage *ImageBallG;
        TImage *ImageBallB;
        TImage *ImagePlayer1;
        TImage *ImagePlayer1Jump;
        TImage *ImagePlayer2;
        TImage *ImagePlayer2Jump;
        TImage *ImageBasket2_0;
        TImage *ImageBasket2_1;
        TImage *ImageBasket2_2;
        TImage *ImageBasket1_2;
        TImage *ImageBasket1_1;
        TImage *ImageBasket1_0;
        TImage *ImageBackground;
        TImage *Image7;
        TImage *Image1;
private: // User declarations
public: // User declarations
        __fastcall TFormSprites(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormSprites *FormSprites;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormWhatsNew.cpp

 

//---------------------------------------------------------------------------
/*
  PokeVolley, Pokemon volleyball game
  Copyright (C) 2005  Richel Bilderbeek

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "UnitFormWhatsNew.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormWhatsNew *FormWhatsNew;
//---------------------------------------------------------------------------
__fastcall TFormWhatsNew::TFormWhatsNew(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

 

 

 

 

 

UnitFormWhatsNew.h

 

//---------------------------------------------------------------------------
/*
  PokeVolley, Pokemon volleyball game
  Copyright (C) 2005  Richel Bilderbeek

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#ifndef UnitFormWhatsNewH
#define UnitFormWhatsNewH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
//---------------------------------------------------------------------------
class TFormWhatsNew : public TForm
{
__published: // IDE-managed Components
        TRichEdit *RichEdit;
private: // User declarations
public: // User declarations
        __fastcall TFormWhatsNew(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormWhatsNew *FormWhatsNew;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitMain.cpp

 

//---------------------------------------------------------------------------
/*
 *  PokeVolley. A simple game.
 *  Copyright (C) 2005  Richel Bilderbeek
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
//---------------------------------------------------------------------------
// The program was created at the 24th of September of 2005
// The program can be downloaded at http://www.richelbilderbeek.nl
// The author's e-mail adress can be found at http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "UnitMain.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormMain *FormMain;
//---------------------------------------------------------------------------
#include <algorithm>
//---------------------------------------------------------------------------
__fastcall TFormMain::TFormMain(TComponent* Owner)
  : TForm(Owner), mBigImages(false)
{
  //List of keys that are/aren't pressed
  mKeyA = false;
  mKeyD = false;
  mKeyW = false;
  mKeyLeft = false;
  mKeyRight = false;
  mKeyUp = false;
  mScoreLeft = 0;
  mScoreRight = 0;

  BackGround->Picture->LoadFromFile("BeachSmall.bmp");
  Buffer->Picture->LoadFromFile("BeachSmall.bmp");


  if (mBigImages==true)
  { //Big images
    PlayerLeft->Picture->LoadFromFile("SquirtleStaandLinks.bmp");
    PlayerRight->Picture->LoadFromFile("SquirtleStaandRechts.bmp");
    Ball->Picture->LoadFromFile("Pokeball.bmp");
  }
  else
  { //Small images
    PlayerLeft->Picture->LoadFromFile("SquirtleLeftSmall.bmp");
    PlayerRight->Picture->LoadFromFile("SquirtleRightSmall.bmp");
    Ball->Picture->LoadFromFile("PokeballSmall.bmp");
  }

  //Fill Basket ImageLists
  //Left Basket
  BasketLeft->Picture->LoadFromFile("GhastlyLeft1.bmp");
  ImageListBasketLeft->Width = BasketLeft->Width;
  ImageListBasketLeft->Height = BasketLeft->Height;
  ImageListBasketLeft->AddMasked(BasketLeft->Picture->Bitmap,clLime);
  BasketLeft->Picture->LoadFromFile("GhastlyLeft2.bmp");
  ImageListBasketLeft->AddMasked(BasketLeft->Picture->Bitmap,clLime);
  //Right Basket
  BasketRight->Picture->LoadFromFile("GhastlyRight1.bmp");
  ImageListBasketRight->Width = BasketRight->Width;
  ImageListBasketRight->Height = BasketRight->Height;
  ImageListBasketRight->AddMasked(BasketRight->Picture->Bitmap,clLime);
  BasketRight->Picture->LoadFromFile("GhastlyRight2.bmp");
  ImageListBasketRight->AddMasked(BasketRight->Picture->Bitmap,clLime);


  mPlayerLeftJumps = false;
  mPlayerRightJumps = false;
  mPlayerLeftX = 0;
  mPlayerLeftY = ClientHeight - PlayerLeft->Height;
  mPlayerRightX = ClientWidth - PlayerRight->Width;
  mPlayerRightY = ClientHeight - PlayerRight->Height;
  mPlayerLeftSpeedY = 0.0;
  mPlayerRightSpeedY = 0.0;

  resetCoordinats();



}
//---------------------------------------------------------------------------
void TFormMain::resetCoordinats()
{
  //Set coordinats
  mBallX = (ClientWidth / 2) - (Ball->Width / 2);
  mBallY = 0.0;
  mBallSpeedX = (static_cast<double>(rand()%100)/10.0)-5.0;
  mBallSpeedY = 0.0;

  BasketLeft->Left = 0;
  BasketLeft->Top = (ClientHeight / 2) - (BasketLeft->Height / 2);
  BasketRight->Left = ClientWidth - BasketRight->Width;
  BasketRight->Top = (ClientHeight / 2) - (BasketRight->Height / 2);

  Caption = "PokeVolley, Copyright (C) 2006 Richel Bilderbeek: " + IntToStr(mScoreLeft) + " : " + IntToStr(mScoreRight);
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::FormKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
  switch(Key)
  {
    case 65: //A: Left
      mKeyA = true; mKeyD = false; break;
    case 87: //W: Up
      mKeyW = true; mKeyS = false; break;
    case 68: //D: Right
      mKeyD = true; mKeyA = false; break;
    case 83: //S: Down
      mKeyS = true; mKeyW = false; break;
    case VK_LEFT:
      mKeyLeft = true; mKeyRight = false; break;
    case VK_UP:
      mKeyUp = true; mKeyDown = false; break;
    case VK_RIGHT:
      mKeyRight = true; mKeyLeft = false; break;
    case VK_DOWN:
      mKeyDown = true; mKeyUp = false; break;
  }
}
//---------------------------------------------------------------------------
void TFormMain::processKeys()
{
  if (mKeyA == true)
  {
    mPlayerLeftSpeedX -= 1.0;
  }
  if (mKeyD == true)
  {
    mPlayerLeftSpeedX += 1.0;
  }
  if (mKeyW == true)
  {
    if (mPlayerLeftJumps==false)
    {
      mPlayerLeftJumps = true;
      PlayerLeft->Picture->LoadFromFile("SquirtleLeftSmallJump.bmp");

      mPlayerLeftY -=50;
      mPlayerLeftSpeedY = -20.0;
    }
  }
  if (mKeyS == true)
  {
    if (mPlayerLeftJumps==true) mPlayerLeftSpeedY += 0.5;
  }
  if (mKeyLeft == true)
  {
    mPlayerRightSpeedX -= 1.0;
  }
  if (mKeyRight == true)
  {
    mPlayerRightSpeedX += 1.0;
  }
  if (mKeyUp == true)
  {
    if (mPlayerRightJumps==false)
    {
      mPlayerRightJumps = true;
      PlayerRight->Picture->LoadFromFile("SquirtleRightSmallJump.bmp");
      mPlayerRightY -=50;
      mPlayerRightSpeedY = -20.0;
    }
  }
  if (mKeyDown == true)
  {
    if (mPlayerRightJumps==true) mPlayerRightSpeedY += 0.5;
  }


}
//---------------------------------------------------------------------------
void TFormMain::moveBall()
{
  mBallX += mBallSpeedX;
  mBallY += mBallSpeedY;
  mBallSpeedY += 0.5;

  if (mBallX < 0)
  {
    mBallSpeedX = -mBallSpeedX;
    mBallX = 0.0;
  }
  if (mBallY < 0)
  {
    mBallSpeedY = -mBallSpeedY;
    mBallY = 0.0;
  }
  if (mBallX + Ball->Width > ClientWidth)
  {
    mBallSpeedX = -mBallSpeedX;
    mBallX = ClientWidth - Ball->Width;
  }
  if (mBallY + Ball->Height > ClientHeight)
  {
    mBallSpeedY = -mBallSpeedY;
    mBallY = ClientHeight - Ball->Height;
  }

  Ball->Left = mBallX;
  Ball->Top = mBallY;
}
//---------------------------------------------------------------------------
void TFormMain::movePlayers()
{
  //Friction
  mPlayerLeftSpeedX *=0.95;
  mPlayerRightSpeedX *=0.95;

  //Gravity
  if (mPlayerLeftJumps == true) mPlayerLeftSpeedY +=0.5;
  if (mPlayerRightJumps == true) mPlayerRightSpeedY +=0.5;

  mPlayerLeftX  += mPlayerLeftSpeedX;
  mPlayerRightX += mPlayerRightSpeedX;
  mPlayerLeftY  += mPlayerLeftSpeedY;
  mPlayerRightY += mPlayerRightSpeedY;

  if (mPlayerLeftX < 0)
  {  //Player left leaves screen on left side
    mPlayerLeftX = 0;
    mPlayerLeftSpeedX = ( mPlayerLeftSpeedX < 0 ? -mPlayerLeftSpeedX : mPlayerLeftSpeedX);
  }

  if (mPlayerRightX < 0)
  {  //Player right leaves screen on left side
    mPlayerRightX = 0;
    mPlayerRightSpeedX = ( mPlayerRightSpeedX < 0 ? -mPlayerRightSpeedX : mPlayerRightSpeedX);
  }

  if (mPlayerLeftX + PlayerLeft->Width > ClientWidth)
  {  //Player left leaves screen on right side
    mPlayerLeftX = ClientWidth - PlayerLeft->Width;
    mPlayerLeftSpeedX = ( mPlayerLeftSpeedX > 0 ? -mPlayerLeftSpeedX : mPlayerLeftSpeedX);
  }

  if (mPlayerRightX + PlayerRight->Width > ClientWidth)
  {  //Player right leaves screen on right side
    mPlayerRightX = ClientWidth - PlayerRight->Width;
    mPlayerRightSpeedX = ( mPlayerRightSpeedX > 0 ? -mPlayerRightSpeedX : mPlayerRightSpeedX);
  }


  if (mPlayerLeftY < 0)
  { //Player left leaves screen with head
    mPlayerLeftSpeedY = -mPlayerLeftSpeedY;
    mPlayerLeftY = 0.0;
  }
  if (mPlayerRightY < 0)
  { //Player right leaves screen with head
    mPlayerRightSpeedY = -mPlayerRightSpeedY;
    mPlayerRightY = 0.0;
  }
  if (mPlayerLeftY + PlayerLeft->Height > ClientHeight)
  { //Player left leaves screen with feet
    mPlayerLeftSpeedY = 0.0;
    mPlayerLeftJumps = false;
    PlayerLeft->Picture->LoadFromFile("SquirtleLeftSmall.bmp");
    mPlayerLeftY = ClientHeight - PlayerLeft->Height;
  }
  if (mPlayerRightY + PlayerRight->Height > ClientHeight)
  { //Player right leaves screen with feet
    mPlayerRightSpeedY = 0.0;
    mPlayerRightJumps = false;
    PlayerRight->Picture->LoadFromFile("SquirtleRightSmall.bmp");
    mPlayerRightY = ClientHeight - PlayerRight->Height;
  }

  PlayerLeft->Left  = mPlayerLeftX;
  PlayerRight->Left = mPlayerRightX;
  PlayerLeft->Top  = mPlayerLeftY;
  PlayerRight->Top = mPlayerRightY;

}
//---------------------------------------------------------------------------
void TFormMain::detectCollision()
{
  TRect rect;

  //Check collision of player left and ball
  IntersectRect(rect,Ball->BoundsRect, PlayerLeft->BoundsRect);
  if (IsRectEmpty(rect)==false)
  {
    //Change the direction
    if (rect.Width() > rect.Height())
    { //Vertical collision
      if (mPlayerLeftSpeedY==0.0)
      { //Bounce on head
        mBallSpeedY = -mBallSpeedY;
      }
      else
      {
        std::swap(mBallSpeedY,mPlayerLeftSpeedY);

      }
      //Bounce ball
      //mBallSpeedY = -mBallSpeedY;
      mBallSpeedX += random(3)-1;
      //Bounce player
      //mPlayerLeftSpeedY = -mPlayerLeftSpeedY;
    }
    else
    { //Horizontal collision
      std::swap(mBallSpeedX,mPlayerLeftSpeedX);
      if (mBallSpeedX > 0 && mPlayerLeftSpeedX > 0) mPlayerLeftSpeedX = -mPlayerLeftSpeedX;
      if (mBallSpeedX < 0 && mPlayerLeftSpeedX < 0) mPlayerLeftSpeedX = -mPlayerLeftSpeedX;
      //Bounce ball
      //mBallSpeedX = -mBallSpeedX;
      mBallSpeedY += random(3)-1;
      //Push player
      PlayerLeft->Left += ( Ball->Left < PlayerLeft->Left ? 10 : -10);
    }
    //Move the ball
    mBallX += mBallSpeedX; mBallY += mBallSpeedY;
  }

  //Check collision of player right and ball
  IntersectRect(rect,Ball->BoundsRect, PlayerRight->BoundsRect);
  if (IsRectEmpty(rect)==false)
  {
    //Change the direction
    if (rect.Width() > rect.Height())
    { //Vertical collision
      if (mPlayerRightSpeedY==0.0)
      { //Bounce on head
        mBallSpeedY = -mBallSpeedY;
      }
      else
      {
        std::swap(mBallSpeedY,mPlayerRightSpeedY);
      }
      //mBallSpeedY = -mBallSpeedY;
      mBallSpeedX += random(3)-1;
      //Bounce player
      //mPlayerRightSpeedY = -mPlayerRightSpeedY;
    }
    else
    { //Horizonal collision
      std::swap(mBallSpeedX,mPlayerRightSpeedX);
      if (mBallSpeedX > 0 && mPlayerRightSpeedX > 0) mPlayerRightSpeedX = -mPlayerRightSpeedX;
      if (mBallSpeedX < 0 && mPlayerRightSpeedX < 0) mPlayerRightSpeedX = -mPlayerRightSpeedX;
      //mBallSpeedX = -mBallSpeedX;
      mBallSpeedY += random(3)-1;
      //Push the player
      PlayerRight->Left += ( Ball->Left < PlayerRight->Left ? 10 : -10);
    }
    //Move the ball
    mBallX += mBallSpeedX; mBallY += mBallSpeedY;
  }

  //Check collision of basket left and ball
  IntersectRect(rect,BasketLeft->BoundsRect, Ball->BoundsRect);
  if (IsRectEmpty(rect)==false)
  { //Right player has scored
    ++mScoreRight;
    resetCoordinats();
  }
  IntersectRect(rect,BasketRight->BoundsRect, Ball->BoundsRect);
  if (IsRectEmpty(rect)==false)
  { //Right player has scored
    ++mScoreLeft;
    resetCoordinats();
  }

}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormKeyUp(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
  switch(Key)
  {
    case 65: mKeyA = false; break;
    case 68: mKeyD = false; break;
    case 83: mKeyS = false; break;
    case 87: mKeyW = false; break;
    case VK_LEFT: mKeyLeft = false; break;
    case VK_RIGHT: mKeyRight = false; break;
    case VK_UP: mKeyUp = false; break;
    case VK_DOWN: mKeyDown = false; break;
  }

}
//---------------------------------------------------------------------------
void __fastcall TFormMain::Timer1Timer(TObject *Sender)
{
  moveBall();
  processKeys();
  movePlayers();
  detectCollision();

  //Draw BackGround on Buffer
  Buffer->Canvas->Draw(0,0,BackGround->Picture->Graphic);
  //Draw Baskets on Buffer
  ImageListBasketLeft->Draw(Buffer->Canvas,BasketLeft->Left,BasketLeft->Top,rand()%2,true);
  ImageListBasketRight->Draw(Buffer->Canvas,BasketRight->Left,BasketRight->Top,rand()%2,true);
  //Draw Squirtles and ball on Buffer
  Buffer->Canvas->Draw(PlayerLeft->Left, PlayerLeft->Top,PlayerLeft->Picture->Graphic);
  Buffer->Canvas->Draw(PlayerRight->Left, PlayerRight->Top,PlayerRight->Picture->Graphic);
  Buffer->Canvas->Draw(Ball->Left, Ball->Top, Ball->Picture->Graphic);
  //Draw Buffer on Form
  Canvas->Draw(0,0,Buffer->Picture->Graphic);
        
}
//---------------------------------------------------------------------------



 

 

 

 

 

UnitMain.h

 

//---------------------------------------------------------------------------
/*
 *  PokeVolley. A simple game.
 *  Copyright (C) 2005  Richel Bilderbeek
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
//---------------------------------------------------------------------------
// The program was created at the 24th of September of 2005
// The program can be downloaded at http://www.richelbilderbeek.nl
// The author's e-mail adress can be found at http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#ifndef UnitMainH
#define UnitMainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
#include <AppEvnts.hpp>
#include <ImgList.hpp>
//---------------------------------------------------------------------------
class TFormMain : public TForm
{
__published: // IDE-managed Components
  TImage *PlayerRight;
  TImage *Ball;
  TImage *PlayerLeft;
  TImage *BackGround;
  TImage *Buffer;
  TImage *BasketLeft;
  TImage *BasketRight;
  TImageList *ImageListBasketLeft;
  TImageList *ImageListBasketRight;
        TTimer *Timer1;
  void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
  void __fastcall FormKeyUp(TObject *Sender, WORD &Key, TShiftState Shift);
        void __fastcall Timer1Timer(TObject *Sender);
private: // User declarations
  const bool mBigImages;
  bool mKeyA, mKeyD, mKeyLeft, mKeyRight, mKeyW, mKeyUp, mKeyS, mKeyDown;

  double mBallX, mBallY;
  double mBallSpeedX, mBallSpeedY;

  double mPlayerLeftX, mPlayerLeftY;
  double mPlayerRightX, mPlayerRightY;
  double mPlayerLeftSpeedX, mPlayerLeftSpeedY;
  double mPlayerRightSpeedX, mPlayerRightSpeedY;
  bool mPlayerLeftJumps, mPlayerRightJumps;

  int mScoreLeft, mScoreRight;
  void resetCoordinats();
  void moveBall();
  void movePlayers();
  void detectCollision();
  void processKeys();
public: // User declarations
  __fastcall TFormMain(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormMain *FormMain;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict