ajh1138

Archive for June, 2008

Inertia

In Uncategorized on June 27, 2008 at 5:52 am

More futzing with the “drift” on my game.  I believe the correct term is “inertia”.  I really need to read that “pysics for game developers” book.

i simply took the ship’s current rotation and generated a vector from it based on an arbitrary thrust value, then added that to the ship’s current velocity vector.

like so:

CalculateMovement((int)curRot, .3, out newX, out newY); // this function ripped off from Silverlight Rocks

velocityX += newX;
velocityY += newY;

_playerVel = new Vector2D(velocityX, velocityY);     // i then use this vector to move my background layers, as well as the player’s position in the game universe.

And I have a check in there to make sure the ship doesn’t go too fast in any direction.   Before I had the check in there, the thing could go to warp speed in a few seconds.  It was a good test of my starfield generating algorithm, anyway.

So now I’m slipping and sliding all over the place.  It looks really good.   I’ve found a bug with my min/max check that I knew would happen, though.  More thinking and tweaking before I upload a new version.

Solving the velocity problem

In Uncategorized on June 25, 2008 at 3:05 pm

Last night I fiddled with my game’s physics a bit and I came close to a method of providing “drift” to the player’s ship when you change direction and add thrust.  The previous version instantly changed direction but maintained the same speed – not realistic, not elegant, and highly dangerous.  (Instant 180 degree turns would probably turn your crew and cargo into a nice thick paste coating the rear wall of your ship.)

Here’s the solution I came up with after playing Three Card Monty with the variables (I am not a math person by any means)…

currentHeading – ((directionShipIsPointing – currentHeading) * arbitraryThrustValue) = newHeading

This works great for the most part…but a problem arises when you turn the ship from, say, 5 degrees to 350 degrees…my algorithm interprets that as a change of 355 degrees, and thus the ship bounces backward for a second before coming to its correct course.  I won’t bother posting the actual code here since it’s WRONG!

Oy!  What to do?  Fortunately, Avi Pilosof just posted a thorough, illustrated and wonderful set of blog entries about this very thing.  I cought it via Silverlight Cream.  So I’m going through that and I’ll rework my physics using vectors instead of basing everything on rotations.  This will help me out with Second Life programming, too, I’m sure.

Password Guidelines

In Uncategorized on June 24, 2008 at 4:24 pm

Here’s a password message I’m expecting to see in corporate use fairly soon:

Your password will expire in 7 weeks.  Would you like to change it now?

Passwords must contain at least 20 characters, including 3 uppercase and no more than 5 lowercase characters.  Characters may not be repeated.  Passwords cannot contain any characters used in your last 8 passwords.  You must use at least three non-English (US) characters and passwords cannot contain any dictionary words from any actual or imaginary language (including Klingon, Huttese, Proto-Eldarin, or Quenya), nor can your password be phonetically construed to contain any dictionary words.  Passwords must conform to the syllabic pattern of Haiku, or in some special circumstances, Senryu.

Moving backgrounds

In Uncategorized on June 20, 2008 at 4:35 am

I was using a pretty lame technique to move the background starfield under the player’s ship and the more I struggled with it, the more I saw its flaws.  I had 4 panels, each was the same size as the game screen and a pretty nice starfield pattern.  I would move the panels according to the ship’s velocity and direction.  When one panel went offscreen, I would move it to the opposite side so it could be re-used.

My primary flaw in logic was that I had a cyclic error when testing to see if the panels’ x,y coordinates were less/greater/equal to the boundaries of the game.  I’d detect that panel 1 was off-screen, then place it in a position where it would then get picked up by another off-screen check and guess what?  You’d never see that panel again.  The equal-to part of the check was the main problem.

Anyway, I decided to use two overlapping randomly-generated starfields instead.  My offscreen checks are now nice and tight, and I can get funky with what happens in those checks (like change the star’s color or whatever).  The double-starfield looks sweet, too.  The top layer has 3-pixel stars and the bottom has 1-pixel stars.  The bottom layer moves a bit slower.  The effect pleases me.  I am pleased.  Yes.

Your first taste of Splodge Pre-Alpha .0001

The ship is ripped off from Lost Garden’s free game graphics collection.  I highly recommend Lost Garden for anybody noodling about in the indy game cosmos.  I’m probably going to use some of my kids’ art as soon as I get it digitized, or they’ll make some for me on their ‘puters.

Anywhooo, this is your first chance to test out Splodge Pre-Alpha v0.00001!  Some notes before you check it out:

- Click yer left mouse button to fire, use your mouse to aim/steer.
- Press W to accelerate, S to decelerate.  I don’t have fancy physics worked out so that your velocity/direction is dampened correctly when you turn and burn.
- I don’t have thrust sound or graphics yet.
- The laser shot sounds get clipped occasionally.  Still working on that.
- The stars are really cool.  Just keep that in mind.
- Be careful using Silverlight in Firefox (especially FF3, apparently).  I’ve seen it crash several times, and not on my stuff, but on the official Silverlight.net site mostly.
- This build was made with Silverlight 2 Beta 2.

Some steps forward

In Uncategorized on June 13, 2008 at 3:34 pm

