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

2020/2/29

remove an intersecting object

1
2
Claudiu Claudiu

2020/2/29

#
hi. when i use Actor bus = getOneIntersectingObject(masina2.class); getWorld().removeObject(bus); it doesn t remove instantly .. it removes when another masina2 object is intersecting with the bus
Claudiu Claudiu

2020/2/29

#
HELPPPPP
danpost danpost

2020/2/29

#
Claudiu wrote...
HELPPPPP
Please show entire class code for review.
Claudiu Claudiu

2020/2/29

#
i solved it.. now i need smth else... i add 7 car at the beginning of game and then when it is at the middle of world i wanna add another 7 seven cars but it adds double cars like 14....
Claudiu Claudiu

2020/2/29

#
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.List; import java.util.ArrayList;/** * Write a description of class masina2 here. * * @author (your name) * @version (a version number or a date) */ public class masina2 extends Actor { /** * Act - do whatever the masina2 wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public boolean atMiddleWorld() { if(getY()>290&&getY()<300) { return true; } else { return false; } } public void act() { setLocation(getX(),getY()+3); // if(atMiddleWorld()==true) if(getY()>290&&getY()<300) { World W = getWorld(); int y=2; int x= Greenfoot.getRandomNumber(600); W.addObject(new masina2(),x,y); } if(isTouching(bus.class)) getWorld().removeObject(this); } }
Claudiu Claudiu

2020/2/29

#
and how should i do it combined with the condition checking if it is at the middle of the world?
danpost danpost

2020/2/29

#
Your cars only move 3 cells at a time. Limit the spawning to a range of 3. Use:
if (getY() >= 299 && getY() < 302)
danpost danpost

2020/2/29

#
Claudiu wrote...
and how should i do it combined with the condition checking if it is at the middle of the world?
I deleted my initial post (ignore what it had said).
Claudiu Claudiu

2020/2/29

#
it doesnt work:(( it still doubles the number of cars every rime...
danpost danpost

2020/2/29

#
Claudiu wrote...
it doesnt work:(( it still doubles the number of cars every rime...
Where did you make the change? Show revised class code (entire class).
Claudiu Claudiu

2020/2/29

#
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.List; import java.util.ArrayList;/** * Write a description of class masina2 here. * * @author (your name) * @version (a version number or a date) */ public class masina2 extends Actor { /** * Act - do whatever the masina2 wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public boolean atMiddleWorld() { if(getY()>290&&getY()<300) { return true; } else { return false; } } public void act() { setLocation(getX(),getY()+3); // if(atMiddleWorld()==true) if(getY()>290&&getY()<302) { World W = getWorld(); int y=2; int x= Greenfoot.getRandomNumber(600); W.addObject(new masina2(),x,y); } if(isTouching(bus.class)) getWorld().removeObject(this); } }
danpost danpost

2020/2/29

#
You copied incorrectly. You only copied the last value.
Claudiu Claudiu

2020/2/29

#
THANKS A LOTTTT. it kinda works... ih hope you will still help me if i have any questions anymore
danpost danpost

2020/2/29

#
Claudiu wrote...
THANKS A LOTTTT. it kinda works... ih hope you will still help me if i have any questions anymore
I may be not answer immediately; but, Lord willing, I will respond sooner or later.
Claudiu Claudiu

2020/2/29

#
can you tell me how can i detect a collision like when masina hits masina2 and how can i stop the game and write game over... PLSSS it s for a school project
There are more replies on the next page.
1
2