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

2013/12/19

Gyroscope project

coldxms coldxms

2013/12/19

#
Hello for a school project i need to add a gyroscope to my ship. My idea was to have a counter if a container from the left side was picked it changes the image. This worked, but the problem is if i take a container front the right side (at least further front he mid point) it has to change back. not all but a little... How can i do this? I was thinking of a counter that start with 4 and if u pick from the left side it is decremented by 1. if u pick from the right side, added with 1 etc.. if the counter == 3 the gyroscope has a image with arrow pointing left, if it equals 5 it has 1 pointing right.. etc... I want to do this in my Gyroscope class. the Containers get picked by clicking it in the World (haven).
coldxms coldxms

2013/12/19

#
Some code examples of a container being picked.
 public boolean container0()
        {
            if(Greenfoot.mouseClicked(container))
            {
                container0 = true;
            }
            return container0;
        }
public boolean container000()
        {
            if((kraan.getX() == container.getX()) && (container.getY() > 100 && container.getY() < 337 +1/2))
            {
                container000 = true;
            }
            return container000;
        }
       public void moveCrane()
        {
            if(container0())
            {
                actcont1();
            }
            if(container000())
            {
                actycont1();
            }
}
coldxms coldxms

2013/12/19

#
I fixed it myself =)!. I just did it in the World class. But how could i do it in the object's class? So i can learn from it!
danpost danpost

2013/12/22

#
Show the code you used (how you did it) in the World class.
coldxms coldxms

2013/12/23

#
public class Haven extends World
{
       public int gaugecounter = 4;
}

//this code contineu's for all 8 containers
public boolean container0()
        {
            if(Greenfoot.mouseClicked(container))
            {
                container0 = true;
                gaugecounter--;
            }
            return container0;
        }
 //till here.

public void gaugeimage()
        {
            if(gaugecounter == 3)
            {
                gauge.setImage(gauge2);
            }
            if(gaugecounter == 2)
            {
                playSound1();
                gauge.setImage(gauge4);
            }
            if(gaugecounter == 1)
            {
                addObject(finish, 400,300);
                Greenfoot.stop();
            }
            if(gaugecounter == 4)
            {
                gauge.setImage(gauge1);
            }
            if(gaugecounter == 5)
            {
                gauge.setImage(gauge3);
            }
            if(gaugecounter == 6)
            {
                    playSound();
                    gauge.setImage(gauge5);
            }
            if(gaugecounter == 7)
            {
                addObject(finish, 400,300);
                Greenfoot.stop();
            }
        }
danpost danpost

2013/12/23

#
I cannot tell where any of the methods are being called from or where any of the fields (variables) are being declared.
coldxms coldxms

2013/12/24

#
All variables are being declared in the World. As in above all methods. This is where 2 methods get called:
    public Haven()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(800,600,1);
        create();
        tonLocation();
        //moveCrane();
    }
and in the act method, the following gets called:
            moveCrane();
            checkContainer();
            counter();
            gaugeimage();
danpost danpost

2013/12/24

#
Do not tell me that your Containers class has eight subclasses, one for each container in your world.
coldxms coldxms

2013/12/25

#
No, i have 3 kind of containers which means 3 classes, and 3 objects of each class in the world
danpost danpost

2013/12/25

#
Do the 3 container classes have an intermediate class between them and the Actor class? or do they each extend the Actor class directly?
coldxms coldxms

2013/12/26

#
All classes extend the actor class. So No subclasses.
danpost danpost

2013/12/26

#
Still, without seeing the Haven class in its entirety, it would be hard to say how it would be coded in the Actor classes.
You need to login to post a reply.