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

2016/12/14

Collision

1
2
3
danpost danpost

2016/12/22

#
I guess you will have to move off of the intersecting objects individually. That would involve changing lines 7 through 13 to the something like the following:
for (Object obj : getIntersectingObjects(Actor.class))
{
    if (! (obj instanceof Box) || ((Box)obj).isThere)
    {
        while (intersects((Actor)obj))
        {
            setLocation(getX(), getY()-dir);
            if (vSpeed > 0) onSurface = true; // landing on surface
            vSpeed = 0; // kill speed
        }
    }
}
Nosson1459 Nosson1459

2016/12/22

#
Nosson1459 wrote...
danpost wrote...
move as directed horizontally and stop at obstacles
How was I directed, which obstacles do I stop at (I only want to stop at the boxes or blocks when isThere==true)? ...
danpost wrote...
This is totally without the Mover class.
The Mover class was used for seeing which actors and when to hit/collide, the above (your) code is for hitting mystery boxes (the code for hitting mystery boxes (by me) is in the Box class not Mover).
Where would I put the above code, in the jump() method for Pengu? And what about the effect of hitting the box, the item from inside coming out?
danpost danpost

2016/12/22

#
Nosson1459 wrote...
Where would I put the above code, in the jump() method for Pengu?
No. In the 'moveVertically' method I had just given. It should replace lines 7 -- NO! -- lines 8 through 13.
And what about the effect of hitting the box, the item from inside coming out?
That was dealt with at line 5.
danpost danpost

2016/12/22

#
Nosson1459 wrote...
How was I directed, which obstacles do I stop at (I only want to stop at the boxes or blocks when isThere==true)?
As directed means by user input (I presume that Pengu is your main character that the user will control). Code similar to what we just implemented in the 'moveVertically' method can be applied (but, not with the exact coding) within the 'moveHorizontally' method to accomplish the same thing.
Nosson1459 Nosson1459

2016/12/22

#
danpost wrote...
In the 'moveVertically' method I had just given.
What should I do with the moveVertically() method I just call it by if (Greenfoot.isKeyDown("up"))?
That was dealt with at line 5.
I got mixed up with the replacement code for lines 8 - 13 and line 5, similar ifs. How would the coding for moveHorizontally() go (with bumping into cliffs and solid blocks and boxes)?
Nosson1459 Nosson1459

2016/12/22

#
I tried using your code but I had a few problems:
  • The jumping is too fast and it looks unrealistic
  • Now Pengu can't move while in the air so he can only jump a few pixels (50 - 100) which isn't good for jumping over empty space
  • When Pengu hits a coin from the bottom he goes back down instead of collecting it and continuing to go up
  • When I hold down the up arrow key everything behaves differently then if I just press and then release it
So when I just press the up arrow key once he sort of floats up, but when I hold it down it's makes it difficult to control the Pengu. Pengu seems to collide with actors that I don't want him to collide with. IMPORTANT NOTICE: The Objects that I want Pengu to collide with are: Cliffs, solid Boxes and solid Blocks. The Box and Block class both extend Boxes and Boxes and Cliff both extend SideObjects. First I put your method in an isKeyDown if but then I realized you/I already had one so I took it out and now "The jumping is too fast and it looks unrealistic" even if/when I don't hold down the up arrow key.
Nosson1459 Nosson1459

2016/12/22

#
If I change the Actor.class to SideObjects.class then I'll fall through the platform. I can't make the Platform extend SideObjects because SideObjects extends SideScrollers which is used for sideScrolling when I'm on a platfrom so I don't want to side-scroll the platform. Platform extends SideScrollers1 which is for regular moving side-scrolling. So I want to land on:
  • Cliffs
  • Solid Boxes
  • Solid Blocks
  • Platforms
All those but nothing else (that's what all those onGround methods are for in Mover).
danpost danpost

2016/12/22

#
Nosson1459 wrote...
What should I do with the moveVertically() method I just call it by if (Greenfoot.isKeyDown("up"))?
No -- you call it unconditionally:
public void act()
{
    moveHorizontally();
    moveVertically();
    // other calls
}
How would the coding for moveHorizontally() go (with bumping into cliffs and solid blocks and boxes)?
Similar to the vertical movement -- except without jumping and activating boxes.
danpost danpost

2016/12/22

#
Nosson1459 wrote...
I tried using your code but I had a few problems: * The jumping is too fast and it looks unrealistic
It should not be any different than before (we did not change anything other than maybe slowing it down by one act cycle)
* Now Pengu can't move while in the air so he can only jump a few pixels (50 - 100) which isn't good for jumping over empty space
Show the 'moveHorizontally' method you are using.
* When Pengu hits a coin from the bottom he goes back down instead of collecting it and continuing to go up
We can add a 'while' loop before line 7 (before the code in the top post above):
while (isTouching(Coin.class))
{
    Scene scene = (Scene)getWorld();
    scene.score(100);
    scene.coins++;
    removeTouching(Coin.class);
}
* When I hold down the up arrow key everything behaves differently then if I just press and then release it So when I just press the up arrow key once he sort of floats up, but when I hold it down it's makes it difficult to control the Pengu.
Then something else is effecting Pengu (you are checking for the key elsewhere in your code). Did you remove the 'checkFall' and 'jump' methods from the Pengu class? (remove the calls from the act method also) You need to remove the 'coins' method and its call in the act, also.
danpost danpost

2016/12/22

#
Nosson1459 wrote...
If I change the Actor.class to SideObjects.class then I'll fall through the platform. I can't make the Platform extend SideObjects because SideObjects extends SideScrollers which is used for sideScrolling when I'm on a platfrom so I don't want to side-scroll the platform. Platform extends SideScrollers1 which is for regular moving side-scrolling. So I want to land on:
  • Cliffs
  • Solid Boxes
  • Solid Blocks
  • Platforms
All those but nothing else (that's what all those onGround methods are for in Mover).
You can remove the Mover class. You do not need the SideObjects class, either. You do not even need the SideScroller and SideScroller1 classes. You are going about scrolling the wrong way; there should be no need for two different types of scrolling. If you have a moving platform, then it (the platform) should check for object on top of it and move them with it. That way, they will be consistent with everything else for scrolling. The on ground state is taken into consideration in the code I gave for all objects as required.
danpost danpost

2016/12/22

#
Okay, I see that the Block objects need special attention as well, as far as possibly being invisible. Remove the following line from both the Box and Block classes:
public boolean isThere=true;
and place one copy of it in the Boxes class. Then change 'Box' to 'Boxes' in the 'for' loops of the movement codes:
if (! (obj instanceof Boxes) || ((Boxes)obj).isThere)
Nosson1459 Nosson1459

2016/12/23

#
I'll have to get back to this/you tomorrow, (but) I still have problems (naturally).
Nosson1459 Nosson1459

2016/12/26

#
danpost wrote...
Similar to the vertical movement -- except without jumping and activating boxes.
I can't figure out how to do it, but/because I don't really know what you did in the moveVertically() method.
Show the 'moveHorizontally' method you are using.
/**
 * Called in Pengu when right arrow key is pressed (and !touchingRightSide)
 */
public void moveRight()
{
    setLocation ( getX() + speed, getY() );
}

/**
 * Called in Pengu when left arrow key is pressed (and !touchingLeftSide)
 */
public void moveLeft()
{
    setLocation ( getX() - speed, getY() );
}
You do not even need the SideScroller and SideScroller1 classes. You are going about scrolling the wrong way; there should be no need for two different types of scrolling. If you have a moving platform, then it (the platform) should check for object on top of it and move them with it. That way, they will be consistent with everything else for scrolling.
The way you told me to do scrolling is:
// adjust position of all actors (that can move with 'setLocation') when the right arrow key is pressed
for (Object obj : getObjects(null))
{
    Actor actor = (Actor) obj;
    actor.setLocation(actor.getX()-7, actor.getY());
}
and then put
public void setLocation(int x, int y) {}
in all the Actors that I don't want to scroll. But you didn't tell me what to do with pengu (see here), so I figured out a way to move only the things that I want (as you can see from the world code in this discussion) by ectending all those actors from a specific one. By the platform I don't want the platform to move when I'm on it, because then I'm limited to a space the size of my scenario width, what's supposed to happen (what I want to happen which it does the way I coded it with the SideScrollers Actors) is that when I'm on the platform all the sideScroller Actors besides for the platform (and Pengu) are supposed to move back and forth with switching direction when the platform and Box/Block/Cliff collide.
The on ground state is taken into consideration in the code I gave for all objects as required.
Right now the Pengu doesn't touch anything (isn't standing on it) so when I try to squish a monster it doesn't get squished because the Pengu is a few pixels above it and the code for the squishing is in Monster so it doesn't detect the Pengu (because of your coding). When I walk into an Actor instead of bumping into it which my touchingRightSide methods are supposed to do I just collide with it then appear on top of it even though the touchingRightSide methods are still active and I'm not using any other type of moveHorizontally method (yet). Now When I jump on a coin (or shooting which I did the same thing as coin since it's also a method in pengu) instead of going straight through it and collecting the coin, I bounce off them (onSurface==true) and collect the coin, if I move the code into the Coin class then it doesn't get collected at all (as mentioned above) because the Pengu isn't actually touching it, so I can't do if or while isTouching.
danpost danpost

