This project is read-only.

Initial Exploratory Phases

Nov 11, 2008 at 2:54 AM
Edited Nov 11, 2008 at 6:09 PM
I plan to use this forum to discuss the overall game design & logic flow (that's the theory, at least).

I spent some time today outlining the initial steps I plan to undertake to help prototype some aspects of the game engine.  The following is is an overview of the initial steps.

Phase I - Display Map & Enable Scrolling
  • Create a sample terrain sprite sheet consisting of a few basic sprites (bottom graphics layer)
    • clear (SHP # 140), mtn (103), all water (73), airport (129), city (206), fortress (170), rough (201), swamp (135), woods (139), improved (178)
  • Create a sample unit sprite sheet (middle graphics layer)
    • Player 0: 0-inf, 1-eng, 2-towed arty, 3-towed AT, 4-SP arty, 5-SP AA, 6-A/C, 7-tank, 8-truck, 9-halftrack
    • Player 1: 10-inf, 11-eng, 12-towed arty, 13-towed AT, 14-SP arty, 15-SP AA, 16-A/C, 17-tank, 18-truck, 19-halftrack
  • Create a sample effects sprite sheet (top graphics lay)
    • 0-Player0 ownership, 1-Player1 ownership, 2-shaded can-move, 3-shaded cannot-move
  • Create a simple 2D array of terrain values for map definition
  • Create Initialize method to init member variables
    • const VIEWPORT_HEX_HEIGHT = 10?
    • const VIEWPORT_HEX_WIDTH = 15?
    • int ViewportHexX = 0
    • int ViewportHexY = 0
    • etc
  • Create Draw method to display map terrain for visible viewport
  • Create Update method to process user input
    • arrow keys scroll map in appropriate direction by 5? hexes
    • moving mouse pointer near edge of screen (x or y within 10? pixels) scrolls the map in that direction
      • moving mouse pointer to absolute edge of screen (x or y = 0) scrolls the map much faster
Phase II - Convert mouse x,y to map hex x,y
  • Implement algorithm to convert mouse x,y coordinates to viewport map (hex) x,y 
  • Display current mouse x,y plus viewport map x,y plus terrain type in corner of screen for every update/draw cycle
Phase III - Display Units & Enable Simple Selection/Movement/Deselection
  • Initialize simple unit struct array consisting of a few units (x, y, type, owner, etc)
  • Initialize variable holding current selected unit # (-1 == none)
  • Process user input
    • left-clicking unit selects the unit (if none currently selected)
    • right-clicking deselects unit (if currently selected)
    • left-clicking empty hex moves the currently selected unit to that hex and deselects it

Nov 12, 2008 at 3:52 AM
I have create a small BMP bitmap containing a few select PG terrain images.  The bitmap contains 20 images (2 rows of 10) although only I'll likely only be using the images in the top row (the second row's terrain was already there).  I changed pink to magenta for the transparent corners of the hexes and all looks good.
Nov 12, 2008 at 3:54 AM
Edited Nov 12, 2008 at 4:25 PM
Eureka!  I have successfully added the Visual Studio 2008 xnaPanzer project to the source code repository using VisualSVN.  It was easy to do ONCE I figured out how (I never found CodePlex docs on how to upload the initial source code!).  I modified the Game1.cs file a bit and committed the change and all looks good in the repository.  Progress!
Nov 18, 2008 at 1:38 AM
I have made slow, steady progress in the past few days.  The map draws correctly and it scrolls (albeit without any delay built in) and there is an algorithm that converts from mouse x,y coordinates to map hex x,y location.  I have removed the code that displayedsequentially unit & terrain sprites (new ones every update/draw cycle).  I have also added a few comments in preparation for publishing the project (this evening?).  There is currently no GUI or anything Panzer General-specific except for the map terrain.

Another big task is pathfinding: visually indicating which hexes, if any, a particular unit can move to.  Hexes the unit cannot move to should be shaded when the unit is selected.  I am publishing the project in hopes of getting assistance on this algorithm (it will be good brain food!).
Nov 19, 2008 at 2:08 AM
I implemented the algorithm to perform basic pathfinding whereby you select a hex by left-clicking it and the map highlights the hexes a fictitious unit could move to.  Unfortunately, there is a slight bug in the algorithm.  Even more of a problem is that I just realized that I need to shift the odd-numbered columns UP by half a hex instead of down.  This requires a reworking of the mouse-to-hex conversion  algorithm.  Oh joy.
Nov 20, 2008 at 2:48 AM
I fixed all the issues that were preventing the game from working properly.  I shifted odd-numbered hexes up rather than down.  I tweaked the mouse x,y to hex x,y conversion.  I tweaked the pathfinding to account for shifting odd-numbered columns.  Selecting a hex by left-clicking it will shade all hexes a fictitious unit cannot (moves = 2) move to (without regard to terrain, enemies, etc).  I also displayed basic instructions at the top of the game screen.

Two of my next big tasks are (1) to draw a hex grid overlay and (2) to draw a special hex overlay atop the hex that the mouse is currently on (thus, it would zip around the map wherever the mouse cursor is located--it would, of course, disappear when the mouse moved off the map).
Nov 21, 2008 at 1:51 AM
I created a hexagon-shaped cursor and am displaying that in place of the mouse cursor when the mouse is within the map viewport.  It follows the mouse position around until the mouse moves outside of the map viewport, at which time the normal mouse cursor is displayed.
Nov 21, 2008 at 3:30 AM
I tweaked the hex grid cursor (partial & full) images to make them darker and therefore easier to see.  They need further tweaking but they'll be fine for the prototype stage.
Nov 21, 2008 at 3:10 PM
Looks good I think. But why are there zero units? i see where a unit cold move but I dont see a real unit on the map. without a real unit how do i know how far it should be able to move, like 2 or 3 or 4 or more spaces? and will there be a mini map for big maps?
Nov 22, 2008 at 2:33 AM

Those are good questions.  You're the only person who has provided feedback thus far.  Maybe my assertion that the world is full of PG lovers was a reach without merit.

Anyway, let me see if I can answer your questions.  The very first version I did included units but I realized most of the graphics-related game complexities involve the map (units are fairly easy), so I removed the units and focused on experimenting with displaying & scrolling the map, mouse-to-hex conversion algorithm, pathfinding, hex cursors and the like.  I have successfully tackled those hurdles with relative ease.  XNA is so simple, even a caveman could do this stuff.

Some of the remaining graphical hurdles include how to dynamically scale the game screen, how to implement GUI components like buttons and dialogs, how to capture the original PG font and how to display a mini map

My next few tasks will likely involve units.  I plan to display a few friendly & enemy units, allow the player to select & move them, and introduce terrain & enemy evaluation in the pathfinding algorithm.  Eventually, I'll get around to actually designing the game structures as a prelude to building a real game instead of just a prototype.

Thanks again for your feedback.  Feedback is important to help me stay focused and within the realm of reality.  If you're inclined to code and/or provide design suggestions, please don't hesitate to step forward.  I'm hoping others get involved to accelerate the progress rate.

Take care.

Nov 23, 2008 at 4:41 AM
I have started implementing code to auto-scroll the map when a hex is selected so that 2 full hexes are visible all around the selected hex.  Thus, if you selected a hex at the edge of the visible map, it should scroll the map enough so that you can see all around the selected hex.  I have finished the code for auto-scrolling in the left & up directions; I'll do the same for right & down directions tomorrow.