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

2015/10/9

world transition

hoothoot hoothoot

2015/10/9

#
i'm having trouble transitioning one world at a time. if you can help, please do. here's the code i'm having trouble with.
private void hitEnemy() {
        Cell cell = (Cell) getOneObjectAtOffset(0, 0, Cell.class);
        if (cell != null) {
                cell.setHealth(-1000);
                cell.move(40);
                       if (cell.health <=0)
                            {
                                mark();
                                win();
                                getWorld().removeObject(cell);
                                Greenfoot.playSound("gohanyelling.wav");
                                if (timer.millisElapsed() > 4000)
                                { 
                                    if (level == 1) {
                                        level = 2;
                                        Greenfoot.setWorld(new level2());
                                        Greenfoot.delay(30);
                                        mark();
                                        getWorld().removeObject(this);
                                }
                                 if (level == 2) {
                                        level = 3;
                                        Greenfoot.setWorld(new level3());
                                        Greenfoot.delay(30);
                                        mark();
                                        getWorld().removeObject(this);
                                    }
                                    
                            }
                        }
            } 
    }
hoothoot hoothoot

2015/10/9

#
i used a simple timer to help but it didn't work for some reason
danpost danpost

2015/10/10

#
hoothoot wrote...
i used a simple timer to help but it didn't work for some reason
I do not think the timer is the issue here. Your check for the first level sets the value of 'level' to '2' and the check for the second level will find 'level' at '2' immediately after. Simple solution: change the 'if' on line 21 above to 'else if'.
You need to login to post a reply.