Wednesday, February 27, 2008

Of course!

Got my code semi-running after yesterday, unfortunately the character immediately falls through the floor, even though it is detecting he hits the floor! It seems in my rush to create most of the states for the character, I forgot one of the most important - where he's standing still! So at the moment after he's created he never hit tests at all, so thats on my list today!

Since this code is all written and just needs bug testing now, the character should be moving properly by the end of today, a couple of days later than I'd hoped but this is one of the last major milestones before the game begins to look like I intended!

Once the character moves and the second half of the game is in, I can concentrate on performance indicators, start, finish and loading screens, and finally, making the actual level for the project and improving the graphics. After that, its simply a task of adding more features to the game, which will be a particularly interesting part!

Tuesday, February 26, 2008

Don't code too much at once

Have just added a LOT of code to my game today, but can't test it yet! Need to write another four functions before I'll be able to test it, and then there will be a lot of debugging I expect. Nonetheless I should have a working version by mid-afternoon tomorrow ready to post on here, and I can then add the second half of the game in finally!

I really hope the code I've spent so much time on today doesn't have many bugs..

Sunday, February 24, 2008

Next on the list..

Tomorrow my target is to get the character moving realistically once the secondary hit test function works correctly. After this I'll be adding the second half of the game in.. which will hopefully also be done tomorrow.

For those of you who happen to be reading this that aren't on my course, watch this space over the next few days as the game is really going to start coming together. As I haven't yet explained to anyone outside the course what my game concept is, hopefully the next few posts will be very interesting to some of you!

