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

2022/11/12

Create border where object bounds off

N8TH1N6 N8TH1N6

2022/11/12

#
Hello, I want to make a specific "border" at a certain area where the cpu bounces off. Here is a image of the world https://ibb.co/X2L2WMr The gray are in the middle is the are where everything caped. You should not move over the playable area. Also the cpu when it touches this area should bounce of and turn like with this code
if (amRand()) {drehe(95);}
the "amRand" only checks the whole world and not the gray area . So how can I do that Best
danpost danpost

2022/11/13

#
N8TH1N6 wrote...
Hello, I want to make a specific "border" at a certain area where the cpu bounces off. Here is a image of the world << Link Omitted >> The gray are in the middle is the are where everything caped. You should not move over the playable area. Also the cpu when it touches this area should bounce of and turn like with this code << Code Omitted >>
Probably, the best way is to create a new type actor and add it over the gray area and check for collisions with it.
N8TH1N6 N8TH1N6

2022/11/13

#
danpost wrote...
N8TH1N6 wrote...
Hello, I want to make a specific "border" at a certain area where the cpu bounces off. Here is a image of the world << Link Omitted >> The gray are in the middle is the are where everything caped. You should not move over the playable area. Also the cpu when it touches this area should bounce of and turn like with this code << Code Omitted >>
Probably, the best way is to create a new type actor and add it over the gray area and check for collisions with it.
How do I check the colision?
danpost danpost

2022/11/14

#
N8TH1N6 wrote...
How do I check the colision?
Well, let us say you named your transparent collision actor GrayArea, then:
if (isTouching(GrayArea.class))
{
    turn(95);
}
should do.
N8TH1N6 N8TH1N6

2022/11/14

#
danpost wrote...
N8TH1N6 wrote...
How do I check the colision?
Well, let us say you named your transparent collision actor GrayArea, then:
if (isTouching(GrayArea.class))
{
    turn(95);
}
should do.
Thanks
N8TH1N6 N8TH1N6

2022/11/14

#
danpost wrote...
N8TH1N6 wrote...
How do I check the colision?
Well, let us say you named your transparent collision actor GrayArea, then:
if (isTouching(GrayArea.class))
{
    turn(95);
}
should do.
Now I got the problem that my player class when he runs into it I set the walking speed to 0 but than the controls doesnth work. Is there another way to stop the player when he touches the the barrier and make him stop moving?
danpost danpost

2022/11/15

#
N8TH1N6 wrote...
Now I got the problem that my player class when he runs into it I set the walking speed to 0 but than the controls doesnth work. Is there another way to stop the player when he touches the the barrier and make him stop moving?
Show relevant codes (class of the player).
N8TH1N6 N8TH1N6

2022/11/16

#
danpost wrote...
N8TH1N6 wrote...
Now I got the problem that my player class when he runs into it I set the walking speed to 0 but than the controls doesnth work. Is there another way to stop the player when he touches the the barrier and make him stop moving?
Show relevant codes (class of the player).
Movemwnt
boolean w = Greenfoot.isKeyDown("w");
        boolean a = Greenfoot.isKeyDown("a");
        boolean s = Greenfoot.isKeyDown("s");
        boolean d = Greenfoot.isKeyDown("d");
        detectMove = false;
        if (w == true)
        {
            drehe(4);
            detectMove = true;
        }

        if (a == true)
        {
                rw();
                detectMove = true;
            
        }

        if (s == true)
        {
            drehe(-4);
            detectMove = true;
        }

        if (d == true)
        {
                vw();
                detectMove = true;
        
        }
How the movement works:
double winkel = Math.toRadians( getRotation() );
        int x = (int) Math.round(getX() + Math.cos(winkel) * LAUFGESCHWINDIGKEIT);
        int y = (int) Math.round(getY() + Math.sin(winkel) * LAUFGESCHWINDIGKEIT);
        
        setLocation(x, y);
danpost danpost

2022/11/17

#
N8TH1N6 wrote...
Movemwnt << Code Omitted >> How the movement works: << Code Omitted >>
Where is the code setting speed to zero? and, how is the speed declared within the class? (show codes)
N8TH1N6 N8TH1N6

2022/11/17

#
the speed is the movemnt I already send an the speed to zero was the same check for the border just set the LAUFGESCHWINDIGKEIT to 0 normaly it is set to 5
danpost danpost

2022/11/18

#
N8TH1N6 wrote...
the speed is the movemnt I already send an the speed to zero was the same check for the border just set the LAUFGESCHWINDIGKEIT to 0 normaly it is set to 5
The speed should not be set to zero unless you want to freeze the actor at that spot. You are not trying to stop the actor from moving -- just stop it from moving over the gray area or the border. Just revert any movement on act steps where the gray area or a border is intersected. After line 30 above, check for collision with gray area or border and in the event collision occurs, undo the previous movements in the reverse order as they were originally done.
N8TH1N6 N8TH1N6

2022/11/18

#
danpost wrote...
N8TH1N6 wrote...
the speed is the movemnt I already send an the speed to zero was the same check for the border just set the LAUFGESCHWINDIGKEIT to 0 normaly it is set to 5
The speed should not be set to zero unless you want to freeze the actor at that spot. You are not trying to stop the actor from moving -- just stop it from moving over the gray area or the border. Just revert any movement on act steps where the gray area or a border is intersected. After line 30 above, check for collision with gray area or border and in the event collision occurs, undo the previous movements in the reverse order as they were originally done.
Perfect, thank you very much
N8TH1N6 N8TH1N6

2022/11/18

#
danpost wrote...
N8TH1N6 wrote...
the speed is the movemnt I already send an the speed to zero was the same check for the border just set the LAUFGESCHWINDIGKEIT to 0 normaly it is set to 5
The speed should not be set to zero unless you want to freeze the actor at that spot. You are not trying to stop the actor from moving -- just stop it from moving over the gray area or the border. Just revert any movement on act steps where the gray area or a border is intersected. After line 30 above, check for collision with gray area or border and in the event collision occurs, undo the previous movements in the reverse order as they were originally done.
I also got some other entities I added but when I spawn them with this code
for (w=0; w<5; w++) {
                int x = Greenfoot.getRandomNumber(600);
                int y = Greenfoot.getRandomNumber(600);
                addObject( new Wurm(), x, y);
They dont spawn in the gray area I tried to move them diagonily in the middle but dont really know how
danpost danpost

2022/11/20

#
N8TH1N6 wrote...
I got some entities I added but when I spawn them with this code << Code Omitted >> They dont spawn in the gray area I tried to move them diagonily in the middle but dont really know how
If you know the size of the gray area, call it gas (for gray area size), then use:
int x =(getWidth()-gas)/2+Greenfoot.getRandomNumber(gas);
int y = (getHeight()-gas)/2+Greenfoot.getRandomNumber(gas);
If the size of the gray area is immutable, then you can just use the value itself (instead of a variable name, which would need to be declared and set to the appropriate value).
You need to login to post a reply.