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

2014/6/16

Achievements not Working!!! Help pls

Mint_Greenie Mint_Greenie

2014/6/16

#
I have a game called 'Infinity' and I want infinity to have an achievement. When the user gets to the 10th pipe then stop the game, and present a dialog. I've tried this: Bird Class:
    public void act() {

        // Checks if the bird flaps.
        checkFlap();
        // Moves the bird.
        move();
        // Checks if the bird hits the obstacles.
        if (checkHit()) {
            Sky sky = (Sky) getWorld();
            sky.gameOver(score);
        } else {
            // Checks if the bird gets ths score.
            checkScore();
        }
        Sky sky = new Sky();
        AchievementOne achievementOne = new AchievementOne();
        if(this.intersects(achievementOne)){
            sky.adddies();
            sky.ahievement();
            System.out.println("pass");
        }
    }
Sky (game) code
 int dies = 0;
    Boolean menue=false;
    /**
     * Constructor for objects of class Sky.
     * 
     */
    public Sky() {
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1);
        addObject(new Bird(), getWidth() / 2, getHeight() / 2);
        scoreBoard = new ScoreBoard();
        addObject(scoreBoard, 70, 50);
        pipeTimer = PIPE_INTERVAL * 2;
        setPaintOrder(GameOver.class, ScoreBoard.class, Bird.class, Pipe.class);
        Greenfoot.playSound("sounds/background.mp3");
    }
    //The 2 blocks of code are for the 'Die after 10 pillars' achievement.
    public void adddies()  
    {  
        dies++;  
    }  

    public void ahievement()  
    {  
        if(dies>2&&menue==true)  
        {  
            addObject(new AchievementOne(),100,100);  
        }  
    }  

    /**
     * Things to do for each turn.
     * 
     */
    public void act() {
        // Adds a pipe pair periodically.
        addPipePairPeriodically();
        Greenfoot.setSpeed(40);
        adddies();
        ahievement();
    }

    /**
thanks!
danpost danpost

2014/6/16

#
In your Bird class act method, you are creating an AchievementOne object on line 16 and then asking if the Bird intersects it on line 17. But, you never add the object into the world. So, the condition on line 17 will always be false and the 'if' block will never execute.
Mint_Greenie Mint_Greenie

2014/6/16

#
@danpost what co-ords do I put to add them? The game stays in one place but keeps refreshing!
danpost danpost

2014/6/16

#
I just realized something else and I do not think this is what you wanted to do. You are creating a new Sky world (line 15 in the act method of the Bird class above) and doing things to it instead of the world that 'this' bird is in. The end result will be that the new world will be flagged for garbage collection as soon as the block of code has finished executing (at lines 21 above). Also, I do not see the code that stops the scenario when the achievement displays (which could be displayed at (getX(), getY()) -- the center of the world.
You need to login to post a reply.