Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

Mars Mission (4) : Astronauts

, 5 Jul 2011
Rate this:
Please Sign up or sign in to vote.
strategy/action game defending the solar system : incorporating astronauts, resources, and actions inside and outside the ships

Requirements

  1. MS C# 2010
  2. computer mouse with two buttons and mouse-wheel
  3. dreams of flying in the solar system

Introduction

I've been working on this project for about six months now and in the two months since the last post in this series the project has seen many changes that make use of the structure-interior that you got a glimpse of in Mars Mission (3). The structures themselves now have resources, astronauts & ships and in the game you no longer control a ship, per se, but instead you now control the astronauts that control the ships. Each astronaut has a name and a rating describing their skills in four categories : Piloting, Engineering, Chemistry & Geology. The actions which any astronaut can perform are determined by their location (ship, base, surface, etc.), their qualifications (skill-sets) and resources available. There's plenty that's new so climb aboard and step up to the Navigation console, ensign, we're gonna learn to fly.

Setting Up

You've probably already noticed the dozen-odd files ready for you to download. Many of the contents of these zip files are included in the download files of previous articles in this series but it would be more confusing, and frustrating I would expect, for you to try and reuse the files you already have instead of just downloading everything here again but i promise you in the next articles i will make an effort to avoid having to upload/download as much material for each step of this project since much of it is redundant(you could, however, copy your solarObjectImages.soi file and then plug it back into the same directory to spare yourself much of the image rebuilding process without too much trouble). Well, here we are, downloading files again. For you newbies in the Code world and the C# novitiates let me step you through what you'll have to do to get yourself inside a Raptor and fly your way into the interplanetary void.

  1. first you'll need a copy of C#2010 up and running on your computer. Microsoft provides this software free for anyone to download at MS downloads.
  2. then you'll have to grab all the files listed at the top of this page. Starting with the source code. This is the actual program and it also contains the subdirectory in which all the other files are to be included. When you've extracted this file download all the remaining files and extract them into the last MarsMission subdirectory where you'll also find the application's reddish icon.
  3. when you've got all the files extracted into the correct directory you'll have to spark-up your C#2010 IDE (the MS software mentioned above) and load the project's solution file wherever it was that you extracted it on your computer.
  4. because the files this project needs to run are so big (100s of times bigger than what you've downloaded) they cannot be posted on this site but need to be generated the first time you run the application. this takes time. So what I suggest you do is, instead of running the application in the debugger like most people would do when downloading the code from a new CodeProject article, compile the application and then find the executable and run it. For a newbie this may a bit rough but its not too bad. Load the project and press F6. When the C# IDE has finished compiling there won't be any fanfare or lights or buzzers or anything but you'll notice the words "Build start", "Build Progress"(with a progress bar) and "Build Complete" written at the very bottom left of the screen. When that's done you can exit the C# program and go to your Windows Explorer a-huntin' for the executable which will be located in the project's newly created sub-directory \bin\release\. You can recognize it by its icon, except the file your looking for this time will not be an icon file but an application.
  5. next, after you've double-clicked the file's name, a lot of things will start to happen but if you're in an elevator and you suddenly feel weightless you might have a problem that I can't help you with. Primarily what you should expect is this: the application will start to generate all the files it needs and, as i promised earlier, will take some time. There'll be a bunch of caching involved but hopefully no real crashing while it builds file-streams for the different resources you might find laying around any untidy space-ship and then the screen will show a star-scape and soon you'll get a text-box asking you how many images you want per quarter rotation. If you've tried the previous installments of this project this is pretty much the same as before but I'll explain again. The number of images per quarter rotation refers to the number of angles the planets will be visible per quarter turn about their own axes. The higher the number the more fluid the planets will appear to rotate and the smaller the number the clunkier the whole machine will clang about(silently though, if that's possible). Either way, the orbits remain the same and it just looks cooler if you pick a number like 90 but if you're in a hurry you can go with 4. Essentially : better smoother graphics take time and you'll be sitting in front of that screen watching it work for hours and hours (six? eight? not sure. depends on the size of that box you got there) but since this looks like its going to be a long article you may as well take the time anyway because ultimately its really worth it.
  6. it'll take the time it takes to build all the files it needs so just get her started and then come back to read this article and i'll give you an idea of whats in store for you today.

Game Controls

If you know how to type you'll find that the keyboard controls aren't too bad because they're virtually all around your left hand and it doesn't have to move while your right hand remains on the mouse which you'll need to use or else your computer may explode. No, I'm just kidding, your computer won't explode. I promise. But you'll still need a mouse that has a mouse-wheel in order to play this game.

When you start a new game you'll see the BattleStar(that's a big assed fancy war ship) called the Union in the middle of the screen(image courtesy of BattleStar Galactica whose lawyers have yet to find my home-address) to zoom in and out at any time during the game simply move the mouse cursor over the view screen and, while pressing the Z key turn the mouse wheel one way to zoom in or the other way to zoom out. One of the first things you'll notice when you zoom in is that there is some writing on the ship to tell you where the docking ports are whenever you zoom in to the ship close enough for these to be relevant, the orange stars are the actual docking locations. If the astronaut you're currently controlling is piloting a ship then what you'll see on the screen is the ship that astronaut is piloting, thus when you start a new game the controls automatically revert to the astronaut at the navigation console aboard the Union, our hero, friend and pilot Chuck Carmarthen. Chuck's a great pilot but his lettering ain't so good and he don't know no-how about much other than the stick in the c***-pit but if you want to know more about him you can have a look at the controls console on the right of the screen.

One of the new features in this installment of Mars-or-Bust! is the folding console display which allows you to drop-down whatever part of the console you need to look at and collapse what you don't want to see right yet by pressing the up/down triangles that appear on the right of each sub-console on the screen. At the top right of the controls console you'll have the green box with Chuck's name writ on it. Click the green triangle on the right end of that box and it'll expand to reveal a few other green boxes inside. These are the Proficiencies which tell you about the skills of the astronaut you're currently controlling, Location will tell you where Chuck is at the moment and the Communication console gets you in contact with the different astronauts in the game. Go ahead and have a look(don't worry if your computer's busy right now, you can have a look later).

If you expand the Communications console a list of names will appear, each with their own green triangle ready to be expanded to reveal the location of every other astronaut. By clicking the connect button you will transfer control from the pilot Chuck Carmarthen to whatever astronaut you choose. Read through the locations of some of the other astronauts and you'll notice that Gwen Abel is also sitting in the Battlestar Union's CIC. Clicking on her connect button will transfer game control from Chuck to Gwen and you'll no longer have an external view of the Union but rather you'll peer into the CIC itself where both Chuck and Gwen are sitting busily operating the ship.

screenCapture_ScienceOfficer.PNG

And the Astronaut console will look like this.

screenCapture_ScienceOfficer_controlPanel.PNG

You'll probably notice that Gwen, though a capable pilot in her own right ready to take over should Chuck have to wind his way to the loo, she is quite knowledgeable in chemistry with a dab of know-how in geology and engineering. Her designation as Science Officer Gwen Abel tells you that she is currently serving aboard the Union in the capacity of a Science Officer as opposed to an Electronics Technician, Chemist or Pilot, like Chuck sitting beside her. Expanding the red navigation console will show you details about the ship and more specifically concerning Gwen and her job as a science officer aboard the Union. Simply, expand the red tab beneath labelled Science Console. Whenever a ship has at least one active Science Officer the science console will be available and this is where you discover the atmospheric pressure exerted on the ship as well as the different chemical compounds and their relative densities at your current altitude. Also, a science officer will help you find the caves which may be difficult to spot from a high altitude.

But I've probably distracted you from the really cool stuff happening on the screen. Now that the astronaut you're currently controlling is not a pilot what you'll see is the astronaut herself, in this case Science Officer Gwen Abel in the CIC of the Battlestar Union. You may have to zoom-in a bit but don't be shy about looking over her shoulder this is a military operation and there's no privacy here so press down on the Z-key and turn that mouse-wheel to have a good look. You should see her busily at work sitting at her science station. This is the CIC. A bit sparse at the moment and there's only the two of them but Chuck and Gwen have it all together.

If you click the right mouse button a context menu will appear and if Chuck was on the screen when you did it you'll have the option of taking control of him and leaving Gwen to her work. When you do that the screen will show you the outside of the ship again because Chuck is still the Union's pilot. Clicking the right mouse now will summon the same context-menu as before except this time you'll have a third option to toggle the ship's mouse control, I'll talk about that later, but first click on Show Available Actions and another window will appear near your mouse cursor listing the actions which Chuck can do at the moment. On a good day Chuck couldn't be bothered to do much except pilot the ship but since that's what he's currently doing the only thing he can do now is abort : navigate which, to Chuck, means 'break time' and maybe a little R'n'R for a chance to ease back and drink some Grape KneeHigh. When you tell him to quit piloting the ship, he'll sit back in his chair and you can almost see his brain straining to think what it was he was going to do while he waits for you to tell him.

Here's where the keyboard comes in. There are a bunch of keys but, like i said before, its not too bad. The keys around the letter 'D' on the keyboard are left, right, up and down.

Astronaut Move Controls

(indoors)

  • S - move left
  • F - move right
  • E - move up
  • C - move down
  • R - stand up
  • X - sit down
  • V - crouch down
  • Enter - perform-automatic-action (e.g. sit, pilot, enter ship, etc.)i know this is the wrong hand

(outdoors)

  • S move left
  • F move right
  • E jump
  • Enter - perform-automatic-action

Piloting a Ship

Let's have a look at a Raptor. I was lucky enough to call Miley Cyrus away from Disney and she agreed only if she could bring her friend Hannah Montana. I tried to object because I'm not sure about Hannah but since I like Miley so much I decided to go with my instinct and just trust her on this one. So click on Miley's connect button and you can spot her aboard the Raptor with her good friend Hannah Montana at the Science Console. They're both already sitting at their stations so as soon as you take control of either one you can either press the right-mouse button and get them to work by using the show available actions menu or, since they're already briefed, just press the auto-get-to-work button marked Enter on your keyboard and they'll get to, Hannah as Science Officer and Miley piloting the ship. Once Miley's in control of the stick your view will jump away from the inside to the outside of the Raptor, and since the Raptor is inside the Union's hanger that's what you'll see.

ScreenCapture_RaptorInHanger.PNG

The raptor Leverage in the image above is seen inside the Union's hanger. To the left of Miley's ride is the door to the launch bay and any Galactic Ghoul that may lay beyond. A lot of things have changed in terms of piloting the ship. You may be glad to know that the old shuttle and its gangly leg-type landing gear are no longer part of this game. Instead you're flying Raptor-style now, baby! And inside the hanger, or anytime you're indoors as opposed to out, you'll see a dorsal view of the ship. This is the same view you'll see when you're in interplanetary space. The only time you'll get a port (or Starboard) view is when you're on the surface of a planet. So, for now, you're looking down from the top. and don't it feel good! To get a hand at flying this thing what you need to do is have another look at that red navigation console we glimpsed at briefly before. Expanding the red box with Pilot Miley Cyrus written on it you'll get the ship's status and controls. You may want to collapse some of the other boxes to see everything, just click the green triangles above and that stuff'll disappear.

screenCapture_PilotConsole.PNG

So here we are. There's a few things here you have to understand before you go dropping off the deep end. First of all, you've got to set the ship's vertical dampers which allow you to hover without falling on your ass and damaging that pretty hull. The numeric controls you see on the screen, both the horizontal and vertical dampers on the left and all five engine controls to the right of these require the use of the mouse-wheel. You simply position the mouse over anyone of these controls and the value will change accordingly. As your mouse moves across from the most significant value on the left to the least significant value on the right the value beneath the mouse will be highlighted and that's the value which the mouse-wheel will be controlling. Reducing a value is sometimes a bit tricky because if you go past zero you jump back up to nine so if your intention is to tank the value of whatever control just press the right mouse-button before turning the wheel and they'll all just drop everything down to zero. a double click locks these controls (red) and clicking once again shuts them off again(gray).

Wheel your way to setting the vertical damper controls to 2.000 then double click it so that it appears like the one in the image above.

Now the engines. They're a bit different. There are five controls for the engines but depending on the mouse-setting you may only need to tackle the middle numeric control. The mouse-setting I'm referring to determines whether you use the mouse location on the screen to direct the force of the engines(and as a consequence the path of the ship) or if you use the keyboard to fly in a way similar to walking your astronaut (left, right, up or down). To toggle this setting you click the right-mouse button on the view-screen when in control of a pilot and you either toggle on or toggle off the mouse move heading. Whenever the mouse-move-heading is toggled on the fifth middle numeric-engine-control will be visible and that's the one you need to set. Keep in mind that these engines are made to fly the vastness of space and so 0.003 is ample power to get out of the hanger.

Set the middle, main-engine numeric control, to 0.003 like you did with the vertical-damper but do not double click it.

Now you're ready to fly. Did you tell Hannah to get the Science Station on-line? To check just look at the Science-Station console heading and it should read 'on-line' if she's at her station or, as I suspect, you might need to click her control button in the communications console to get her going. and now you're all set. Have Miley fly the stick, she's all set, and we're all good to go!

Now that we're in control of the raptor Leverage again and flying inside the hanger, try rotating the ship by pressing either the R or W keys to the right and left of the move up key (E).

Piloting indoors and Interplanetary Space

  • R - turn clockwise
  • W - turn counter-clockwise
  • V - vertical dampers
  • H - horizontal dampers

Piloting on the Surface

  • D - turn
  • V - vertical dampers
  • H - horizontal dampers

Your pilot's skill will affect how fast the ship rotates but the distance between the center of the view-screen and the mouse location allows you to adjust the turning speed as well. The further away the mouse is from the center of the screen the faster the ship will rotate. Play around with the damper controls. The key controls for the dampers are a bit dangerous if you're not careful. Pressing down on the V key will activate the vertical damper but then releasing the same key will shut the dampers off, unless you have the shift-key pressed down before you release it. Forgetting to press the shift-key will plumet the ship to a quick and untimely crash. and we don't want that! While either damper control key is down you can use the mouse-wheel to increase/decrease that control's value by 1/10th, just don't forget to shift before releasing.

If you move the mouse around the ship and look at the four engine controls that are located on all four sides of the main-engine control you'll notice that the power of the engines is transferred to the engines on the side the mouse is relative to the center of the screen. While you're in the hanger and your engines are at a measley 0.003 and the mouse is the the north-west of the ship then the up and left engine-controls will indicate their share of the 0.003 you've given them while the other two will remain zero. clicking on the screen will fire up the engines that you're giving power to.

First Time Slow

The first time you run this game the animation will appear very slow as the images are built and cached. This means that opening and closing those big circular doors will appear intolerably slow but don't worry that just happens the first time the door is opened and the first time the door is closed. As soon as these images have been built they're hidden away safe on the hard-drive and every other time the same sequence of images need to be called up they'll splash on the screen without so much as a wink.

Mouse-Heading Control

Toggling off the Mouse-Heading-Control means that the mouse position will no longer determine how much strength each engine will have. And although using the up, down, right and left controls (E, C, F & S) always works regardless of the mouse-heading-control setting. The engine strength is still either determined by the mouse position(mouse-heading-control toggled on) or locked at whatever you set them manually(mouse-heading-control toggled off). This is useful if you want to move the ship around while controlling a different astronaut. Let's say you untoggle the mouse-heading-control and then manually set each of the four engines to 0.002 and take control of Joe Harmer who just happens to be hanging around on the deck wishing he was in with Miley. Even though you're currently controlling Joe and he is not piloting the Leverage you can still activate the ship controls by clicking on the numeric buttons. This can be handy because now you can zoom in close enough to see the raptor's hatch and walk Joe south into the Leverage's path while directing Miley to fly backwards into Joe who can then hop on by pressing the Enter key just as the ship flies by.

It takes time for star-ships to fire-up their engines and you'll have to keep the left mouse button down for a few seconds before you begin to move. The main engine's power guage will start to display from green to yellow and then from yellow to red before the ship will begin to move and when you cut the engine the power will slowly dissipate. The raptor's engines are pretty efficient compared to a battlestar or a maintenance duty-craft and you'll begin to notice the difference when you fly these different machines.

When you exit the hanger you'll be in an isolation area that will air-lock you between the hanger and the vacuum of space. Just let the ship glide through (if you were flying too fast in the hanger you might have hit the door before it was opened and halted your progress, just fire-up the engines again and you'll be on your way) and then you'll be flying over the landscape outside. Here's a close up of the Leverage as it exits the union.

