Monday, September 28, 2009

Potentially Useful Functions (#1 in a series)

The original aim of this blog was for me to impart my knowledge of programming, or for people to point out bugs and problems with my code. Either way, it was supposed to be about programming rather than subliminal advertising for my games.

This post aims to correct that, so to get things started here's two nice small graphics function that someone somewhere may find useful:-

This one rotates an image:-


public static Image rotateImage(Image inputImage, float ang_deg, ImageObserver ob) {
BufferedImage sourceBI = new BufferedImage(inputImage.getWidth(ob), inputImage.getHeight(ob), BufferedImage.TYPE_INT_ARGB);

Graphics2D g = (Graphics2D) sourceBI.getGraphics();
g.drawImage(inputImage, 0, 0, null);

AffineTransform at = new AffineTransform();

// rotate 45 degrees around image center
at.rotate(ang_deg * Math.PI / 180.0, sourceBI.getWidth()/2, sourceBI.getHeight()/2);

// instantiate and apply affine transformation filter
BufferedImageOp bio;
bio = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);

BufferedImage destinationBI = bio.filter(sourceBI, null);

return destinationBI;
}


And this one scales an image

public static Image scaleImage(Image inputImage, int w, int h, ImageObserver ob) {
BufferedImage sourceBI = new BufferedImage(inputImage.getWidth(ob), inputImage.getHeight(ob), BufferedImage.TYPE_INT_ARGB);

Graphics2D g = (Graphics2D) sourceBI.getGraphics();
g.drawImage(inputImage, 0, 0, null);

AffineTransform at = new AffineTransform();

// scale image
float sx = (float)w / (float)inputImage.getWidth(ob);
float sy = (float)h / (float)inputImage.getHeight(ob);
//at.scale(w / inputImage.getWidth(ob), h / inputImage.getHeight(ob));
at.scale(sx, sy);

//at.rotate(45 * Math.PI / 180.0, sourceBI.getWidth()/2, sourceBI.getHeight()/2);

// instantiate and apply affine transformation filter
BufferedImageOp bio;
bio = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);

BufferedImage destinationBI = bio.filter(sourceBI, null);

return destinationBI;
}



Needless to say, if anyone knows a better way to do this, or just tweaks to the above code, please let me know.

Thursday, September 24, 2009

A great idea, or maybe not

"Woah!", I hear you say. "Slow down young Steve. With all this blogging, you're going to burst one of the tubes!". However, I thought I'd mention a great idea I thought I had. See if you can spot the flaw.

I didn't watch Derren Brown pretend to predict the lottery, but his suggestion of using the Wisdom of the Crowds gave me an idea - why not create a website where people can enter their prediction for the numbers. The website will then show the average of everyone's numbers, and people can use those numbers for their actual choices!

Any mathematicians out there may spot the flaw sooner that the rest of us. So let's save me lots of time and programming and all just choose the numbers 24, 24, 24, 24, 24 and 24.

Changed my mind

Instead of Interstellar Forces, I'm going to call it Stellar Forces. Don't you go registering the domain you rascals!

Here's a picture of the website to celebrate the change of name:

Wednesday, September 23, 2009

Announcing: Interstellar Forces

I've finally though of a title! "Interstellar Forces" - mark its name my friend as you will (hopefully) hear a lot more about it in the future.

I've now nailed down the HUD, with its Terminator (as in Schwarzenegger) style text, and the Terminators (as in WH40k) for the models. I might replace these from some of those in UFO:AI though, as I think the licence allows this.

One thing that crossed my mind now that I've got to the stage of a 3D applet is all the other possibilities that have opened up for this code; I could turn it into a 3D RTS like Starcraft III, or write a Diablo clone, or anything my evil mind might think up.

Monday, September 21, 2009

I'm getting that fimbly feeling

There comes a time in a project (especially the more ambitious kinds) where it suddenly seems like you've managed to overcome all the major hurdles, and it actually will be possible to complete the game. This is also usually combined with the stage at which the project starts to take shape and you have something nice to look at. It's a great feeling, and it occurred to me when I produced the screenshot you see here, for my still un-named game.

