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

18
19
20
21
Super_Hippo Super_Hippo

2014/1/12

#
Maybe you found out a new way. For me, it would be too annoying to put this counter every time you add an object. But nevertheless, you did find a solution!
coldxms coldxms

2014/1/13

#
In the world u are creating a new shark with a return type "counter". And in your shark class all u do is say that counter equals pointcounter You however have not declared a start value and are trying to add -15 to counter. U must have a counteradd+= pointcounter
danpost danpost

2014/1/13

#
virginia001 wrote...
I've build the score counter according to the code in one of my previous posts where I've Showed the counter class.
It is not the class you are showing -- it is an object of that class (Counter) you are giving it (the shark) a reference to.. Please show all places where you create Shark objects as well as everything related to the Counter object being passed back to that Counter objects creation. Also, specify where each bit of code is located (method and where it is called from as well as the class it is in).
coldxms coldxms

2014/1/13

#
public class world1 extends World
{   
 Score slot0 = new Score();          //Score digits
    Score slot1 = new Score();
    Score slot2 = new Score();
    Score slot3 = new Score();
    Score slot4 = new Score();
    Score slot5 = new Score();
    Score slot6 = new Score();
    Score slot7 = new Score();
    int slotdigit1;                     //The most left digit of the score
    int slotdigit2;
    int slotdigit3;
    int slotdigit4;
    int slotdigit5;
    int slotdigit6;                     //The most right digit of the score
    
    int scorenumber = 0;                //The actual score

 public world1(){
        addObject(slot0, 621, 100);
        addObject(slot1, 638, 100);
        addObject(slot2, 655, 100);
        addObject(slot3, 672, 100);
        addObject(slot4, 689, 100);
        addObject(slot5, 706, 100);
        addObject(slot6, 723, 100);
        addObject(slot7, 740, 100);
        slot0.digit = -1;            //These slots are empty
        slot7.digit = -1;
        slot0.setImage("nr_empty.png");
        slot7.setImage("nr_empty.png");

}
    void score(){
        
        slot1.digit = Math.round((scorenumber % 1000000)/100000);
        slot2.digit = Math.round((scorenumber % 100000)/10000);
        slot3.digit = Math.round((scorenumber % 10000)/1000);
        slot4.digit = Math.round((scorenumber % 1000)/100);
        slot5.digit = Math.round((scorenumber % 100)/10);
        slot6.digit = Math.round((scorenumber % 10));
    }

//Example of points being added.
public void game(){
        if(!eatpizza){
            if((pizza.getImage().getTransparency() == 0)){
            
                scorenumber += 150;
                removeObject(pizza);
                eatpizza = true;
            }
//add some more score counters for example (make a boolean sharkhitboat in the constructor, starting it at false).
        if(!sharkhitboat)
           if(shark/**Your name of the shark must be at the left side of this comment*/.getImage().getTransparency()== 0)){
         scorenumber += 50; //50 score is added.
        removeObject(/**sharkname*/);
        sharkhitboat = true;
        }
//call all methods.
    public void act(){
        int playerx = player.getX();
        score();
        game();
                }
            }
    }
Create a class called score :

public void act() 
    {
        if(digit == 0){
            setImage("nr_0.png");
        }
        if(digit == 1){
            setImage("nr_1.png);
       }
        if(digit == 2){
            setImage("nr_2.png");
        }
        if(digit == 3){
            setImage("nr_3.png");
        }
        if(digit == 4){
            setImage("nr_4.png");
        }
        if(digit == 5){
            setImage("nr_5b.png");
        }
        if(digit == 6){
            setImage("nr_6.png");
        }
        if(digit == 7){
            setImage("nr_7.png");
        }
        if(digit == 8){
            setImage("nr_8.png");
        }
        if(digit == 9){
            setImage("nr_9.png");
        }
}
}
Where nr_*.png is an image of the corresponding number. for this to work u must set the transparency of the image in your player (boat) class to 0. public void hitShark() { Actor Shark; Shark = getOneObjectAtOffset(0,0,shark.class); if( shark != null) { shark.getImage().setTransparency(0); } } This should be easy to implement.
Super_Hippo Super_Hippo