ScreenCapture_RaptorExitingUnion_close.PNG

zoom out with the Z-key and mouse wheel some more and you get a better look.

ScreenCapture_RaptorExitingUnion_Mid.PNG

a little further still

ScreenCapture_RaptorExitingUnion_far.PNG

and you're on your way.

The Hanger

After you've had a fly-about and aced your first solo-flight around the planet and into space and back, or even if you found the quickest way to crash, you might want to have a look around the ship and beyond the CIC. Try selecting another astronaut from the list in the communications console. Supposing we take a look at Vanessa Paradis inside the hanger of the ship. Zoom in on her using the mouse-wheel again and notice what happens when you move the wheel after you've released the Z-key. and now you know how to rotate your astronaut's arm. This'll probably come in handy later when you start shooting aliens who've boarded the ship but for now that kung-fu arm swing and reach'n grab action thing the mouse-button does will let you pick things up and put them down again. Try picking up the tool kit by moving her close to it then rotating the arm into position and pressing the left mouse button. When you've picked up the tool kit carry it next to that broken radio and drop it by pressing the left mouse button again.

Now, you may not already know this, but Vanessa is a bit of a crack engineer. So you can make best use of her skills in the hanger repairing that radio. Step her close to the radio and the tool kit.

ScreenCapture_RepairRadioVanessaParadis.PNG

