I’ve got a tough one if someone wants to help me out. This is the first time I’ve tried to program anything more than a basic array, so …
In exchange, I’ll be happy to include your name in the credit screen of Move It, Soldier! and also pass along a gift certificate to Amazon, Chapters etc online book retailer for $35. I’m out of work at the end of the month or I’d offer more, sorry. You will, of course, have my eternal gratitude. Any way …
The basic problem is that I want to apply a random Texture2D to a fixed number (11) of GUITexture objects. It’s to create the random visual field of battle in my game. But there is a catch …
Here’s the problem …
-
I have 11 GUITexture objects of 3 types (light,medium,heavy) that need to have random Texture2Ds applied to them on the start of a scene. These represent terrain areas a player moves linearly through.
-
Each of these 3 types (light, medium, heavy) though, has a further handful of random sub-types that can be applied. These subtypes do not affect gameplay, they are only to provide visual variety. For example, a light terrain type that costs 1 to move into and provides no cover might look like an open area, or a field, or a stream, etc.
-
To confuse matters more, I am placing the 3 “classes” of visual subtypes into an array so that they have 10 options to choose from based on the frequency you’d find them in in western Europe, 1944 (see my code below).
-
The 11 GUITexture objects need to also be, I think, in an array so that I can determine not only their visual look when I run function createTerrain (), but also allows me to determine where a player is to know move costs and cover value. I need to pull these later two values out of the array (ignoring the terrain visual) during gameplay.
-
Plus this all requires an additional shuffle function so that the 11 items in point 1 get their order randomized each time a battlefield gets generated. But JS arrays lack a shuffle function, I have found.
Here is my code to try to explain things … I’d be delighted if someone might help me out.
// set terrain area texture graphics
// each terrain type has a variety of associated images that are ONLY for visual change
// light = open, fields, road, hedges, walls, stream, marsh
// medium = rough, rubble, hills, orchard, bocage, gully
// heavy = woods, ruins, buildings, manor/farm, village
var lightOpen : Texture2D;
var lightFields : Texture2D;
var lightRoad : Texture2D;
var lightHedges : Texture2D;
var lightWalls : Texture2D;
var lightStream : Texture2D;
var lightMarsh : Texture2D;
var mediumRough : Texture2D;
var mediumRubble : Texture2D;
var mediumHills : Texture2D;
var mediumOrchard : Texture2D;
var mediumBocage : Texture2D;
var mediumGully : Texture2D;
var heavyWoods : Texture2D;
var heavyManor : Texture2D;
var heavyRuins : Texture2D;
var heavyBuildings : Texture2D;
var heavyVillage : Texture2D;
// identify terrain slots ... need 11
var area1 : GUITexture;
var area2 : GUITexture;
var area3 : GUITexture;
var area4 : GUITexture;
var area5 : GUITexture;
var area6 : GUITexture;
var area7 : GUITexture;
var area8 : GUITexture;
var area9 : GUITexture;
var area10 : GUITexture;
var area11 : GUITexture;
function createTerrain () {
// create random integer 0-9
var terrainNumber = (Random.Range(0,9));
// each terrain image array has 10 objects, based on frequency of occurrence in Western Europe terrain
// light = open, open, fields, fields, fields, road, hedges, walls, stream, marsh
// medium = rough, rough, rubble, rubble, hills, hills, orchard, bocage, bocage, gully
// heavy = woods, woods, ruins, ruins, buildings, buildings, manor, village, village
// starting step -- we don't need to know MP and cover costs, as they are the same for light/medium and heavy types
var lightTerrain = [
lightOpen,lightOpen,lightFields,lightFields,lightFields,lightRoad,lightHedges,lightWalls,lightStream,lightMarsh
];
var mediumTerrain = [
mediumRough,mediumRough,mediumRubble,mediumRubble,mediumHills,mediumHills,mediumOrchard,mediumBocage,mediumBocage,mediumGully
];
var heavyTerrain = [
heavyWoods,heavyWoods,heavyWoods,heavyRuins,heavyRuins,heavyBuildings,heavyBuildings,heavyManor,heavyVillage,heavyVillage
];
// assign the following array value and graphics after SHUFFLE to the 11 terrain areaX above -> 4 light, 4 med, 3 heavy
var terrainArray = [
lightTerrain,lightTerrain,lightTerrain,lightTerrain,
mediumTerrain,mediumTerrain,mediumTerrain,mediumTerrain,
heavyTerrain,heavyTerrain,heavyTerrain
];
// final step -- apply the terrain visual in this array to a var areaX : GUITexture;
}
I am on iChat (AIM) all day as well, should anyone need to ask questions (WidgetMonkeys) or if I have completely buggered up my thoughts.
First gameplay screen shown with the 11 terrain slots I referred to showing at top of screen.