Friday, 5 June 2015

Game #6, everything but the bad guys

Well, it's now possible to play JetPac but it's rather easy, because there aren't any bad guys yet. But you can construct the rockets and refuel them and so on.

I made a mistake though. This is using Physics for the Astronaut flight and the dropping of things, and I probably shouldn't have, should have done it in Custom Movement or something.

You can see a consequence in the picture. The astronaut is riding down on the fuel cell, because, well, that's what the Physics engine wants. It does make logical sense. Likewise you can do odd things like carry fuel cells about on your head and so on. Still, that's the whole point of this exercise, learning lessons.

Thursday, 4 June 2015

Game#6 : Jetpac Moving only

Not done a lot on Jetpac today, though I was lucky enough to find someone had already ripped the Sprites out which made it much easier. I can't draw at all. I mean, really bad. The Galaxians and Asteroids gfx come from images of the originals. So does this. I have found that 3D modelling with something like Blender helps.

At the moment it can just move about and fire, but there's nothing to hit or collect as yet.

I actually visited ACG (the home of Ultimate) once, when they were in Ashby de la Zouch (in the Midlands) and I was at Keele University. I was trying to get hold of a copy of Alien 8 for the BBC, very difficult, so I went to the source and asked them for a copy.

Amazingly it worked. Perhaps they thought I was mad, so they'd better humour me, I don't know. I also used the same trick with Acornsoft in Wellingborough to get a copy of "Revs" by Geoff Crammond, similarly "unavailable".


Game #5 : Asteroids

Asteroids is now up, in both code and runnable form here.

Note that it is now on github in .caproj format, not as a .capx. I had a problem with a C2 bug I cannot reproduce occasionally losing image files.


As you can see this has two layouts, there is a high score table implemented with localstorage and a main screen.

The localstorage implementation is fairly straightforward ; it checks for the presence of the key (in the constant ASTEROID_KEY) and if present, loads it into the array of high scores, if not it loads it with defaults (incidentally the name is always AAA). It then adds the score returned (initially this is -1), sorts the array and reverses it (highest first) and displays it, writing it back to localstorage at the same time.