Now press the right mouse-button and call up the available actions list. When they appear you can get details of each action which an engineer like Vanessa Paradis might be interested in doing and though the ones that appear in red are not currently available for some reason you can see what requirements are necessary by moving the mouse cursor over top of the 'details' label shown below. If you were to move the mouse cursor over the details button of the action Build Solar Array you would see that though Vanessa has the skills to do that task she only has a tool-kit handy and none of the other stuff that goes into making one of those fancy solar-arrays.

ScreenCapture_RepairRadioDetails.PNG

However, in the image above you can see(near the bottom and behind the near form that reads "Repair Radio") what happens when the mouse cursor is positioned on top of the details label for the action Repair Radio. There are three types of resources involved in any action : input, interrupt and output. An action here is kind of like a recipe that requires ingredients and bowls and pots and pans or whatever for input and then on the output side of it you get whatever it is you baked (plus, as an added bonus, you also get all those dirty dishes back!). So to repair a radio you need 1) a broken radio and, 2) a tool kit. then when the necessary time has elapsed and the action has been carried through the output resources are rendered : 1) a radio (no longer broken), 2) the same tool-kit as before, plus 3) a little bit of engineering experience. So now to get Vanessa to fix this radio and play us some tunes you just click on the name of the action in the available actions list and in the time it takes to say "she sells sea shells" that old broken radio of yours'll be fixed.

Cave-at

I must make a caveat here about the caves. They're still there and they do look cool but dudes don't like going down there because code in them parts ain't up to snuff. The ships still fly around and you can walk about but i haven't tested it properly. I'm working on it but so far the landscape is working and the caves just ain't. next time...

The Code

where to start? ouch... I've been at this for a couple of months since the last article and there's a lot to talk about. I'll try to remember every thing I did but there's bound to be a bunch of stuff that's just going to slip by. There's a few new controls that are all located in the classControls, and the astronauts are really cool. but first I want to tell you about the dynamically generated collision-detection polygon(CDP). If you recall from the last article (which, I admit, was really boring and probably a let down) I talked about the polygon collision detection scheme that this project uses for collisions occuring indoors but since then the astronauts now dynamically mold their CDPs around their current configuration and step. Let me explain ...

Dynamic Molding of the Collision Detection Polygon

The astronaut images consist of sprites generated using the Sprite Editor 2.0. These are essentially a bunch of images created using the images of the various limbs which make up the astronauts, and positioning these limbs at whatever angle necessary to animate the characters. The sequences of images are called Configurations and each step in these configuration is a step(oddly enough) and so the third image in the walk animation can be referred to as the "third step in the walk configuration". Since the astronauts change their shape as they walk and move around i decided that it would be cool to mold their collision detectin polygons around their sprite configurations but was averse to the idea of actually painstakingly doing this by hand so i ordered my computer to do it which was relatively painless. to me at least. I'm not sure about my computer but there hasn't been any complaints so far.

