Hello,
(source : http://www.greenfoot.org/scenarios/12962)
I've been trying to make a system that grants 10 points (balance points) once a crate makes contact with a balance board, I've got this kinda working with a boolean like so ;
Note : i've been trying to use diffrent methods ( isTouching / Intersecting ) for testing purposes.
The problem with this code is that if one crate makes contact with a balance board, it will take up all the ''slots'' ( the 8 booleans), and add X points till all the booleans are used up. Sigh.
I've been trying to think of a way to add points once if a crate makes contact with a balance board, and than remove those points once that crate no longer makes contact with the balance board.
Do I need to make multiple Crate2 classes, give every crate an unique ID ?
Any help would be greatly appreciated.
Sincerly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | private boolean boolean1 = true ; // 8 booleans like this Actor Crate2 = getOneIntersectingObject(crate2. class ); World2 world2 = (World2) getWorld(); Balancecounterleftp1 counter2 = world2.getCounter1(); if (isTouching(crate2. class )&& boolean1 == true ) { counter2.bumpCount( 10 ); boolean1 = false ; } if (Crate2 != null && boolean1 == false && boolean2 == true ){ counter2.bumpCount( 10 ); boolean2 = false ; } |