Next on the list after this game is completed (well technically it's just a single level rather than a full game) is to create my own website which is long overdue. Once it is complete, this blog will be moved there and I will be creating a secondary blog which will include only highlights from this and hopefully more interesting posts.

Following this is finally getting the 3dBuzz work done so come the new term of University I'll be making some awesome characters. This part may be delayed if the new project is due shortly after Easter, but we shall see!

More, more, more!

I've been working on the character hit tests today, now that the new hit test in the previous post works perfectly, I've been adding the secondary hit test to the character. Unfortunately, like all things seem to be with coding this game, adding this functionality negates some of my other code which will henceforth be useless.

This will however enable far more realistic jumping and collision reaction, and furthermore will allow me to move the character up slopes realistically, so the advantages are clear. Just the fact that when he jumps and hits a ceiling he'll start to fall down is nice in itself, and the knowledge that the code I'm writing will be re-usable to the extent that I can EASILY make another platform game afterwards is inspiring to say the least, and in itself, the only reason I am continuing down this difficult road.

This game: Many, many hours of coding to get it working as I want
Next platform game I make: A few days of graphical changes, a bit of game-specific AI coding/minor tweaks and constructing the levels!

Saturday, February 23, 2008

hitTest changes

Have recently mostly recoded my game to improve the hit-testing - I had planned to do this for a short while as the speed increase provided is around 100%!!

The reason for this is, before I was creating an entire world-size bitmap to perform hit-tests against with the character, meaning it would create a 21x16 tile bitmap in memory - so thats 336 tiles it had to copy before even doing the hit test. It would then have to redo this after the hit-test to refresh the screen in the correct location.

In the new version, it creates a mini-bitmap of the tiles surrounding the characters centre point and does the hit-tests on this instead, so instead of 336 tiles being loaded into a large bitmap, only 9 tiles are loaded into a much smaller bitmap.

This of course will have an impact on not only how fast the screen will redraw each frame, but also the hit tests will use far less calculations since it only needs to test the non-transparent pixels in the 3x3 tile mini bitmap, so speed increases all round!

Not only that, but I also changed how the array is created to a way that makes it around 90% quicker to access after creation (something to do with Flash' optimization code) than how I was using it, so overall now the game should be running MUCH faster!

Here is the game now, with the mini bitmap it is performing the hit-tests against in the top left corner (move the character around and you'll see!)

Wednesday, February 20, 2008

Actionscript 3: Learning more

I'm taking a break from coding the game today in order to learn Actionscript 3 a lot better.

Most importantly I want to be able to split my code up into a few seperate actionscript files so it's easier to see whats what and edit individual parts seperately (hopefully) without messing up anything else.

Other than this, I think its about time I learnt more about Actionscript 3. After all it's hugely different and the many things I've learnt during this project so far are only lightly touching upon the surface of its true power.

I figure that one day spent today will save me many more hours over the coming 2 weeks before the deadline, meaning the game could be even better!

Even if it doesn't save me that much time, it is still a worthwhile investment as when I am creating my portfolio page over the Easter holidays of uni, I will be able to use the improved programming knowledge to aid my (re-)learning of PHP/mySQL which I haven't used for a long time, but fully intend to use to create a back-end for me to update the site easily.

Tuesday, February 19, 2008

Wasted time but light on the horizon

I spent most of yesterday (well, about 14 hours) trying to get my character moving nicely but as it reached the last 30 mins, I realised that I can't tell how the character is hitting things at the moment; I can't differentiate at the moment whether the character is hitting something with his head or his feet.

This causes undesirable behaviour such as if he jumps into another object he can jump higher because he's hit something which resets the jump counter.

I've thought about various ways to solve this and this is what I've come up with (in order of thought):

1. Use various points around the character and if the whole character hits something, perform a hittest on those objects and see which ones are colliding at the same point as the character is.



Advantages: Gives some indication of which part of character is colliding.

Disadvantages: if the character hits a spike or anything in the middle of himself, only the collision on the character will register and this may still cause undesirable effects.


2.
Use four half-character hit tests to determine what quadrant he's hit. This is basically the same as above but with bigger hit test areas.



Advantages: Won't miss any spikes and a general area where he's been hit will always be generated.

Disadvantages: Still a lot of inaccuracy in the detection. This may be absolutely fine however.


3. Find the four tiles surrounding the character and put ONLY these into a bitmap. This will hugely improve the speed of the game running as it only has to load 4 tiles each frame for hit testing instead of 300 as it does currently.

Using these four tiles id numbers, identify them as slopes or solid ground etc, and use calculations to figure out where the character should be based on that.



Advantages: Very accurate and covers how the character should be angled upon the slope immediately.

Disadvantages: Will take a lot of coding and may not be possible in the scope of this game.


4. Again use the four tiles around the character, but this time identifying them as slopes or uneven/flat ground. Instead of calculating where the character will have to be when he lands, find out where his hands and feet need to be seperately and change his animation accordingly.



Advantages: Most realistic animation possible. [Excuse the incredibly bad paint image, didn't have much time!]

Disadvantages: Actually animating the character may be difficult. This may likely by alleviated by the fact the game is solely black and white.


I'm thinking at the moment that the most likely choices will be either number four or numbers 2 and 3 combined.

I've also been thinking about using verlet integration for the game, but right now I've got no idea how to understand what it is since American mathematics is written using so many symbols it means nothing to me!

Monday, February 18, 2008

Troubles with movement..

Been having a lot of trouble getting the character moving today, but I've just had a moment of potential hope as I've just found an excellent site on hitTests which may very well help me hugely with this stage of the programming.

Here's the tutorial:

Link

The end result is very close to what I want for the character. Obviously since my code is different I'll have to modify it a bit but its a great start! Not sure if it's AS3 but hopefully it is!

He jumps, he scores!

Mr Block has moved to a different world, and is now affected by gravity.

It's not all bad for him though, he's learnt how to jump!

Here he is for anyone who wants to see him jumping:

Code speed explanation!

The code isn't actually impossibly fast, in fact, it could be almost twice as fast (so I will be changing it shortly!)

It turns out, flash optimizes its arrays if they contain only integers, which my code happened to, but since I was using split to create the arrays, I can actually nearly double the speed the arrays are accessed, as well as speeding the build time by around 20% by changing from using split to either push or fixed length arrays!

So code will soon be even faster!

Sunday, February 17, 2008

Mr Block is suddenly stopped on his rampage

I've added a basic testing character in now and he moves around - not properly yet, but he moves! I'm about to fix the most obvious problem with it at the moment - when he hits any objects side, he gets stuck in the object.

This is caused by my code creating the moved world after the character is moved, so its just a bit of rearranging needed.

Soon he will rule the world! Muahaha!

Saturday, February 16, 2008

My code runs impossibly fast!?!?

I recently posted my code so far on the actionscript.org forums in case anyone else attempting to make a tile-based game like this may find it useful.

It seems however after a post today by friendly forumite "sgartner" that my code shouldn't possibly be able to run as fast as it is! Here's the post:

http://www.actionscript.org/forums/showthread.php3?t=160386

So basically, because I happened to make my code with the split() function it seems to have made the arrays faster to access than if I had created them in any other way!

I hope that I've discovered some unbelievable flaw in actionscript that will make peoples code run faster, and that it's not just a (unlikely) coding error in the changed examples by sgartner!

This should turn out to be extremely interesting, and I want to find out if it will have the same effect with single, linear arrays or if it is limited to multi-dimensional arrays as I have used.

Friday, February 15, 2008

Physics? Meh..

OK, so I've sadly missed a couple of days where I could have worked as I took a temporary job for 2 days (and valentines day - watching jumper was a must!) but during that time I've been thinking of what will be the easiest way to get the character moving.

The most efficient way I can think of doing it is by implementing a rudimentary physics engine (well just gravity really for now) to do it.

I figure this will also enable me to easily add realistic jumping into it as if there is a force constantly pulling down on the character, all I need to do to jump is oppose that force and put a decay on the opposing force over time. Assuming the decay is calculated properly (I'm thinking exponentially right now, but I'm not too sure really!) then it should automatically give the character a jump that slows at the top and speeds up on the way down, like real life!

So my next task now is to get the character in the game and, hopefully, moving!

Watch this space..

Wednesday, February 13, 2008

Flash keyPolling

Just found this keyPoll class which tests if a key is down or up in flash. My code currently does this but it could be better!

This class seems interesting and I might see if I can modify parts to improve my code..

Here's a link if anyones interested in taking a look:

FlashGameCode.net

They also have a few other classes and even code for a particle system in flash! Definitely worth a look.

Here's a few other sites which other's may find useful:

8BitRocket: This guy has some really good tutorials on actionscript 3 game development including pixel level collision detection (lots of you will need this!) and other things.

Fisix Engine: A physics engine in flash! Looks very interesting!

Papervision 3d: A 3d rendering engine in flash - import your 3d models and animate them! Actionscript 3 has revolutionised flash development..

WOW 3D Physics Engine: A 3D physics engine in flash! Trumps all the others but isn't complete yet - still is going to be amazing when done - think of the games and things you'll soon be able to create in flash! I can't wait!

Hope someone finds these as interesting as I did!

5 minutes of coding later..

5 minutes of coding done after the previous post (plus a shower and breakfast!) and I've fixed the most important bugs in the new scrolling screen.

Now it scrolls smoothly and doesn't have any black gaps on the sides, and also doesn't jump when it gets to the final rows/final columns tile, so overall is FAR better from just a couple of minutes changing where a few things were.

There is one small bug left to fix - when you get to the last row/column, it tries to load a nonexistant tile from the next row/column (which is causing it to pause until you get away from that row/column) - just need a quick bit of code to fix that, but I know exactly what to do so this part (should) be simple :)

Edit: Just fixed it and updated the link - there is now no pauses at all when navigating the map - works perfectly at this stage!

Here's the better scrolling version:



Next steps:

1. Update comments/reorganise code so its cleaner and easier to read.

2. Add the character and start getting him moving!

I'm looking forward to this step :D

IT'S ALIVE!!!

Finally got it moving and refreshing the screen! Spent about 6 hours yesterday including help from David Downes and Danny Kaye trying to fix a bug in the code, not figuring it out at all - we thought of various things it could have been and ended up with the conclusion that one line was only working the first time it was run.

I then found out the line should have worked which made little sense at the time, as we'd spent ages trying to clear the bitmap in case it needed to be cleared before running a copyPixels command again.

So ended up going home with still no idea, had a few further ideas such as parameters and things to check, but somehow I still missed the obvious answer.

A further post on flash forums, posting all my code and other files so far, got a response from a really helpful person called 5TonsOfFlax, who told me what I should have realised way before, I wasn't resetting one variable, which told it where to paste the next tile using copypixels.

What this means is, after the first time it ran through, which would work fine, it would then be copying pixels and working perfectly, but it was copying to x values greater than the screen width so we never saw it! Bah!

The only thing that needed adding to fix the problem was this line:

myX = 0;

Yep, thats right, six or seven hours of painstaking troubleshooting, is fixed with 6 characters of code.

So now, in all its glory, is the shiny new version that MOVES!
(Z = LEFT, X = RIGHT, / = DOWN, ' = UP)

Tuesday, February 12, 2008

Map displayed from XML

Finally got it to work by grabbing the tiles from the XML file, now working from a very basic 8-tile set and a 100x20tile map created in Mappy. Here's how it looks now:



The code will have to be more complex later on as I'll need to load parts of the top half and parts of the bottom half of the map seperately, so should be interesting trying to get it to work!

Monday, February 11, 2008

Ready to rumble!

Finally got through bringing the XML stuff into flash, now the seemingly simpler task of rendering bitmaps and enabling some keyboard functionality.. I'll leave that for tomorrow though, just wanted to make a victory post!

Sunday, February 10, 2008

Struggling with XML...

Having a few "teething" errors bringing the XML file into flash. I've been posting a few questions on actionscript.org then figuring it out myself just before someone answers and am nearly there now!

Have now got the XML file loading into flash and going into a multidimensional array [eek!] ready for use. Unfortunately getting through about 15 lines of code has taken me hours which is really irritating.

I hate you Actionscript 3.

Making a basic map in xml to test

I've had a bit of luck today and found this short tutorial, which though I can't use most of it, the Mappy software and xml lua script seem very useful for this project - a free level editor which exports to xml? Perfect!

So now I've downloaded it tested it with my basic two tile tilesheet and modified the xml exporting script so that it exports by column instead of rows (which was a remarkably simple change!), I think I'll be able to use this as my level editor for the project, reducing the time needed for putting the tiles together/making my own level editor.

Now I need to get flash to read it as I want it.. the tutorial isn't really suitable since he is using only a static screen and I need to get my information at a specific part of the map at any one time, our aims are quite different, and so will the code need to be! I may also possibly need to edit the xml script further so it includes the column number but I'm not sure if that will be necessary - can probably do that part in flash!

Lots to think about..

Saturday, February 9, 2008

A tiled screen works.. now to get it scrolling

Now have a screen populated with tiles based on what number is in a position in an array. Not sure I'll be keeping on down this road since I intend to use XML to lay out the tiles, but it means I've got something to test the scrolling with and start getting things moving around!

Here's where I am so far:


That's me done for today, tomorrow is time to make it scroll and add Mr Block [below] and add some keyboard functionality.

One tile works!

Took a little while, but finally got the first tile to be cut out of a png and pasted into a stage-sized bitmap!


Here's the file in all its glory!

Making a tile-based scrolling platform game in AS3.0 (argh!)

I've been looking over various forums such as the kirupa forums for information on making a tile-based platform game in actionscript 3. It seems the information is limited but basically, if you want it to run fast, then you have to do it as follows:

Use a single bitmap file containing all the tiles you will use in the level (this is the tilesheet.)

Plot the tiles onto a single, screen-sized blank bitmap in flash, using copyPixels to grab the tiles from the tilesheet bitmap.

And do this again every time the screen needs to move.

Of course its a bit more detailed than that since I need it to scroll left/right, I'll need a list of tiles in the correct locations put into a file (I'm planning to use XML for this) and then load the columns as needed. I think I will have the background seperate from the tiles (which will be in PNG format - bitmaps with transparency, what more could you want?) and move it independantly. Not sure on this yet however!

It's going to be a lot of work to do, so first things first I'm going to try and render a couple of tiles on a static screen in flash, and see if I can get that working..

Get ready to see it in my next post!

Deadlines and replacing targets

In my previous post I set myself some overly-ambitious targets, which though I could have achieved them, they have been taken over by other things - for example the games project to produce a flash platform game that uses Phidgets.

So instead, I am now setting myself some different targets.. first and foremost is the target to hand my project in one day early (so I don't have to go to uni on my birthday!) on the 4th March, 26 days away from today.

Shorter term targets:

1. Get scrolling tiles and a basic character (a box?) jumping/running around by the end of this coming Monday.

2. Get it all working together using basic tiles so the character can properly move around the level including switching polarity (if you haven't seen my game design you won't understand this till later) by Friday. Use XML for tile locations if possible.

3. Figure out characters back-story and reason for the game on Saturday. As detailed as possible.

4. Create background tiles and other graphics in photoshop by next Friday.