To do this the algorithm takes the positions of all the limbs and hinges (you'll have to read the Sprite Editor 2.0 article for an explanation of these terms) in the sprite and converts them to radial coordinates away from the center of the sprite. Then it reorders these into ascending order of angles (this turns out to be clockwise because all the calculations are done assuming that your trig-teacher lied and the Y-axis is really upside down so that positive radial motion is clockwise instead of counter-clockwise as the gods of trigonometry would have it). Then the algorithm keeps a running tally of which points have not yet been eliminated and goes round and round testing a line between the center of the sprite and a test point crossing it with a line between the previous remaining point and the next remaining point in the collision-detection-polygon. If these two lines cross the test-point is still valid and if they do not cross then the test point is invalid and is therefore removed from the list of points that make up the CDP. When the algorithm has gone around a full circle without eliminating any points it quits and we've got ourselves the smallest convex polygon that can contain your active, healthy astronaut in whatever position he or she may be in(embarassing or otherwise).

Here's some of the code you can find in the classAstronaut.rebuildCDP(). After it has gathered all the cartesian points, converted them to radial coordinates, reordered them according to their angles and eliminated any doubles, it picks a test point and the before and after points and starts to the loop around. It does test for certain line which fall on the wrong side of center but generally its pretty straight forward. Here's the loop below :

while (intTestsSinceLastElimination < intNumPointsValid)
{
    intTestsSinceLastElimination++;

    ////if difference in angle between next & previous points is greater -> test point is valid
    double dblDifference = 0;
    if (cRadArray[intNext].angle < cRadArray[intPrevious].angle)
    { // looping past zero
        dblDifference = cRadArray[intNext].angle + classMath.twoPi - cRadArray[intPrevious].angle;
    }
    else
    {
        dblDifference = cRadArray[intNext].angle - cRadArray[intPrevious].angle;
    }

    bool bolAngleTest = dblDifference > Math.PI;

    classMath.classDoubleLine dlinCross = new classMath.classDoubleLine(dptArray[intPrevious], dptArray[intNext]);
    classMath.classDoubleLine dlinTest = new classMath.classDoubleLine(dptZero, dptArray[intTest]);
    if (bolAngleTest || classMath.LinesIntersect(dlinCross, dlinTest, ref dptIntersection))
    {
        ////the test point is valid -> move on
        intPrevious = intTest;
        intTest = intNext;
    }
    else
    {
        ////the test point is invalid -> set as eliminated and move on
        bolPointsEliminated[intTest] = true;
        intTest = intNext;
        intNextAtLastDeletion = intNext;
        intNumPointsValid--;
        intTestsSinceLastElimination = 0;
    }
    do
    {
        intNext = (intNext + 1) % bolPointsEliminated.Length;
    }
    while (bolPointsEliminated[intNext]);

    intDebugIndex++;
}

Have a look at an animation I put together to demonstrate this algorithm in action :

dynamic_CDP_Molding.gif

The purple lines form the current resultant polygon and as the algorithm loops around the test point (in red) forms a red line between itself and the center against which another cross line is measured. If the dark black line joining the previous point with the next point does not cross the dark red line then the red test-point is eliminated from the algorithm and we try the next one, on and on until we've looped around the whole thing without eliminating any points.

For the moment this doesn't really play much of a role in the game and it was so slow to generate all the different CDPs for every position that just sitting at her desk Gwen was taking up a lot of MIPs so I had to implement a RAM caching system which keeps in memory every CDP for each configuration/step combination and then these are adjusted against a normal sized astronaut (did I tell you? the astronauts vary in height and size!). Its not exactly one size fits all but each Configuration/step's CDP is generated using the standard astronaut height of 1.73m (I think, i could look it up but I'll let you do it instead, just don't leave too many mean comments if this isn't the exact value) and this value is stored in the cache then is immediately retrieved by the astronaut who needed it and is resized (remember these values are stored in radial coordinates so we're only multiplying the radius by a factor close to 1.0) to fit that astronaut.

This way i figure, when i get to that point where aliens may board the ship, astronauts can duck under fire while the marines can take cover!

Teleporters

As I promised at the end of the previous article, teleporters allow the astronauts and ships to travel from one room to the next and from outside to inside and from inside to outside any structure. I haven't actually patented my teleporter device yet and though this ground-breaking computerized simulation used as a basic feasibility study of the project it seems to conclusively prove previous teleportation theories which have thus far only managed to transport minute iota of matter any distance but I am confident that in time this device will dramatically cut the travel time to the Burger Palace before the end of this century. In this electronic environment, however, we are light-years ahead!

I know. I'm sure I'm not fooling you into believing that I've actually invented a teleportation device. but the classTeleporter connects two regions of the cyber-world ultra-magically. The idea here is to simulate the passage through a doorway and though the inside of any structure is not confined to any realistic dimensions and there is no limit to the number of rooms that can be fitted inside a structure, for the sake of continuity in game play I've made an effort to have doors(teleporters) match their counter-part in the direction of motion. What I mean is, if your dude is walking towards the left in one room when he reaches a teleporter then the teleporter which that first teleporter was connected to, in a separate room, will be on the right side of that room and will allow the character to exit while moving to the left. In on one side walking left, out on the other side walking left. and the illusion of having stepped through a door is almost believable.

There are occasions when this is not possible such as when a Raptor is flying out of a Battlestar's starboard-launch-isolation-area. Supposing the battlestar is on the surface of planet earth and the starboard side of the ship is visible to the player (the ship is facing right), since the internal structure of the ship has the front of the ship facing left then a raptor moving to the left inside is moving towards the bow of the ship but then must be moving towards the right once it has exited the ship and the scene switches from internal to external. This led to a few minor glitches whenever the engines were being fired by the mouse cursor on the screen because if you're flying to the left and suddenly want to move to the right just as the switch s made then the mouse needs to be relocated at that instance from the left side of the screen to the right side of the screen. But fortunately this is done automatically with the use of a library i downloaded from the CodeProject Global Mouse and Keyboard Library and whenever there's a transition like that the mouse is positioned so that the change is made without the player even noticing it.

Structure Editor

In the program.cs file you'll find a few alternate applications which come with this project. Two of them are pretty important : the resource/actions-editor and the structure editor. These are the programs that I made to help me edit a lot of the details that go into making this game. To load the structure editor you need only change the eProgram value shown in the code below.

public enum enuPrograms { MarsMission, StructureEditor, ResourceEditor, test26 , testNumericButton}
public static enuPrograms eProgram = enuPrograms.MarsMission ;
[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    switch (eProgram)
    {
        case enuPrograms.MarsMission:
            Application.Run(new formMarsMission());
            break;

        case enuPrograms.ResourceEditor:
            Application.Run(new formXmlResourcesActionsEditor());
            break;

        case enuPrograms.StructureEditor:
            Application.Run(new formStructureInteriorEditor());
            break;

        case enuPrograms.test26:
            Application.Run(new formTestClass26());
            break;

        case enuPrograms.testNumericButton:
            Application.Run(new formTestNumericButton());
            break;
    }
}

When you execute the application again the structure editor will appear. There's a lot of changes here and I won't go into as much detail about that program as the main MarsMission application but it is quite complex and still almost user-friendly. Each ship model has its own generic structure interior which has all the chairs and consoles, walls and panelling as well as all the teleporters and the odd tool-kit lying around but the structure editor is also used to build the initial start-up battlestar Union with all its crew, resources and ships. Load the file called StructureInterior_battlestar_union.xml in the structure editor and you can see what i'm talking about. There are two combo boxes near the top and a horizontal scroll bar at the bottom. The first combobox lists all the rooms inside the structure and the other gives you the choice of defining whether this structure is inside a ship or a base (the bases are not currently on-line, just the ships) while the horizontal scroll bar allows you to zoom-in/out (I have yet to implement the handy Z-key/Mouse-Wheel combination here). Aside from these all the controls are done using the mouse-context menus, by right-clicking the screen(i reinvented the four-sided wheel when i built my own context-menu a couple of months ago and now that i know what this thing does i've got use for it all over the place!). There are several different modes : edit_astronaut, edit_structure, edit_ship, edit_resources and so on, but there's also the move mode which allows you to control astronauts and move them around one at a time(which you need to do just to get these space nerds to sit down!). Its still a little buggy but for the most part it works pretty good and it is, as I said, fairly user-friendly so that anyone who's worked with a computer before can probably pick it up with only a little bit of effort.

