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

4 days ago

Problem with walls in window

RevoltecX7 RevoltecX7

4 days ago

#
Hi there, I want ask you guys, how you can solve this - when I have Player and this player can create the bullet with speed 2 and more(like move(2) etc.). And this bullet has some % chance to don't check window wall, if I go throw that or not - wall = window (like size of the window-game). How u guys tell the bullet, if I have window size x = 600, to remove itself when I will reach 600+ x position? Sorry for my eng. but hope it's full understable.
CompCampGuy CompCampGuy

4 days ago

#
In the act function of your bullet object, have an if statement to check if the x value is either below 0 (The left wall) or over 600 (The right wall). I think the statement should look like if(getX() =< 0) and if(getX() => 600).
RevoltecX7 RevoltecX7

4 days ago

#
Yea.. I know this way to solve this. But when I have like a lot of objects? (Like 5 enemies with different speed/roration, bullets with speed-changable speed, etc etc etc..) That's why I am asking. If there is any way, to solve this. :) I have idea about - what if I will put around the space some block- what will delete all, what will contact with it. Sooo, how should I do that? How can some wall remove any object when it will be in contact? Is there any public function for it? Like (stupid example ->) if(isTouch(ANYOBJECT)) {remove it}
RevoltecX7 RevoltecX7

3 days ago

#
Someone?
Yehuda Yehuda

3 days ago

#
Put the following if-statement in the Bullet's act method:
if (getX() >= getWorld().getWidth()) getWorld().removeObject(this);
Reply if this is not what you're looking for (or even if it is what you were looking for).
Super_Hippo Super_Hippo

2 days ago

#
Your "stupid example" is:
if (isTouching(A.class)) removeTouching(A.class);
or even just
removeTouching(A.class);
if you don't need the condition for something else. But I am not sure what exactly you want.
RevoltecX7 RevoltecX7

2 days ago

#
I know guys and thanks. But I mean if there anywhere exist something like: U will put some condition/function in World class what will check, when any object will go over 600 x position, it will remove itself. So what I am trying to ask you guys is - how to not use in every object(actor) condition:
if(getX()>600){getWorld().removeBoject(this);} 
But just put 1 contidion/function in world for check actors. So - u will not use 5 the same code in every actor what u will need, but just in world some function. And I am asking if there is any function or no, or even it can be real or not. :)
Super_Hippo Super_Hippo

2 days ago

#
Well, you could do that in your world:
    public void act()
    {
        for (Actor a : getObjects(Actor.class))
        {
            if (a.getX() > getWidth()) removeObject(a);
        }
    }
RevoltecX7 RevoltecX7

2 days ago

#
Yeee, this exactly I was finding! Thank you so much :)
You need to login to post a reply.