Jump to content
• Advertisement
• entries
2
• comments
0
• views
115

Game Initialization

617 views

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.

1. Game Over (You Lose)
1. 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)
2. 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
3. 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
2. Game Over (You Win)
1. For this I can probably use a trigger box as well, only defining the behavior a little differently
3. Score
1. Haven't even given this any thought yet.

Images

1.
2.
3.
4.
5.
View the entire Gogger album

Recommended Comments

Okay, this is actually supposed to be for the Frogger challenge (or having to do with Frogger anyway)... I'm pretty sure?

Those sprites are pretty. Also damn, I wish I could have been smart enough to forego tile/jump-based movement, I could have saved myself some headache. On the other hand, I'm working in Unity, I clearly don't have enough to do (compared to C++).

Share this comment

Link to comment

Sounds like you're getting a good foundation in place!

Share this comment

Link to comment

Posted (edited)

On 11/10/2018 at 1:22 PM, supermikhail said:

Okay, this is actually supposed to be for the Frogger challenge (or having to do with Frogger anyway)... I'm pretty sure?

Those sprites are pretty. Also damn, I wish I could have been smart enough to forego tile/jump-based movement, I could have saved myself some headache. On the other hand, I'm working in Unity, I clearly don't have enough to do (compared to C++).

Thanks, all the sprites and tile set is from opengameart.org! The LPC stuff! Your own project looks like its coming along nicely!

On 11/11/2018 at 8:28 PM, jbadams said:

Sounds like you're getting a good foundation in place!

It's coming along! Hoping to get my next blog entry this week, hopefully with some working game events.

Edited by JWColeman

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
• Advertisement
• Advertisement

×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!