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

2014/6/15

Falling Blocks

TallMidget TallMidget

2014/6/15

#
So I'm working on a platformer game and I had the idea to add falling blocks on one of the levels. By "falling blocks" I mean they look like any other ground block in the game, but when you step on it, it would fall from underneath you. I've tried a couple of different things but I can't seem to get it to work properly. Any help would be greatly appreciated. This is what I have right now : private int vSpeed = 5; private int acceleration = 1; public void act() { checkDrop(); Drop(); } public boolean checkDrop() { Actor Lemur = getOneIntersectingObject(Lemur.class); if (Lemur == null) { return false; } return true; } public void Drop() { if (checkDrop() == true) { this.setLocation (getX(), getY() + vSpeed); vSpeed = vSpeed + acceleration; } }
CooliMC CooliMC

2014/6/15

#
I would do it like this : if Lemur is the Actor you move with :
private int vSpeed=5;
private int acceleration
private Boolean startfalling=false;
public void act()
{
Actor Lemur = (Lemur)getOneIntersectingObject(Lemur.class);
if(Lemur!=null)
{
startfalling=true;
}
if(startfalling==true)
{
setLocation(getX(),getY()+vSpeed);
vSpeed=vSpeed+accleration;
}
}
if you are german because of Lemur : Wenn du Deutscher bist wegen Lemur :D erklär ich dir hier nochmal was ich gemacht hab, also es wird überprüft ob der Stein einen Lemuren berührt wenn ja wird ein Booleean auf ja gesezt und wenn des ja is fällt der stein herunter , dein problem war , dass er nur gefallen ist wenn er den Lemur berührt hat und sobal der dann ein stück weiter unten war war kein lemur mehr da und er hat gestoppt :D Hoffe ich konnte dir helfen Hope i could help you
TallMidget TallMidget

2014/6/17

#
This works great, thank you very much! You helped me a lot, and by the way I'm not German, the "Lemur" class is there because it is from a school project, but I think it's awesome that you did that to help because it's the thought that counts. Thanks again :D
CooliMC CooliMC

2014/6/19

#
No Problem :D
You need to login to post a reply.