Posts RSS Comments RSS Digg Technorati Blinklist Furl reddit 105 Posts and 7 Comments till now
This wordpress theme is downloaded from wordpress themes website.

Treasure Cards

In HeroQuest, the Hero’s turn is (Move then Action) or (Action then Move).  The six actions are – attack, spell, search traps, search doors, search treasure, disarm trap.  The latest I’m working on is search for treasure.  You can only search rooms for treasure (no corridors).  When you search a room for treasure, you either get special treasure or a random treasure card.  I implemented support for drawing a card from a treasure card deck.

OpenGL vs. UE4

My first thought with the deck was that if this were OpenGL then I might draw the entire deck in a single draw call.  Each card is only 24 verts (6 sides * 4 per verts side), so 24 cards is 24*24 = 576 verts.  I could use a single texture atlas for the draw call, and each card’s vert’s texture coordinates define which card it is.  I used SpriteSheetPacker to generate the texture atlas png (and uv txt) (my treasure card scans can be crammed in one or two 2048×2048 textures).

Each card needs independent transformations (just simple translation and rotation), so I could do that similar to skeletal animation see ( ).  My GLSL VS would just have (uniform mat4 Bone[24];) – one mat4 for each of 24 cards.  Each vert would have a boneIdx param that specifies which mat4 to use.

So to do this in UE4, I implemented a material that did rotation and translation.  However, I ran into a problem – it broke up the lighting.  I thought the issue might be that the normals so I tried doing VertexNormalWS > RotateAboutWorldAxis_cheap > output Normal to match what I output for Absolute World Position > RotateAboutWorldAxis_cheap > World Position Offset.  I read that inverse transpose of the model view matrix is not required for basic rotation, but I tried that anyway by implementing my own matrix math for rotations in material nodes (blueprints).

I did rotation experiments with a white sphere and it didn’t seem to work as I expected.  I may come back to this idea later, but I realized that for a reasonable authentic implementation of the HeroQuest, I don’t really need to render 24 cards with independent transformations.  So I moved on to a simpler implementation (at least for the short-term).

UE4 Implementation

Instead of 24 actors I have three actors – deck, card, and discard pile. I created a Blueprint actor "deckBp" which can resize (ie shrink when the player draws a card). In the level editor, I placed a deckBp for treasure deck main and for discard. The level Blueprint’s BeginPlay resizes these to 24 cards and 0 cards. My C++ code can reference treasure main deck and discard deck (pile) via the level Blueprint.

When the player draws a card, it shrinks the deck by one card then does a simple transformation lerp’ed over time in Tick(). Placing the treasure card draw destination relative to the camera doesn’t make sense because the player can move the camera, so the destination is to rotate the card 180 degrees and place it above the current turn player. The card sits there (so the player can read it) until the player clicks the card (or types space / enter / gamepad-A), then it lerp-translates to the discard pile (and the discard pile grows).  Here’s a video of it in action:

Trackback this post | Feed on Comments to this post

Leave a Reply