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

2013/10/1

HELP PLEASE!

mezboycalday mezboycalday

2013/10/1

#
hi guys, I have a counter and I want it to reset to 0 when it goes over a certain area of the game, in this case the base camp. please help thanks
Well, resetting the counter to 0 is easy (if it's an int like I think you're talking about)
counter = 0;
But you need to tell it to do that when it reaches the base camp. Is your base camp an actor, or a new world? I'm going to assume it's an actor. You can use the getOneIntersectingObject() method for Actor to see if specific actors are intersecting the actor that calls the method. It will return an actor, or null, if no actor intersects this one. So you can use the method like this:
if (getOneInetersectingObject(BaseCamp.class) != null) //In other words, if a BaseCamp object is interesecting this, and exists
{
    counter = 0;
}
Hope that helped!
mattjames mattjames

2013/10/1

#
Mez what's this counter called? is it your second one? and post the code from this counter pls
mattjames mattjames

2013/10/1

#
Also I need your code for the picking up passengers and then increasing the counter when you pick a person up
mezboycalday mezboycalday

2013/10/1

#
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; /** * A simple counter with graphical representation as an actor on screen. * * @author mik * @version 1.0 */ public class Counter1 extends Actor { private static final Color transparent = new Color(0,0,0,0); private GreenfootImage background; private int value; private int target; /** * Create a new counter, initialised to 0. */ public Counter1() { background = getImage(); // get image from class value = 0; target = 0; updateImage(); } /** * Animate the display to count up (or down) to the current target value. */ public void act() { if (value < target) { value++; updateImage(); } else if (value > target) { value--; updateImage(); } } /** * Add a new score to the current counter value. */ public void add(int score) { target += score; } /** * Return the current counter value. */ public int getValue() { return value; } /** * Set a new counter value. */ public void setValue(int newValue) { target = newValue; value = newValue; updateImage(); } /** * Update the image on screen to show the current value. */ private void updateImage() { GreenfootImage image = new GreenfootImage(background); GreenfootImage text = new GreenfootImage("" + value, 22, Color.BLACK, transparent); image.drawImage(text, (image.getWidth()-text.getWidth())/2, (image.getHeight()-text.getHeight())/2); setImage(image); } }
mezboycalday mezboycalday

2013/10/1

#
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.List; import java.util.ArrayList; /** * Write a description of class robot here. * * @author (your name) * @version (a version number or a date) */ public class robot extends Actor { private int canMove = 0; private Counter theCounter; private int points = 0; private Counter1 counter1; public robot(Counter1 pointCounter1) { counter1 = pointCounter1; } public void act() { int x; int y; x=getX(); y=getY(); canMove = canMove -1; if (Greenfoot.isKeyDown("down")&&(canMove <=0)) { setLocation(getX(),getY()+1); Greenfoot.delay(10); canMove = -1; scorer(); }// Add your action code here. if (Greenfoot.isKeyDown("up")) { setLocation(getX(),getY()-1); Greenfoot.delay(10); scorer(); } if (Greenfoot.isKeyDown("right")) { move (1); Greenfoot.delay(10); scorer(); } if (Greenfoot.isKeyDown("left")) { move (-1); Greenfoot.delay(10); scorer(); } Actor person; person = getOneObjectAtOffset(0, 0, person.class); if (person != null) { World World; World = getWorld(); World.removeObject(person); counter1.add(1); } } public void scorer() { world worldWorld =(world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-1); } }
mezboycalday mezboycalday

2013/10/1

#
first is counter code second is robot
mattjames mattjames

2013/10/1

#
what does the
public void scorer() 
    {
        world worldWorld =(world) getWorld();
        Counter counter = worldWorld.getCounter();
        counter.bumpCount(-1);
    }
do???
mezboycalday mezboycalday

2013/10/1

#
its for the fuel counter it reduces it by one
mattjames mattjames

2013/10/1

#
Ok in your robot create a class next as so: first create two variables called passengerscarrying=0; and passengersleft=4; at teh very start. Then when you pick up a passenger add - passengerscarrying=passengerscarrying+1; Here is the code to go below scorer():
 public void atbasecamp(){

         locationytwo =getY();
         locationxtwo =getX();

       
        if(locationxtwo==6&&locationytwo==3) { 

            while(passengerscarrying>0){
           
                world worldWorld = (world) getWorld();
            //need to call your counter like you do in line 4 of the post above
           counter1.add(-1);
            passengersleft=passengersleft-1;
            passengerscarrying=passengerscarrying-1;
           

        }

            //send to where you want it to go next

        
    }
    
    }
mezboycalday mezboycalday

2013/10/1

#
ta flying rabid unicorn lad
Yes? Sorry for late response.
mezboycalday mezboycalday

2013/10/1

#
my counter is a actor not an int variable
You can change the values in the int, can't you? If not, make a variable to change it.
danpost danpost

2013/10/1

#
You should be able to use 'counter.add(-counter.getValue();' or 'counter.setValue(0)'.
You need to login to post a reply.