Programming some stuff
January 21, 2006 on 4:05 am | In Computing |I played some Zuma Deluxe and Atlantis the other day. Zylom/PopCap games are great to play when you’re bored. ![]()
So anyway, being a programmer, I will usually wonder how they achieve certain features in games/applications (and usually I will succeed in thinking of a way).
So while playing Zuma I wondered how they defined levels. After getting bored of Zuma, I decided to try out an easy theory I had on how to make the Zuma levels.

I had made my first AWT/Swing+ application the day before, so I decided to try my theory in Java, so that I would learn more about java and especially writing GUI applications in the process of testing my theory. What was my theory, you ask? Well, just before I tell you, I’ll remind you that it’s a very very plain solution to the ‘problem’. My theory was that they just defined a lot of points (AKA combinations of X and Y coordinates) and the balls would basically move along the track that these points formed.
In the end my test was quite successfull. Basically, you draw the track in the application using the mouse, and then you can play the ‘animation’ which simply means it loops through all the nodes and draws a circle around them. (Of course the example image contains very few nodes which are very spread out, to make it clearer)
Shortly before I finished my application I already knew what my second Zuma Theory was going to be: instead of having nodes every pixel or so, it could also be done with less nodes, and having the code that moves the balls make the balls move in a nice curve.
Anyhow, below are my observations:
- There does not appear to be a simple Image component in Swing. I had to rip one off an example in one of my schoolbooks, Objects First With Java - A practical introduction using BleuJ. Furthermore, there are draw methods for the shapes of all, err… shapes and sizes. However I couldn’t find any methods for drawing a single pixel. Furthermore furthermore, setting the context color to white and drawing a filled rectangle as large as the ImagePanel component, resulted in a the component being filled with black. Suffice to say, drawing stuff was the biggest challenge.
- Eclipse SDK really is a very good IDE. I mainly had experience with it’s code editor (which rocks), but while writing my little program I noticed some other nice features, features of which I had already figured that they’d exist, but not how easy they were to use. For example, to respond to the mouse movements and clicks, I implemented the
MouseListenerandMouseMotionListenerinterfaces. Instead of looking up which methods to implement, I could just add the interface to the ‘implements clause’ - as I’ve dubbed it - and then go toSource->Override/Implement Methods...There you can select which interfaces to implement. Not only this, but it apparently also detects which interfaces or even which individual methods of interfaces are not yet implemented, and automatically checks their checkboxes. Long story short, it takes exactly three clicks to implement an interface and all of it’s methods. - I spent around 30 minutes looking at my code, trying to find out why my
ImagePanelhad disappeared even though I hadn’t edited any of the GUI code apart from adding another button.
In the end the conclusion was that it is not wise to have aBorderLayoutlayout manager with some components in it and to add a label to thecontentPanewithout specifying where in theBorderLayoutit should appear. Apparently the default isBorderLayout.CENTER, which is where myImagePanelwas. In the process of adding the extra button, I also created aJPanelwith aFlowLayout, and placed the buttons in said panel. In the refactoring process I also accidentally removed theBorderPanel.NORTHparameter from the label’scontentPane.Add();call. Because the label was still being added to theBorderPanelhowever, it basically ‘overdrew’ theImagePanel. - Mistaking
drawRectangle(int x, int y, int width, int height);fordrawRectangle(int x1, int y1, int x2, int y2);is the recipe for an unexpected but cool and funny effect. When dragging the from the top-left to the bottom-right, for instance, you create a ‘tunnel’ of rectangles. This also took me some time to figure out. I blame Eclipse in this case. It’s Code Completion feature does not actually saywidthandheightbut it’ll instead name all the argumentsarg0,arg1,arg2, etc… It doesn’t hurt to look at the Java API, even when you have code completion.
Now, I’m sure there are only a few people out there who read my blog and understood a word of what I just wrote, but I felt like blogging this. One of the reasons for it was that the Planet TT-Forums RSS feed is getting smaller and smaller because only 1 person blogged anything during the last 48 hours.
6 Comments »
RSS feed for comments on this post. TrackBack URI
Leave a comment
Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds.
Valid XHTML and CSS. ^Top^

Never fear, I shall be posting a blog soon!
I’d write more just now in this comment, but I’m very hungry. Foooood…
Comment by Owen Rudge — January 21, 2006 #
Damn, now you’ve written one I haven’t got the time to read it (but I will later)
Comment by Martin — January 21, 2006 #
OK, I’ve now read it and I feel dazed :O
As for blogs, I’ll be doing one soon as well.
Comment by Martin — January 21, 2006 #
I figured as much.

When I was writing it I knew the blog was going to be rather vague
Comment by GoneWacko — January 21, 2006 #
This was long, confusing and lacking any trace of the links containing the pornographic material you promised me.
Comment by Kopa — January 22, 2006 #
*This text…
Comment by Kopa — January 22, 2006 #