The only drawback is that it's usually soon after this point that there are no challenges left, and the rest of the programming is boring donkeywork with no payoff until the project is completed. This is usually the stage where I lose interest and move to something else. Not in this case though.

Maybe it's because it's my favourite genre (squad-level turn-based strategy game) and I've got the inspiration of Laser Squad and LSN to look at, and it's going to be multi-player, but I feel like I'm going to see this one through to the end. Then the challenge will be the hardest one yet - getting people to play it!

Wednesday, September 16, 2009

My Magnum Opus

I've been a bit quiet on the blogging front lately, but there's a good reason: I've been working on my latest project, and I'm pretty excited about it.

In a nutshell, it's Laser Squad Nemesis with Laser Squad Mechanics (i.e. properly turn-based rather than We-Go). I hope no-one groans at that, wondering why I'm just copying another game. In my defence, AFAIK there is no open-source equivalent (or even closed-source). The main reason I'm doing it is because my most enjoyable gaming session was playing Laser Squad all day against one of my friends. It's a brilliant game, and never gets boring against a human opponent.

It should be noted that I've never actually played LSN; the only aspect I am copying is the fact that you can request games and play them against other people, while a server keeps track of it all. In addition, it's going to be a 3D applet (as the pre-alpha screenshot with the slightly broken z-order will testify) allowing the player to move their camera anywhere around the map.

So, it will come with it's own web front-end which will allow people to request/join games, take their turn, post messages, update halls of fame etc... Once a game has been accepted, players can equip and deploy their units and then take turns trying to fulfill their mission objectives. Needless to say, there will be several different kinds of missions, each with it's own special units like robots, aliens or plain old space marines (obtaining good 3D models notwithstanding).

This is a pretty ambitious project, incorporating a web server, 3D applets and networking, but if it will produce a game which allows me to play turn-based squad-level strategy games, then it's a task I'm looking forward to. And suggestions for a name for this game are more than welcome!

Wednesday, September 09, 2009

In praise of Google Code

I'm probably blogging a bit early about this as I've only been using it a few days and have yet to come across the world-destroying problem with it that everyone else except me knows about. However, in those few days it's been great to me; all I wanted was somewhere to store my source code and large downloadable zips, and for that it's perfect.

I used to use Sourceforge, but their website seems far too bloated and long-winded to do anything. If you want to create a project, you have to go through approx 7 pages worth of options before finally submitting it, and waiting several days before they "approve it", like they should decide what software is allowed or not. (Again, bear in mind that I've not even logged onto my Sourceforge account for several years now so it may have changed since). If you want to upload a large file, you have to ftp it to their web server, and then select it (from a long list containging everyone else's files) and then fill in some dropdown boxes about it's version or package name or whatever. Jeez, just accept the file with the name I've given it [already]!

Compare this to Google Code - to create a project you give it a name, a short description, a long description and blam - it's there ready for you to use. Want to upload a file? Just select it and upload it and it's there.

At least Sourceforge Smorshforge have taken steps to ease the downloading of files. You used to have to go to the download page, choose the package, choose the file, then choose the mirror, and then wonder if it's doing anything for 5 minutes.

I just wish there was a way to remove my projects from Sourceforge. And don't get me started on the number of projects at "Status: Planning"!

Tuesday, September 08, 2009

Concept Art

Concept art!? Pah, who needs it. It doesn't contribute anything directly to a project and just wastes the artists time.

Or so I used to think. However, I'm now coming round to the idea that it's a great way to engender interest and life into your programming project.

It's very hard to empathise with pages of code or small sprites, but concept art creates the world in which your game exists - in a way that you can actually see, rather than the original vision in your head which slowly fades away or gets distorted as the project fleshes out. The milieu is something that inspires people to continue working on a project long after the initial excitement has faded, and is a constant reminder of your projects original aim.