Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's games.

 

 

 

 

 

(C++) BinnenVolley v. 0.9 source code

 

BinnenVolley v. 0.9 source code contains the full source of BinnenVolley.

 

 

 

 

 

Operating system: Windows XP

IDE: C++ Builder 6.0 Enterprise edition

Project type: unknown

Compiler: Borland BCC32.EXE version 6.0.10.157

Libraries used:

 

 

 

 

 

ProjectBinnenVolley.cpp

 

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

#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("UnitFormMain.cpp", FormMain);
USEFORM("UnitFormSprites.cpp", FormSprites);
USEFORM("UnitFormMenu.cpp", FormMenu);
USEFORM("UnitFormControls.cpp", FormControls);
USEFORM("UnitFormWhatsNew.cpp", FormWhatsNew);
USEFORM("UnitFormAdditionalCopyright.cpp", FormAdditionalCopyright);
USEFORM("UnitFormAbout.cpp", FormAbout);
USEFORM("UnitFormWon.cpp", FormWon);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
  try
  {
     Application->Initialize();
     Application->Title = "BinnenVolley";
                 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.h

 

#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
        TRichEdit *RichEdit1;
        TButton *ButtonWhatsNew;
        TLabel *Label1;
        TLabel *Label2;
        TLabel *Label3;
        TLabel *Label4;
        TLabel *Label5;
        TLabel *Label6;
        TLabel *Label7;
        TImage *Image1;
        TImage *Image2;
        TButton *ButtonAdditionalCopyright;
        TButton *ButtonQuit;
        void __fastcall ButtonWhatsNewClick(TObject *Sender);
        void __fastcall ButtonAdditionalCopyrightClick(TObject *Sender);
        void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
        void __fastcall ButtonQuitClick(TObject *Sender);
private: // User declarations
public: // User declarations
        __fastcall TFormAbout(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormAbout *FormAbout;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormAbout.cpp

 

#include <vcl.h>
#pragma hdrstop

#include <boost/scoped_ptr.hpp>
#include "UnitFormAbout.h"
#include "UnitFormWhatsNew.h"
#include "UnitFormAdditionalCopyright.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();
}
//---------------------------------------------------------------------------
void __fastcall TFormAbout::ButtonAdditionalCopyrightClick(TObject *Sender)
{
  boost::scoped_ptr<TFormAdditionalCopyright> f(new TFormAdditionalCopyright(0));
  f->ShowModal();
}
//---------------------------------------------------------------------------


void __fastcall TFormAbout::FormKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
  switch (Key)
  {
    case 'n': case 'N': ButtonWhatsNewClick(0); break;
    case 'c': case 'C': ButtonAdditionalCopyrightClick(0); break;
    case 's': case 'S': ButtonQuitClick(0); break;
  }
}
//---------------------------------------------------------------------------

void __fastcall TFormAbout::ButtonQuitClick(TObject *Sender)
{
  Close();
}

 

 

 

 

 

UnitFormAdditionalCopyright.h

 

