Hello,
Im interested in using CGE for a basic city building game and was wondering if anybody can offer any advice before I get to far into it…
My main questions at the moment is how I should approach dragging and dropping the infrastructure assets onto a snapping grid that is overlaid on my terrain / map during run time.
All assets are 3d models build in blender.
Would this type of game be a practical application for CGE ?
Is there any specific documenting or portions of the API I should be focusing on ?
Any and all information is appreciated.
Thanks
I didn’t have much successful experience with drag-n-drops (it’s a complicated mecnanics by itself and I’ve rarely seen it done well). But in either case you’ll most likely want to create some “grid” constructed of TCastleTransform
s with TCastleTransform.Pickable = true
(see Castle Game Engine: CastleTransform: Class TCastleTransform).
This will allow you to raycast and see which transform is under the mouse in the current frame, e.g. by using TCastleViewport.MouseRayHit
(see Castle Game Engine: CastleViewport: Class TCastleViewport).
Personally I’d go and override
TCastleTransform
with something like TEmptyGroundTile
- which has additional “metadata”, like it’s position on a grid. Then if your MouseRayHit
hits such TEmptyGroundTile
you can display the preview of the building being constructed or if it’s another override
of TCastleTransform
- TBuilding
then show some additional interaction UI (at least change cursor to display interaction possible).
Then you have some sort of GameMapManager
unit that keeps track of the game map (as array[0...SizeX, 0..SizeY] of TMapTileSomething
) and determines what can/can’t be built here and also handles Update
of those tiles every frame - e.g. to progress the construction animation or provide income/expense for the Player, or integrate with other game mechanics such as logistics or electricity networks.
There will be a “tricky” component called “roads” - you will need to write a proper “update” of such components when they get constructed (as the road looks depend on its neighbours - e.g. if a new neighbor was constructed, this tile should also change it’s view from T to +, etc.). Building navigation network on such roads is also far from trivial, most likely you’ll need to add several waypoints, or maybe even vector paths (cars may need that) and implement some at least basic pathfinding (in my experiments Dijkstra was easy to implement and does its job well).
Would this type of game be a practical application for CGE ?
Yes, I don’t think there would be any troubles with that.
Thanks for the info Eugene. I will experiment and see what works best for me. Appreciate it !