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

2016/5/20

Collision Distance

Ty1erH00ven Ty1erH00ven

2016/5/20

#
I started a Flappy Bird type game with 3 levels. On one level there is an image very similar to this on > Mario Pipe <. The bird is dying when it touches that top left corner of the image. The transparent pixels are killing the bird, and this is making it "Greenfoot.stop();" when the bird is obviously not touching the creature or pipe. I don't have the code at the moment but all it is is "if (isTouchingBluePipe)){ Greenfoot.stop(); Greenfoot.removeTouching(this); } This is in the bird class. Any ideas on how to make the touch detection pixel perfect, if not very close?
SPower SPower

2016/5/20

#
Busch2207 made a pixel-perfect collision detection scenario a while back, perhaps you could look at it.
danpost danpost

2016/5/20

#
Ty1erH00ven wrote...
Greenfoot.removeTouching(this);
There is no 'removeTouching' method in the Greenfoot class. This should not compile. When posting code: (1) please use code tags (see the link 'Posting code? read this!' below the reply box); (2) copy/paste the actual code so we can see what you actually have;
Ty1erH00ven Ty1erH00ven

2016/5/20

#
Danpost, my apologies, I wasn't on the computer with that stuff. Here is the actual code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/**
     * Act - do whatever the Bird wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()
    {
        checkKeys();
        checkFall();
        
 <Some Code Emitted>
 
        if(isTouching(BluePipeLongUD.class))
        {
            Level2 myWorld = (Level2)getWorld();
            myWorld.addScore(-100);
        }
    }
Ty1erH00ven Ty1erH00ven

2016/5/20

#
SPower wrote...
Busch2207 made a pixel-perfect collision detection scenario a while back, perhaps you could look at it.
I looked at it and the "Toucher" is a subclass of "Collision." The issue is, I already have my "Bird" class as a subclass of "Mover" in order to make it jump.
SPower SPower

2016/5/20

#
You could make Mover a subclass of Toucher, then, to avoid the issue (although that's only possible if Toucher is also ultimately a subclass of Actor - it's been a while since I looked at the source code of that project).
Ty1erH00ven Ty1erH00ven

2016/5/20

#
SPower wrote...
You could make Mover a subclass of Toucher, then, to avoid the issue (although that's only possible if Toucher is also ultimately a subclass of Actor - it's been a while since I looked at the source code of that project).
Would it be possible for me to post the game and you can take a look at it?
SPower SPower

2016/5/20

#
I don't really see the need to, honestly. The line which says this:
1
public class Mover extends Actor
You could simply change to:
1
public class Mover extends Toucher
After you've copied the classes.
Ty1erH00ven Ty1erH00ven

2016/5/20

#
SPower wrote...
I don't really see the need to, honestly. The line which says this:
1
public class Mover extends Actor
You could simply change to:
1
public class Mover extends Toucher
After you've copied the classes.
That's what I did. Its Collision extends Mover and Bird extends Mover.
SPower SPower

2016/5/20

#
Now having looked at the code, I see that you should make it a subclass of Collision, not Toucher (Toucher is simply a demo class). You then need to use the getTouchedObjects method to check the collision (the Toucher class shows how to use it).
Ty1erH00ven Ty1erH00ven

2016/5/20

#
Could you further explain? Minor brain fart on that
SPower SPower

2016/5/20

#
In the Mover class:
1
public class Mover extends Collision
In the class doing the collision:
1
2
3
4
5
6
7
public void act()
{
    // stuff
    if (getOneTouchedObject(BluePipeLongUD.class) != null) {
        // stuff
    }
}
Ty1erH00ven Ty1erH00ven

2016/5/20

#
Oh okay. I'll try it out when I get the chance
Ty1erH00ven Ty1erH00ven

2016/5/23

#
SPower wrote...
In the Mover class:
1
public class Mover extends Collision
In the class doing the collision:
1
2
3
4
5
6
7
public void act()
{
    // stuff
    if (getOneTouchedObject(BluePipeLongUD.class) != null) {
        // stuff
    }
}
This worked great! Thank you so much!
You need to login to post a reply.