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

2017/12/9

update the height of stacked objects

spaceleaf spaceleaf

2017/12/9

#
hello i'm a beginner in programming and i have this stacking game which of course the height (accumulated height from the actors previously stacked) will continue to be updated as long as another object (actor) keeps being added to the existing stack (of actors previously stacked), so then i can end the game when a certain height is reached. question is, how can i do this? sorry if my explanation is a bit messy
danpost danpost

2017/12/9

#
At the moment when an actor is placed on a stack, you can test the height by subtracting half the height of its image from the y-coordinate of its location. If this value is equal to or less than some limiting y-coordinate value of the world, end the game.
spaceleaf spaceleaf

2017/12/9

#
ok i kinda understand that... but actually i'm still confused how do i check when an actor is placed on the stack? do i use getOneIntersectingObject? i've been using isTouching to pile up the actors. here's my code--it's in the stuff class:
1
2
3
4
if(isTouching(Plate.class) || isTouching(Stuff.class)) {
            vSpeed = 0;
            setLocation(plateX, getY());
        }
danpost danpost

2017/12/9

#
I do not know the movement of the actor(s) or what moves them. I do not know how accurate you want to be in the placement of the objects. All I know is you are trying to limit how high the actors stack and, now with your last post, I am presuming that the placed actor is to align horizontally with a Plate object (which it may or may not be touching). Maybe you can give a synopsis of what you want to happen and how -- so any answer given is an informed one.
You need to login to post a reply.