2016/12/26

#
Nosson1459 wrote...
I can't figure out how to do it, but/because I don't really know what you did in the moveVertically() method.
What I meant was to add the collision detection to the horizontal movement as well. I will get back to this issue at the end of this post.
The way you told me to do scrolling is: < Code Omitted > and then put
public void setLocation(int x, int y) {}
in all the Actors that I don't want to scroll. But you didn't tell me what to do with pengu (see here), so I figured out a way to move only the things that I want (as you can see from the world code in this discussion) by ectending all those actors from a specific one. By the platform I don't want the platform to move when I'm on it, because then I'm limited to a space the size of my scenario width, what's supposed to happen (what I want to happen which it does the way I coded it with the SideScrollers Actors) is that when I'm on the platform all the sideScroller Actors besides for the platform (and Pengu) are supposed to move back and forth with switching direction when the platform and Box/Block/Cliff collide.
As far as the moving platform with Pengu on it -- you are looking at it all wrong. As long as the platform moves the Pengu object with it, the change in the Pengu object will cause a scrolling that will place both the platform and the Pengu object back at center. The result is no change in location for either (as if not moving -- but both moving and scrolling).
Right now the Pengu doesn't touch anything (isn't standing on it) so when I try to squish a monster it doesn't get squished because the Pengu is a few pixels above it and the code for the squishing is in Monster so it doesn't detect the Pengu (because of your coding).
This can be dealt with in the same way as the platform checks for the Pengu when it moves. This can also wait till the end of this post.
When I walk into an Actor instead of bumping into it which my touchingRightSide methods are supposed to do I just collide with it then appear on top of it even though the touchingRightSide methods are still active and I'm not using any other type of moveHorizontally method (yet).
Your horizontal moving code will be replaced soon enough. Just wait.
Now When I jump on a coin (or shooting which I did the same thing as coin since it's also a method in pengu) instead of going straight through it and collecting the coin, I bounce off them (onSurface==true) and collect the coin, if I move the code into the Coin class then it doesn't get collected at all (as mentioned above) because the Pengu isn't actually touching it, so I can't do if or while isTouching.
This, as well as the other issues I said could wait till the end of this post can be checked out by looking at my Sample Platformer scenario. Notice the horizontal and vertical movement codes in the Man class, how the coins are collected in each one and the boxes are activated in the vertical movement code; how the Platform class moves the Man object (by moving up one pixel before checking for the Man object; then, moving back down that one pixel -- which enemies can also do to check for being squished. Notice, also, how simple the scrolling code in the World subclass is. The code within the sample scenario can be used as a starting point for what you are trying to do (the only thing missing, I think, is animating the actor(s) and setting of specific box types (which I gave a starting point for; but did random generating of type and used a Coin object to display which type was given it. If nothing else, you will see that it runs pretty much the way you want yours to.
danpost danpost

2016/12/26

#
Nosson1459 wrote...
(comment on Sample Platformer) It looks like you uploaded this just for me :)
I did reference it above. If you wish me to apply more things that you require in yours, just ask. I will, however, be updating it occasionally with added features.
There are more replies on the next page.
1
2
3