Last night I decided that my Silverlight game wasn’t heading in the direction it should, so I went back to a previous iteration with some insights from my recent effort. I’ve had a problem getting the vision of the game solid in my head.

At first I had built a top-down, ship-centric shooter but I decided to try a map-driven, simpler game where you click on planets and then do your trading. I had the map part working nicely, but man it would have been a pretty dull game.

So mow I’m going for a model that’s much closer to Escape Velocity…top-down, player-in-the-center pew-pew game with a galactic map, commerce and weapon/ship upgrades. Last night I was able to (with the assistance of my older boy, Max) get a starfield moving under the ship, and move the ship around using velocity, etc. I still need to do the physics for thrust/velocity/turning, but for a guy that’s used to doing event-driven programming all the time, seeing this real-time action is pretty exciting.

One of the aspects of the game that I’m apprehensive about is building the AI for non-player ships (NPS? hehe). They’ll need to turn, thrust, fire weapons, target the player, etc. etc. Sometimes I think I’m getting a little too ambitious, but that’s what I need to do so I don’t get bored.

Where I am Now:

  • The game universe is 30000×30000 pixels. I generate a background starfield using about 7,000 randomly-placed white circles.
  • player ship in the center; a target reticle is moved by the mouse, which causes the ship to rotate to point at it.
  • ship fires lasers when the left mouse button is clicked. no sound yet.
  • ship increases velocity when the W key is pressed. the starfield moves in relation to the ships velocity/direction.
  • Map currently represents one solar system. You can click on a planet and your ship ( a totally different ship ) appears there.

Next steps:

  • Create the background more efficiently. The stars take too long to generate, IMHO, and maybe take up too much memory. I’m thinking a tiled bitmap would be better. Requires investigation.
  • Get the thrust/maneuvering to be fluid. Add some graphics for thrust, sound too.
  • Create a new data hierarchy to have star systems with planets/moons/stations. Each system should have a security rating, description, etc.
  • Refactor the map to show star systems and enable jumping between those systems.

Pet Peeve Mitigation 1

In Uncategorized on June 11, 2008 at 9:19 pm

When I’m banging out some CSS in Visual Studio, I like to keep my attribute values tabbed nice and neat. One of the problems I’ve had in VS is that when I try to tab-indent my values, it causes Intellisense to select the first available value for me, which is rarely what I want to happen.

I have found, however, that if one uses a Shift-Tab you can get out of the Intellisense menu once it drops down. After that, you’re free to hammer on that tab key as much as you want. I’ll upload some pics and code samples to explain a little better.

RPGs, XML documents, stuff, things

In Uncategorized on June 1, 2008 at 6:50 am

Going from my happy little web-based world (with forms and spans and whatnot, with C# on the backend and JavaScript handling the stuff in between) to the XAML/Silverlight world has been like switching classes in an RPG. Those of you familiar with role-playing games of any genre will know what I’m talking about. You get really used to playing a rogue or a warrior, and then all of a sudden you decide to try out a warlock or mage. The way you play is completely different from class to class.

So I’m not only dealing with XAML newbtasticness, but I’m also struggling due to the fact that Silverlight 2.0 just doesn’t yet have the same documentation/tutorialization/discussion board saturation level as more established (I don’t dare say “legacy” hehehe) technologies. It’s almost got a hobbyist feel to it, and I kinda like that.

Anyway, I’ve been avoiding the ‘light for the past week due to illness (pinkeye and strep simultaneously!) and becuase I couldn’t figure out how to do something that would be dead simple for me in regular C# winforms/asp.net…how to read an XML file and use its data.

After some rigorous searching I finally figured out the following:
1. How to stash an XML document into your Silverlight app the right way: Create the document in your project, then right-click on it, go to Properties and set the Build Action to “Embedded Resource”. Now your document will be neatly tucked away inside your code file when the user downloads it.

2. How to read said XML document: First off, you’ll need to add the System.Xml.Linq namespace to your References in your project. Then, make sure you add your “using System.Xml.Linq;” statement (or VB equivalent) in the file you want to do XML magic with. THEN…do this:

XmlReader rdr = XmlReader.Create(this.GetType().Assembly.GetManifestResourceStream(“YourApplication.YourFileName.xml”));

You’re creating an XmlReader that grabs the file that you tucked away inside the application. Of course, you might want to toss this into a using block so it cleans up better, but you get the idea.

THEN…create an XDocument (a fancy Linq XmlDocument) like this:

XDocument xdoc = XDocument.Load(rdr);

see how it loads the content of the reader? nifty.

THEN…use Linq to XML to grab the stuff you need out of the XML. I’m not gonna cover that on this post. ScottGu does that much better. Download his example app and study it.

The part that was driving me crazy with this was the whole XDocument thing. I read some articles that said XDocument wasn’t even supported in Silverlight! Maybe they meant v.1? Anyway, I finally saw ScottGu mention that you have to reference System.Xml.Linq, and there was much joy in my heart as I finally saw all the pieces fit together.

I realize that what would probably help alleviate some of my frustration would be to go through all the tutorials I come across step by step and build my knowledge before I start my own projects…but man, that bores the hell out of me.