Sunday 29 April 2012

Gotcha!

OK, so a little bit of coding before bed. Now the harpoon responds appropriately when it has caught a fish, retracting at a fairly nippy speed back to the boat, carrying the fish.

The main challenge here was getting the harpoon and fish to communicate with each other. They're separate objects which don't share scope. I solved it by making the harpoon do all the work. It detects the fish, tells the fish it has been caught, then tells it to track it all the way back. It even tells the fish when they have reached the boat, so the fish knows when to disappear. Stupid fish.


Updated Source Code (wave9.py)

Saturday 28 April 2012

Fishing Game: Now with fish.

So, after a burst of programming at 5am this morning, I have managed to make my boat's harpoon move as it should, as well as adding fish to the game.

As this is a learning experience, I have tried yet another way of handling graphics for the fish. Each fish will be animated, with at least 2 frames of animation. I could do this by storing each frame of animation separately (called fish1.bmp, fish2.bmp etc), but I have decided to organise them using sprite sheets. This is a large image containing several different frames of the same picture. When you want to use it, you tell the program to grab the appropriate section of the larger image.

You might not be able to tell, but the
two frames are slightly different.
I am hoping that this will also cut down on disk accessing, and may be more efficient.

So, I have created a class of fish which is quite adaptable. It should enable me to have lots of different fish which have different appearances, sizes, speeds, numbers of frames and score values. I can set my program to generate these fish as frequently as I wish, so later levels can be teeming with targets. Later levels will include fish which lose you points (such as endangered species) or damage your boat, (like an electric eel or a shark).

Beginners' harpoons will only be able to catch one fish before returning, but later upgrades will let you plough through a whole load of fish in one go!

Updated source files



Tuesday 24 April 2012

Give me your details!

I just made a change to the music database. For what seems like for ever, the password reminder function has not been working. I know this, because I get an alert every time someone tries to log in unsuccessfully, and I see the same people trying to log into the system time and time again with the wrong passwords. I sometimes want to shout "it's fluffykitten38! Don't you remember?!"

I used to have access to a file with all my users' school email addresses, so entering them en masse was easy. I don't get that any more, so most users do not have an address in the system, which is fine until they need a password reminder. So I decided to persuade them to give me an address.

So now, when you log in, you'll be asked to enter a valid address. And if you don't enter one, you'll be prompted to every time. It might be annoying at first, but at least it will solve some problems.

Monday 23 April 2012

Fishing game: harpoon added

Today I limited the movement of the harpoon turret to 45 degrees left and right, and created a basic harpoon. When you press space, this harpoon appears at the barrel of the gun and rotates to an appropriate angle. It doesn't move yet.

Thinking ahead, I could perhaps draw the chain from the harpoon to the boat as a simple line. That way I could draw it on the fly as it extends, re-drawing the line in each frame. This would allow the boat to continue bobbing up and down. The alternative is to freeze the boat in place until the harpoon has finished firing. This is what happens at the moment (the boat stops moving when a firing action is happening). I'll have to wait and see what works best.

Updated files

Fun with LEDs

A couple of weeks ago we went to the Bradford Media Museum to look at their new computer exhibition (good, but too small). While there, I spotted a cool rotating LED light thing (see video). I found it quite mesmerising, so I had a look at the circuit-board to see how it was made. I spotted that it was manufactured by picprojects.org, a group who encourage people to play around with little programmable computer chips called PIC microcontrollers.

The appeal of these chips is that they are very cheap, and seem to be quite versatile. You can use them for building little custom-made devices that flash lights, read sensors etc.

The downside is that they're not for beginners. You need to be handy with a soldering iron and, if you want to get the chip to do anything other than what it was pre-programmed to do, you need to get your hands dirty with some programming. From what I have seen, it's not easy programming either. These chips don't have a high-level language built in, so you're looking at something akin to Assembly language if you want to write your own programs.

That doesn't scare me though. I don't know much assembly yet, but I'm willing to learn. For starters, I wanted to get my hands on a little beginners kit and try it out, so I chose the LED mood board kit.

This thing has 9 LEDs and a bunch of resistors and capacitors, all of which need to be soldered together, and a pre-programmed PIC chip. Fix it all up, plug it in and away it goes, cycling colours through a bunch of sequences. You can write your own programs with an adaptor kit (to attach it to your PC), but I haven't done that yet.
Louis loves the light on its own, even as a bare circuit board. It's really bright, and lights up the room.

Hopefully I'll get around to programming it and then move onto the 5x5 monster, but not for a little while.

Sunday 22 April 2012

Fishing game: early stages

I'm playing around with Python, which seems to be a nice programming language. It's free to download and there are versions for all sorts of computers including PC, Mac and Linux. It is fairly lenient on syntax, with no silly semi-colons at the end of each line. You don't have to round off FOR loops or IF conditions with an EndFor or a curly bracket. It also seems to run fairly quickly and you can do lots of interesting things with it. People have written extensions to add extra functions, so it can be adapted to a huge variety of uses.

I have been working with a book called "Python Programming For The Absolute Beginner", which has covered the basics well. I'm now ready to try something a bit more challenging, so I have started a little game. This will be a "fishing" game, where you have to catch fish using a harpoon.

So far I have animated the water and created a boat which can be moved left and right using keys. There is a harpoon gun on the boat which can be rotated, and the boat bobs up and down as the waves move past.

I'll be creating fish which swim past under the boat, and you have to aim your harpoon at the fish. Different fish will give more points, and there will be fish to avoid such as sharks and electric eels. You'll be able to sell your catch to get better equipment such as a better boat, faster harpoon, stun grenade etc.

I've been getting used to object-oriented programming, which is quite a new concept for me. It's a way of organising your program by splitting it up into chunks which manage themselves. So, there's an object called Boat which has code to make it move, and bob up and down. Another object is the gun, and it need to contain code which allows it to rotate and follow the boat around.

Drawing the screen in Python takes some getting used to. There's a plug-in module called Pygame which handles the graphics, but you need to do quite a bit to get it working. In Small Basic you just have to say "here's a sprite", but in Python you have to say: "Create a sprite object. Open an image. Apply the image to the surface of the sprite. Copy the sprite's surface onto the screen's surface. Tell the screen to update itself."

You can also ignore sprites altogether and just draw the images directly onto the screen myself. In the example so far I have done both. The waves are drawn onto the screen manually, as is the gunbarrel. The boat and the gun-base are Sprites. I don't know which one I prefer. I don't even know why someone would do one rather than the other. If you know, please leave a comment.



So far, I like the way it's moving. The graphics are a touch ugly. Python doesn't seem to anti-alias, so the edges are quite rough. I'll work on tarting up the bitmaps later when I have it working properly.

Image resources are here.
Download the source code here.