🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Cripes 2.0 Class Layout

Published February 08, 2009
Advertisement
Last updated: 4:49pm on February 17th, 2009

It occured to me while I was writing my last post that even though I might know what these classes do, if I just toss the names out there carelessly the post might take a little work to decipher. So, for my reference and others', here's a class layout for Cripes 2.0 as of now. I'm going to update this post when I add new classes, so don't count on this post staying the same.

Heirarchy:
Game
-Keyboard
-World
--Map
--EntityMap
-EntityFactory

"Independent" classes (granular classes possibly used in multiple places)
Entity
MazeGen


Class: Game
Purpose: This is where my game loop is. I'm not actually sure what Game's exact purpose is. I just think of it as a pseudo-main()-plus-globals thing. This is because my main.cpp is just a main() with a constructed Game and a call to Game::Run(). It remains to be seen whether that's a good idea. (I like to think it is)

Class: World
Purpose: Patches together the components of the visual world, including the world map and its entities. Can be Draw()n, which gathers the clips of the components and copies them together, drawing to a given console buffer (or STD_OUTPUT_HANDLE if none is supplied).

Class: Keyboard
Purpose: Maintains an internal state map of the keys on a keyboard. Its Update() function should be called once per frame. Every key has four possible states, numbered 0 to 3: inactive, down, held, and releasing. When a key is hit, it enters the down state on the next Update(). If it's still down during the next Update(), it's promoted to held. If a key is down when it's released, it's moved to releasing, then inactive. This is to give the program a chance to handle the key before it's released, as it only goes into releasing if it was tapped and released within the same frame/update. If a key is held when it's released, it's moved directly to inactive.

Class: Map
Purpose: Constructs and maintains a CHAR_INFO buffer representing the game map. It can be Clip()ped, trimming the viewing clip given a viewport width and height and returning the result. Some fun cartesian/geometric math here which 'sews' the opposite edges of the map together.

Class: EntityMap
Purpose: Keeps track of an Entity list, and can create a Clip() just like the Map can. There's some -really- fun code involved in the clipping. Yes, maybe even more fun than the Map code! *shudder*

Class: Entity
Purpose: Contains a vector of CHAR_INFO sprites (all of the same dimensions) that can be used as frames for animated sprites. Also has coordinate variables which the EntityMap uses to determine where the entity is on the map.

Class: EntityFactory
Purpose: Factory class that can load Entity definitions from a file and store them in a std::map with string identifier keys. If there's a Player defined in the file, calling ConstructEntity("Player") returns an instance of an Entity with the defined Player frames and size.

Class: MazeGen
Purpose: Constructed with an EntityFactory pointer, it Generate()s a vector of wall Entities given a maze width/height (in cells, not pixels). See this page for the algorithm I use to generate a maze.
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement