CATIA V5 as a gaming platform? Well, nothing is impossible. Thanks to the powerful VBA language, you can create simple games even in CATIA V5. But which game to choose? Good old Tetris is probably the best choice. Simple and addictive game is an excellent candidate to test CATIA as a game engine. And CATIA, as usual, did a great job.
Wanna see it in action?
Then watch this video:Play Tetris in CATIA V5 drawing
It is the heart of the Tetris game. It contains the game logic, timer, it serves keyboard events, virtually all except the user interface. There is only one public method called MainLoop and with the outside world it communicates through the set of events such as LinesClearedEvent, RedrawGridEvent, RedrawPieceEvent, RedrawNextPieceEvent. The advantage of such an approach is that game logic is completely independent of the user interface and you can easily port this game to any application which supports VBA. As a frontend, I have chosen CATIA drawing, but it could be easily ported to any VBA compatible application like MS Excel, MS Access or MS PowerPoint. All you have to do is to implement GameCore class to your application a handle GameCore events.
Before I started with programming I made a couple of tests to find the best way to implement game graphic. Originally I wanted to use CATIA 2D component (DrawingComponent class) as a grid/piece element, but I found out that a picture (DrawingPicture class) performs much better. On my computer rendering of the picture was roughly 5x faster than the rendering of 2D component. If you are interested, you can test it yourself, with methods DrawingComponentRedraw and DrawingPictureRedraw stored in a module Test.
Will be finished soon ...