When you're editing the structure you can add/delete rooms as well as polygons inside the rooms and you can, of course, add points that make up the polygons and reshape the room. To move the room around you need only grab the screen with the left mouse button and move it where ever you like and to move any object, ship, astronaut, point or transporter component you just grab the little circles that light up as you position the mouse cursor over them.

Though you can add all the rooms you like they are not connected together until you edit some teleporters. The teleporters are a little bit trickier. to connect two rooms together via a pair (coupling) of teleporters you need to call the Show Teleporter Page and if you don't already have the teleporters you need you'll have to Add Coupling. Teleporters come in pairs and though each teleporter has its own defined location they both share the same size and door-style(currently there are only two styles : sliding door and circular) and the Teleporter Page is where you set these features that are common to both teleporters in any coupling as well as deciding what room each teleporter is going to be in. And its also where you give them their pet names like 'Tigger' or 'Snuffles'(that is, if you're a bit flaky, otherwise you can just give them more meaningful and descriptive names). Just click Ok when you're done.

The sprites for these teleporters were kind of difficult to make. The sliding door requires to extra hinges for each panel. These hinges create an arm-like connection between the door-panel and the frame. When these hinges are turned the door panel remains vertical and moves sideways. You can look at these by downloading the Sprite Editor 2.0 and loading the two sprites. Building them was a bit more trouble than your average sprites, however. Because there are so many parts that have to move at exactly the same rate it would have been extremely tedious and tiresome to do this by hand. So instead, I added a fancy button on my sprite-editor and had its event-handler perform the job for me one step at a time. First I added a single limb and positioned it in the closed position. Then I had my button create all the other limbs by taking the first limb as an example and making the necessary adjustments for each one. Then measuring the open position of the one piece compared to its closed position i had it do all the work to build the four different open, close, opened & closed configurations. It wasn't too bad and though they look cool I may re-think the circular one because it seems to slow things down considerably. more and different sprite for these teleporters are in the works and I may eventually build myself a turbo-lift, though I'm not sure exactly how that would work just yet.

If you take a look at the image below you'll see how to set the controls of a teleporter. First I should explain a bit about how the teleporters know who to send where. Whenever someone(or something) moves into an area of the teleporter measured away from its central position no further than a distance dblRadius then that object or character is placed inside that teleporter's teleportation-queue and the teleporter starts to open (the animation to open is activated) and when that teleporter has finished opening then all the objects in its queue is tested again to be certain they haven't stepped away from the central circular region and each object that is still ready to be transported is removed from that room and relocated a specific distance away from the center of the original teleporter's link-teleporter and mate in the teleporter coupling.

See the image below.

structureEditor_teleporter.PNG

You can see that the dblRadius defines the region which triggers the teleporter's open animation, the radial coordinate puts arriving objects that are being teleported from its mate-teleporter and the dptPos is the position in the game-world where the teleporter is located. To edit these you just grab the center, or rad points and move them like you would any other object (though the radius is a bit buggy in that the editing-point you have to grab is not being consistently drawn at the correct location. Its sometimes being drawn on the top-left corner of the smallest square that can contain the circle despite requiring the editor to position the mouse directly on the circle in order to resize the radius, minor annoying glitch i need to fix, and that's really the only bug I've noticed in the structure-editor).

You can add/remove ships, astronauts and resources in each of their respective editing-modes but when you add a ship it'll ask you what type of model of ship you want and then you can go inside that ship's interior and edit it using a second instance of the same formStructureEditor. You don't need to save the structure of any ship inside another ship, just make the changes and they will be passed on to the mother ship when you exit that form using the File-Exit menu option. but just be certain to save all the changes you make in the mother ship before quitting.

an important note here is this : each resourceObject, astronaut and ship has its own uniqueID. In past projects I've made use of a static counter that increments with each instance of a class and then assigns every new instance its own uniqueID but doing that with this project would result in a lot of issues because the objects are created in one session then saved and reloaded in another session causing real problems when the same uniqueID is used by both a previously saved object and a newly created one. To avoid this I invented a base-26 counting system that uses the alphabet and have each type (resourceObject, astronaut, ship and base) save their latest values to xml files between sessions so that elements created in new games are assigned values that keep increasing, ad infinitum. and since we're really dealing with a string of characters that count "A" = 0, "B" =1, ..., "Z" = 25, "BA" = 26 and "BB" = 27 then there is no limit to the number of uniqueIDs this scheme can generate over years and years of game play while never causing any overflow errors or even so much as a confusing loop back to zero. The class can currently add, subtract, increment and decrement and I'll probably teach it to multiply and divide eventually though I may never bother. This concept can be used to represent exact integer values of any magnitude despite being extremely slow computators relative to their distant mantissa/radix relatives that make up the floats and doubles which have decreasing precision with increasing range, or the integer type variables which are limited in range to the number of bits used to represent them.

Moving on.

Actions

As briefly explained above the actions consist of inputs, interrupts and outputs. The interrupt resources are those resources which are returned should the action be interrupted. The actions can be edited in the resource/action editor's action tab shown below.

actions_editor.PNG

Here you can see the action Operate_Science_Station along with the textbox to edit that job's title "Science Officer" and though the requisite proficiency type is set to Geologist the required proficiency level setting of zero means that there is no proficiency requirements for this action. most of these options are self-explanatory : automated-selection means that this action is available for automatic-selection whenever the player presses the Enter-key(which upon reflection I may change to the left-hand accessible Space-key) and all the requirements are met. If the action is 'hidden' it will not appear in the available actions list unless it is available, as opposed to other actions that may be displayed there even if one or two of the requirements aren't yet met. This allows the player to see what can be done if certain ingredients in the action's recipe are available while others aren't, e.g. "I have a broken radio but it says here that if i had a tool-kit i could repair it!". The action Operate_Science_Station has a loop action which means that when completed another action, of the type specified by the loop-action option, will be started. In this case the loop action is the same as this action which means that once the time alotted to complete this action has expired the astronaut will simply do it again after having earned her 'experience points'. This makes for some added versatility since several actions can be combined into a cyclical sequence if you wanted to break down some action into several different partial actions like 1) mix cake batter, 2) pour cake batter into mold, 3) put uncooked cake into oven, 4) cook cake, 5) remove cake from oven. but sciency space stuff, you know, i'm just kind of hungry right now. All you'd have to do for that to happen is set the first action's loop equal to the second, the second action's loop equal to the third and so on and then set the last one's loop action equal to the first and the whole thing just keeps on looping cyclically so long as the resources are available.

