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

Report as inappropriate.

trimil
trimil presents ...

2016/4/18

Collision Detection Demo

You may use this class for anything you want to make.

The Mover class is a class that handles collision detection between actors. To use it you make a subclass, set the movement speed and gravity in the constructor, and call methods. Use the method setBlockingClasses(Class[]) to set which classes of objects the actor cannot go through. Call the doGravity() method every act cycle to cause the actor to fall if it isn't supported and to move upwards if it recently jumped. I used this for the scenario I still need a name for. Please drop a comment on that scenario with what you think I should call it.

CONTROLS for the demo:
A - move left
D - move right
W - jump

Press multiple keys to do both actions at once.

Enjoy :D

5483 views / 17 in the last 7 days

Tags: game physics demo with-source collision wombat

open in greenfoot
Your browser does not support the canvas tag.
Let me play!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! with you
trimiltrimil

2016/4/18

what?
danpostdanpost

2016/4/18

In the Mover class, in methods 'canMoveRight' and others, where you get a list of each type of barrier, you do not need to ask if the list is null as there will always be a list returned -- it might be an empty list, but it is a list just the same. I will not ask, but suggest that you just set 'vSpeed' to zero in the 'onGround' method of the Mover class. Then you will not need to ask the programmer to add the code at the end of the act method.
A new version of this scenario was uploaded on 2016-04-18 14:59:43 UTC Removed unnecessary code Removed need of setVSpeed(0) at end of act() method
trimiltrimil

2016/4/18

Thanks :D
DadDad

2018/5/26

When there is a barrier above the actor, it will try and jump through but will get stuck. how could one fix this?

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

Who likes this?

No votes yet.