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

17
18
19
20
21
coldxms coldxms

2014/1/12

#
Virginia, I suppose you have a picture of your Ship or shark. With a transparent background .png file. If so, you must change the border width's of this picture as close as possible to the ship. In example; His image border is his whole frame. you must resize this.
virginia001 virginia001

2014/1/12

#
had them both transparent already but it doesn't work but I'll found it out myselff..ty anyway Im just gonna focus on my score now...So far i have some code in my counter class that looks like the below code.. My goal for this score counter is letting it do the following things: - let it add 50 points when loading the good crate on the truck - letting it subtract 20 points when loading the wrong crate on a ship and truck - letting it subtract 15 points when the ship collides with the shark - add up the time left after finishing the game, so example when finished there are 26 seconds left add up 26 points to the final score
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 Counter 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 Counter()
    {
        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);
    }
}
Super_Hippo Super_Hippo

2014/1/12

#
Maybe you could write how you solved it, so someone who has the same problem can find the solution here. Same with your previous problem.
virginia001 wrote...
So far i have some code in my counter class that looks like the below code..
This looks exactly like the Counter class which you can import. With that, you have everything you need! Why don't you just try it yourself and only ask if you stuck? Maybe you want to say something like this later: "This is my scenario, which I made by myself, isn't it great?" and not "I uploaded this scenario. Some guys in the forum did all the work.". Trying out is the most funniest part of programming (for me at least). If it is really not possible for you, it is the best way to ask, but before that, you should try out if you are able to do it by yourself.
coldxms coldxms

2014/1/12

#
Super_Hippo wrote...
Why don't you just try it yourself and only ask if you stuck? Maybe you want to say something like this later: "This is my scenario, which I made by myself, isn't it great?" and not "I uploaded this scenario. Some guys in the forum did all the work.". Trying out is the most funniest part of programming (for me at least). If it is really not possible for you, it is the best way to ask, but before that, you should try out if you are able to do it by yourself.
I rest my case as i Saïd on page 6, nevertheless iTS fun to help!
Super_Hippo Super_Hippo

2014/1/12

#
Yes, it is. But it is more fun, if you have some code to work on and/or correct existing code instead of starting from zero.
virginia001 virginia001

2014/1/12

#
Super_Hippo wrote...
Maybe you could write how you solved it, so someone who has the same problem can find the solution here. Same with your previous problem.
virginia001 wrote...
So far i have some code in my counter class that looks like the below code..
This looks exactly like the Counter class which you can import. With that, you have everything you need! Why don't you just try it yourself and only ask if you stuck? Maybe you want to say something like this later: "This is my scenario, which I made by myself, isn't it great?" and not "I uploaded this scenario. Some guys in the forum did all the work.". Trying out is the most funniest part of programming (for me at least). If it is really not possible for you, it is the best way to ask, but before that, you should try out if you are able to do it by yourself.
If I found it out myself it will cost me tons of time that I dont have I do have a life besides working for school all day.. And if you find it annoying to solve my problems you just don't do it..simple as that
Super_Hippo Super_Hippo

2014/1/12

#
You did find out your latest problems by yourself or at least you said it. Look at the first sentence of the text you quoted.
coldxms coldxms

2014/1/12

#
I think what super_hippo implies is that u learn nothing from this. You say that it is for school. So why don't u put a little effort in it, and learn.
virginia001 virginia001

2014/1/12

#
okay I see next time I'll try write down the solutions...but you guys also must understand I have like 6 weeks experience with writing java code so don't expect me to solve my problems without help
Super_Hippo Super_Hippo

2014/1/12

#
First, it would be great if you post the last solutions. You can also edit them into your posts where you said that you solved it. Second, we don't expect that you do everyone by yourself. I got to know java/Greenfoot in school, too. The lessons were quite boring, but it was fun to play around with the program and try things out. After 6 weeks, I was already fascinated by it. It was fun, so I even do it after school now. If you put a little effort in it, you will understand what we tell you here. Most parts are not really complicated. Well, some are, but you do not have such complicated issues(, yet). The best idea is just start and try, what the code does. Then you adjust it until it does what it should.
virginia001 virginia001

2014/1/12

#
virginia001 wrote...
solved it already
This part was solved because I hadn't declared the good name in the 'Greenfoot.playSound("myimage.wav") ' in my code where the sound supposed to play.
virginia001 virginia001

2014/1/12

#
coldxms wrote...
Virginia, I suppose you have a picture of your Ship or shark. With a transparent background .png file. If so, you must change the border width's of this picture as close as possible to the ship. In example; His image border is his whole frame. you must resize this.
This I have solved in the program paint.net with the magic wand function and eventually resized it to as small as possible with the selection function.
virginia001 virginia001

2014/1/12

#
Okay now back to my problem.. I have fixed the first part of the score counter in my Shark class. Now I also want to add the score when loading crates in the truck,ship and crates class. So first of all in my Kratten class i declared the counter class in the world constructor
public Kratten(Counter pointCounter)
    {
        counter = pointCounter;
    }
And also in the world class for all the subclass objects
groen groen = new groen(counter);
        addObject(groen, 296, 596);
        groen groen2 = new groen(counter);
        addObject(groen2, 502, 734);
        oranje oranje = new oranje(counter);
        addObject(oranje, 353, 596);
        rood rood = new rood(counter);
        addObject(rood, 502, 594);
        rood rood2 = new rood(counter);
        addObject(rood2, 294, 664);
        geel geel = new geel(counter);
        addObject(geel, 496, 660);
        geel geel2 = new geel(counter);
        addObject(geel2, 361, 728);
        zwart zwart2 = new zwart(counter);
        addObject(zwart2, 436, 734);
        zwart zwart = new zwart(counter);
        addObject(zwart, 366, 665);
        paars paars2 = new paars(counter);
        addObject(paars2, 294, 729);
        paars paars = new paars(counter);
        addObject(paars, 411, 667);
        
In the subclasses of the Kratten I get the error: required Constructor in Kratten cannot be applied to the given types; required Counter Code of a subclass of the crates:
public class geel extends Kratten
{
    public geel()  
    {  
        super();
        setColor("geel"); 
    }
} 
Super_Hippo Super_Hippo

2014/1/12

#
You do not have to put the counter in the constructor of any actor. You only have to create the counter in the world class. Then you can use something like 'Counter.add(score);' But because that never worked for me, I made the 'private int target' static. To add a score then, you can call 'Counter.target+=score' As long as you only have one object of the class Counter, this works fine.
virginia001 virginia001

2014/1/12

#
I've build the score counter according to the code in one of my previous posts where I've Showed the counter class. So I work according to a counter in a class not only in the world class because this video on youtube explained the whole thing but when I follow the instructions from this video exactly how its showed is still doesn't work. this is the part of the shark class that does work and it's still done in the same way.
public class Shark extends Actor
{
    private int lifecounter = 100;

    private Counter counter;

    public Shark(Counter pointCounter)
    {
        counter = pointCounter;
    }

    public void act() 
    {
        lifecounter--;
        move();
        Schip s = (Schip)getOneIntersectingObject(Schip.class);
        if (s != null && lifecounter <= 0)
        {
            removeLive();
            counter.add(-15);
            lifecounter = 100;
        }
    } 
and i've declared it in the same in the world class Shark shark = new Shark(counter); addObject(shark, 185, 345);
There are more replies on the next page.
17
18
19
20
21