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

2022/8/24

how to avoid two object in same place when using random greenfoot

vbh vbh

2022/8/24

#
Hi im trying to add 4 different object my goal is to avoid object at the edge and not in same place, i have tried different methods but haven't found a solution hope someone can help My bacis addObject method world width and height: 900 - 700 public void createObjects() { for(int i = 0; i<=3;i++) { addObject(new SurpriseA_bomb(), Greenfoot.getRandomNumber(400)+50, Greenfoot.getRandomNumber(300)+50); } for(int i = 0; i<=3;i++) { addObject(new SurpriseM_bomb(), Greenfoot.getRandomNumber(800)+50, Greenfoot.getRandomNumber(600)+50); } for(int i = 0; i<3;i++) { addObject(new SurpriseA(), Greenfoot.getRandomNumber(400)+50, Greenfoot.getRandomNumber(300)+50); } for(int i = 0; i<3;i++) { addObject(new SurpriseM(), Greenfoot.getRandomNumber(800)+50, Greenfoot.getRandomNumber(600)+50); } addObject(new Ball(), getWidth()/2, getHeight()/2); }
danpost danpost

2022/8/24

#
vbh wrote...
Hi im trying to add 4 different object my goal is to avoid object at the edge and not in same place,
My Snake Trapper scenario has my XWorld class. It;s an extension of the World class that provides multiple helper methods. It contains just what you need, but it is split up into parts due to factorization. You will need to look at (1) addObjectInside(XActor, x, y, x2, y2, overlapAllowed) -- (XActor can be replaced with Actor in your case) (2) range(min, max) (3) random(chance)
vbh vbh

2022/9/30

#
thanks, is it possibel you can show me your code?
danpost danpost

2022/10/2

#
vbh wrote...
thanks, is it possibel you can show me your code?
Run scenario and click on buttons at bottom of scenario window to view codes.
You need to login to post a reply.