Some actions like operate_solar_array do not require an astronaut's attention and though these actions are not currently part of the game the plan is to have an astronaut start-up the solar-array and then walk away from it letting the eVolts accumulate in whatever nearby lithium-batteries have space for them and then loop on so long as the sun-shines letting any excess energy go to waste when there are no more nearby containers to hold them as they are generated.

The resource-editor is in the same application as the actions-editor but on a different tab and it allows you to edit the resources available. I just noticed there's something wrong with the way their images are being displayed in the editor but this is a minor detail I'll get to later, mostly it looks pretty good. Since the game works using the metric system and a game-world yard-stick the conversion from real-world definition(set in the resource editor) to game-world application is done using two conversion functions in the main formMarsMission form.

public static double ConvertRWUnitsToGWUnits(double dblRealWorldUnitOfLength)
{
return dblRealWorldUnitOfLength * formMarsMission.dblDistanceConverstionFactor_RW_to_GW;
}

public static double ConvertGWUnitsToRWUnits(double dblGameWorldUnitOfLength)
{
return dblGameWorldUnitOfLength * formMarsMission.dblDistanceConverstionFactor_GW_to_RW;
}

By defining the height of a resource object here in the editor an image of any size can be used to generate that resource's sprite. And adding a new type of resource is relatively painless since we need only create it in the editor and a simple dumb-sprite can be generated if one doesn't already exist by providing an image file with the resource's name in the working directory. The sprite is then generated by the function listed below :

static classSprite createSpriteAndSaveToFile(enuResources eResource)
{
string[] strFiles = System.IO.Directory.GetFiles(strWorkingDirectory,"resource_" +  eResource.ToString().Trim().Replace(" ", "_") + ".*");
if (strFiles.Length > 1)
{
    MessageBox.Show("ambiguous filenames found creating sprite for handtool : \r\n\r\n" + eResource.ToString().Trim() + "\r\n\r\n in resources directory : \r\n\\r\n" + strWorkingDirectory.Trim());
}
else if (strFiles.Length < 1)
{
    return null;
}
else
{
    classSprite cRetVal = classSprite.spriteMaker.getSprite(true, 16, false, eResource.ToString());

    cRetVal.hinges = new Sprite.classSpriteHinge[2];                
    cRetVal.limbs = new classSpriteLimb[2];
                
    // add main image as a limb
    Sprite.classSpriteHinge hinNew = new Sprite.classSpriteHinge("main hinge");
    Sprite.classSpriteLimb limNew = new Sprite.classSpriteLimb(ref cRetVal, true, false, eResource.ToString());
    Bitmap bmpBaseImage = (Bitmap)Bitmap.FromFile(strFiles[0]);
    limNew.initImages(bmpBaseImage);
    hinNew.Limb_Master = cRetVal.MasterLimb;
    hinNew.Limb_Slave = limNew;
    hinNew.RadCoor_Master = new classMath.classRadialCoor(0, 0);
    hinNew.RadCoor_Slave = new classMath.classRadialCoor(0, 0);

    cRetVal.MasterLimb.mySlaveLimbs = new Sprite.classSpriteLimb[2];
    cRetVal.MasterLimb.mySlaveLimbs[0] = limNew;
    limNew.MasterHinge = hinNew;
    cRetVal.limbs[0] = limNew;
    cRetVal.hinges[0] = hinNew;
                
    // add extra limb to locate bottom of resource
    Sprite.classSpriteHinge hinBottom = new Sprite.classSpriteHinge(conResourceBottom_LimbName + "_hinge");
    Sprite.classSpriteLimb limBottom = new Sprite.classSpriteLimb(ref cRetVal, true, false, conResourceBottom_LimbName);
    limBottom.initImages((Bitmap)Properties.Resources.MasterBlock);
    hinBottom.Limb_Master = cRetVal.MasterLimb;
    hinBottom.Limb_Slave = limBottom;
    hinBottom.RadCoor_Master = new classMath.classRadialCoor(Math.PI/2, bmpBaseImage.Height/2);
    hinBottom.RadCoor_Slave = new classMath.classRadialCoor(0, 0);

    cRetVal.MasterLimb.mySlaveLimbs[1] = limBottom;
    limBottom.MasterHinge = hinBottom;
    cRetVal.limbs[1] = limBottom;
    cRetVal.hinges[1] = hinBottom; 

    cRetVal.MasterLimb.IRotate = true;
                
    Sprite.classConfiguration conMain = new Sprite.classConfiguration();
    cRetVal.Configurations = new Sprite.classConfiguration[1];
    conMain.name = "main";
    conMain.steps = new Sprite.classConfigurationStep[1];
    conMain.steps[0] = new Sprite.classConfigurationStep(ref cRetVal);
    conMain.steps[0].hingeDetails = new classConfigurationStepHinge[2];

    conMain.steps[0].hingeDetails[0] = new classConfigurationStepHinge();                
    conMain.steps[0].hingeDetails[0].hinge = cRetVal.hinges[0];
    conMain.steps[0].hingeDetails[0].angle = 0;

    conMain.steps[0].hingeDetails[1] = new classConfigurationStepHinge();
    conMain.steps[0].hingeDetails[1].hinge = cRetVal.hinges[1];
    conMain.steps[0].hingeDetails[1].angle = 0;
                                
    conMain.LimbDrawSequence = new Sprite.classSpriteLimb[2];
    conMain.LimbDrawSequence[0] = hinNew.Limb_Slave;
    conMain.LimbDrawSequence[1] = hinBottom.Limb_Slave;

    cRetVal.Configurations[0] = conMain;

    string strSpriteFilename = strFiles[0];
    int intCutChr = strSpriteFilename.IndexOf(".");
    strSpriteFilename = strSpriteFilename.Substring(0, intCutChr) + ".sp3";
    classSprite.spriteMaker.saveSprite(ref cRetVal, strSpriteFilename);

    cRetVal.cFileStream.fs.Close();

    cRetVal = classSprite.spriteMaker.loadSprite(strSpriteFilename);
    cRetVal.cCache.initCache();
    return cRetVal;
}
return null;
}

