This is an advanced demo.
More...
This is an advanced demo.
Similar to the basic demo, this details the basic scene header as well as a game object setup with all of the 'able' functions. Here is the beginning scene:
class Tank;
class TankScene :
public Scene {
public:
TankScene() = {};
~TankScene() = {};
private:
Tank* tank;
}
As well as the implementation file:
TankScene::Initialize() {
pFrigate = new Frigate();
pFrigate.setPosition(Vect(40, 10, 40));
pGlobTerrain->Initialize();
}
TankScene::SceneEnd() {
delete pFrigate;
BulletFactory::Terminate();
}
The header of the Frigate itself includes:
public:
Frigate();
Frigate(const Frigate&) = delete;
~Frigate();
virtual void Alarm0()
override;
virtual void Alarm1()
override;
virtual void Alarm2()
override;
virtual void Alarm3()
override;
virtual void Update()
override;
virtual void Draw()
override;
virtual void Collision(Cottage*);
virtual void Collision(Frigate*) { DebugMsg::out("Collision Frigate with Frigate\n"); }
Vect shipPos;
Matrix shipRot;
Matrix shipScale;
const float shipTransSpeed = 1.0f;
const float shipRotAngle = 0.05f;
Vect CamShipOffset;
Vect CamLookAt;
private:
GraphicsObject_TextureLight* pObjFT;
Matrix WorldMat1;
float angle;
};
The resulting implementation must define the overloaded functions and do something interesting with the position and activity of the model.
Frigate::Frigate() {
Vect LightColor(1.50f, 1.50f, 1.50f, 1.0f);
Vect LightPos(1.0f, 1.0f, 1.0f, 1.0f);
shipScale.set(SCALE, 0.5f, 0.5f, 0.5f);
shipRot.set(IDENTITY);
shipPos.set(0, 20, 0);
Matrix world = shipScale * shipRot * Matrix(TRANS, shipPos);
pObjFT->SetWorld(world);
Collidable::SetCollidableGroup<Frigate>();
}
How these various 'able' functions are defined are going to vary wildly with each implementation of a game object. Below are a few common ways of implementing a couple of these functions.
void Frigate::Alarm0() {
DebugMsg::out("Alarm0 called in Frigate, deregistering alarm 2\n");
}
void Frigate::KeyPressed(AZUL_KEY inputKey) {
switch (inputKey) {
case AZUL_KEY::KEY_SPACE:
EnemyBulletFactory::CreateBullet(shipRot, shipPos);
break;
default:
DebugMsg::out("PROBLEM, Key %i was not meant to be processed", inputKey);
}
}
void Frigate::Collision(Cottage* theCottage) {
UNREFERENCED_PARAMETER(theCottage);
DebugMsg::out("Collision Frigate with Cottage\n");
}
void Frigate::Update() {
if (Keyboard::GetKeyState(AZUL_KEY::KEY_W))
{
shipPos += Vect(0, 0, 1) * shipRot * shipTransSpeed;
}
else if (Keyboard::GetKeyState(AZUL_KEY::KEY_S))
{
shipPos += Vect(0, 0, 1) * shipRot * -shipTransSpeed;
}
if (Keyboard::GetKeyState(AZUL_KEY::KEY_A))
{
shipRot *= Matrix(ROT_Y, shipRotAngle);
}
else if (Keyboard::GetKeyState(AZUL_KEY::KEY_D))
{
shipRot *= Matrix(ROT_Y, -shipRotAngle);
}
Matrix world = shipScale * shipRot * Matrix(TRANS, shipPos);
pObjFT->SetWorld(world);
this->UpdateCollisionData(world);
}
void Frigate::Draw() {
}
Frigate::~Frigate() {
delete pObjFT;
}