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

Report as inappropriate.

danpost
danpost presents ...

2012/5/15

Barriers and Bars

Demonstration on collision-detection, using barriers. With example code for moving so you do not pass over them. Also includes a demonstration on how to sub-class my Bar class.

8591 views / 24 in the last 7 days

9 votes | 0 in the last 7 days

Tags: mouse demo with-source bar danpost barrier collision-detection

This scenario is a member of: Demos by danpost


open in greenfoot
Your browser does not support the canvas tag.
A new version of this scenario was uploaded on Fri Oct 05 11:36:39 UTC 2012 Added angled lines and adjusted movement code. Also, added a barrier thickness adjuster bar.
danpostdanpost

2012/10/5

The robot (or man) has eight-way movement; meaning that you can use two arrows keys at one time to move diagonally (like 'up' and 'left'). Even with a little resistance in the direction of movement, the robot will 'slide' along the barrier. Maximizing the thickness of the barriers (clicking on the right, outside the Barrier Thickness bar) with the robot next to a barrier may 'trap' him. Better is to press and hold inside the bar on the right side (or move the robot away from any barriers before maximizing the thickness of the barriers).
SparkySparky

2013/7/26

should i use this to learn how to make barriers?
danpostdanpost

2013/7/26

@Sparky, oftentimes new programmers find that even though they put some kind of collision checking in their code, they still have problems with the actor passing by some barriers (usually when the speed of the object is quite fast and the barrier is quite thin). Although this scenario was intended to help in that situation, it is still possible to learn collision checking by examining its code.
davemib123davemib123

2013/12/6

this is great - should have seen this before!
FloodMeisterFloodMeister

2014/10/17

Hey, this has been so useful for me but i have one thing i cant figure out which is on one side of the barrier i can get close to it and then on the other side it has a gap, do you have any solutions to this?
FloodMeisterFloodMeister

2014/10/17

sorry do not look for this. it was my amateur mistake of the image have transparent pixels sorry
A new version of this scenario was uploaded on 2017-01-20 22:43:53 UTC
A new version of this scenario was uploaded on 2017-01-20 23:19:53 UTC
A new version of this scenario was uploaded on 2020-10-31 12:53:49 UTC

See all comments

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

Who likes this?

BavarianLP TomazVDSN FloodMeister JetLennit davemib123 adamkjelstroem sparrow72 h123n dlanni