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

2015/5/1

Make different when Level increase [HELP]

pandu4431 pandu4431

2015/5/1

#
i make my game with level, but i can't make a different even the level increase. i hope the enemy would be added when the level has increase, can anyone give the solution about that, i'm so glad if you can gives your code here and show me where method that i can place the code <sorry for bad English>
pandu4431 pandu4431

2015/5/1

#
is it true if i add this code in level method.? :
1
2
3
4
5
6
7
8
9
public void addLevel(){
        level++;
       if (level%1==0){
           World myWorld = getWorld();
           ScrollWorld sw = (ScrollWorld)myWorld;
           int l = Greenfoot.getRandomNumber(sw.getWidth());
           sw.addObject( new Asteroid(), l, Greenfoot.getRandomNumber (sw.getHeight())-680); 
       }
    }
danpost danpost

2015/5/1

#
Are you calling 'addLevel' from anywhere? (like the 'act' method of the class)
pandu4431 pandu4431

2015/5/1

#
yap, i calling in counter score method
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import greenfoot.*;
import java.awt.Color;
 
/**
 * Write a description of class Counter here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class Counter extends Actor
{
    int score =0;
    /**
     * Act - do whatever the Counter wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()
    {
        setImage(new GreenfootImage("SCORE : "+score, 24, Color.GREEN, Color.BLACK));
    }   
 
    public void addScore(){
        score+=5;
        if (score %100 ==0){
            World myWorld = getWorld();
            ScrollWorld sw = (ScrollWorld)myWorld;
            Level level = sw.getLevel();
            level.addLevel();
        }
    }
}
danpost danpost

2015/5/1

#
There are two things at this point which may be of concern. The first one is line 3 in the 'addLevel' method which will always be true (any integer value divided by one will have no remainder). The other one is line 7 of the same method which places the new asteroid at a y location of between '-680' and 'getHeight()-679' (mostly off the left edge of the world or at the left edge if your world is bounded by using 'super(int, int, int)' or 'super(int, int, int, true)' to create the world).
pandu4431 pandu4431

2015/5/4

#
i think i want make my enemy / Asteroid accelerate when level increase can you help me?? i tried some method to add the speed, such like i put "int m=5;" in asteroid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Level lvl = new Level();
    int m =5;
public boolean AtWorldEdge() 
    double w=getImage().getWidth(),h=getImage().getHeight(); 
    return getX()==w || getY()==h || getX()==getWorld().getWidth()/-(w+2) || getY()==getWorld().getHeight()-(h+2); 
 
    /**
     * Act - do whatever the rock wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()
    {
         
        setLocation(getX(), getY()+6);
         
        if (AtWorldEdge()) {
            int ran = Greenfoot.getRandomNumber ( 500 );
            getWorld().addObject( new Asteroid(), ran, 0);
            getWorld().removeObject(this);
            
        }
}
and then i add in the level method
1
2
3
4
5
6
7
public void addLevel(){
        level++;
        World myWorld = getWorld();
           Asteroid as = new Asteroid();
           as.m+=6;
       
    }
pandu4431 pandu4431

2015/5/4

#
ups, in Asteroid in act() i have change "setLocation(getX(), getY()+m);" but when the enemy touch the bottom edge, it won't disappear
danpost danpost

2015/5/4

#
pandu4431 wrote...
but when the enemy touch the bottom edge, it won't disappear
There is something amiss in your 'atWorldEdge' method. The last two conditions are not coded similarly.
pandu4431 pandu4431

2015/5/4

#
so how i can fix it? i hope, even "m" is changes the asteroid not stuck in bottom. can you help me master??? i'm so glad if you can gives me a fix code
danpost danpost

2015/5/4

#
Remove the division sign, "/", in the middle of line 6 of the 'atWorldEdge' method (in the 'return' statement).
You need to login to post a reply.