Question
I have a space shooter game I have the code for. I need to make the following changes. I would like to able to track
I have a space shooter game I have the code for. I need to make the following changes.
I would like to able to track the players score and save the high score, add a new enemy type and a new weapon type, have a new level with different enemy patterns and add an options menu.
Here is he code I need to base the changes from.
int main() {return (newSpaceFighter())->Run(); }Spacefighter.cpp
#include"KatanaEngine.h"
#include"SpaceFighter.h"
#include"MainMenuScreen.h"
#include"Projectile.h"
usingnamespace KatanaEngine;
SpaceFighter::SpaceFighter()
{
SetScreenResolution(1600, 900);
SetFullScreen(false);
InitializeScreenManager();
SetResourceDirectory("..\\SpaceFighter\\Content\\");
// Font for displaying the frame rate
Font::SetLoadSize(18, true);
Font *pFont = GetResourceManager()->Load("Fonts\\Arialbd.ttf",false);
SetFrameCounterFont(pFont);
}
voidSpaceFighter::Draw(SpriteBatch *pSpriteBatch)
{
Game::Draw(pSpriteBatch);
DisplayFrameRate();
}
voidSpaceFighter::LoadContent(ResourceManager *pResourceManager)
{
// Load static resources
Projectile::SetTexture(pResourceManager->Load("Textures\\Bullet.png"));
GetScreenManager()->AddScreen(newMainMenuScreen());
ResetGameTime();
}
Spacefighter.h
#pragmaonce
#include"KatanaEngine.h"
#include"SpriteBatch.h"
usingnamespace KatanaEngine;
classSpaceFighter :publicGame
{
public:
SpaceFighter();
virtual ~SpaceFighter() { }
virtual std::string GetName()const {return"SpaceFighter"; }
virtualvoid Draw(SpriteBatch *pSpriteBatch);
virtualvoid LoadContent(ResourceManager *pResourceManager);
};
Collision Manager.cpp
#include"CollisionManager.h"
voidCollisionManager::AddCollisionType(constCollisionTypetype1,constCollisionTypetype2,OnCollisioncallback)
{
Collision c;
c.Type1= (type1
c.Type2= (type1>type2) ?type1 :type2;
c.Callback =callback;
m_collisions.push_back(c);
}
voidCollisionManager::CheckCollision(GameObject *pGameObject1,GameObject *pGameObject2)
{
CollisionType t1 =pGameObject1->GetCollisionType();
CollisionType t2 =pGameObject2->GetCollisionType();
if (t1== t2 || t1==CollisionType::NONE || t2==CollisionType::NONE)return;
bool swapped =false;
if (t1> t2)
{
std::swap(t1, t2);
swapped =true;
}
m_nonCollisionIt= m_nonCollisions.begin();
for (; m_nonCollisionIt!= m_nonCollisions.end(); m_nonCollisionIt++)
{
NonCollision nc =*m_nonCollisionIt;
if ((nc.Type1== t1 && nc.Type2== t2))return;
}
m_collisionIt= m_collisions.begin();
for (; m_collisionIt!= m_collisions.end(); m_collisionIt++)
{
Collision c =*m_collisionIt;
if ((c.Type1== t1 && c.Type2== t2))
{
Vector2 difference =pGameObject1->GetPosition() -pGameObject2->GetPosition();
float radiiSum =pGameObject1->GetCollisionRadius() +pGameObject2->GetCollisionRadius();
float radiiSumSquared = radiiSum * radiiSum;
if (difference.LengthSquared() <= radiiSumSquared)
{
if (!swapped) c.Callback(pGameObject1,pGameObject2);
else c.Callback(pGameObject2,pGameObject1);
}
return;
}
}
AddNonCollisionType(t1, t2);
}
voidCollisionManager::AddNonCollisionType(constCollisionTypetype1,constCollisionTypetype2)
{
NonCollision nc;
nc.Type1= (type1
nc.Type2= (type1>type2) ?type1 :type2;
m_nonCollisions.push_back(nc);
}
Collision Manager.h
#pragmaonce
#include"GameObject.h"
typedefvoid(*OnCollision)(GameObject *pGameObject1,GameObject *pGameObject2);
classCollisionManager
{
public:
virtual ~CollisionManager() { }
virtualvoid AddCollisionType(constCollisionTypetype1,constCollisionTypetype2,OnCollisioncallback);
virtualvoid AddNonCollisionType(constCollisionTypetype1,constCollisionTypetype2);
virtualvoid CheckCollision(GameObject *pGameObject1,GameObject *pGameObject2);
private:
structNonCollision
{
CollisionType Type1;
CollisionType Type2;
};
structCollision
{
CollisionType Type1;
CollisionType Type2;
OnCollision Callback;
};
std::vector m_nonCollisions;
std::vector::iterator m_nonCollisionIt;
std::vector m_collisions;
std::vector::iterator m_collisionIt;
};
Collision Type.cpp
#include"CollisionType.h"
constCollisionTypeCollisionType::NONE = CollisionType(0);
constCollisionTypeCollisionType::PLAYER =CollisionType(1 << 0);
constCollisionTypeCollisionType::ENEMY =CollisionType(1 << 1);
constCollisionTypeCollisionType::SHIP = CollisionType(1 << 2);
constCollisionTypeCollisionType::PROJECTILE=CollisionType(1 << 3);
Collision Type.h
#pragmaonce
classCollisionType
{
public:
CollisionType() { m_value = 0; }
virtual ~CollisionType() { }
staticconstCollisionType NONE;
staticconstCollisionType PLAYER;
staticconstCollisionType ENEMY;
staticconstCollisionType SHIP;
staticconstCollisionType PROJECTILE;
CollisionType &CollisionType::operator=(constCollisionType &type)
{
m_value =type.m_value;
return *this;
}
boolCollisionType::operator==(constCollisionType &type)const
{
return m_value ==type.m_value;
}
boolCollisionType::operator!=(constCollisionType &type)const
{
return m_value !=type.m_value;
}
boolCollisionType::operator<(constCollisionType &type)const
{
return m_value
}
boolCollisionType::operator>(constCollisionType &type)const
{
return m_value >type.m_value;
}
constCollisionTypeoperator|(constCollisionType &type)const
{
return (CollisionType)(m_value |type.m_value);
}
CollisionType &CollisionType::operator|=(constCollisionType &type)
{
m_value |=type.m_value;
return *this;
}
constCollisionTypeoperator&(constCollisionType &type)const
{
return (CollisionType)(m_value & type.m_value);
}
CollisionType &CollisionType::operator&=(constCollisionType &type)
{
m_value &=type.m_value;
return *this;
}
constCollisionTypeoperator^(constCollisionType &type)const
{
return (CollisionType)(m_value ^type.m_value);
}
CollisionType &CollisionType::operator^=(constCollisionType &type)
{
m_value ^=type.m_value;
return *this;
}
bool Contains(constCollisionType &type)
{
return (m_value & type.m_value) > 0;
}
protected:
CollisionType(constunsignedshortvalue) { m_value =value; }
private:
unsignedshort m_value;
};
BioEnemyShip.cpp
#include"BioEnemyShip.h"
// The BioEnemyShip class represents an enemy ship that is fought in the game.
BioEnemyShip::BioEnemyShip()
{
// Set the speed of the ship.
SetSpeed(150);
// Set the maximum hit points of the ship.
SetMaxHitPoints(1);
// Set the collision radius of the ship.
SetCollisionRadius(20);
}
voidBioEnemyShip::Update(const GameTime*pGameTime)
{
if (IsActive())
{
// Get the x position of the ship.
float x = sin(pGameTime->GetTotalTime() * Math::PI + GetIndex());
// Multiply the x position by the speed and time elapsed.
x *= GetSpeed() *pGameTime->GetTimeElapsed() * 1.4f;
// Translate the position of the ship.
TranslatePosition(x, GetSpeed() *pGameTime->GetTimeElapsed());
// If the ship is not on screen, deactivate it.
if (!IsOnScreen()) Deactivate();
}
// Call the update method of the base class.
EnemyShip::Update(pGameTime);
}
voidBioEnemyShip::Draw(SpriteBatch*pSpriteBatch)
{
if (IsActive())
{
// Draw the ship.
pSpriteBatch->Draw(m_pTexture, GetPosition(), Color::White, m_pTexture->GetCenter(), Vector2::ONE, Math::PI, 1);
}
}
BioEnemyShip.h
#pragmaonce
#include"EnemyShip.h"
classBioEnemyShip :publicEnemyShip
{
public:
BioEnemyShip();
virtual ~BioEnemyShip() { }
virtualvoid SetTexture(Texture *pTexture) { m_pTexture =pTexture; }
virtualvoid Update(constGameTime *pGameTime);
virtualvoid Draw(SpriteBatch *pSpriteBatch);
private:
Texture *m_pTexture =nullptr;
};
EnemyShip.cpp
#include"EnemyShip.h"
EnemyShip::EnemyShip()
{
SetMaxHitPoints(1);
SetCollisionRadius(20);
}
voidEnemyShip::Update(constGameTime *pGameTime)
{
if (m_delaySeconds > 0)
{
m_delaySeconds -=pGameTime->GetTimeElapsed();
if (m_delaySeconds <= 0)
{
GameObject::Activate();
}
}
if (IsActive())
{
m_activationSeconds +=pGameTime->GetTimeElapsed();
if (m_activationSeconds > 2 && !IsOnScreen()) Deactivate();
}
Ship::Update(pGameTime);
}
voidEnemyShip::Initialize(constVector2position,constdoubledelaySeconds)
{
SetPosition(position);
m_delaySeconds =delaySeconds;
Ship::Initialize();
}
voidEnemyShip::Hit(constfloatdamage)
{
Ship::Hit(damage);
}
EnemyShip.h
#pragmaonce
#include"Ship.h"
classEnemyShip :publicShip
{
public:
EnemyShip();
virtual ~EnemyShip() { }
virtualvoid Update(constGameTime *pGameTime);
// EX: Pure Virtual
virtualvoid Draw(SpriteBatch *pSpriteBatch) = 0;
virtualvoid Initialize(constVector2position,constdoubledelaySeconds);
virtualvoid Fire() { }
virtualvoid Hit(constfloatdamage);
virtual std::string ToString()const {return"Enemy Ship"; }
virtualCollisionType GetCollisionType()const {returnCollisionType::ENEMY|CollisionType::SHIP; }
Question:
I have a space shooter game I have the code for. I need to make the following changes.
I would like to able to track the players score and save the high score, add a new enemy type and a new weapon type, have a new level with different enemy patterns and add an options menu.
Here is he code I need to base the changes from.
Main.cpp
#include"SpaceFighter.h"
int main() {return (newSpaceFighter())->Run(); }
Spacefighter.cpp
#include"KatanaEngine.h"
#include"SpaceFighter.h"
#include"MainMenuScreen.h"
#include"Projectile.h"
usingnamespace KatanaEngine;
SpaceFighter::SpaceFighter()
{
SetScreenResolution(1600, 900);
SetFullScreen(false);
InitializeScreenManager();
SetResourceDirectory("..\\SpaceFighter\\Content\\");
// Font for displaying the frame rate
Font::SetLoadSize(18, true);
Font *pFont = GetResourceManager()->Load("Fonts\\Arialbd.ttf",false);
SetFrameCounterFont(pFont);
}
voidSpaceFighter::Draw(SpriteBatch *pSpriteBatch)
{
Game::Draw(pSpriteBatch);
DisplayFrameRate();
}
voidSpaceFighter::LoadContent(ResourceManager *pResourceManager)
{
// Load static resources
Projectile::SetTexture(pResourceManager->Load("Textures\\Bullet.png"));
GetScreenManager()->AddScreen(newMainMenuScreen());
ResetGameTime();
}
Spacefighter.h
#pragmaonce
#include"KatanaEngine.h"
#include"SpriteBatch.h"
usingnamespace KatanaEngine;
classSpaceFighter :publicGame
{
public:
SpaceFighter();
virtual ~SpaceFighter() { }
virtual std::string GetName()const {return"SpaceFighter"; }
virtualvoid Draw(SpriteBatch *pSpriteBatch);
virtualvoid LoadContent(ResourceManager *pResourceManager);
};
Collision Manager.cpp
#include"CollisionManager.h"
voidCollisionManager::AddCollisionType(constCollisionTypetype1,constCollisionTypetype2,OnCollisioncallback)
{
Collision c;
c.Type1= (type1
c.Type2= (type1>type2) ?type1 :type2;
c.Callback =callback;
m_collisions.push_back(c);
}
voidCollisionManager::CheckCollision(GameObject *pGameObject1,GameObject *pGameObject2)
{
CollisionType t1 =pGameObject1->GetCollisionType();
CollisionType t2 =pGameObject2->GetCollisionType();
if (t1== t2 || t1==CollisionType::NONE || t2==CollisionType::NONE)return;
bool swapped =false;
if (t1> t2)
{
std::swap(t1, t2);
swapped =true;
}
m_nonCollisionIt= m_nonCollisions.begin();
for (; m_nonCollisionIt!= m_nonCollisions.end(); m_nonCollisionIt++)
{
NonCollision nc =*m_nonCollisionIt;
if ((nc.Type1== t1 && nc.Type2== t2))return;
}
m_collisionIt= m_collisions.begin();
for (; m_collisionIt!= m_collisions.end(); m_collisionIt++)
{
Collision c =*m_collisionIt;
if ((c.Type1== t1 && c.Type2== t2))
{
Vector2 difference =pGameObject1->GetPosition() -pGameObject2->GetPosition();
float radiiSum =pGameObject1->GetCollisionRadius() +pGameObject2->GetCollisionRadius();
float radiiSumSquared = radiiSum * radiiSum;
if (difference.LengthSquared() <= radiiSumSquared)
{
if (!swapped) c.Callback(pGameObject1,pGameObject2);
else c.Callback(pGameObject2,pGameObject1);
}
return;
}
}
AddNonCollisionType(t1, t2);
}
voidCollisionManager::AddNonCollisionType(constCollisionTypetype1,constCollisionTypetype2)
{
NonCollision nc;
nc.Type1= (type1
nc.Type2= (type1>type2) ?type1 :type2;
m_nonCollisions.push_back(nc);
}
Collision Manager.h
#pragmaonce
#include"GameObject.h"
typedefvoid(*OnCollision)(GameObject *pGameObject1,GameObject *pGameObject2);
classCollisionManager
{
public:
virtual ~CollisionManager() { }
virtualvoid AddCollisionType(constCollisionTypetype1,constCollisionTypetype2,OnCollisioncallback);
virtualvoid AddNonCollisionType(constCollisionTypetype1,constCollisionTypetype2);
virtualvoid CheckCollision(GameObject *pGameObject1,GameObject *pGameObject2);
private:
structNonCollision
{
CollisionType Type1;
CollisionType Type2;
};
structCollision
{
CollisionType Type1;
CollisionType Type2;
OnCollision Callback;
};
std::vector m_nonCollisions;
std::vector::iterator m_nonCollisionIt;
std::vector m_collisions;
std::vector::iterator m_collisionIt;
};
Collision Type.cpp
#include"CollisionType.h"
constCollisionTypeCollisionType::NONE = CollisionType(0);
constCollisionTypeCollisionType::PLAYER =CollisionType(1 << 0);
constCollisionTypeCollisionType::ENEMY =CollisionType(1 << 1);
constCollisionTypeCollisionType::SHIP = CollisionType(1 << 2);
constCollisionTypeCollisionType::PROJECTILE=CollisionType(1 << 3);
Collision Type.h
#pragmaonce
classCollisionType
{
public:
CollisionType() { m_value = 0; }
virtual ~CollisionType() { }
staticconstCollisionType NONE;
staticconstCollisionType PLAYER;
staticconstCollisionType ENEMY;
staticconstCollisionType SHIP;
staticconstCollisionType PROJECTILE;
CollisionType &CollisionType::operator=(constCollisionType &type)
{
m_value =type.m_value;
return *this;
}
boolCollisionType::operator==(constCollisionType &type)const
{
return m_value ==type.m_value;
}
boolCollisionType::operator!=(constCollisionType &type)const
{
return m_value !=type.m_value;
}
boolCollisionType::operator<(constCollisionType &type)const
{
return m_value
}
boolCollisionType::operator>(constCollisionType &type)const
{
return m_value >type.m_value;
}
constCollisionTypeoperator|(constCollisionType &type)const
{
return (CollisionType)(m_value |type.m_value);
}
CollisionType &CollisionType::operator|=(constCollisionType &type)
{
m_value |=type.m_value;
return *this;
}
constCollisionTypeoperator&(constCollisionType &type)const
{
return (CollisionType)(m_value & type.m_value);
}
CollisionType &CollisionType::operator&=(constCollisionType &type)
{
m_value &=type.m_value;
return *this;
}
constCollisionTypeoperator^(constCollisionType &type)const
{
return (CollisionType)(m_value ^type.m_value);
}
CollisionType &CollisionType::operator^=(constCollisionType &type)
{
m_value ^=type.m_value;
return *this;
}
bool Contains(constCollisionType &type)
{
return (m_value & type.m_value) > 0;
}
protected:
CollisionType(constunsignedshortvalue) { m_value =value; }
private:
unsignedshort m_value;
};
BioEnemyShip.cpp
#include"BioEnemyShip.h"
// The BioEnemyShip class represents an enemy ship that is fought in the game.
BioEnemyShip::BioEnemyShip()
{
// Set the speed of the ship.
SetSpeed(150);
// Set the maximum hit points of the ship.
SetMaxHitPoints(1);
// Set the collision radius of the ship.
SetCollisionRadius(20);
}
voidBioEnemyShip::Update(const GameTime*pGameTime)
{
if (IsActive())
{
// Get the x position of the ship.
float x = sin(pGameTime->GetTotalTime() * Math::PI + GetIndex());
// Multiply the x position by the speed and time elapsed.
x *= GetSpeed() *pGameTime->GetTimeElapsed() * 1.4f;
// Translate the position of the ship.
TranslatePosition(x, GetSpeed() *pGameTime->GetTimeElapsed());
// If the ship is not on screen, deactivate it.
if (!IsOnScreen()) Deactivate();
}
// Call the update method of the base class.
EnemyShip::Update(pGameTime);
}
voidBioEnemyShip::Draw(SpriteBatch*pSpriteBatch)
{
if (IsActive())
{
// Draw the ship.
pSpriteBatch->Draw(m_pTexture, GetPosition(), Color::White, m_pTexture->GetCenter(), Vector2::ONE, Math::PI, 1);
}
}
BioEnemyShip.h
#pragmaonce
#include"EnemyShip.h"
classBioEnemyShip :publicEnemyShip
{
public:
BioEnemyShip();
virtual ~BioEnemyShip() { }
virtualvoid SetTexture(Texture *pTexture) { m_pTexture =pTexture; }
virtualvoid Update(constGameTime *pGameTime);
virtualvoid Draw(SpriteBatch *pSpriteBatch);
private:
Texture *m_pTexture =nullptr;
};
EnemyShip.cpp
#include"EnemyShip.h"
EnemyShip::EnemyShip()
{
SetMaxHitPoints(1);
SetCollisionRadius(20);
}
voidEnemyShip::Update(constGameTime *pGameTime)
{
if (m_delaySeconds > 0)
{
m_delaySeconds -=pGameTime->GetTimeElapsed();
if (m_delaySeconds <= 0)
{
GameObject::Activate();
}
}
if (IsActive())
{
m_activationSeconds +=pGameTime->GetTimeElapsed();
if (m_activationSeconds > 2 && !IsOnScreen()) Deactivate();
}
Ship::Update(pGameTime);
}
voidEnemyShip::Initialize(constVector2position,constdoubledelaySeconds)
{
SetPosition(position);
m_delaySeconds =delaySeconds;
Ship::Initialize();
}
voidEnemyShip::Hit(constfloatdamage)
{
Ship::Hit(damage);
}
EnemyShip.h
#pragmaonce
#include"Ship.h"
classEnemyShip :publicShip
{
public:
EnemyShip();
virtual ~EnemyShip() { }
virtualvoid Update(constGameTime *pGameTime);
// EX: Pure Virtual
virtualvoid Draw(SpriteBatch *pSpriteBatch) = 0;
virtualvoid Initialize(constVector2position,constdoubledelaySeconds);
virtualvoid Fire() { }
virtualvoid Hit(constfloatdamage);
virtual std::string ToString()const {return"Enemy Ship"; }
virtualCollisionType GetCollisionType()const {returnCollisionType::ENEMY|CollisionType::SHIP; }
2 I If the olove address is on a coubnet w/ a wabnet 255.255.252.0, write the CIDE address mask - this coulinet in the prefiex / size notation. 3. a company is assigned abtock of consecutive IP addresses starting at 201.18.0.0. If the addresses are to be assigned to four departments in org (HR, Engs, Sales, Research) with Lea. this requiring (2000, 1000, 3500, 600) addresses respectively, give the first IP address assigned, the last IP address assigned, and the associated address in the ...Z/s notation. 4 A router has just received the following new Il addresses: 64.8.96.0/21, 64.8.104.0/21, 64.8.112.0/21, and 64.8.120.0/21. If all of them use the war. use the wam-outgoing line, they can they be aggregated? If so, to what? If not, why?
Step by Step Solution
3.55 Rating (155 Votes )
There are 3 Steps involved in it
Step: 1
To implement the changes you mentioned tracking player score saving high score adding a new enemy type and weapon type creating a new level with diffe...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started