Now with Collision Detection

This post is one in a series that is cross-posted from the Ludum Dare competition that took place August 8-10, to make a game in just 48 hours.

Ended up on the phone for about an hour, and went to the grocery store for a few small things. Came back and made homemade salsa.

The game is coming along. The lines that make up the tower all behave like walls, and the staircases finally behave like staircases! Meaning that you can use them to get between floors. This is great progress, and I’d be really happy if only I didn’t know all the hacky stuff that’s going on behind the scenes. I’m actually thinking about writing some unit tests for the collision and game logic code, since it was a really touch and go process to get the stairs working correctly.

My dog is dying for some attention, so we’re going for a walk, and I’m going to consider what to do next. The easiest thing would be to add items to pick up (keys for locked doors, I’m thinking). But the most technically difficult would be enemies patrolling the floors, since it’s entirely turn based at this point (I only draw when a key is pressed). So I would have to add an animation thread to get something moving on its own.

Comments

Joining the Fray

This post is one in a series that is cross-posted from the Ludum Dare competition that took place August 8-10, to make a game in just 48 hours.

I, too, am a first timer. I have the place to myself (and my dog) and a grocery order delivery scheduled for Saturday afternoon. I’m as ready as I’ll ever be.

Comments

Ludum Dare 48 hour game dev competition

Ludum Dare is coming up, August 8 – 10. I’ve poked around the entries for the competition before, and once I lurked on irc while a compo was in progress. But this will be the first year I’m participating. My wife is out of town and taking her dog, so I will be left with the other dog, and a house to keep up. But other than a good long walk and a workout on Saturday, I’ll be able to devote most of my time to the competition.

I am going to go with out of the box Java, using Java 2D for graphics. That will let me focus on gameplay and design rather than battling with the graphics. The themes to vote on aren’t up yet, but I quite like the “Meanwhile…” theme. I’ll be spending Friday before the compo cleaning the house, installing time lapse software, preparing food and cleaning up my desktop (physically and virtually). Oh and working the day job, of course.

Comments

Code Spelunking

Alex Miller writes about code spelunking techniques for when you’re digesting someone else’s code. He offers some good advice, particularly for tracking down call hierarchies and implementors (and some useful Eclipse shortcuts). What was missing, I thought, was the easiest one of all:

Draw a picture.

He did show a project dependency graph, but I find it’s really best to draw a simple picture, not even in UML, just in whatever comes naturally to you. On this picture, keep the real names of the classes, but then give them useful names, or small summaries, and describe their general responsibilities.

Use this diagram as your map, and don’t complete it for perfectionism, but only follow interesting paths. Invariably you’ll end up pruning paths as it’s clear that it leads to property holders, or utility functions (which is part of classifying the objects, as Alex writes) in which you’re not interested. But in particular, when you draw your own diagram, you have a bread crumb trail to look back on, so when the names don’t make sense, or you can’t remember the big picture, you’ve got your notes of what you’ve already seen.

Besides, if you’re drawing a picture, then the next developer who comes along will need to draw a picture too. So you might be able to do a formal diagram and put it into the project, helping others pick up on the architecture that much faster.

Comments

Java 3D vs. Java OpenGL

I have been experimenting with Java3D and JOGL as 3D libraries. Both are mature, and perfectly acceptable for anything I would be doing with them.

Java OpenGL uses JNI (meaning the underlying system must support OpenGL), and it doesn’t use Java3D’s scene graph approach. With Java 6, Java2D and JOGL can work closer, resulting in swoopy features like a Swing button with a 3D icon image.

Java3D was meant to be a Java wrapper for DirectX and OpenGL. It, too, uses JNI, and it seems there is no sophisticated 3D graphics library that doesn’t. But, as Alexander Schunk writes, JOGL makes Java3D somewhat ineffective as a unifying library among the 3D graphics technologies.

So, I don’t know which I will go with. There are some fantastic books on OpenGL, and it’s certainly a useful skill set. It’s too bad you can’t easily port things over from OpenGL to the scene graph API of Java3D. They’re such different approaches, but that’s why they’re two distinct projects.

Comments

Database Programming Simplified

Ah hah! The solution to my database woes was the PreparedStatement.

The only serious database-intensive application I’ve written used PHP’s Pear DB package. And PHP was just a lot nicer about typing and variable substitution, so I found myself doing less of the quote-escaping and type checking necessary in Java. So it is with great relief that I discovered prepared statements.

It works just like a regular statement, in that you create it off the connection:
PreparedStatement prepstmt = conn.prepareStatement("SELECT * FROM ITEMS WHERE NAME=?");
But, as you can see, the SQL string substitutes values with question marks. The fantastic thing about it is that this statement is not typed. By this I mean that you can put an integer or a string into the statement without changing the SQL. This cleans up a lot of the messiness of the SQL requirement of having single quotes surround strings. And because Java String concatenation is ugliest for short strings, it cleans up your SQL statements several fold, in my opinion.

To set it, all you have to do it:

prepstmt.setString(1, "myname");
ResultSet rs = prepstmt.executeQuery();

So here’s a before:

int rows = stmt.executeUpdate(”INSERT INTO “+
“ConfigData (configkey, configname, “+
“configdate) VALUES (”+configKey+
“, ‘”+configname+”‘, “+configdate+”)”);

And the after:

String sql = "INSERT INTO ConfigData(configkey, configname, configdate) VALUES(?, ?, ?)";
... //Create the prepared statement object
prepStmt.setInt(1, configkey);
prepStmt.setName(2, configname);
prepStmt.setDate(3, configdate);

Even without the performance gains of re-using these PreparedStatements, the cleaner String notation is a great solution for queries with several variables.

Comments