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

2019/10/21

Making objects fall in a certain area

vysh vysh

2019/10/21

#
Hi, I was wondering how I could make objects fall in a certain area. My objects are bombs, and they have their own Bomb class. How do I make them fall in a certain area/range on the screen? Thanks! (Edit: I forgot to mention I also want to have a button that when the user clicks it, a bomb will drop. Thats how I want the bombs to drop. How should I approach this?)
danpost danpost

2019/10/21

#
vysh wrote...
Hi, I was wondering how I could make objects fall in a certain area. My objects are bombs, and they have their own Bomb class. How do I make them fall in a certain area/range on the screen?
How do they move? What range are you cconsidering? What have you tried?
I also want to have a button that when the user clicks it, a bomb will drop. Thats how I want the bombs to drop. How should I approach this?)
Let your world check for button click and add bombs into itself. (you can have an act method in your World subclass).
vysh vysh

2019/10/21

#
The bombs fall straight down from the "sky" and my ideal range was actually on two sides, one small area on the leftmost screen and one on the rightmost! I think I know how to make them fall, I just don't know how to have them activated on both areas(or placed in both areas to fall from the sky
danpost danpost

2019/10/21

#
vysh wrote...
The bombs fall straight down from the "sky" and my ideal range was actually on two sides, one small area on the leftmost screen and one on the rightmost! I think I know how to make them fall, I just don't know how to have them activated on both areas(or placed in both areas to fall from the sky
Okay. Let me presume your world to have a width of 600 and you want the bombs to fall within 100 of either side edge. The range would therefore be 200 and the starting point for spawning would be at 500 (applying wrap-around). A random x-coordinate for spawning will then be:
int spawnX = (500+Greenfoot.getRandomNumber(200))%600;
.....................................^start........^range......................................^wrap
vysh vysh

2019/10/21

#
Thank you lord danpost :D ! I'll try this out!
You need to login to post a reply.