Archive for February 2008

Is John McCain a citizen?

From Wikipedia

In most cases, one is a U.S. citizen if both of the following are true:

1. Both parents were U.S. citizens at the time of the child’s birth
2. At least one parent lived in the United States prior to the child’s birth.

So unless John McCain’s parents were not citizens, John McCain is a citizen.

The New York Times must be really desperate for something. And people thought Romney was squeaky clean.

Slashdot is full of stupid

A response to my license agreement for Bunnies and all my tutorials:

“You may freely use and distribute the code presented in these tutorials under any license EXCEPT the GPL or any other license which denies authors their right to do as they please with their own code.

Hypocrite

If this illiterate tool could read he would see that the restriction applies to MY code. You can relicense MY code anyway you want (as long as proper credit is given if needed) except as a viral license such as the GPL. It does not apply to YOUR code.

The GPL (and like licenses) force your to release YOUR code as GPL if you put one line of GPL code in your code. So if you were to mix GPL code with Bunnies code suddenly it would be GPL licenses which prevents you from being able to use MY code in accordance with MY license agreement.

So to prevent that sort of thing, any code that is added to Bunnies/RTSR tutorials that has an incompatible license is considered public domain until you come up with a compatible license agreement.

The GPL is the most ridiculous license agreement ever invented. This is why a lot of the good open source projects have more of a BSD style license. They recognize they are intended as part of a greater whole and do not have the right to dictate what I can do with MY code.

Some Light Improvements

One of the bottlenecks of Bunnies is the lighting effects. Then I remembered that light intensity is based on the square of the distance from the light source. That meant I was doing unnecessary squareroots.

The other thing I realized is that when you create a light on the Bunnies map editor you set the radius of the light. Well, what does that mean? Does that mean the light should have no effect at a distance greater than that radius? Well that’s impossible.

I / D^2 = i

I is the intensity of the light. D is the distance from the light to the point. i is the resulting intensity at the point.

As you can see as D becomes large i goes to zero but it will never be zero.

So I came up with a way to make the radius mean something. The radius is the point at which the intensity is 10% of the maximum intensity.

I / D^2 = 0.1
I = 0.1 * D^2

So the actual intensity of the light is now adjusted so that it is 10% of its peak intensity at the specified radius D.

It’s completely arbitrary. I just wanted to choose a percentage that was close to dark but not completely dark. If you lower the percentage too much the light starts shrinking considerably and you’re no longer illuminating the radius that was desired.

So now that’s all taken care of. The radius is used to calculate the lumenesence of the light source.

The next issue was there are a lot of lights in map 3. And mathematically every global light effects every pixel in the map to some amount greater than 0. But most of the time that amount is neglegable. So I devised another formula.

SQRT( I / i) = r

where I is the intensity of the light and i is the minimum intensity I care about and r is the distance at which that intensity occurs.

As i decreases, r increases significantly. So I couldn’t pick too low a number. So I went with 0.01. So now, 1% is the minimum intensity before I ignore the light source.

So now when lighting is calculated, the distance from the light source to the point is calculated and if it’s greater than the distance at which the light source is at 1% of it’s peak then it’s ignored.

This gives us a nice lighting effect without wasting time with light sources that are too far away to really do anything anyway.

With these optimizations in place the frame rate with lighting turned on more than doubled. At the location pictured the frame rate is now about 11fps instead of about 4-6fps.

Bunnies Video

Bunnies 2.0 will have an update shortly that adds in video capture. Well, really it’s just saving screenshots at a rate of no more than 24fps. I’m finding that my 1.74Ghz machine can only handle about 17fps which is why the video runs a bit fast. To convert the series of jpgs into a video I use FFmpeg. It’s a free tool that does a lot more than just create MPEG videos out of jpgs.

I’ll be making the Windows binary available on the Bunnies! web-site. Along with the binaries it will also include two BAT files. One creates the video and the other plays it using the FFmpeg player. The video generated also works in Media Player and can be uploaded to YouTube, obviously.

F12 saves a single screenshot in the screenshots folder. F11 starts recording video frames into the movie folder.

I’ll also be putting together a PDF instruction manual for Bunnies. It’s easy enough to download and start playing but I figure it would be a good idea to have a manual that explains everything.

I’m also thinking of reworking the Bunnies! web-site. That also needs a manual and I’d like to make the site easier to use for people who just want to play the game and don’t care to know there’s a huge complex application available.

Bunnies 2.0 is out!

Bunnies 2.0 (7.67MB)

Bunnies 2.0 requires Windows 2000/XP/Vista with the latest updates. A 1.6Ghz processor or faster is recommended. An internet connection is required to play.

The Nazis are at it again. This time they’re breading giant rabbits that will destroy the earth by eating all the green plants we need to generate oxygen and get rid of carbon dioxide. These mutant bunnies multiply every 20 seconds or so. Unless you want to pay the Nazis for oxygen tanks and air conditioning I suggest you kill all the bunnies. You also need to kill all the Nazis and their little dogs, too, to make sure these bunnies never come back.

The bunnies are harmless to humans but will uttery destroy the planet.