#ifndef UnitFormAdditionalCopyrightH
#define UnitFormAdditionalCopyrightH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
class TFormAdditionalCopyright : public TForm
{
__published: // IDE-managed Components
        TRichEdit *RichEdit;
        TImage *Image1;
private: // User declarations
public: // User declarations
        __fastcall TFormAdditionalCopyright(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormAdditionalCopyright *FormAdditionalCopyright;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormAdditionalCopyright.cpp

 

#include <vcl.h>
#pragma hdrstop

#include "UnitFormAdditionalCopyright.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormAdditionalCopyright *FormAdditionalCopyright;
//---------------------------------------------------------------------------
__fastcall TFormAdditionalCopyright::TFormAdditionalCopyright(TComponent* Owner)
        : TForm(Owner)
{
}

 

 

 

 

 

UnitFormControls.h

 

#ifndef UnitFormControlsH
#define UnitFormControlsH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
class TFormControls : public TForm
{
__published: // IDE-managed Components
        TLabel *Label1;
        TImage *Image1;
        TImage *Image3;
        TImage *Image4;
        TImage *Image5;
        TImage *Image6;
        TImage *Image2;
        TImage *Image7;
        TImage *Image8;
        TImage *Image9;
        TImage *Image10;
        TLabel *Label2;
        void __fastcall ButtonWhatsNewClick(TObject *Sender);
        void __fastcall ButtonAdditionalCopyrightClick(TObject *Sender);
        void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
private: // User declarations
public: // User declarations
        __fastcall TFormControls(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormControls *FormControls;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormControls.cpp

 

#include <vcl.h>
#pragma hdrstop

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

void __fastcall TFormControls::FormKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
  switch (Key)
  {
    case 's': case 'S': Close(); break;
  }
}

 

 

 

 

 

UnitFormMain.h

 

#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);
        void __fastcall FormResize(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();
public: // User declarations
  __fastcall TFormMain(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormMain *FormMain;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormMain.cpp

 

#include <vcl.h>
#pragma hdrstop

#include <cassert>
#include <boost/scoped_ptr.hpp>
#include "UnitFormMain.h"
#include "UnitFormSprites.h"
#include "UnitFormWon.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->Picture;
  ImageBasket2->Picture = FormSprites->ImageBasket2->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 = "BinnenVolley (C) 2010 Richel Bilderbeek";
}
//---------------------------------------------------------------------------

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,ImageBasket2->BoundsRect, ImageBall->BoundsRect);
  if (IsRectEmpty(rect)==false)
  { //Left player has scored
    ++mScoreLeft;
    if (mScoreLeft == 15)
    {
      Timer1->Enabled = false;
      boost::scoped_ptr<TFormWon> f(new TFormWon(0));
      f->ImagePlayer2Thumb->Visible = false;
      f->ShowModal();
      Close();
    }
    resetCoordinats();
  }

  //Check collision of basket right and ball
  IntersectRect(rect,ImageBasket1->BoundsRect, ImageBall->BoundsRect);
  if (IsRectEmpty(rect)==false)
  { //Right player has scored
    ++mScoreRight;
    if (mScoreRight == 15)
    {
      Timer1->Enabled = false;
      boost::scoped_ptr<TFormWon> f(new TFormWon(0));
      f->ImagePlayer1Thumb->Visible = false;
      f->ShowModal();
      Close();
    }
    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 ImageBuffer
  ImageBuffer->Canvas->StretchDraw(ClientRect,ImageBackground->Picture->Graphic);
  //Draw score on ImageBuffer
  {
    const int imageScoreWidth = 64;
    const int x = (ClientWidth / 2) - (2 * imageScoreWidth) - (imageScoreWidth / 2);
    const int y = 0;
    ImageBuffer->Canvas->Draw(x + (0 * imageScoreWidth),y,FormSprites->GetNumber(mScoreLeft / 10)->Picture->Graphic);
    ImageBuffer->Canvas->Draw(x + (1 * imageScoreWidth),y,FormSprites->GetNumber(mScoreLeft % 10)->Picture->Graphic);
    ImageBuffer->Canvas->Draw(x + (2 * imageScoreWidth),y,FormSprites->ImageMinus->Picture->Graphic);
    ImageBuffer->Canvas->Draw(x + (3 * imageScoreWidth),y,FormSprites->GetNumber(mScoreRight / 10)->Picture->Graphic);
    ImageBuffer->Canvas->Draw(x + (4 * imageScoreWidth),y,FormSprites->GetNumber(mScoreRight % 10)->Picture->Graphic);
  }
  //Draw baskets on ImageBuffer
  ImageBuffer->Canvas->Draw(ImageBasket1->Left,ImageBasket1->Top,ImageBasket1->Picture->Graphic);
  ImageBuffer->Canvas->Draw(ImageBasket2->Left,ImageBasket2->Top,ImageBasket2->Picture->Graphic);
  //Draw players 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);

}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormResize(TObject *Sender)
{
  ImageBuffer->Picture->Graphic->Width = ClientWidth;
  ImageBuffer->Picture->Graphic->Height = ClientHeight;

}

 

 

 

 

 

UnitFormMenu.h

 

#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
        TLabel *Label1;
        TLabel *LabelStart;
        TLabel *LabelAbout;
        TLabel *LabelQuit;
        TImage *Image1;
        TImage *Image2;
        TLabel *LabelControls;
        void __fastcall OnStartClick(TObject *Sender);
        void __fastcall OnAboutClick(TObject *Sender);
        void __fastcall OnQuitClick(TObject *Sender);
        void __fastcall OnControlsClick(TObject *Sender);
        void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
private: // User declarations
public: // User declarations
        __fastcall TFormMenu(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormMenu *FormMenu;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormMenu.cpp

 

#include <vcl.h>
#pragma hdrstop

#include <boost/scoped_ptr.hpp>
#include "UnitFormMenu.h"
#include "UnitFormMain.h"
#include "UnitFormAbout.h"
#include "UnitFormControls.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::OnQuitClick(TObject *Sender)
{
  Close();
}
//---------------------------------------------------------------------------
void __fastcall TFormMenu::OnControlsClick(TObject *Sender)
{
  boost::scoped_ptr<TFormControls> f(new TFormControls(0));
  f->ShowModal();
}
//---------------------------------------------------------------------------

void __fastcall TFormMenu::FormKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
  switch (Key)
  {
    case 's': case 'S': OnStartClick(0); break;
    case 'b': case 'B': OnControlsClick(0); break;
    case 'o': case 'O': OnAboutClick(0); break;
    case 'e': case 'E': OnQuitClick(0); break;
  }
}

 

 

 

 

 

UnitFormSprites.h

 

#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 *ImagePlayer1;
        TImage *ImagePlayer1Jump;
        TImage *ImagePlayer2;
        TImage *ImagePlayer2Jump;
        TImage *ImageBasket2;
        TImage *ImageBasket1;
        TImage *ImageBackground;
        TImage *Image0;
        TImage *Image1;
        TImage *Image2;
        TImage *Image3;
        TImage *Image4;
        TImage *Image5;
        TImage *Image6;
        TImage *Image7;
        TImage *Image8;
        TImage *Image9;
        TImage *ImageMinus;
        TImage *ImagePlayer1Thumb;
        TImage *ImagePlayer2Thumb;
private: // User declarations
public: // User declarations
  const TImage * const GetNumber(const int x) const;
        __fastcall TFormSprites(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormSprites *FormSprites;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormSprites.cpp

 

#include <vcl.h>
#pragma hdrstop

#include <cassert>
#include <stdexcept>
#include "UnitFormSprites.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormSprites *FormSprites;
//---------------------------------------------------------------------------
__fastcall TFormSprites::TFormSprites(TComponent* Owner)
        : TForm(Owner)
{
  ImageBasket1->Picture->Bitmap->TransparentColor = clLime;
  ImageBasket2->Picture->Bitmap->TransparentColor = clLime;
  /*
  Image0->Picture->Bitmap->TransparentColor = clLime;
  Image1->Picture->Bitmap->TransparentColor = clLime;
  Image2->Picture->Bitmap->TransparentColor = clLime;
  Image3->Picture->Bitmap->TransparentColor = clLime;
  Image4->Picture->Bitmap->TransparentColor = clLime;
  Image5->Picture->Bitmap->TransparentColor = clLime;
  Image6->Picture->Bitmap->TransparentColor = clLime;
  Image7->Picture->Bitmap->TransparentColor = clLime;
  Image8->Picture->Bitmap->TransparentColor = clLime;
  Image9->Picture->Bitmap->TransparentColor = clLime;
  ImageMinus->Picture->Bitmap->TransparentColor = clLime;
  */
}
//---------------------------------------------------------------------------
const TImage * const TFormSprites::GetNumber(const int x) const
{
  assert(x >= 0 && x <= 9);
  switch (x)
  {
    case 0: return Image0;
    case 1: return Image1;
    case 2: return Image2;
    case 3: return Image3;
    case 4: return Image4;
    case 5: return Image5;
    case 6: return Image6;
    case 7: return Image7;
    case 8: return Image8;
    case 9: return Image9;
  }
  assert(!"Should not get here");
  throw std::logic_error("Invalid digit requested in TFormSprites::GetNumber");
}

 

 

 

 

 

UnitFormWhatsNew.h

 

#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

 

 

 

 

 

UnitFormWhatsNew.cpp

 

#include <vcl.h>
#pragma hdrstop

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

 

 

 

 

 

UnitFormWon.h

 

#ifndef UnitFormWonH
#define UnitFormWonH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
class TFormWon : public TForm
{
__published: // IDE-managed Components
        TImage *ImagePlayer2Thumb;
        TImage *ImagePlayer1Thumb;
        TLabel *Label1;
        TTimer *Timer1;
        void __fastcall Timer1Timer(TObject *Sender);
        void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
private: // User declarations
  bool mCanClose;
public: // User declarations
        __fastcall TFormWon(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormWon *FormWon;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormWon.cpp

 

#include <vcl.h>
#pragma hdrstop

#include "UnitFormWon.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormWon *FormWon;
//---------------------------------------------------------------------------
__fastcall TFormWon::TFormWon(TComponent* Owner)
  : TForm(Owner),
    mCanClose(false)
{

}
//---------------------------------------------------------------------------
void __fastcall TFormWon::Timer1Timer(TObject *Sender)
{
  mCanClose = true;
}
//---------------------------------------------------------------------------
void __fastcall TFormWon::FormKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
  if (mCanClose) Close();
}

 

 

 

 

 

Go back to Richel Bilderbeek's games.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict