Game Initialization
I've spent the night shrinking the amount of code it takes to set up my map, goblin player, enemies, and triggers. Here is what I've come up with:
void Game::Initialize(HWND hWnd)
{
// initialize engine components!
renderer = new Renderer(hWnd);
physics = new Physics();
cam = renderer->getCamera();
CSVReader reader;
map = new Map(20, 100, TILESIZE_X, TILESIZE_Y);
map->BuildMapFromFile(renderer, physics, reader.getData("../MyGame/MapFiles/gogger_Base.csv"), 1, FALSE);
map->BuildMapFromFile(renderer, physics, reader.getData("../MyGame/MapFiles/gogger_Foliage.csv"), 2, TRUE);
// set up game objects
Game_Object * goblin = new Game_Object(renderer->RegisterSprite(SpriteID::GOBLIN, map->At(97, 10), 64, 64, 2), physics->RegisterPhysicsObject(32, 32, map->At(97, 10)));
Game_Object * skeleton = new Game_Object(renderer->RegisterSprite(SpriteID::SKELETON, map->At(93, 19), 64, 64, 2), physics->RegisterPhysicsObject(32, 32, map->At(93, 19)));
Game_Object * skeleton1 = new Game_Object(renderer->RegisterSprite(SpriteID::SKELETON, map->At(92, 0), 64, 64, 2), physics->RegisterPhysicsObject(32, 32, map->At(92, 0)));
// define behavior for game objects
skeleton->setVelocity(XMFLOAT3{ -.25,0,0 });
skeleton->setAction("WALK_LEFT");
skeleton1->setVelocity(XMFLOAT3{ +.25,0,0 });
skeleton1->setAction("WALK_RIGHT");
// store game objects
Game_Objects.push_back(goblin);
Game_Objects.push_back(skeleton);
Game_Objects.push_back(skeleton1);
//set up trigger boxes for obstacle lanes
LaneTriggers.push_back(physics->RegisterTriggerBox(map->getDesc(93, 0)));
LaneTriggers.push_back(physics->RegisterTriggerBox(map->getDesc(92, 19)));
// set lane trigger response
for (int i = 0; i < LaneTriggers.size(); i++)
{
LaneTriggers[i]->onIntersect = [](PhysicalObject & object)
{
object.resetPosition();
};
}
// start the clock!
updateTimer.Start();
} This is enough code to set up my first lane, adding more lanes is just adding more objects, and creating triggers for each lane. I could build some Gogger specific objects that define the lanes, as far as direction , start position, and maybe even quantity of game objects. This could consolidate a lot of code and tuck it nicely away. However, I have to attend to some more pressing issues, which are actual requirements for the challenge.
- Game Over (You Lose)
- This occurs when Gogger the Goblin collides with an enemy or a maptile that is a trap (need a way to define map tile collisions that result in death)
- Currently my physical objects don't know what they're running into. I think I need to set up a bit mask for physical objects... This way, the physics engine can better handle collisions, if the collided objects are player and enemy, make the player game object dead
- I think I need to use a trigger box for the deadly map tiles. I can maybe use Tile2d map editor to define their bounds, I can check the kill object trigger(s) to see if its triggered by a player, and set the trigger box behavior to make the game object dead
- Game Over (You Win)
- For this I can probably use a trigger box as well, only defining the behavior a little differently
- Score
- Haven't even given this any thought yet.
Discussion