Up/Down move you forward and backwards. Left/Right rotate your view. Spacebar shoots. You can hold it down for rapid fire.

There are currently two levels. The first level has a few guards that will fire on you as soon as you start. Shoot them and then go kill the bunnies.

The second level is more complex. Follow the corridors and avoid getting killed by guards, dogs and ss soldiers. Oh yes, and don’t forget to kill the bunnies.

If you fail to kill the bunnies fast enough they will multiply. The game is over if the bunnies reach a population of 100.

Almost a Game

You now have health and enemies can hurt you. For testing purposes however you can’t die.

I think the rules will be that in order to win you must kill all the enemies and all the bunnies. You lose if your health drops to zero or the bunny population reaches 100.

The name “Wolfenbunny” was suggested for this game. I think it could be a good nickname but the intention of this game is not to use Wolf3D sprites. As you can see they are pretty terrible in terms of resolution. I’m just using Wolf3D textures and sprites because they’re available and it allows me to focus on the programming aspect rather than making custom sprites and other graphics.

What’ll I’ll probably end up doing is having multiple graphics packs.

Things to add still before the release are some title screens for winning and losing. Static objects like plants, etc and health packs. I’m still deciding whether or not to add additional weapons but I’m thinking they aren’t necessary.

I’d also like to allow for multiple levels. Currently Bunnies! only allows you to specify a single map. It’d be nice to have a transition screen that takes you to the next map when you beat a level and then have a real winning screen.

It’s Getting Intense

There are now guards, dogs and ss officers that chase you when they can see you. Oh yes, and they attack you. The final step in this little exercise is have the player’s health be affected if they get hit by an enemy.

And you thought Bunnies! was going to be a nice little game where you kill harmless little bunnies. The bunnies are still harmless but they have well armed friends.

Once the game mechanics are all working then it’s time to define what it means to win or lose and then display the appropriate screen when you win or lose.

And once that’s all done and I have a real Wolf3D inspired level there will be a new release of Bunnies!

Sample Font


fonts = new font_class("Arial", 64, 255, 255, 255,5);
fonts.add_texture(working_dir + "/resources/metal.bmp");
fonts.outline_text(0, 0, 0, 10);
fonts.add_texture(working_dir + "/resources/invmetal.bmp",0);

The above code generates an Arial bitmap font that is 64 pixels in size and white. The last number “5″ adds some spacing to the characters. This allows for a border. We add a texture to the font. We then outline the text with a black 10 pixel border. And finally we add a texture to the border. We do this by having the border be color 0 (solid black) and applying the texture only to pixels that are color 0.

If you’re feeling ambitious you could add another border and then texture it again so you have two textured borders. The border is applied outside the font so the second border will border the first border. Border border border.

This will allow for some much better looking fonts.

State of the Game

Bunnies! C# finally has a title screen. One of the things I noticed immediately is that the font was very hard to read over the title image. So I added a new feature to the font class: borders. There are a couple ways to add borders to text. The first attempt was to go over the font bitmap four times: left to right, right to left, top to bottom and bottom to top. When it hit a non-masked pixel it would start plotting solid color pixels until X were placed or it hit a masked pixel. This worked fine for very thin borders of only a pixel or two but thicker borders started to show the limitations. Because the border was inside the font and using four directions caused sharp corners, thick borders got very ugly very fast.

The second attempt takes a more sophisticated approach. One pass is made across the entire image and when a non-masked pixel is found circles are made around the point up to X pixels in radius and any masked pixels found are changed to the border color. This makes the border outside the font and creates a nice rounded border around curved letters like “S”.

The thick black border makes the text much more readable. The border can actually be any color. I may also add a masking method which allows you to specify what color to apply a texture to. So for example a downward gradient can be applied to the font. A border can be made and then an upward gradient could be applied to the border.

One of the big pains of game programming is creating fonts. It’s nice to have as much flexibility as possible to allow for dynamic fonts so you don’t have to manually make a font map which is tedius and time consuming.

PHP Gotcha

The first test map for Bunnies was only 32×32 tiles. The second map is 64×64 and suddenly the Bunnies server is getting errors and causing the Bunnies game to crash. Turns out that PHP is not very good at sockets. If a message is sent and then another message is sent before the first is done sending then PHP throws a warning and appears to not send the second message. So now there’s a half second delay before any message is sent. That will of course need to be optimized. I imagine there’s some way for PHP to tell if a socket is ready to be written to. I could be wrong. I don’t imagine too many game servers are written in PHP.

This error is popping up now because the second map is 4x the size of the first map.

Also, the C# version of Bunnies is updated. It would crash out if a map contained an object that it didn’t have the code for. Now the C# version will just ignore any objects it doesn’t know about. For example the Wolf3D map contains a soldier object. The C# available for download doesn’t have the soldier object. So those soldiers just won’t show up. You’ll still be able to walk around the map.

I will probably release a new C# version when the game aspect is 100% done. Title screens, the ability to win and lose, etc.

The Java version will no longer be supported.

ss_blog_claim=70b9168863fc97c91e6d88b40542a327 ss_blog_claim=70b9168863fc97c91e6d88b40542a327