Then a dblDrawSizeFactor is calculated at load time which is used to resize the image for any zoom-magnification such that the relative size of every object, ship or astronaut is proportional to the pre-defined sizes we gave them in the editor regardless of the various source images used to generate the sprites.

Metric System

Making the conversion from some abstract size that obliged me to tinker with the size values every time i created a new object or ship, to the much more versatile and easy to use metric system which allows me to state exactly what size everything is was made difficult by the fact that memory limitations kept the number of landscape cells to some relatively small value (earth has exactly 5000 cells in its landscape definition and is used as the standard against which all other planets and moons are measured, since the gas-giants have no surface to define most planets except for neptune use less than 5000 cells for their landscapes) using too great a value would over-strain the available memory resources(there are several ways which we could get around this but for the moment the game is designed to hold the entire landscape, caves and all in memory! in a future re-write this particular design choice may be re-evaluated).... this meant that to keep the metric system and remain realistic while using only 5000 cells to define the circumference of the earth the ship was reduced in size about 1/1000th the width of a single landscape cell wiping away all details of the surface completely. To keep the same level of detail as before would have required half a million cells just to define the planet earth, never mind the 160 odd other planets and moons besides. I deemed this to be too much for my computer to handle and decided that the puny ship in a giant world was far too ugly to be used so as a compromise the circumference of the earth is no longer realistic once the ship has entered the landscape but is about x100 smaller while maintaining an overly tall ceiling.

and i wash my hands of that...

Atmospheric Gases

The atmospheres of the planets in the solar system have been fairly well documented and I scratched up the necessary information on the internet without too much hassle(i always want to spell hassle like castle for some reason. dunno?!?). Then that data was included in the SolarObject.xml file. You'll notice that the resources-editor includes chemical compounds and these are the compounds which are found in the list of atmospheric components but it would be boring to see that the atmosphere was uniform from top to bottom and that just isn't the case in the real-world anyway so what this program does on request is, at any given altitude, reorder the components according to atomic mass and then calculate how much of each component is found at a specific location in the atmosphere. This way you can find a pocket of argon or neon or nitrogen or whatever and level off wherever it is that you find the compound you need most. I'm not sure exactly how realistic this is but it seems to be a lot cooler than just keeping them static throughout.

And its not just because any old astronaut is sitting at a science station that you get all the details exactly as they are. Some astronauts are just better than others and a good chemist will be able to give you more detailed information than a bad one, or even one that's just not quite up to snuff.

Vehicles

Vehicles like the Moon-buggy, Backhoe and forklift are also available in this version of the Mars-or-Bust Tour. These vehicles are simply complicated resources and can be added to the structures using the structure-editor in edit_resource mode. There are several different types of resources shown here :

public enum enuResource_Type
{
    element,
    molecule,
    tool,
    missile,
    weapon,
    component,
    vehicle,
    _numTypeResource
};

you can see that i've included "missile" and "weapon" (along with "component" though I'm not quite sure what i was thinking there). For the moment, molecules are in the atmosphere and our chemists will later toy with them, as well as whatever the geologists dig up, to make building materials for the engineers who'll dabble with the ship, weapons, bases and what-nots. There really isn't much limit here beyond imagination. the hard part is incorporating each new thing into the game in a meaningful way.

but, back to vehicles...

When an astronaut gets into a vehicle he is removed from the structure's container and added to the resource-vehicle's container so that the astronaut is no longer drawn as part of the room but rather as part of the vehicle, which is drawn as part of the room. Since the animation of each astronaut is done by cycling through the static array of astronauts found in the classAstronaut then losing sight of the astronaut's pointer inside the room is no big bother. Vehicles, however, are a bit of a bother since the astronauts move them by moving themselves and transporting a vehicle across a teleporter means transporting everything inside it, and that took a bit of tinkering.

Further trouble was met in implementing the game save/load when dealing with astronauts located inside a vehicle. They're not actually stored as part of the vehicle, instead the astronauts think they're inside a room and have a pointer to a resource called cVehicle. and we know an astronaut is inside a vehicle when that pointer is not equal to null. but otherwise the astronauts actually think they're still inside a room when they're actually inside a vehicle, this way they can interact with their environment. So when its time to reload the game the resources of type vehicle have to be scanned inside each room and when one of them has an astronaut then that astronaut needs to be told to re-perform the action enter-vehicle before the game restarts again, thus getting rid of any wrinkles. There may be a better way to just tell the astronaut he's in a damned buggy but i got annoyed and this was the first solution that worked so that's the way it is. Create the room -> create the resources and astronauts -> test for vehicles with passengers -> tell the passenger to get into their vehicles... and we move on.

Collision detection while inside a vehicle requires the CDP to incorporate the vehicle in its calculations which means that the astronaut's CDP is rebuilt every time the astronaut either changes arm rotation/action or the vehicle's configuration is changed to alter the CDP. a boolean is kept to determine whether or not a rebuild is necessary.

The backhoe currently has a mouse-button activated 'excavate' animation which does not do any collision detection. this animation will be used later to alter the landscape and will be part of an action for the geologist to perform on the surface below to level the ground in preparation for landscaping, lawn-ornaments and maybe even a painted clay gnome or two before the bases can be built. The Union currently has a backhoe inside the dutycraft located in the ship's cargo hold. Ask Janis Joplin to show you around.

The forklift is Britney's business in the hanger. Its forks can be moved up and down using the mouse-wheel and a mouseclick picks-up/drops resources that are lying around. for the moment the mass of any object is not being taken into consideration when an astronaut tries to pick it up so anything the forklift can heave Joe Harmer, or Britney, can lift with ease. But later, when that's done, the masses of objects will require a forklift and this will be just the thing.

The vehicles don't move any faster than a walking pace for the moment but we're just getting started, it'll take time is what I'm saying.

Sprite Caching

Earlier I spoke about caching the sprite images and how slow the game will appear the first time you run it, let me tell you a bit about what's going on.  The sprites generate images by collating all their limbs together and their specified hinge angles and the resultant images are thrown onto the screen but the actual building of some of these images can sometimes be slow if the sprite in question has a lot of limbs, like the circular doors, for example.  Those are all moving parts and each part has to be slapped onto the screen at just the right spot for each step of each configuration and doing this is a long slow process that totally kills the animation, however, since the sprites make use of a caching system that retrieves the images it has created previously they runs infinitely more smoothly once these caches have been populated and the images in question have been created and put the screen before you need them again.

