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

2014/5/23

Help with level up

1
2
adi110 adi110

2014/5/23

#
What is the code for increasing my level counter when i pass a level?? (ex: from level 1 to level 2 i want my level counter increase by 1) Thanks
danpost danpost

2014/5/23

#
Since you have supplied no code to go by, my response would be:
level++;
hugtvy hugtvy

2014/5/23

#
you need to show what your code, is level 1 a different world to level 2 if so then its much more complicated.
adi110 adi110

2014/5/23

#
level 2 is a different world for level 1
danpost danpost

2014/5/23

#
What is your World sub-structure and in which world and how is your level counter declared?
adi110 adi110

2014/5/23

#
if(Score >= maxScore) { LevelComplete lvl = new LevelComplete(); world.addObject(lvl, world.getWidth()/2, world.getHeight()/2); timerrrStarted = true; complete = true; } . . . . public void Timerrr() { if(levelUp > 0) { levelUp --; if(levelUp == 0) { delayReady = true; levelUp = 120; Greenfoot.setWorld(new bath()); } } } my level 1 world is sandstone and level 2 world is bath; this is the code with which i can get in level 2
hugtvy hugtvy

2014/5/23

#
you need to introduce the counter so that both worlds can identify the counter can you please show some code ei your counter and what actors use it?
adi110 adi110

2014/5/23

#
and i want after i passed the level 1 world my level increase import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; /** * Write a description of class Counter here. * * @author (Adrian Copoiu) * @version 1.0 (May 2014) */ public class Counterr extends Actor { /** * Act - do whatever the Counter wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public int totallevel = 0; Color color = new Color(0,0,0,0); public void bumplevel(int amount) { totallevel += amount; setImage(new GreenfootImage("Level: "+totallevel, 30, Color.BLACK, color)); } public Counterr() { setImage(new GreenfootImage("Level: 0", 30, Color.BLACK, color)); } } this is my level counter code which i thing is not correct....help me
hugtvy hugtvy

2014/5/23

#
why not just add an image that says level one in world one and in world two have one that says level 2? use the prepare method to make it add the image everytime you enter the world, you can make it using photoshop or anything alike.
adi110 adi110

2014/5/23

#
ok i will do that, i think is easier than what i wanted to do; but how can i make a level 3 and acces it?
danpost danpost

2014/5/23

#
The way hugtvy suggested is probably the way to go. With what you have now, however, you could just set the value of the counter when you create it in each world constructor.
// for example
int level = 2;

public Level2()
{
    super(/* world dimensions */);
    Counterr counter = new Counterr();
    counter.bumpLevel(level);
    addObject(counter, /* wherever */);
    // etc.
}
The main problem with this and the previously mentioned solutions is that it would be difficult for any other object to know what level you were at without a lot of code (especially if you plan on having many levels). Again, I ask, what does your World sub-structure look like (what world classes extends what)?
adi110 adi110

2014/5/23

#
public class sandstone extends World { /** * Constructor for objects of class sandstone. * */ Counter theCounter; Counterr theCounterr; snake snk = new snake(); public sandstone() { super(1024, 600, 1); Greenfoot.start(); snk = new snake(); addObject(snk, 300, 200); lemur lmr = new lemur(); int x = Greenfoot.getRandomNumber(1024); int y = Greenfoot.getRandomNumber(600); addObject(lmr, x, y); x = Greenfoot.getRandomNumber(1024); y = Greenfoot.getRandomNumber(600); lmr = new lemur(); addObject(lmr, x, y); flan fln = new flan(); x = Greenfoot.getRandomNumber(1024); y = Greenfoot.getRandomNumber(600); addObject(fln, x, y); theCounter = new Counter(); addObject(theCounter, 50, 50); } public Counter getCounter() { return theCounter; } public snake getSnake() { return snk; } public int getScore() { return snk.getScore(); } } public class bath extends sandstone { /** * Constructor for objects of class bath. * */ public bath() { super(); } } i've done like hugtvy said; can you help me with level 3?? i want to enter in a different world (my first one in sand second one bath third one i want to be brick) how can i do it?
danpost danpost

2014/5/23

#
A 'bath' world is not a particular type of 'sandstone' world; it is a different world altogether. 'bath' should not extend 'sandstone'.
adi110 adi110

2014/5/23

#
if i don''t extend from sandstone i can't go in bath when i hit 15 score; i did't know how to do it in another way
adi110 adi110

2014/5/23

#
if you know a better way please help me (i want to do like 5 levels and i don't know how)
There are more replies on the next page.
1
2