2014/1/13

#
This is even more complicated. Why not use the existing class counter which uses integers if you can create your own counter which uses every digit separated... ;)
virginia001 virginia001

2014/1/14

#
Never mind I've solved the score counter already according to this code: for each object class i've invoked the methods from the below code.
int score = 0;
    
    public void act()
    {
        setImage(new GreenfootImage("Score : " + score, 30, Color.BLACK, null));
    }
    
    public void addScoreShark()
    {
        score -= 15;
    }
    
    public void addScoreKratten()
    {
        score += 40;
    }
    
    public void addScoreFout()
    {
        score -= 70;
    }
My new problem has to do with the audio again. I've created an game over screen and when this pops up I want to play a sound. I've paid attention if the sound is in the good folder, if the sound is working at all in my default music player, and if declared the right name of the sound file.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
 * Write a description of class GameOver here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class GameOver extends Actor
{
    /**
     * Act - do whatever the GameOver wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public GameOver()
    {
        setImage(new GreenfootImage("GAME OVER", 60, Color.RED, null));
        Greenfoot.playSound("fail-trombone-03.wav");
    }
}
coldxms coldxms

2014/1/15

#
What is the error? What does your terminal window show u?
virginia001 virginia001

2014/1/15

#
Could not play soundfile. If you have a sound card installed, check your system settings. java.lang.IllegalArgumentException: No line matching interface SourceDataLine supporting format PCM_SIGNED 48000.0 Hz, 24 bit, stereo, 6 bytes/frame, little-endian is supported. at javax.sound.sampled.AudioSystem.getLine(AudioSystem.java:476) at greenfoot.sound.SoundStream.initialiseLine(SoundStream.java:436) at greenfoot.sound.SoundStream.<init>(SoundStream.java:102) at greenfoot.sound.SoundFactory.createSound(SoundFactory.java:112) at greenfoot.sound.SoundFactory.<init>(SoundFactory.java:65) at greenfoot.sound.SoundFactory.getInstance(SoundFactory.java:78) at greenfoot.gui.GreenfootFrame.makeFrame(GreenfootFrame.java:435) at greenfoot.gui.GreenfootFrame.<init>(GreenfootFrame.java:222) at greenfoot.gui.GreenfootFrame.getGreenfootFrame(GreenfootFrame.java:201) at greenfoot.core.GreenfootMain$2.run(GreenfootMain.java:204) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733) at java.awt.EventQueue.access$200(EventQueue.java:103) at java.awt.EventQueue$3.run(EventQueue.java:694) at java.awt.EventQueue$3.run(EventQueue.java:692) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:703) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138) at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
danpost danpost

2014/1/15

#
virginia001 wrote...
java.lang.IllegalArgumentException: No line matching interface SourceDataLine supporting format PCM_SIGNED 48000.0 Hz, 24 bit, stereo, 6 bytes/frame, little-endian is supported.
Looks like the sound file needs to be converted to a format that is supported by Greenfoot. The GreenfootSound API documentation lists the formats that are supported.
virginia001 virginia001

2014/1/15

#
all my other sounds are .wav too and they're working
virginia001 virginia001

2014/1/16

#
I want to stop the background music when displaying the game over screen, but the music is still playing then so far i've tried a few things but it didn't work this is my gameover world class screen
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class GAMEOVERSCHERM here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class GAMEOVERSCHERM extends World
{

    /**
     * Constructor for objects of class GAMEOVERSCHERM.
     * 
     */

    GreenfootSound backgroundMusic = new GreenfootSound("emerald.wav");
    public GAMEOVERSCHERM()
    {    
        super(400,300,1);
        Greenfoot.playSound("fail-trombone-03.mp3"); 

        addObject(new TRYAGAIN(), 200,80);


        if (backgroundMusic.isPlaying())
        {
            backgroundMusic.stop();
        }
    }

   
}
Super_Hippo Super_Hippo

2014/1/16

#
You have to stop the music before you change the world. You create a new sound in line 17 which is not the background sound that was created in the other world.
virginia001 virginia001

2014/1/16

#
Ye it was i changed it a while ago
You need to login to post a reply.
18
19
20
21