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

Comments for Barriers and Bars

Return to Barriers and Bars

danpostdanpost

2012/5/15

A lot of folks have been asking about how to detect collisions, or how not to pass through objects, so I created this example which also has an example of how one can sub-class my 'Bar' class to give it some functionality.
A new version of this scenario was uploaded on Tue May 15 23:42:19 UTC 2012 Minor bar fixing and widened range of speed bar.
A new version of this scenario was uploaded on Wed May 16 01:21:30 UTC 2012 Fixed the transparency value (it was backward).
dlannidlanni

2012/5/16

Oh wow! I can't wait to have a look at the code. Thanks!
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