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

2017/2/6

@danpost Score switching worlds...

1
2
3
4
Kokoro Kokoro

2017/2/6

#
 GreenfootImage bg = getBackground();
        bg.setColor(Color.white);  -- THIS ONE
        bg.fillRect(684, 15, 100, 30);
        bg.setColor(Color.black); -- THIS ONE
        bg.setFont(new Font("SERIF", Font.BOLD, 28));
        bg.setColor(Color.black);  -- THIS ONE
        bg.drawString(""+score, 684, 40);
    }
     
    private void setAction(int action)
    {
        removeObjects(getObjects(Chaser.class)); // remove old chasers
        actionType = action%5; // set bound action
        int[] distances = { 0, 0, -10, 0, -15 }; // bound ranges
        actionDistance = distances[actionType]; // the range for this action
        String[] texts = { "UNBOUND", "LIMIT", "REMOVAL", "WRAPPING", "BOUNCE" }; // the bounds text
        // adjust bounds display
        GreenfootImage bg = getBackground();
        bg.setFont(new Font("SERIF", Font.BOLD, 36));
        bg.setColor(Color.black); -- THIS ONE
        bg.fillRect(350, 0, 200, 50);
        bg.setColor(Color.gray); -- THIS ONE
        bg.drawString(texts[actionType], 350, 44);
        // reset score
        score = 0;
        // ensure player is in world
Kokoro Kokoro

2017/2/6

#
They have a "--THIS ONE" near them..
Super_Hippo Super_Hippo

2017/2/6

#
I would suggest to not just draw on the background at all. Using an actor to display the variables and change its image is a lot easier. You removed all lines which change the drawing color. Why?
Kokoro Kokoro

2017/2/6

#
well idk so :)) like i have this algorithm and it might broke the whole game ... danpost made the game demo so i thinked if he could just update it with what i requested so..
Super_Hippo Super_Hippo

2017/2/6

#
I think that you don't understand the code so far. Using someone else's code is by far not as satisfying as writing your own code and eventually make it work. It doesn't matter if you get some help with it, but if you end up with a working code that you don't understand, you did something wrong.
Kokoro Kokoro

2017/2/6

#
This are my last request to finish the game that boxes to be transparency and an special actor that shoots...
Super_Hippo Super_Hippo

2017/2/6

#
Go to the end of page 2. Danpost replied there relating to your box problems.
danpost danpost

2017/2/6

#
Kokoro wrote...
This are my last request to finish the game that boxes to be transparency and an special actor that shoots...
My last post ended up at the bottom of the last page. See here.
Kokoro Kokoro

2017/2/6

#
Ok got it with textboxes but what about the "actor" that shoots ? a different class a boss or like that?
Super_Hippo Super_Hippo

2017/2/6

#
If you want every enemy to shoot, just add it into the class code. If you want only some of them to shoot, you can add a variable into the class which saves if it can shoot or not. If it should act entirely different, create a different class.
danpost danpost

2017/2/6

#
Kokoro wrote...
what about the "actor" that shoots ? a different class a boss or like that?
Well create a subclass of Actor and name it Boss. Then add an 'if' statement in the act method that restricts the creating of bullets (code given earlier). You will have to add code to the act method of the class for anything else you might want the boss to do. If you run into specific problems, then post your current code and ask for help. Do not expect use to create the entire class for you.
Kokoro Kokoro

2017/2/7

#
Ok i will try
Kokoro Kokoro

2017/2/7

#
made an if or like that put the code u gave me earlier and... ofc an error... at Chaserbullet it says i need a ")" even if i add i jump in another 3x problems...
import greenfoot.*;

public class Boss extends Actor
{
    int dr = 0; // the current turn rate
    
    public Boss()
    {
        setBoundedAction(Lume1_2.actionType, Lume1_2.actionDistance); // set bound fields
        // create image for this actor
        
        GreenfootImage image = new GreenfootImage(30, 30);
        image.fillOval(0, 0, 30, 30);
        image.setColor(new java.awt.Color(224, 240, 255));
        image.fillOval(7, 7, 16, 16);
        setImage("1.png");
        
    }

    /**
     * turn and move actor
     */
    public void act()
    {
        int dx = 0, dy = 0; // the differences in locational coordinates
        int rate = 0; // the rate of turn and speed
        
        if ChaserBullet bullet = new ChaserBullet(); // adjust class name as needed
          {bullet.setRotation(getRotation());
           getWorld().addObject(bullet, getX(), getY());}
        

        Actor chased = Lume1_1.chased;
        if (chased != null && chased.getWorld() != null)
        { // set variable values
            dx = getX()-chased.getX();
            dy = getY()-chased.getY();
            rate = 400-(int)Math.abs(dx)-(int)Math.abs(dy);

        }

        if (rate > 100)
        { // chase
            // the next code line does what is described in the following commented lines
               // determine shortest turn direction to face chased
            // int angleDiff = getRotation()-(int)(Math.atan2(dy, dx)*180/Math.PI); // range: -359 to 359
            // int anglet = (angleDiff+360+180)%360-180; // range: -180 to 179 (sign is turn direction)
               // turn and move
            // turn(16*rate*(int)Math.signum(anglet)); 
            turn(16*rate*(int)Math.signum((getRotation()-(int)(Math.atan2(dy, dx)*180/Math.PI)+540)%360-180));
            move(rate/8, getQR()); // between 'move(0.1)' to 'move(0.4)' for a non-QActor, which is not possible
        }
        else
        { // wander
            // vary turn rate
            dr += 2-Greenfoot.getRandomNumber(5)-(int)Math.signum(dr);
            // limit turn rate to between 40 q-rotation units left and right
            if (dr < -40) dr = -40;
            if (dr > 40) dr = 40;
            // turn and move
            turn(dr);
            move(35);
        
        }
    }
}
Super_Hippo Super_Hippo

2017/2/7

#
It has to be:
if ( /*some condition*/ )
{
    //things to happen when condition is met
}
else //optional
{
    //things to happen when condition is not met
}
You can't just write an 'if' in the middle of your code expecting that it will know what you want.
Kokoro Kokoro

2017/2/7

#
  public void act()
    {
        int dx = 0, dy = 0; // the differences in locational coordinates
        int rate = 0; // the rate of turn and speed
        
        if (ChaserBullet bullet = new ChaserBullet())
       {
           bullet.setRotation(getRotation());
           getWorld().addObject(bullet, getX(), getY());

        }
       

        Actor chased = Lume1_1.chased;
        if (chased != null && chased.getWorld() != null)
        { // set variable values
            dx = getX()-chased.getX();
            dy = getY()-chased.getY();
            rate = 400-(int)Math.abs(dx)-(int)Math.abs(dy);

        }
Errot at "chasserbullet" invalid way to start the function or like that..
There are more replies on the next page.
1
2
3
4