This site requires JavaScript, please enable it in your browser!
Greenfoot back

Report as inappropriate.

askgriff
askgriff presents ...

2014/1/9

Platformer Tutorial

A request I get a lot is for a platformer game. We'll be doing the basics as a starting point and adding things along the way, then I will leave you to your own devices to customize your game.

27075 views / 88 in the last 7 days

9 votes | 1 in the last 7 days

Tags: game physics demo with-source mario platformer jump platform keys animated sprite

open in greenfoot
Your browser does not support the canvas tag.
A new version of this scenario was uploaded on Mon Feb 10 17:57:14 UTC 2014 Fixed a bug on the first screen with the key. Began implementing a splash screen -- or attempting it.
KytuzianKytuzian

2014/2/11

Looks good so far, but do you just not want a scrolling screen or have you not been able to do it yet? If it is the latter I could help you with that. There is some code that is not necessary or too complicated. For example, in the ShootingManager, you have two subclasses when all you really need is one Bullet class (or whatever). What you need a field called speed, and just add that to x like you are. However, in the constructor you could have a field called Direction which is either 1 or -1 (right or left) and then multiply the speed by it. Also, for the killBadGuys(), you don't need to have two methods for it, you can just call the one method like this: if (!kill(BadGuys.class)) remove(); This way you call your method and do the remove with much less code so that you can really tell what is going on more clearly. Finally, this code could simply go in the act method because it is succinct enough to not over complicate the method.
askgriffaskgriff

2014/2/11

Kytuzian -- thank you! The code is a little verbose because it's a tutorial that I am using to teach beginning programming. We've been doing little pieces at a time and the code has begun to be a bit crazy. I have not yet done the scrolling code because I haven't figured out HOW to do it. I would love suggestions! If you're willing you could email me some fixes (griff@kvusd.org) and I would love to see it.
KalleLarssonKalleLarsson

2014/8/19

If the scrolling is still something you'd want to implement, for future use when teaching, I've uploaded two scenarios. The first (http://www.greenfoot.org/scenarios/12055) is a simple scrolling demo where I use a fictive cam that pans over the level (which i belive is the most intuitive way to implement scrolling), and the other is a platformer game demo using the first scrolling mechanism, aswell as some other functionality that I think can be fun examples to teach :) The game demo is scenario 12048 If you're interested and have any questions or want better commented code you can just Contact me on karlars [at] live.se if Im not Active on here
Kirito101Kirito101

2014/10/1

Not sure I'm going about this the right way but i'm using your map concept and am struggling with adding an actor. I think it has something to do with the constructor i used but i'm not sure how to fix it. I'm pretty sure I need the constructor to re-size my images.Using other things to re-size them always seems to distort the images.
Kirito101Kirito101

2014/10/1

http://www.greenfoot.org/scenarios/12241
RassRass

2015/3/12

Thank you for uploading this, I am using this to help develop my own platformer for my college course. However, one problem I am having currently is that my actor can't collide/jump on platforms and doesn't stand on top of the ground. Since I am still new, I don't know what code you used. If you could help me with this, I would be very grateful!
willMwillM

2015/3/12

I like it :D
ninjaFIninjaFI

2017/3/1

how did u make ur platforms solid
GuzzoGuzzo

2017/4/5

it is good but very jumpy. If i were you i would make the movement use some sort of velocity. For example: Every frame the xSpeed can go up by 1, and it stops going up at like 8 xSpeed. And when you let go the xSpeed goes down by 1 until it hits 0, then it stays 0. Makes the game smoother :)

See all comments

Want to leave a comment? You must first log in.

Who likes this?

yedefei Alola_Sandslash asksteve Rass willM csrgamer bourne vladdes