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

2013/12/17

how to let my ship get a crate

6
7
8
9
10
11
12
virginia001 virginia001

2013/12/22

#
I have uploaded my scenario its called: Ship game: loading crates
danpost danpost

2013/12/22

#
Do it again; but this time check the 'Publish source code' checkbox.
Super_Hippo Super_Hippo

2013/12/22

#
You forgot to publish the code.
danpost danpost

2013/12/22

#
You need to remove all the code out of all your subclasses of Schip. For example your Schipgroen should be like this:
import greenfoot.*;

public class Schipgroen extends Schip
{
}
All the methods, including the 'act' method will be inherited from the Schip class to all these subclasses.
danpost danpost

2013/12/22

#
The same will need done with all your subclasses of Kratten.
virginia001 virginia001

2013/12/22

#
i have this for example for my Schipgroen subclass
public void act() 
    {
        if(Greenfoot.isKeyDown("left"))
        {
            setImage("boat01 groen.png");
            moveLeft();
        } 
        
        if(Greenfoot.isKeyDown("right"))
        {
            setImage("boat01 groen.png");
            moveRight();
            getImage().mirrorVertically();
        }
            
        if(Greenfoot.isKeyDown("up"))
        {
            setImage("boat01 groen.png");
            moveUp();
        } 
        
        if(Greenfoot.isKeyDown("down"))
        {
            setImage("boat01 groen.png");
            moveDown();
        } 
    } 



so if i remove that code the shop doesn't rotate good anymore with the directon
Super_Hippo Super_Hippo

2013/12/22

#
It is always the same image, isn't it? Why do you always set it again? And to be honest, why does the ship rotate at all? Changing between right and left is useful, but up and down? It can be useful to have code in the subclass. For example when you only have one ship which you can control. If you have it in the main class, then you control every ship with the same keys.
danpost danpost

2013/12/22

#
You can move the 'setImage' and 'getImage().mirrorVertically into the appropriate parts of the act method of Schip.
virginia001 virginia001

2013/12/22

#
Super_Hippo wrote...
It is always the same image, isn't it? Why do you always set it again? And to be honest, why does the ship rotate at all? Changing between right and left is useful, but up and down? It can be useful to have code in the subclass. For example when you only have one ship which you can control. If you have it in the main class, then you control every ship with the same keys.
Every ship has its own message thats why it needs to be recoded in every subclass of my Ships
danpost danpost

2013/12/22

#
In the Schip class add an instance field to hold the image of the ship:
private GreenfootImage image;
In the Schip class, add the following constructor to save the image of the ship:
public Schip()
{
    image = getImage();
}
Instead of 'setImage("/* image filename */);', use the following:
setImage(new GreenfootImage(image));
virginia001 virginia001

2013/12/22

#
okay every boat moves how it supposed to now... And when i click on the crate when the ship is against the platform the crate vanishes..so we on the good way i suppose
virginia001 virginia001

2013/12/23

#
I need to load the crates on the truck now but eventually the truck needs to ride forward out of the world when its loaded with a crate.....The second priority is that the player has 3 lives in the game and when a ship load the wrong color crate or load it on the wrong color truck it removes one life...the player needs to restart the game when hes out of lives.
danpost danpost

2013/12/23

#
One thing at a time. Alright, so "when a truck is selected, the crate on any ship docked on the platform the truck is on should be loaded". Click on truck selects truck. The truck needs to 'know' the platform it is on; the platform needs to 'know' what ship is docked at it; and the ship needs to 'know' what crate is loaded on it (this part is already done). The trucks can be informed as to which platform it is on the same way the crates 'knew' what platform they were on. The truck platform class, being a subclass of Platform, should already be inheriting the Schip field and be considered a Platform object, so that part is probably done also. Once you accomplish this part, you can work on the 'lives' part.
virginia001 virginia001

2013/12/23

#
so in this code there must adjusted that when clicked on the truck, the crate will be loaded on it
if (Greenfoot.mouseClicked(this))  
        {  
            if ( platform.getSchip() != null && platform.getSchip().getKratten()
            == null)
            {  
                platform.getSchip().setKratten(this); 
                getWorld().removeObject(this); 
            }
        }
danpost danpost

2013/12/23

#
(1) the ship must have a crate; so the condition would be 'platform.getSchip().getKratten() != null' (2) actions to perform when loading crate on truck are not the same as actions to perform when loading crate on ship; line 6 and 7 need to be replaced with code to do the following (a) determine if correct color crate was loaded onto the truck and adjust score (b) set a flag (set some field) for the truck to use to indicate it can 'roll off the screen'; a simple solution to this is to set the 'platform' field to null; then the act method of the truck can ask 'if the platform field is null, roll off'.
There are more replies on the next page.
6
7
8
9
10
11
12