The way the caching works is really quite simple.  The sprite uses its own sprite-name when deciding what name to call its sprite-cache-file which have the extension .fs (stands for file-stream) then it creates an index of all the possible images which it could eventually be called upon to draw, every step of every configuration, for every possible angle and mirror.  Say 90 images per quarter rotation equals 360 possible angles, an example of 12 configurations with, on average 10 steps each, and multiply all that times the 4 different mirrors and you have 360x12x10x4 possible images.  So right off the starting block the sprite creates is own caching file by writing a '-1' that many times and uses a function to fetch the index of each possible image.  When the value at that index is -1 then the image does not exist and it must be created the hard way before it can be cached.  When it is cached the image is appended to the end of the file and the address of that information is stored as a long integer in the index for that specific config/step/angle/mirror combination for the next time it needs to be retrieved.

In the images I have below you'll see the sprite cache file for the astronaut just after the index has been created (and before any images are stored in it)

sprite_cache__indices__.PNG

 and the second image shows you what that file looks like after running the game for a few days.

sprite_cache.PNG

you can see that at 2.14GB for a single cache, the more complex sprite can generate a huge amount of images and here they all are quickly accessible.

Controls

There are a bunch of fancy controls in the classControls.cs file.

ButtonNumeric

These are the buttons which control the ship's dampers and engines. They're made up of panels that hold an array of textboxes and each textbox has its own value & event-handlers. Whenever a textbox's value is changed and the resultant value causes it to loop past zero or nine then the value of the textbox one order of magnitude higher is also affected. They have set() & reset() functions that hold the value of the button's flag which is tested outside the class. Whenever the button's flag is high the color is red and when the flag is low the color is gray. It wasn't very difficult to make but did require a bit of testing and redoing along the way.

LabelWarning

The LabelWarning class is the class used to display the engine powers, as well as the external atmospheric pressure. Their special power is the ability to change color! Impressive, eh. yea, i know.

panelContainer

A panel container is a panel that holds an array of other panels. Its not exactly a Nobel prize entry but it is handy because it has a vertical-scroll bar which displays the panels it holds one above the other and is easily made to adjust its size to refit any changes in the dimensions of its contents.

textbox_HightlightChange & textbox_Numeric

these textboxes change color highlight to yellow whenever a change is made to their content and then are reset to white after an enter-keypress which activates an event-handler. The numeric textbox also limits the keypress entries to numeric ones(along with del, back, left, right, home, end and return) suppressing all others.

timer_game

a game-timer is now used in MarsMission. Game timers have interval and tick events like any other timer, however, they also have start(), stop(), pause() and restart() functions. The start() and stop() functions work similar to toggling any other timer's Enabled property, however, to pause()a game-timer means telling the timer to take note of the time its being told to stop and then when the restart() function is called the time is tested again and the difference is subtracted from the game-timer's interval before a new delay is set such that the intended game-timer's delay is not slowed down by the work being done during the game.

the pause() is executed at the start of its tick event. then the game goes about its crunching and drawing and fetching and caching and when its done all that for the 1/10th of a second interval it has to do all its work it quits the tick-event by first restart()-ing the timer and although the delay caused by the execution of the code in the event-timer (virtually everything in the game!), so long as that delay does not exceed the alotted 100ms, then the next event will happen exactly when its supposed to.

Of course, we could just just leave the timer on... but I'm pretty sure that a second tick could occur before the first tick has completed and totally screw things up. I think i determined to use this when there was some serious bug somewhere and decided that it was the timer's fault. but it seems stable now so I'll just keep using it.

Save Games

The save game feature is up and running. Hoorah! Thanks entirely to our friends and colleagues at the XML industrial complex. good job, guys. really, stellar!

Every class that requires saving in the game save/load files has a pair of functions specifically for the job, here's the classResourceObject's headers :

public static classResourceObject fromXmlNode(ref XmlNode xNode)
public XmlNode getSaveGameNode(ref XmlDocument xDoc)

Aside from one GameInfo.xml file in the SaveGame subdirectory all the other files that retain the game's state between sessions pertain to the solar-objects. Each solar-object has its own info recorded in its .xml file and all ships flying in interplanetary space have their data recorded in the sun's .xml file while everything else must be contained inside the landscape nodes of the solar objects that hold them. It takes an entire directory to store all this information and keep it all straight, though storing all the files inside a compressed file wouldn't be that difficult at the moment i'm just glad the save/load game feature is working and the entire list of .xml files could alternately be stored inside a single file but during the debugging phase I decided that loading it and looking around would be too memory consuming for my poor computer so I chose this route. In order to save multiple games I'm thinking of using a folder-browser and just storing them in separate directories. neat and simple.

Future Developments

now that Miley Cyrus has joined the team we've got some great plans that include a new music video for MuchMusic and MTV, but it'll have to be in sign-language since we don't have the budget for a sound-driver just yet. working on it.

as for the game itself, the caves need attention. gotta get some excavation done, and there are bases to explore. invent new actions, add mass to the equation, create new resources, explore the concept of a chemistry lab.

"and have it done by wednesday!" (just tell me what year!)

 Update

- there was a glitch in the classLandscape.cs that prevented astronauts from standing on the surface

-  some strangeness concerning what ship one was flying back into : fixed

- March 26, 2011 : uploaded new source-code and .xml files.   I've been fixing and tinkering for the last week and changed the way the schedule is displayed as well as found a bunch of minor problems which needed some attention.

Mars Mission (5) : the Chemistry of Fuel

 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Christ Kennedy
CEO unemployable
Canada Canada
Christ Kennedy, published his fourth novel "Cleats of the Counter Revolution" in the summer of 2010. He grew up in the suburbs of Montreal and is a bilingual Quebecois with a bachelor’s degree in computer engineering from McGill University and is currently walking across ontario plotting a new novel, far away from any computer.

Comments and Discussions

 
QuestionMy Vote of 5*+++++ PinmemberMas1111-Sep-13 23:30 
GeneralMy vote of 5 PinmemberBrent_JR31-Mar-11 2:57 
GeneralRe: My vote of 5 PinmvpChrist Kennedy31-Mar-11 10:56 
GeneralMy Vote of 5 PinmemberRaviRanjankr30-Mar-11 9:20 
GeneralRe: My Vote of 5 PinmvpChrist Kennedy30-Mar-11 10:35 
GeneralMy vote of 5 PinmvpMarcelo Ricardo de Oliveira21-Mar-11 4:14 
GeneralRe: My vote of 5 PinmvpChrist Kennedy21-Mar-11 4:27 
GeneralRe: My vote of 5 Pinmembersam.hill5-Jul-11 12:35 
GeneralRe: My vote of 5 PinmvpChrist Kennedy6-Jul-11 10:07 
GeneralMy vote of 5 PinmemberMarcus Kramer21-Mar-11 3:35 
GeneralRe: My vote of 5 PinmvpChrist Kennedy21-Mar-11 3:47 
GeneralMy vote of 5 PinmemberSlacker00721-Mar-11 0:22 
GeneralRe: My vote of 5 PinmvpChrist Kennedy21-Mar-11 0:51 
GeneralSub-Directories Pinmemberrctaubert20-Mar-11 11:10 
GeneralRe: Sub-Directories PinmvpChrist Kennedy20-Mar-11 12:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 5 Jul 2011
Article Copyright 2011 by Christ Kennedy
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid