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

2012/5/15

Collision Detection

dlanni dlanni

2012/5/15

#
I can't figure out where to add " y=y+getHeight()/2". My col. det. is in class Lana. I even added a getHeight method because I kept on getting error messages. Where can I do the y adjustment? I put all my obstacles in seperate classes cause they had diff. images and locations, although I am going to try again to have them be obstac1,2 and 3, so that I canSee(obstac.clss). Will that work? I will post code next --called Final Project.
danpost danpost

2012/5/15

#
You apparently do have some collision detection working (for Walls and Wall2 objects); though that is not the easiest way to go about it (copying the same image over the top of itself, to get Actors to be detected).
danpost danpost

2012/5/15

#
You apparently do have some collision detection working (for Walls and Wall2 objects); though that is not the easiest way to go about it (copying the same image over the top of itself, to get Actors to be detected). A better way is to create one object called Obstacle or Barrier; but, and this is the neat thing, make it an invisible object (just a black images to cover all the points on the screen the woman is not allowed to go). This way, you have only one object type to check for. There were two things I found that could be easily improved. One is that right now the door only opens (we can make it open and close). The other is, if you click on the radio multiple times, the music starts multiple times (another easy fix -- we will make it turn on AND off).
// For the Door class code
 // add the following to your instance variables
// this will allow for opening AND closing the door
private boolean opened = false;
// change the checkKeyPress method to the following
public void checkKeyPress()
{
    if (Greenfoot.mouseClicked(this))
    {
        Greenfoot.playSound("door-open-7.wav");
        // the next statement will allow the sound to process some
        // before the action of the door is seen
        Greenfoot.delay(20);
        // here we change the state of the door
        opened = !opened
        // and now set the appropriate image
        if (!opened) setImage(image1);
        else setImage(image2);
    }
}
// for the Radio class
// the complete class code follows
import greenfoot.*; 

public class Radio extends Actor
{
    // we save the GreenfootSound object in an instance variable (aka: object field)
    GreenfootSound gs = new GreenfootSound("Animal Crossing - K.K. Aria.mp3");

    public void act()
    {
        if (Greenfoot.mouseClicked(this))
        {
            if (!gs.isPlaying()) gs.play();
            else gs.stop();
        }
    }
}
BTW, got a kick out of the song!
danpost danpost

2012/5/15

#
Check out my new scenario 'Barriers and Bars'. Download and look at the code; maybe you could get some ideas.
dlanni dlanni

2012/5/16

#
As always Dan, thanks a zillion! I couldn't bring myself to use the KK song cause I like this one of his so much better. I pulled a photo of Kazumi Totaka off the web and am going to put it as one of the paintings in the house.
dlanni dlanni

2012/5/16

#
Danpost--I looked all over for your Barriers and Bars. Where is it?
danpost danpost

2012/5/16

#
I do not know how you could miss it! Go to the home page, look underneath this comment, look to the right under 'Latest Scenarios', go to my page and look through my scenarios. Look in 'Scenarios' (just Updated). Go here.
You need to login to post a reply.