Archives from S:\ Drive

Good to keep around methinks
This commit is contained in:
Amrit Panesar committed 2015-04-01 21:23:15 -07:00
1 parent eadaf70b9e
commit 6dd63cc439
606 files changed
+50212

No files matched your search

@@ -0,0 +1,9 @@
Code change needed from the handout.
Use the following code to instantiate your root object in the Pong constructor:
#ifdef _DEBUG
rootPtr = new Root("Plugins_d.cfg"); // initialize Root object
#else
rootPtr = new Root("Plugins.cfg"); // initialize Root object
#endif
@@ -0,0 +1,20 @@
Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Ogre Project", "Ogre Project\Ogre Project.vcproj", "{220D5644-C06B-4022-A9D7-7B43CEBC46D8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{220D5644-C06B-4022-A9D7-7B43CEBC46D8}.Debug|Win32.ActiveCfg = Debug|Win32
{220D5644-C06B-4022-A9D7-7B43CEBC46D8}.Debug|Win32.Build.0 = Debug|Win32
{220D5644-C06B-4022-A9D7-7B43CEBC46D8}.Release|Win32.ActiveCfg = Release|Win32
{220D5644-C06B-4022-A9D7-7B43CEBC46D8}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,20 @@
Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Ogre Project", "Ogre Project\Ogre Project.vcproj", "{220D5644-C06B-4022-A9D7-7B43CEBC46D8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{220D5644-C06B-4022-A9D7-7B43CEBC46D8}.Debug|Win32.ActiveCfg = Debug|Win32
{220D5644-C06B-4022-A9D7-7B43CEBC46D8}.Debug|Win32.Build.0 = Debug|Win32
{220D5644-C06B-4022-A9D7-7B43CEBC46D8}.Release|Win32.ActiveCfg = Release|Win32
{220D5644-C06B-4022-A9D7-7B43CEBC46D8}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,165 @@
// Ball.cpp
// Ball class member-function definitions.
#include <Ogre.h> // Ogre class definition
using namespace Ogre; // use the Ogre namespace
#include <OgreAL.h> // OgreAL class definition
#include "Ball.h" // Ball class definition
#include "Paddle.h" // Paddle class definition
#include "Pong.h" // Pong class definition
// Ball constructor
Ball::Ball( SceneManager *ptr )
{
sceneManagerPtr = ptr; // set pointer to the SceneManager
soundManagerPtr = new OgreAL::SoundManager(); // create SoundManager
speed = 100; // speed of the Ball
direction = Vector3( 1, -1, 0 ); // direction of the Ball
} // end Ball constructor
// Ball destructor
Ball::~Ball()
{
// empty body
} // end Ball destructor
// add the Ball to the scene
void Ball::addToScene()
{
// create Entity and attach it to a node in the scene
Entity *entityPtr =
sceneManagerPtr->createEntity( "Ball", "cube.mesh" );
entityPtr->setMaterialName( "ball" ); // set material for the Ball
entityPtr->setNormaliseNormals( true ); // fix the normals when scaled
nodePtr = sceneManagerPtr->getRootSceneNode()->createChildSceneNode( "Ball" ); // create a SceneNode
nodePtr->attachObject( entityPtr ); // attach the Entity to SceneNode
nodePtr->setScale( .05, .05, .05 ); // scale SceneNode
// attach sounds to Ball so they will play from where Ball is
wallSoundPtr = soundManagerPtr->createSound( "wallSound", "wallSound.wav", false );
nodePtr->attachObject( wallSoundPtr ); // attach a sound to SceneNode
paddleSoundPtr = soundManagerPtr->createSound( "paddleSound", "paddleSound.wav", false );
nodePtr->attachObject( paddleSoundPtr ); // attach sound to SceneNode
scoreSoundPtr = soundManagerPtr->createSound( "cheer", "cheer.wav", false ); // create a Sound
// attach the score sound to its own node centered at ( 0, 0, 0 )
sceneManagerPtr->getRootSceneNode()->createChildSceneNode( "score" )->attachObject( scoreSoundPtr );
} // end function addToScene
// move the Ball across the screen
void Ball::moveBall( Real time )
{
nodePtr->translate( ( direction * ( speed * time ) ) ); // move Ball
Vector3 position = nodePtr->getPosition(); // get Ball's new position
// get the positions of the four walls
Vector3 topPosition = sceneManagerPtr->getSceneNode( "WallTop" )->getPosition();
Vector3 bottomPosition = sceneManagerPtr->getSceneNode( "WallBottom" )->getPosition();
Vector3 leftPosition = sceneManagerPtr->getSceneNode( "WallLeft" )->getPosition();
Vector3 rightPosition = sceneManagerPtr->getSceneNode( "WallRight" )->getPosition();
const int WALL_WIDTH = 5; // the width of the walls
// check if the Ball hit the left side
if ( ( position.x - RADIUS ) <= leftPosition.x + ( WALL_WIDTH / 2 ) )
{
nodePtr->setPosition( 0, 0, 0 ); // place Ball in center of screen
Pong::updateScore( Players::PLAYER2 ); // update the score
scoreSoundPtr->play(); // play a sound when player 2 scores
} // end if
// check if the Ball hit the right side
else if (
( position.x + RADIUS ) >= rightPosition.x - ( WALL_WIDTH / 2 ) )
{
nodePtr->setPosition( 0, 0, 0 ); // place Ball in center of screen
Pong::updateScore( Players::PLAYER1 ); // update the score
scoreSoundPtr->play(); // play a sound when player 1 scores
} // end else
// check if the Ball hit the bottom wall
else if (
( position.y - RADIUS ) <= bottomPosition.y + ( WALL_WIDTH / 2 ) &&
direction.y < 0 )
{
// place the Ball on the bottom wall
nodePtr->setPosition( position.x,
( bottomPosition.y + ( WALL_WIDTH / 2 ) + RADIUS ), position.z );
reverseVerticalDirection(); // make the Ball start moving up
} // end else
// check if the Ball hit the top wall
else if (
( position.y + RADIUS ) >= topPosition.y - ( WALL_WIDTH / 2 ) &&
direction.y > 0 )
{
// place the Ball on the top wall
nodePtr->setPosition( position.x,
( topPosition.y - ( WALL_WIDTH / 2 ) - RADIUS ), position.z );
reverseVerticalDirection(); // make the Ball start moving down
} // end else
hitPaddle(); // check if the Ball hit a Paddle
} // end function moveBall
// reverse the Ball's horizontal direction
void Ball::reverseHorizontalDirection()
{
direction *= Vector3( -1, 1, 1 ); // reverse the horizontal direction
paddleSoundPtr->play(); // play the "paddleSound" sound effect
} // end function reverseHorizontalDirection
// reverse the Ball's vertical direction
void Ball::reverseVerticalDirection()
{
direction *= Vector3( 1, -1, 1 ); // reverse the vertical direction
wallSoundPtr->play(); // play the "wallSound" sound effect
} // end function reverseVerticalDirection
// control the Ball colliding with the Paddle
void Ball::hitPaddle()
{
// get the position of the Paddles and the Ball
Vector3 leftPaddlePosition = sceneManagerPtr->
getSceneNode( "LeftPaddle" )->getPosition(); // left Paddle
Vector3 rightPaddlePosition = sceneManagerPtr->
getSceneNode( "RightPaddle" )->getPosition(); // right Paddle
Vector3 ballPosition = nodePtr->getPosition(); // the Ball's position
const int PADDLE_WIDTH = 2; // width of the Paddle
const int PADDLE_HEIGHT = 30; // height of the Paddle
// is the Ball in range of the left Paddle?
if ( ( ballPosition.x - RADIUS ) <
( leftPaddlePosition.x + ( PADDLE_WIDTH / 2 ) ) )
{
// check for collision with left Paddle
if ( ( ballPosition.y - RADIUS ) <
( leftPaddlePosition.y + ( PADDLE_HEIGHT / 2 ) ) &&
( ballPosition.y + RADIUS ) >
( leftPaddlePosition.y - ( PADDLE_HEIGHT / 2 ) ) )
{
reverseHorizontalDirection(); // reverse the Ball's direction
// place the Ball at the edge of the Paddle
nodePtr->setPosition(
( leftPaddlePosition.x + ( PADDLE_WIDTH / 2 ) + RADIUS ),
ballPosition.y, ballPosition.z );
} // end if
} // end if
// is the Ball in range of the right Paddle?
else if ( ( ballPosition.x + RADIUS ) >
( rightPaddlePosition.x - ( PADDLE_WIDTH / 2 ) ) )
{
// check for collision with right Paddle
if ( ( ballPosition.y - RADIUS ) <
( rightPaddlePosition.y + ( PADDLE_HEIGHT / 2 ) ) &&
( ballPosition.y + RADIUS ) >
( rightPaddlePosition.y - ( PADDLE_HEIGHT / 2 ) ) )
{
reverseHorizontalDirection(); // reverse the Ball's direction
// place the Ball at the edge of the Paddle
nodePtr->setPosition(
( rightPaddlePosition.x - ( PADDLE_WIDTH / 2 ) - RADIUS ),
ballPosition.y, ballPosition.z );
} // end if
} // end else
} // end function hitPaddle
@@ -0,0 +1,40 @@
// Ball.h
// Ball class definition (represents a bouncing ball).
#ifndef BALL_H
#define BALL_H
#include <Ogre.h> // Ogre class definition
using namespace Ogre; // use the Ogre namespace
#include <OgreAL.h> // OgreAL class definition
class Paddle; // forward declaration of class Paddle
const int RADIUS = 5; // the radius of the Ball
class Ball
{
public:
Ball( SceneManager *sceneManagerPtr ); // constructor
~Ball(); // destructor
void addToScene(); // add the Ball to the scene
void moveBall( Real time ); // move the Ball across the screen
private:
SceneManager *sceneManagerPtr; // pointer to the SceneManager
SceneNode *nodePtr; // pointer to the SceneNode
OgreAL::SoundManager *soundManagerPtr; // pointer to the SoundManager
OgreAL::Sound *wallSoundPtr; // sound played when Ball hits a wall
OgreAL::Sound *paddleSoundPtr; // sound played when Ball hits a Paddle
OgreAL::Sound *scoreSoundPtr; // sound played when someone scores
int speed; // speed of the Ball
Vector3 direction; // direction of the Ball
// private utility functions
void reverseHorizontalDirection(); // change horizontal direction
void reverseVerticalDirection(); // change vertical direction
void hitPaddle(); // control the Ball hitting the Paddles
}; // end class Ball
#endif // BALL_H
@@ -0,0 +1,307 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="Ogre Project"
ProjectGUID="{220D5644-C06B-4022-A9D7-7B43CEBC46D8}"
RootNamespace="OgreProject"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;$(GDD_OGRE_HOME)\Ogre3D\include&quot;;&quot;$(GDD_OGRE_HOME)\OpenAL\include&quot;;&quot;$(GDD_OGRE_HOME)\OgreAL\include&quot;;&quot;$(GDD_OGRE_HOME)\ogg\include&quot;;&quot;$(GDD_OGRE_HOME)\vorbis\include&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="OgreMain_d.lib OIS_d.lib OgreAL_d.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;$(GDD_OGRE_HOME)\Ogre3D\lib\$(ConfigurationName)&quot;;&quot;$(GDD_OGRE_HOME)\OgreAL\lib\$(ConfigurationName)&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="&quot;$(GDD_OGRE_HOME)\Ogre3D\include&quot;;&quot;$(GDD_OGRE_HOME)\OpenAL\include&quot;;&quot;$(GDD_OGRE_HOME)\OgreAL\include&quot;;&quot;$(GDD_OGRE_HOME)\ogg\include&quot;;&quot;$(GDD_OGRE_HOME)\vorbis\include&quot;"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="OgreMain.lib OIS.lib OgreAL.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;$(GDD_OGRE_HOME)\Ogre3D\lib\$(ConfigurationName)&quot;;&quot;$(GDD_OGRE_HOME)\OgreAL\lib\$(ConfigurationName)&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\Ball.cpp"
>
</File>
<File
RelativePath=".\Paddle.cpp"
>
</File>
<File
RelativePath=".\Pong.cpp"
>
</File>
<File
RelativePath=".\PongMain.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\Ball.h"
>
</File>
<File
RelativePath=".\Paddle.h"
>
</File>
<File
RelativePath=".\Pong.h"
>
</File>
<File
RelativePath=".\resource.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
<File
RelativePath=".\resources\BlueBold.fontdef"
>
</File>
<File
RelativePath=".\resources\bluebold.ttf"
>
</File>
<File
RelativePath=".\resources\boing.wav"
>
</File>
<File
RelativePath=".\resources\boing1.wav"
>
</File>
<File
RelativePath=".\resources\cheer.wav"
>
</File>
<File
RelativePath=".\resources\cube.mesh"
>
</File>
<File
RelativePath=".\resources\MenuMaterial.material"
>
</File>
<File
RelativePath=".\resources\MenuOverlay.overlay"
>
</File>
<File
RelativePath=".\resources\paddleSound.wav"
>
</File>
<File
RelativePath="..\..\..\..\..\Downloads\pong.ico"
>
</File>
<File
RelativePath="..\..\..\..\..\Downloads\pong.png"
>
</File>
<File
RelativePath=".\resources\PongMaterials.material"
>
</File>
<File
RelativePath=".\resources\PongOverlays.overlay"
>
</File>
<File
RelativePath=".\resources\PongScore.fontdef"
>
</File>
<File
RelativePath=".\resources\PongScore.ttf"
>
</File>
<File
RelativePath=".\resources\PongText.fontdef"
>
</File>
<File
RelativePath=".\resources\PongText.ttf"
>
</File>
<File
RelativePath=".\Resource.rc"
>
</File>
<File
RelativePath=".\resources\sphere.mesh"
>
</File>
<File
RelativePath=".\resources\wallSound.wav"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{220D5644-C06B-4022-A9D7-7B43CEBC46D8}</ProjectGuid>
<RootNamespace>OgreProject</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.40219.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>$(GDD_OGRE_HOME)\Ogre3D\include;$(GDD_OGRE_HOME)\OpenAL\include;$(GDD_OGRE_HOME)\OgreAL\include;$(GDD_OGRE_HOME)\ogg\include;$(GDD_OGRE_HOME)\vorbis\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalDependencies>OgreMain_d.lib;OIS_d.lib;OgreAL_d.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(GDD_OGRE_HOME)\Ogre3D\lib\$(Configuration);$(GDD_OGRE_HOME)\OgreAL\lib\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>$(GDD_OGRE_HOME)\Ogre3D\include;$(GDD_OGRE_HOME)\OpenAL\include;$(GDD_OGRE_HOME)\OgreAL\include;$(GDD_OGRE_HOME)\ogg\include;$(GDD_OGRE_HOME)\vorbis\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalDependencies>OgreMain.lib;OIS.lib;OgreAL.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(GDD_OGRE_HOME)\Ogre3D\lib\$(Configuration);$(GDD_OGRE_HOME)\OgreAL\lib\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Ball.cpp" />
<ClCompile Include="Paddle.cpp" />
<ClCompile Include="Pong.cpp" />
<ClCompile Include="PongMain.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Ball.h" />
<ClInclude Include="Paddle.h" />
<ClInclude Include="Pong.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Ball.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Paddle.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Pong.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PongMain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Ball.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Paddle.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Pong.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
@@ -0,0 +1,45 @@
// Paddle.cpp
// Paddle class member-function definitions.
#include <Ogre.h> // Ogre class definition
using namespace Ogre; // use the Ogre namespace
#include "Paddle.h" // Paddle class definition
// constructor
Paddle::Paddle( SceneManager *ptr, String paddleName, int positionX )
{
sceneManagerPtr = ptr; // set the pointer to the SceneManager
name = paddleName; // set the Paddle's name
x = positionX; // set the Paddle's x coordinate
} // end Paddle constructor
// destructor
Paddle::~Paddle()
{
// empty body
} // end Paddle default destructor
// add the Paddle to the scene
void Paddle::addToScene()
{
Entity *entityPtr = sceneManagerPtr->
createEntity( name, "cube.mesh" ); // create an Entity
entityPtr->setMaterialName( "paddle" ); // set the Paddle's material
entityPtr->setNormaliseNormals( true ); // fix the normals when scaled
nodePtr = sceneManagerPtr->getRootSceneNode()->createChildSceneNode( name ); // create a SceneNode for the Paddle
nodePtr->attachObject( entityPtr ); // attach Paddle to the SceneNode
nodePtr->setScale( .02, .3, .1 ); // set the Paddle's size
nodePtr->setPosition( x, 0, 0 ); // set the Paddle's position
} // end function addToScene
// move the Paddle up and down the screen
void Paddle::movePaddle( const Vector3 &direction )
{
nodePtr->translate( direction ); // move the Paddle
if ( nodePtr->getPosition().y > 52.5 ) // top of the box
nodePtr->setPosition( x, 52.5, 0 ); // place Paddle at top of box
else if ( nodePtr->getPosition().y < -52.5 ) // bottom of the box
// place the Paddle at the bottom of the box
nodePtr->setPosition( x, -52.5, 0 );
} // end function movePaddle
@@ -0,0 +1,27 @@
// Paddle.h
// Paddle class definition (represents a paddle in the game).
#ifndef PADDLE_H
#define PADDLE_H
#include <Ogre.h> // Ogre class definition
using namespace Ogre; // use the Ogre namespace
class Paddle
{
public:
// constructor
Paddle( SceneManager *sceneManagerPtr, String paddleName,
int positionX);
~Paddle(); // destructor
void addToScene(); // add a Paddle to the scene
void movePaddle( const Vector3 &direction ); // move a Paddle
private:
SceneManager* sceneManagerPtr; // pointer to the SceneManager
SceneNode *nodePtr; // pointer to a SceneNode
String name; // name of the Paddle
int x; // x coordinate of the Paddle
}; // end of class Paddle
#endif // PADDLE_H
@@ -0,0 +1,14 @@
# Defines plugins to load
# Define plugin folder
PluginFolder=.
# Define plugins
Plugin=RenderSystem_Direct3D9
Plugin=RenderSystem_GL
Plugin=Plugin_ParticleFX
Plugin=Plugin_BSPSceneManager
Plugin=Plugin_OctreeSceneManager
Plugin=Plugin_CgProgramManager
@@ -0,0 +1,14 @@
# Defines plugins to load
# Define plugin folder
PluginFolder=.
# Define plugins
Plugin=RenderSystem_Direct3D9_d
Plugin=RenderSystem_GL_d
Plugin=Plugin_ParticleFX_d
Plugin=Plugin_BSPSceneManager_d
Plugin=Plugin_OctreeSceneManager_d
Plugin=Plugin_CgProgramManager_d
@@ -0,0 +1,407 @@
// Pong.cpp
// Pong class member-function definitions.
#include <sstream>
#include <stdexcept>
#include <Ogre.h> // Ogre class definition
using namespace Ogre; // use the Ogre namespace
using namespace std; // use the Standard C namespace
#include <OgreAL.h> // OgreAL class definition
#include <OgreStringConverter.h> // OgreStringConverter class definition
#include <OIS/OISEvents.h> // OISEvents class definition
#include <OIS/OISInputManager.h> // OISInputManager class definition
#include <OIS/OISKeyboard.h> // OISKeyboard class definition
#include "Ball.h" // Ball class definition
#include "Paddle.h" // Paddle class definition
#include "Pong.h" // Pong class definition
int Pong::player1Score = 0; // initialize player 1's score to 0
int Pong::player2Score = 0; // initialize player 2's score to 0
bool Pong::wait = false; // initialize wait to false
// directions to move the Paddles
const Vector3 PADDLE_DOWN = Vector3( 0, -1, 0 );
const Vector3 PADDLE_UP = Vector3( 0, 1, 0 );
// constructor
Pong::Pong()
{
#ifdef _DEBUG
rootPtr = new Root("Plugins_d.cfg"); // initialize Root object
#else
rootPtr = new Root("Plugins.cfg"); // initialize Root object
#endif
// use the Ogre Config Dialog Box to choose the settings
//if ( !( rootPtr->showConfigDialog() ) ) // user canceled the dialog box
// throw runtime_error( "User Canceled Ogre Setup Dialog Box." );
WIN32_FIND_DATA w32FD;
HANDLE h = FindFirstFile(L"ogre.cfg", &w32FD);
if(FAILED(h)){
if(!rootPtr->showConfigDialog()){
throw runtime_error( "User Canceled Ogre Setup Dialog Box." );
} else {
rootPtr->saveConfig();
}
} else {
rootPtr->restoreConfig();
}
// get a pointer to the RenderWindow
windowPtr = rootPtr->initialise( true, "Pong! 2014 Edition" );
// create the SceneManager
sceneManagerPtr = rootPtr->createSceneManager( ST_GENERIC );
// create the Camera
cameraPtr = sceneManagerPtr->createCamera( "PongCamera" );
cameraPtr->setPosition( Vector3( 0, 0, 200 ) ); // set Camera position
cameraPtr->lookAt( Vector3( 0, 0, 0 ) ); // set where Camera looks
cameraPtr->setNearClipDistance( 5 ); // near distance Camera can see
cameraPtr->setFarClipDistance( 1000 ); // far distance Camera can see
// create the Viewport
viewportPtr = windowPtr->addViewport( cameraPtr );
viewportPtr->setBackgroundColour( ColourValue( 0, 0, 0 ) );
// set the Camera's aspect ratio
cameraPtr->setAspectRatio( Real( viewportPtr->getActualWidth() ) /( viewportPtr->getActualHeight() ) );
// set the scene's ambient light
sceneManagerPtr->setAmbientLight( ColourValue( 0.75, 0.75, 0.75 ) );
// create the Light
Light *lightPtr = sceneManagerPtr->createLight( "Light" ); // a Light
lightPtr->setPosition( 0, 0, 50 ); // set the Light's position
unsigned long hWnd; // variable to hold the window handle
windowPtr->getCustomAttribute( "WINDOW", &hWnd ); // get window handle
OIS::ParamList paramList; // create an OIS ParamList
// add the window to the ParamList
paramList.insert( OIS::ParamList::value_type( "WINDOW", Ogre::StringConverter::toString( hWnd ) ) );
// create the InputManager
inputManagerPtr = OIS::InputManager::createInputSystem( paramList );
keyboardPtr = static_cast< OIS::Keyboard* >( inputManagerPtr->createInputObject( OIS::OISKeyboard, true ) ); // create a Keyboard
keyboardPtr->setEventCallback( this ); // add a KeyListener
rootPtr->addFrameListener( this ); // add this Pong as a FrameListener
// load resources for Pong
ResourceGroupManager::getSingleton().addResourceLocation("resources", "FileSystem", "Pong" );
ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
quit = pause = false; // player has not quit or paused the game
time = 0; // initialize the time since Ball was reset to 0
paddle[0] = paddle[1] = 0;
} // end Pong constructor
// Pong destructor erases objects contained in a Pong object
Pong::~Pong()
{
Ogre::WindowEventUtilities::removeWindowEventListener(windowPtr, this);
windowClosed(windowPtr);
// free dynamically allocated memory for Keyboard/mouse
if(inputManagerPtr)
{
//inputManagerPtr->destroyInputObject( mousePtr );
//mousePtr = 0;
inputManagerPtr->destroyInputObject( keyboardPtr );
keyboardPtr = 0;
OIS::InputManager::destroyInputSystem(inputManagerPtr);
inputManagerPtr = 0;
}
// free dynamically allocated memory for Root
delete rootPtr; // release memory pointer points to
rootPtr = 0; // point pointer at 0
// free dynamically allocated memory for Ball
delete ballPtr; // release memory pointer points to
ballPtr = 0; // point pointer at 0
// free dynamically allocated memory for Paddle
delete leftPaddlePtr; // release memory pointer points to
leftPaddlePtr = 0; // point pointer at 0
// free dynamically allocated memory for Paddle
delete rightPaddlePtr; // release memory pointer points to
rightPaddlePtr = 0; // point pointer at 0
} // end Pong destructor
// create the scene to be displayed
void Pong::createScene()
{
// get a pointer to the Score Overlay
Overlay *scoreOverlayPtr = OverlayManager::getSingleton().getByName( "Score" );
scoreOverlayPtr->show(); // show the Overlay
// make the game objects
ballPtr = new Ball( sceneManagerPtr ); // make the Ball
ballPtr->addToScene(); // add the Ball to the scene
rightPaddlePtr = new Paddle( sceneManagerPtr, "RightPaddle", 90 );
rightPaddlePtr->addToScene(); // add a Paddle to the scene
leftPaddlePtr = new Paddle( sceneManagerPtr, "LeftPaddle", -90 );
leftPaddlePtr->addToScene(); // add a Paddle to the scene
// create the walls
Entity *entityPtr = sceneManagerPtr->createEntity( "WallLeft", "cube.mesh" ); // create the left wall
entityPtr->setMaterialName( "wall" ); // set material for left wall
entityPtr->setNormaliseNormals( true ); // fix the normals when scaled
// create the SceneNode for the left wall
SceneNode *nodePtr = sceneManagerPtr->getRootSceneNode()->createChildSceneNode( "WallLeft" );
nodePtr->attachObject( entityPtr ); // attach left wall to SceneNode
nodePtr->setPosition( -95, 0, 0 ); // set the left wall's position
nodePtr->setScale( .05, 1.45, .1 ); // set the left wall's size
entityPtr = sceneManagerPtr->createEntity( "WallRight", "cube.mesh" );
entityPtr->setMaterialName( "wall" ); // set material for right wall
entityPtr->setNormaliseNormals( true ); // fix the normals when scaled
// create the SceneNode for the right wall
nodePtr = sceneManagerPtr->getRootSceneNode()->createChildSceneNode( "WallRight" );
nodePtr->attachObject( entityPtr ); // attach right wall to SceneNode
nodePtr->setPosition( 95, 0, 0 ); // set the right wall's position
nodePtr->setScale( .05, 1.45, .1 ); // set the right wall's size
entityPtr = sceneManagerPtr->createEntity( "WallBottom", "cube.mesh" );
entityPtr->setMaterialName( "wall" ); // set material for bottom wall
entityPtr->setNormaliseNormals( true ); // fix the normals when scaled
// create the SceneNode for the bottom wall
nodePtr = sceneManagerPtr->getRootSceneNode()->createChildSceneNode( "WallBottom" );
nodePtr->attachObject( entityPtr ); // attach bottom wall to SceneNode
nodePtr->setPosition( 0, -70, 0 ); // set the bottom wall's position
nodePtr->setScale( 1.95, .05, .1 ); // set bottom wall's size
entityPtr = sceneManagerPtr->createEntity( "WallTop", "cube.mesh" );
entityPtr->setMaterialName( "wall" ); // set the material for wall
entityPtr->setNormaliseNormals( true ); // fix the normals when scaled
// create the SceneNode for the top wall
nodePtr = sceneManagerPtr->getRootSceneNode()->createChildSceneNode( "WallTop" );
nodePtr->attachObject( entityPtr ); // attach top wall to SceneNode
nodePtr->setPosition( 0, 70, 0 ); // set the top wall's position
nodePtr->setScale( 1.95, .05, .1 ); // set the top wall's size
} // end function createScene
// start a game of Pong
void Pong::run()
{
createScene(); // create the scene
Ogre::WindowEventUtilities::addWindowEventListener(windowPtr, this);
rootPtr->startRendering(); // start rendering frames
} // end function run
// update the score
void Pong::updateScore( Players player )
{
// increase the correct player's score
if ( player == Players::PLAYER1 )
player1Score++;
else
player2Score++;
wait = true; // the game should wait to restart the Ball
updateScoreText(); // update the score text on the screen
} // end function updateScore
// update the score text
void Pong::updateScoreText()
{
ostringstream scoreText; // text to be displayed
scoreText << "P2: " << player2Score; // make the text
// get the right player's TextArea
OverlayElement *textElementPtr = OverlayManager::getSingletonPtr()->getOverlayElement( "right" );
textElementPtr->setCaption( scoreText.str() ); // set the text
scoreText.str( "" ); // reset the text in scoreText
scoreText << "P1: " << player1Score; // make the text
// get the left player's TextArea
textElementPtr = OverlayManager::getSingletonPtr()->getOverlayElement( "left" );
textElementPtr->setCaption( scoreText.str() ); // set the text
} // end function updateScoreText
// respond to user keyboard input
bool Pong::keyPressed( const OIS::KeyEvent &keyEventRef )
{
// if the game is not paused
if ( !pause )
{
// process KeyEvents that apply when the game is not paused
switch ( keyEventRef.key )
{
case OIS::KC_ESCAPE: // escape key hit: quit
quit = true;
break;
case OIS::KC_UP: // up-arrow key hit: move the right Paddle up
paddle[0] = 1;
break;
case OIS::KC_DOWN: // down-arrow key hit: move the right Paddle down
paddle[0] = -1;
break;
case OIS::KC_NUMPAD8: // 8 key hit: move left Paddle up
paddle[1] = 1;
break;
case OIS::KC_NUMPAD2: // 2 key hit: move left Paddle down
paddle[1] = -1;
break;
case OIS::KC_W: // W key hit: rotate board 'up'
break;
case OIS::KC_A: // A key hit: rotate board 'left'
break;
case OIS::KC_S: // S key hit: rorate board 'down'
break;
case OIS::KC_D: // D key hit: rotate board 'right'
break;
case OIS::KC_P: // P key hit: pause the game
pause = true; // set pause to true when the user pauses the game
Overlay *pauseOverlayPtr = OverlayManager::getSingleton().getByName( "PauseOverlay" );
pauseOverlayPtr->show(); // show the pause Overlay
break;
} // end switch
} // end if
else // game is paused
{
// user hit 'R' on the keyboard
if ( keyEventRef.key == OIS::KC_R )
{
pause = false; // set pause to false when user resumes the game
Overlay *pauseOverlayPtr = OverlayManager::getSingleton().getByName( "PauseOverlay" );
pauseOverlayPtr->hide(); // hide the pause Overlay
} // end if
} // end else
return true;
} // end function keyPressed
// process key released events
bool Pong::keyReleased( const OIS::KeyEvent &keyEventRef )
{
switch ( keyEventRef.key )
{
case OIS::KC_UP: // up-arrow key released, stop moving that direction
if (paddle[0] != -1) // if we're not moving down already
paddle[0] = 0;
break;
case OIS::KC_DOWN: // down-arrow key released, stop moving that direction
if (paddle[0] != 1) // if we're not moving up already
paddle[0] = 0;
break;
case OIS::KC_NUMPAD8: // number pad 8 key released, stop moving that direction
if (paddle[1] != -1) // if we're not moving down already
paddle[1] = 0;
break;
case OIS::KC_NUMPAD2: // number pad 2 key released, stop moving that direction
if (paddle[1] != 1) // if we're not moving up already
paddle[1] = 0;
break;
}
return true;
} // end function keyReleased
// return true if the program should render the next frame
bool Pong::frameEnded( const FrameEvent &frameEvent )
{
WindowEventUtilities::messagePump();
if(windowPtr->isClosed())
{
return false;
}
return !quit; // quit = false if the user hasn't quit yet
} // end function frameEnded
// process game logic, return true if the next frame should be rendered
bool Pong::frameStarted( const FrameEvent &frameEvent )
{
keyboardPtr->capture(); // get keyboard events
// paddle moving logic
if (paddle[0] != 0) // [0] = left paddle
{
//process
if (paddle[0] < 0) // go down
{
leftPaddlePtr->movePaddle( PADDLE_DOWN );
} else if (paddle[0] > 0) // go up
{
leftPaddlePtr->movePaddle( PADDLE_UP );
}
}
if (paddle[1] != 0) // [1] = right paddle
{
//process
if (paddle[1] < 0) // go down
{
rightPaddlePtr->movePaddle( PADDLE_DOWN );
} else if (paddle[1] > 0) // go up
{
rightPaddlePtr->movePaddle( PADDLE_UP );
}
}
// the game is not paused and the Ball should move
if ( !wait && !pause )
{
// move the Ball
ballPtr->moveBall( frameEvent.timeSinceLastFrame );
} // end if
// don't move the Ball if wait is true
else if ( wait )
{
// increase time if it is less than 4 seconds
if ( time < 4 )
// add the seconds since the last frame
time += frameEvent.timeSinceLastFrame;
else
{
wait = false; // shouldn't wait to move the Ball any more
time = 0; // reset the control variable to 0
} // end else
} // end else
return !quit; // quit = false if the user hasn't quit yet
} // end function frameStarted
//Adjust mouse clipping area
void Pong::windowResized(Ogre::RenderWindow* rw)
{
unsigned int width, height, depth;
int left, top;
rw->getMetrics(width, height, depth, left, top);
const OIS::MouseState &ms = mousePtr->getMouseState();
ms.width = width;
ms.height = height;
}
//Unattach OIS before window shutdown (very important under Linux)
void Pong::windowClosed(Ogre::RenderWindow* rw)
{
}
bool Pong::mousePressed(const OIS::MouseEvent &,OIS::MouseButtonID)
{
return true;
}
bool Pong::mouseReleased(const OIS::MouseEvent &,OIS::MouseButtonID)
{
return true;
}
bool Pong::mouseMoved(const OIS::MouseEvent &)
{
return true;
}
@@ -0,0 +1,80 @@
// Pong.h
// Pong class definition (represents a game of Pong).
#ifndef PONG_H
#define PONG_H
#include <Ogre.h> // Ogre class definition
using namespace Ogre; // use the Ogre namespace
#include <OIS\OISEvents.h> // OISEvents class definition
#include <OIS\OISInputManager.h> // OISInputManager class definition
#include <OIS\OISKeyboard.h> // OISKeyboard class definition
#include <OIS\OISMouse.h>
#include <OgreWindowEventUtilities.h>
class Ball; // forward declaration of class Ball
class Paddle; // forward declaration of class Paddle
enum Players { PLAYER1, PLAYER2 };
class Pong : public FrameListener, public OIS::KeyListener, public Ogre::WindowEventListener, public OIS::MouseListener
{
public:
Pong(); // constructor
~Pong(); // destructor
void run(); // run a game of Pong
// handle keyPressed and keyReleased events
virtual bool keyPressed( const OIS::KeyEvent &keyEventRef );
virtual bool keyReleased( const OIS::KeyEvent &keyEventRef );
// handle mouseMoved, mousePressed, and mouseReleased events
virtual bool mousePressed(const OIS::MouseEvent &,OIS::MouseButtonID);
virtual bool mouseReleased(const OIS::MouseEvent &,OIS::MouseButtonID);
virtual bool mouseMoved(const OIS::MouseEvent &);
// move the game objects and control interactions between frames
virtual bool frameStarted( const FrameEvent &frameEvent );
virtual bool frameEnded( const FrameEvent &frameEvent );
static void updateScore( Players player); // update the score
private:
void createScene(); // create the scene to be rendered
static void updateScoreText(); // update the score on the screen
// Ogre objects
Root *rootPtr; // pointer to Ogre's Root object
SceneManager *sceneManagerPtr; // pointer to the SceneManager
RenderWindow *windowPtr; // pointer to RenderWindow to render scene in
Viewport *viewportPtr; // pointer to Viewport, area that a camera sees
Camera *cameraPtr; // pointer to a Camera in the scene
// OIS input objects
OIS::InputManager *inputManagerPtr; // pointer to the InputManager
OIS::Keyboard *keyboardPtr; // pointer to the Keyboard
OIS::Mouse *mousePtr; // pointer to the mouse
// Ogre::WindowEventListener
virtual void windowResized(Ogre::RenderWindow* rw);
virtual void windowClosed(Ogre::RenderWindow* rw);
// game objects
Ball *ballPtr; // pointer to the Ball
Paddle *leftPaddlePtr; // pointer to player 1's Paddle
Paddle *rightPaddlePtr; // pointer to player 2's Paddle
// variables to control game states
bool quit, pause; // did user quit or pause the game?
Real time; // used to delay the motion of a new Ball
static bool wait; // should the Ball's movement be delayed?
static int player1Score; // player 1's score
static int player2Score; // player 2's score
int paddle[2];
}; // end class Pong
#endif // PONG_H
@@ -0,0 +1,37 @@
// PongMain.cpp
// Driver program for the game of Pong
#include <iostream>
#include "Pong.h" // Pong class definition
// If running on Windows, include windows.h and define WinMain function
#if OGRE_PLATFORM==PLATFORM_WIN32 || OGRE_PLATFORM==OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
int WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
// If not, define normal main function
#else
int main( int argc, char **argv )
#endif
{
try
{
Pong game; // create a Pong object
game.run(); // start the Pong game
} // end try
catch ( std::runtime_error &error )
{
#if OGRE_PLATFORM==PLATFORM_WIN32 || OGRE_PLATFORM==OGRE_PLATFORM_WIN32
MessageBoxA( NULL, error.what(), "Exception Thrown!",
MB_OK | MB_ICONERROR | MB_TASKMODAL );
#else
std::cerr << "Exception Thrown: " << error.what() << std::endl;
#endif
} // end catch
return 0;
} // end main
@@ -0,0 +1,122 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,3,3,7
PRODUCTVERSION 1,3,3,7
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x2fL
#else
FILEFLAGS 0x2eL
#endif
FILEOS 0x4L
FILETYPE 0x0L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments", "Pong! 2014 Edition"
VALUE "CompanyName", "Copyright Amrit Panesar 2014"
VALUE "FileDescription", "Pong - a 2 bit game on a 32 bit computer"
VALUE "FileVersion", "1, 3, 3, 7"
VALUE "InternalName", "Pong"
VALUE "LegalCopyright", "Copyright Amrit Panesar (C) 2014"
VALUE "LegalTrademarks", "Amrit Panesar"
VALUE "OriginalFilename", "Pong.exe"
VALUE "PrivateBuild", "This build is far from private"
VALUE "ProductName", "Pong!"
VALUE "ProductVersion", "1, 3, 3, 7"
VALUE "SpecialBuild", "All my builds are special"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
/////////////////////////////////////////////////////////////////////////////
//
// PNG
//
IDB_PNG1 PNG "C:\\Users\\77260\\Downloads\\pong.png"
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON1 ICON "C:\\Users\\77260\\Downloads\\pong.ico"
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
@@ -0,0 +1,19 @@
Render System=OpenGL Rendering Subsystem
[Direct3D9 Rendering Subsystem]
Allow NVPerfHUD=No
Anti aliasing=None
Floating-point mode=Fastest
Full Screen=Yes
Rendering Device=NVIDIA GeForce GTX 460
VSync=No
Video Mode=1280 x 1024 @ 32-bit colour
[OpenGL Rendering Subsystem]
Colour Depth=32
Display Frequency=N/A
FSAA=16
Full Screen=No
RTT Preferred Mode=PBuffer
VSync=Yes
Video Mode=1024 x 768
@@ -0,0 +1,17 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by Resource.rc
//
#define IDB_PNG1 101
#define IDI_ICON1 102
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
@@ -0,0 +1,24 @@
# Resource locations to be added to the 'boostrap' path
# This also contains the minimum you need to use the Ogre example framework
[Bootstrap]
FileSystem=resources
Zip=../../media/packs/OgreCore.zip
# Resource locations to be added to the default path
[General]
FileSystem=../../media
FileSystem=../../media/fonts
FileSystem=../../media/materials/programs
FileSystem=../../media/materials/scripts
FileSystem=../../media/materials/textures
FileSystem=../../media/models
FileSystem=../../media/overlays
FileSystem=../../media/particle
FileSystem=../../media/gui
FileSystem=../../media/DeferredShadingMedia
Zip=../../media/packs/cubemap.zip
Zip=../../media/packs/cubemapsJS.zip
Zip=../../media/packs/dragon.zip
Zip=../../media/packs/fresneldemo.zip
Zip=../../media/packs/ogretestmap.zip
Zip=../../media/packs/skybox.zip
@@ -0,0 +1,15 @@
// define the BlueBold font
BlueBold
{
// define the font type
type truetype
// set the source file for the font
source bluebold.ttf
// set the font size
size 16
// set the font resolution (96 is standard)
resolution 96
}
@@ -0,0 +1,12 @@
// menu material definition
material menu
{
technique
{
pass
{
ambient 1.0 1.0 1.0
diffuse 1.0 1.0 1.0
}
}
}
@@ -0,0 +1,167 @@
// An Overlay to display an options menu
MenuOverlay
{
// set a high z-order to display on top of everything
zorder 600
// the root container for the menu items
container Panel(rootPanel)
{
material menu
// text for the root Panel
element TextArea(instructionsText)
{
// position the text toward the bottom center of the screen
top 0.8
left 0.2
// set font use for caption and set the size and color
font_name BlueBold
char_height .05
colour 1 1 1
caption Press Enter to start or Esc to exit
}
// end of instructionsText
// container for the Ball options
container Panel(ballPanel)
{
// position the container toward the left side of the screen
top 0.1
left 0.1
width 0.3
height 0.5
// TextAreas to display Ball options
element TextArea(ballOptionsTitle)
{
// position and size the TextArea
height 0.1
left 0.05
// set font use for caption and set the size and color
font_name BlueBold
char_height .05
colour 1 1 1
caption Ball Options
}
// end of ballOptionsTitle
element TextArea(ballSlow)
{
// position and size the text
top 0.2
height 0.1
// set font use for caption and set the size and color
font_name BlueBold
char_height .05
colour 1 1 1
caption Slow Ball (Press A)
}
// end of ballSlow
element TextArea(ballMedium)
{
// position and size the text
top 0.3
height 0.1
// set font use for caption and set the size and color
font_name BlueBold
char_height .05
colour 1 1 1
caption Medium Ball (Press B)
}
// end of ballMedium
element TextArea(ballFast)
{
// position and size the text
top 0.4
height 0.1
// set font use for caption and set the size and color
font_name BlueBold
char_height .05
colour 1 1 1
caption Fast Ball (Press C)
}
// end of ballFast
}
// end of ballPanel
// container for the Paddle options
container Panel(paddlePanel)
{
// position the container toward the right side of the screen
top 0.1
left 0.5
width 0.3
height 0.5
// TextAreas to display Paddle options
element TextArea(paddleOptionsTitle)
{
// position and size the text
height 0.1
left 0.05
// set font use for caption and set the size and color
font_name BlueBold
char_height .05
colour 1 1 1
caption Paddle Options
}
// end of paddleOptionsTitle
element TextArea(paddleSlow)
{
// position and size the text
top 0.2
height 0.1
// set font use for caption and set the size and color
font_name BlueBold
char_height .05
colour 1 1 1
caption Slow Paddles (Press 1)
}
// end of paddleSlow
element TextArea(paddleMedium)
{
// position and size the text
top 0.3
height 0.1
// set font use for caption and set the size and color
font_name BlueBold
char_height .05
colour 1 1 1
caption Medium Paddles (Press 2)
}
// end of paddleMedium
element TextArea(paddleFast)
{
// position and size the text
top 0.4
height 0.1
// set font use for caption and set the size and color
font_name BlueBold
char_height .05
colour 1 1 1
caption Fast Paddles (Press 3)
}
// end of paddleFast
}
// end of paddlePanel
}
// end of rootPanel
}
// end of MenuOverlay
@@ -0,0 +1,51 @@
// ball material definition
material ball
{
// define one technique for rendering the Ball
technique
{
// render the Ball in one pass
pass
{
// color the Ball White
ambient 1 1 1
diffuse 1 1 1
specular 1 1 1 255
}
}
}
// paddle material definition
material paddle
{
// define one technique for rendering a Paddle
technique
{
// render a Paddle in one pass
pass
{
// color the Paddle white
ambient 1 1 1
diffuse 1 1 1
specular 1 1 1 255
}
}
}
// wall material definition
material wall
{
// define one technique for rendering a wall
technique
{
// render a wall in one pass
pass
{
// color the wall cyan
ambient 0 0 0
diffuse 0 0 0
specular 0 0 0 255
}
}
}
@@ -0,0 +1,146 @@
// An Overlay to display the score
Score
{
// set a high z-order, displays on top of anything with lower z-order
zorder 500
// create a PanelOverlayElement container to hold the text areas
container Panel(ScorePanel)
{
// use relative metrics mode to position this container at the
// top-left corner of the screen
metrics_mode relative
left 0.0
top 0.0
// make it 1/10 the height and the full width of the screen
width 1.0
height .1
// create a TextAreaOverlayElement to display player 1's score
element TextArea(left)
{
// position and size the element relative to the container
metrics_mode relative
// position it at the top of the container 5% from the left and
// make it the same height and half as long as the container
left 0.05
top 0.0
width 0.5
height 1.0
// set font use for caption and set the size and color
font_name PongScore
char_height .05
colour 1 1 1
caption P1: 0
}
// create a TextAreaOverlayElement to display player 2's score
element TextArea(right)
{
// position and size the element relative to the container
metrics_mode relative
// position it at the top of the container 69% from the left and
// make it the same height as the container, stretch to the end
left 0.69
top 0.0
width 0.5
height 1.0
// set font use for caption and set the size and color
font_name PongScore
char_height 0.05
colour 1 1 1
caption P2: 0
}
}
}
// An Overlay to display "Game Paused" when the player pauses the game
PauseOverlay
{
// set a high z-order, displays on top of anything with lower z-order
zorder 500
// create a PanelOverlayElement container to hold the text area
container Panel(Pause)
{
// use relative metrics mode to position and size this container
metrics_mode relative
// place the container at the top-left corner of the window
left 0.0
top 0.0
// make the container the same size as the window
width 1.0
height 1.0
// create a TextAreaOverlayElement to display the text
element TextArea(pauseText)
{
// position and size the element relative to its container
metrics_mode relative
// center it vertically in the container
vert_align center
// put the left corner 4/10 from the left of the container and
// make it 2/10 the width of the container and 1/10 the height
left 0.4
width 0.2
height 0.1
// set font use for caption and set the size and color
font_name PongText
char_height 0.05
colour 1 1 1
caption Game Paused (Press R to Continue)
}
}
}
// An Overlay to display which player won the game
WinnerOverlay
{
// set a high z-order, displays on top of anything with lower z-order
zorder 500
// create a PanelOverlayElement container to hold the text area
container Panel(Winner)
{
// use relative metrics mode to position and size this container
metrics_mode relative
// place the container at the top-left corner of the window
left 0.0
top 0.0
// make the container the same size as the window
width 1.0
height 1.0
// create a TextAreaOverlayElement to display the text
element TextArea(winnerText)
{
// position and size the element relative to its container
metrics_mode relative
// put the left corner 4/10 from the left of the container and
// make it 2/10 the width of the container and 1/10 the height
left 0.4
top 0.3
width 0.2
height 0.1
// set font use for caption and set the size and color
font_name PongText
char_height 0.05
colour 1 1 1
}
}
}
@@ -0,0 +1,15 @@
// define the PongScore font
PongScore
{
// define the font type
type truetype
// set the source file for the font
source PongScore.ttf
// set the font size
size 16
// set the font resolution (96 is standard)
resolution 96
}
@@ -0,0 +1,15 @@
// define the PongText font
PongText
{
// define the font type
type truetype
// set the source file for the font
source PongText.ttf
// set the font size
size 16
// set the font resolution (96 is standard)
resolution 96
}
@@ -0,0 +1,15 @@
// define the BlueBold font
BlueBold
{
// define the font type
type truetype
// set the source file for the font
source bluebold.ttf
// set the font size
size 16
// set the font resolution (96 is standard)
resolution 96
}
@@ -0,0 +1,12 @@
// menu material definition
material menu
{
technique
{
pass
{
ambient 1.0 1.0 1.0
diffuse 1.0 1.0 1.0
}
}
}
@@ -0,0 +1,167 @@
// An Overlay to display an options menu
MenuOverlay
{
// set a high z-order to display on top of everything
zorder 600
// the root container for the menu items
container Panel(rootPanel)
{
material menu
// text for the root Panel
element TextArea(instructionsText)
{
// position the text toward the bottom center of the screen
top 0.8
left 0.2
// set font use for caption and set the size and color
font_name BlueBold
char_height .05
colour 0 0 0
caption Press Enter to start or Esc to exit
}
// end of instructionsText
// container for the Ball options
container Panel(ballPanel)
{
// position the container toward the left side of the screen
top 0.1
left 0.1
width 0.3
height 0.5
// TextAreas to display Ball options
element TextArea(ballOptionsTitle)
{
// position and size the TextArea
height 0.1
left 0.05
// set font use for caption and set the size and color
font_name BlueBold
char_height .05
colour 0 0 0
caption Ball Options
}
// end of ballOptionsTitle
element TextArea(ballSlow)
{
// position and size the text
top 0.2
height 0.1
// set font use for caption and set the size and color
font_name BlueBold
char_height .05
colour 0 0 0
caption Slow Ball (Press A)
}
// end of ballSlow
element TextArea(ballMedium)
{
// position and size the text
top 0.3
height 0.1
// set font use for caption and set the size and color
font_name BlueBold
char_height .05
colour 1.0 0 0
caption Medium Ball (Press B)
}
// end of ballMedium
element TextArea(ballFast)
{
// position and size the text
top 0.4
height 0.1
// set font use for caption and set the size and color
font_name BlueBold
char_height .05
colour 0 0 0
caption Fast Ball (Press C)
}
// end of ballFast
}
// end of ballPanel
// container for the Paddle options
container Panel(paddlePanel)
{
// position the container toward the right side of the screen
top 0.1
left 0.5
width 0.3
height 0.5
// TextAreas to display Paddle options
element TextArea(paddleOptionsTitle)
{
// position and size the text
height 0.1
left 0.05
// set font use for caption and set the size and color
font_name BlueBold
char_height .05
colour 0 0 0
caption Paddle Options
}
// end of paddleOptionsTitle
element TextArea(paddleSlow)
{
// position and size the text
top 0.2
height 0.1
// set font use for caption and set the size and color
font_name BlueBold
char_height .05
colour 0 0 0
caption Slow Paddles (Press 1)
}
// end of paddleSlow
element TextArea(paddleMedium)
{
// position and size the text
top 0.3
height 0.1
// set font use for caption and set the size and color
font_name BlueBold
char_height .05
colour 0 0 1.0
caption Medium Paddles (Press 2)
}
// end of paddleMedium
element TextArea(paddleFast)
{
// position and size the text
top 0.4
height 0.1
// set font use for caption and set the size and color
font_name BlueBold
char_height .05
colour 0 0 0
caption Fast Paddles (Press 3)
}
// end of paddleFast
}
// end of paddlePanel
}
// end of rootPanel
}
// end of MenuOverlay
@@ -0,0 +1,51 @@
// ball material definition
material ball
{
// define one technique for rendering the Ball
technique
{
// render the Ball in one pass
pass
{
// color the Ball violet
ambient 0.58 0 0.827
diffuse 0.58 0 0.827
specular 0.58 0 0.827 120
}
}
}
// paddle material definition
material paddle
{
// define one technique for rendering a Paddle
technique
{
// render a Paddle in one pass
pass
{
// color the Paddle dark orange
ambient 1 0.549 0
diffuse 1 0.549 0
specular 1 0.549 0 120
}
}
}
// wall material definition
material wall
{
// define one technique for rendering a wall
technique
{
// render a wall in one pass
pass
{
// color the wall cyan
ambient 0 0.545 0.545
diffuse 0 0.545 0.545
specular 0 0.545 0.545 120
}
}
}
@@ -0,0 +1,146 @@
// An Overlay to display the score
Score
{
// set a high z-order, displays on top of anything with lower z-order
zorder 500
// create a PanelOverlayElement container to hold the text areas
container Panel(ScorePanel)
{
// use relative metrics mode to position this container at the
// top-left corner of the screen
metrics_mode relative
left 0.0
top 0.0
// make it 1/10 the height and the full width of the screen
width 1.0
height .1
// create a TextAreaOverlayElement to display player 1's score
element TextArea(left)
{
// position and size the element relative to the container
metrics_mode relative
// position it at the top of the container 5% from the left and
// make it the same height and half as long as the container
left 0.05
top 0.0
width 0.5
height 1.0
// set font use for caption and set the size and color
font_name BlueBold
char_height .05
colour 1.0 0 0
caption Player 1 Score: 0
}
// create a TextAreaOverlayElement to display player 2's score
element TextArea(right)
{
// position and size the element relative to the container
metrics_mode relative
// position it at the top of the container 69% from the left and
// make it the same height as the container, stretch to the end
left 0.69
top 0.0
width 0.5
height 1.0
// set font use for caption and set the size and color
font_name BlueBold
char_height 0.05
colour 1.0 0 0
caption Player 2 Score: 0
}
}
}
// An Overlay to display "Game Paused" when the player pauses the game
PauseOverlay
{
// set a high z-order, displays on top of anything with lower z-order
zorder 500
// create a PanelOverlayElement container to hold the text area
container Panel(Pause)
{
// use relative metrics mode to position and size this container
metrics_mode relative
// place the container at the top-left corner of the window
left 0.0
top 0.0
// make the container the same size as the window
width 1.0
height 1.0
// create a TextAreaOverlayElement to display the text
element TextArea(pauseText)
{
// position and size the element relative to its container
metrics_mode relative
// center it vertically in the container
vert_align center
// put the left corner 4/10 from the left of the container and
// make it 2/10 the width of the container and 1/10 the height
left 0.4
width 0.2
height 0.1
// set font use for caption and set the size and color
font_name BlueBold
char_height 0.05
colour 0 0 0
caption Game Paused
}
}
}
// An Overlay to display which player won the game
WinnerOverlay
{
// set a high z-order, displays on top of anything with lower z-order
zorder 500
// create a PanelOverlayElement container to hold the text area
container Panel(Winner)
{
// use relative metrics mode to position and size this container
metrics_mode relative
// place the container at the top-left corner of the window
left 0.0
top 0.0
// make the container the same size as the window
width 1.0
height 1.0
// create a TextAreaOverlayElement to display the text
element TextArea(winnerText)
{
// position and size the element relative to its container
metrics_mode relative
// put the left corner 4/10 from the left of the container and
// make it 2/10 the width of the container and 1/10 the height
left 0.4
top 0.3
width 0.2
height 0.1
// set font use for caption and set the size and color
font_name BlueBold
char_height 0.05
colour 0 0 0
}
}
}