Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Free platformer code, tutorial

Author
Message
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 19th Jul 2014 03:09 Edited at: 27th Jul 2014 03:54
Ok, so with work now fully under way on AppGameKit V2 which should attract a few new users, and my feeling the need for a break from the code heavy AI of my main game, I decided to try bashing out a simple scrolling Mega Jump style platform routine, and offer it up here as a free starting point/tutorial for people. So, attached is Platform Run in it\'s first extremely basic form, but the groundwork is here. Anyone is free to take this and do as they see fit with it, however please be aware that the asset for the running sprite and the platform tiles are from Google - they should be royalty free but if you use them it\'s on your own head. The rest of the backgrounds and water are all my own work, again you\'re free to use them if you wish.

So, what does this do? Right now, it reads the level data in and runs sideways. Tapping the screen causes the sprite to jump, and the idea is not to fall out the bottom. Quick features list:

*Level is 100 blocks long, however the engine is extremely efficient and can handle unlimited lengths - could easily be adapted to create a self generating \"infinite mode\"
*Tile blocks are created and deleted in real time and only as needed, so only the barest minimum of sprites are ever being handled
*The speed of everything can be completely controlled with two variables - speed up power-ups can be added very very easily due to this
*The level has 5 data flags reserved for now - later tiles can have effects (speed up, slow mo, die etc)
*The background uses the graphics and parallax from my flappy clone - this offers 5 layers but still runs at 60fps on decent devices. I may later used the 3d perspective mode for the water and sky from flappy, will see.
*Simple design features mean that levels can be created by simply dropping new assets into numbered folders


What I intend to add:
*A simple editor mode to build levels
*Linked tile sets so that platform edges etc are automatically done
*Code to handle multiple levels
*Dieing through spikes etc - or any flagged obstacle
*Level data that uses flags so tiles can have effects( speed up, bounce high etc)
*Optional Rayman style foreground layer
*vertical overlay (the bottom row of the screen currently is reserved for GUI)
*On screen jump button

If there\'s interest I might also add vertical movement so that maps can be built that extend beyond the height of the screen. At the moment this is about 6 hours work, so it is rough and some of it is copy and pasted from another project, but I\'ll tidy it up and comment it properly over the next week or so.

As I said, feel free to do with it as you wish, and modify it as you see fit. If someone makes some decent changes, feel free to tag them into this post, the point is to give new people a starting point on how to do some basic stuff.

Enjoy.

[img][/img]

EDIT: I redid the code with some decent commenting now, and also made some quick optimizations to some of the code, specifically the collision detection so it should been a bit faster on slow devices now. New ZIP file uploaded.

EDIT 22/07/2014
New version uploaded today, see post below.

EDIT 27/07/2014
New version uploaded today, see bottom post.

Attachments

Login to view attachments
IronGiant
AGK Bronze Backer
12
Years of Service
User Offline
Joined: 27th Feb 2012
Location: the great state of madness
Posted: 19th Jul 2014 21:09
Thanks for the tutorial Santman, Always great when code is posted to teach those that need to learn. And tile mapping is one area I think needs covered more in AGK.

It's Bird! , It's Plane!, No its a rocket powered Squirrel holding some acorns and a smile!
Uechi
17
Years of Service
User Offline
Joined: 2nd Sep 2006
Location:
Posted: 20th Jul 2014 17:28
Santman, thanks for this tutorial and the commented code. I think I
can learn a lot from this.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 21st Jul 2014 12:47
Thanks guys, and no problem. The tutorial is far from complete, but I won't get too much time until towards the end of this week to update it. The basic editor is almost in, and once that's done the other features won't take too much more than a couple evenings to add in, and I'll clearly explain the map text files too.

Feel free to share any improvements you make though, it's a quick and rough job so far.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 23rd Jul 2014 03:03 Edited at: 23rd Jul 2014 03:04
Added a very basic editor this evening, and a simply expanded tile set which auto picks the correct frame to display based on surrounding tiles. Now at any point on a PC you can right click, and change the level to your hearts desire, then press S to save the new map. This is very simple, but works and is easily expanded on. Some tweaks to the maps data file too, now the level length is saved off. The default level is only 100 tiles, but will soon work out it's own length.

Also, added a new ghost sprite to the player which is much thinner, and changed collision detection to this sprite so the player can now fall through a single block gap perfectly instead of running over the top of it.

Next up, looping levels, deathly sprites in the map, and some sound.

NB The archive in the first post is updated, and always will be - just download that again for the changes.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 27th Jul 2014 03:31 Edited at: 27th Jul 2014 03:33
Ok, so another little update added now. The editor works slightly better now, and I've shown the basics of setting up decoration sprites. There are more detailed comments to follow, however the basics of what has been set up:

*map saving is now complete
*map tiles work off a data set now - this allows tiles to be marked as walkable or background decoration, dangerous, a collision offset, and have their depth altered
*spikes will now kill the player, but only if they land on them
*the level will now end - looping to a new level is just a case of upping the level integer and calling the load function again
*added music

Next up, that raymam scrolling foreground....and maybe something a little special!!

Archive at top updated.

Login to post a reply

Server time is: 2024-03-28 16:09:39
Your offset time is: 2024-03-28 16:09:39