In the main events, a score of -1 is indicative of a new game, and events 1 + 2 do that reset. Events 3 to 6 create asteroids and set values like speedScalar (how fast it's going), update the score and so on (it reloads the layout to start a new level).

Asteroids are wrapped bullets, and there is only one object which is scaled to make the three types. This is done using currentSize and requiredSize - if you look at 5 it sets current to -1 and required to 1. Going down for a minute to event 10, if it finds these values to be different, it resizes, sets speed, rotate speed  and animation of the asteroid. So the asteroid can be automatically resized just by setting "requiredSize" (currentSize is initially set to -1 in case of a previous value).

Events 7-9 are over complicated because I didn't realise you could PickNearest - this works out all the distances the asteroids are from the player if the player is "hiding" - in Asteroids there is a delay when the player appears so it doesn't appear on top of an asteroid, and enables the player if they are all far enough away.

Events 11 through 15 handle the Asteroid moving - rotation, thrust and in 15 the natural friction slowing it down. Event 16 handles spawning of bullets, allowing a maximum of four, and enforcing a delay time between the bullets (the lastFireTime variable). This is all done with the help of CustomMovement.

Events 17 to 23 are slightly tricky. Initially it detects a collision between a bullet and an asteroid, uses hitAsteroid to make it unique (could have used Pick instance here). However it is slightly tricky because when you hit the non-smallest asteroids they split into two. What I do is to shrink the asteroid hit, and send it off in a new direction, and create another one (in 21) and in 24, when it finds this newly created asteroid (currentSize is -1) it fills in the details saved in the variables about how big it is and what direction it is going in.

Event 22 just destroys the smallest (size = 3) asteroid , and 23 forces a restart of the layout with the next level if all the asteroids are dead.

Event 25 onwards drives the UFO - there are two times for this timer, how long it takes the first time, and how long it takes subsequent times. If it has timed out, and there isn't one already, it creats a UFO, with a 50/50 chance of a large or small one (small ones are quicker and fire accurately). The UFO firing is done in 28, and the bullet is initially aimed at the player, 29 checks the instance variable in the UFO to see if it is a big one, and if it is randomises that angle.

Events 30 through 33 check for collisions with the player (hitting a UFO, UFO Bullet or Asteroid) and then if this has happened it restarts, and handles the restart, displaying the level number (35)or Game Over 36, when that Game Over fades out in 37 the game goes back to the high score table.

Finally 38 and 39 update the score and lives display in a function.

This isn't bad but it is a bit messy. I've winged it to date, from now on (Game #6 is Jetpac, a Sinclair Spectrum game) a little more consideration will go into the design, I shall use event groups and so on.

Wednesday, 3 June 2015

Preview of Game#5 : Asteroids

A preview of Game # 5 which is Asteroids. The game itself is pretty much done and dusted, though I may add something resembling a proper high score table. At the moment it's like Galaxians, it just has one layout which plays the whole game.

No code or game here, tomorrow, maybe ;-)

Game#4 : Galaxians

I'm back. I've fixed the bug (see later) and I've also uploaded the new .capx to the github account.

As an additional (err....) treat, I've uploaded a built version of the game via ftp, so you can now play it by clicking on this link, keyboards only :)

As this is a bit longer, I'll talk through it bit by bit.

The first bit is relatively simple, it creates the slowly scrolling star backgrounds, which are stars with a setColor effect, so they ripple through colours. They are set to wrap so they keep going round and round.

This is just a single layout, for simplicity, so Event 4 sets everything up on startup and disables firing.

Event 5 enables firing when the "Get Ready" has faded out.

Events 6 through 8 make the galaxian "fleet" move left to right, flipping whenever they hit the edge (nearly) hence the X < 16 or X > LayoutWidth-16

The next section deals with the swooping down bit, where aliens detach from the main fleet. This is done using a timer.(9 onwards). I didn't realise here that timers could be random, so you could have a repeating timer with a random timeout rather than what I do here, fire it once and keep firing it when it fires :)

LaunchDirection here sets whether it attacks left (-1) or right (1) as the ships attack diagonally. 11 picks a ship that attacks.

There is a trick ; as you can see from the picture, aliens can also attack in groups of up to four. To make a whole group of four attack at once, the LaunchCollider is used - this is created and looks like an upside down yellow "T". Collision with this, in 14, sets the "shouldLaunchAttack" flag for each of the ships the LaunchCollider covers.

Event 15 checks to see if any ships have their "shouldLaunchAttack" flag set, and if so they are put into "isAttacking" mode (e.g. they will come down the screen). The bullet is disabled (the bullet is used to do the left/right movement) and the attack direction is stored. Finally it makes a screechy attacking noise.

The attacking is continued in 16 and 17, where it moves according to the attack direction and the speed scalar (how fast the game is running) and it reverses direction if it goes off either edge.

Event 18 is a bit of a cheat. In real Galaxians, if an attacker drops off the bottom, it comes back on the top, dropping down into position. Here, I've faded it into the correct position and set the instance variables/bullet enabling accordingly.

Ah, now how does it know where to go. Well this is what the marker is for. It is a red X at the top left of the "alien pack". The aliens position relative to this is stored in startX and startY (in Event 8) and even if the whole alien pack moves, this relative position to the red "X" (you can see it in the CapX) tells it where to go back to.

This (and the LaunchCollider) are the two tricks that make Galaxians operate. The use of the 'shouldLaunchAttack' instance variable is quite useful too, as it allows more than one action to cause an attack - it can be done individually on the random choice, or through collision with the LaunchCollider.

Beyond that it is fairly straightforwards. Players and Aliens can fire bullets (19-32) and if the player is hit, then he loses a life and the game is over if there are no lives left.

The bug was in Events 26 and 27. Originally the Condition 26 (hitting ships or enemy bullet) fired Event 28 (reduce lives). If the player got hit by more than one thing at the same time, more than one life was lost - it was possible to lose all three lives in the one 'hit'. Using the "playerHit" global works round this - it only occurs once. I was going to use Pick 0th Instance but don't think this works with the "or"

It still has faults ; the speed adjustment stuff doesn't work very well and doesn't reset properly :) Really, I need to move all this into a function, it gets rather fast rather fast.

Sunday, 31 May 2015

Moved to GitHub

Rather than FTPing everything up, I've created a github for the files on this blog, which is in the links bar on the right and here

Game #3 : Breakout (and a preview)

Game number three is also quite uninteresting. It's probably less interesting than the previous game to be honest, and I didn't really learn anything very much from doing it.

I'm off for a couple of days, so to make things interesting for my readers (note the optimism in the plural) I've also uploaded the nearly finished Game number 4, Galaxians, a screenshot of which will be on this page somewhere dependent on the vagaries of HTML.

I am quite pleased with this one and it does have some interesting features and one huge cop out that I will write about when I get back. Not now, it's a bit late. I've been out all day.

There's also a bug in it which I have only just realised, which isn't terribly terrible but I must fix. I might do this tomorrow sometime, depends :)

A free Opal Fruit to anyone who spots the bug. Two to anyone who diagnoses why it behaves like that.