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

2015/1/3

Remove score once.

Gzilia Gzilia

2015/1/3

#
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 ;
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;
    }
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.
Gzilia Gzilia

2015/1/3

#
Edit : I've solved my problem by making every crate have a balance board actor underneath it. that checks if it is touched by a crate.
danpost danpost

2015/1/3

#
Would it not have been easier to just have the balance board count the number of crates it intersects?
1
2
3
4
counter2.setValue(getIntersectingObjects(Crate.class).size()*10);
// or better
int count = getIntersectingObjects(Crate.class).size();
if (counter2.getValue() != count*10) counter2.setValue(count*10);
Gzilia Gzilia

2015/1/3

#
danpost wrote...
Would it not have been easier to just have the balance board count the number of crates it intersects?
1
2
3
4
counter2.setValue(getIntersectingObjects(Crate.class).size()*10);
// or better
int count = getIntersectingObjects(Crate.class).size();
if (counter2.getValue() != count*10) counter2.setValue(count*10);
I would not know, taking your word for it! Ill try and incorperate your solution into it, thanks for the reply.
1
(counter2.getValue() != count*10) counter2.setValue(count*10);
That is the kind of logic I was having trouble with, thanks.
danpost danpost

2015/1/3

#
The initial line I gave would be the least you would need; however, this would require the counter to update its image every act cycle. The second way, lines 3 and 4, is better only in that the counter only updates when needed -- that is, when the score actually changes. This reduces the workload on the system as working with multiple or large images is one of the major causes in producing lag.
You need to login to post a reply.