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

2014/11/21

Character Selection Game

1
2
3
4
danpost danpost

2014/12/9

#
joanne_wm wrote...
Since I wanted to make the characters eat "SuperCandy.class", I entered the code into every single character < Code Omitted > Yep, and some of the characters say that they can't find the symbol.
The 'canSee' and 'eat' methods are part of the Animal class. You may have some of your actor class that you put this code in extending it and others not. Unless you are using an old version of greenfoot, you can replace 'canSee' with 'isTouching' and you can replace 'eat' with 'removeTouching'.
So regarding the code you gave me above < Code Omitted > so i know where the problem is, and it says that the size given does not match with the size in the actor. I tried solving it by changing the numbers in the code above, but if I want to resize it, which row below is the one to change? < Code Omitted >
The images of the Selector objects are just resized copies of the images of the actors. They do not have to be the same size. When you say 'it says that the size given does not match with the size in the actor', what is telling you that? exactly (copy/paste) what message were you getting?
one more thing
I will need to see your L4_SpaceWorld code to see how you were using the 'int' value that was previously being brought in by the selection process to determine how to implement the actual actor being brought in.
joanne_wm joanne_wm

2014/12/10

#
Thanks for the first one, I got that one there. For the second one, I actually have solved the problem so I think I'm fine with that. Just if you need to know, since I solved it I can't find the error code, but it was something like this {Size does not match with ---- (basically the size in the actor code)} So what happened is that for example in the SelectionWorld, an actors size was set to (500, 1000), but in the actor itself, it was set to (1.1). I adjusted it so its fine now. Here is the L4_SpaceWorld code.
import greenfoot.*;  // (Actor, World, Greenfoot, GreenfootImage)

public class L4_SpaceWorld extends World
{
     private CountdownClock timer;
     private GreenfootSound backgroundMusic = new GreenfootSound("행복 Happiness.mp3");
     private int Charselect;  
  
public int setCharselect(int x)     
{      
    Charselect = x;      
    return Charselect;      
}   

    /**
     * Create the space world (the universe). Our world has a size 
     * of 900x600 cells, where every cell is just 1 pixel.
     */
       public L4_SpaceWorld() 
    {
        super(560, 560, 1);
        //etc. backgroundMusic.playLoop();
        
        prepare();
        
        setPaintOrder(CountdownClock.class,SuperCandy.class);
    }
    
     /**
     * Prepare the world for the start of the program. That is: create the initial
     * objects and add them to the world.
     */
    private void prepare()
    {       
        timer = new CountdownClock(60);
        
        addObject(timer, 60, 45);
        
        
        addRandomSuperCandy(10);
    }
    
   
    private void addRandomSuperCandy(int howMany)
   {
       int i;
       for (i=0; i < howMany; i++)
       {
           addObject(new SuperCandy(), 200 + Greenfoot.getRandomNumber(getWidth() - 200),
                       100 + Greenfoot.getRandomNumber(getHeight()) - 200);
        }
   }
   
 public void act()
    {
        if (timer.getCounter() <= 0)
        {
       Greenfoot.stop();  
    }
    
    {if (Greenfoot.isKeyDown("A")) 
   Greenfoot.setWorld(new LB_HeavenWorld()); 
}

if (timer.getCounter() <= 0)
        {
            gameOver("Oh no! You ran out of time!");
        }
        
         java.util.List SuperCandys = getObjects(SuperCandy.class);
        if (SuperCandys.isEmpty())
        {
            gameOver("You win\nAll candies eaten. Press 'A' to go to the next level.");
     
       }
    }
  
    public void gameOver(String msg)
    {
        PopUpMessage popup = new PopUpMessage(msg);
        addObject(popup, getWidth() / 2, getHeight() / 2);
        Greenfoot.stop();
    }
}
So since the selection process is incomplete, I guess its normal for the code:
if (Greenfoot.mouseClicked(this))  
        {  
            L4_SpaceWorld spaceWorld = new L4_SpaceWorld();  
            spaceWorld.setSelection(selection);  
            Greenfoot.setWorld(spaceWorld);  
        }  
to have the 'setSelection' undefined.
danpost danpost

2014/12/10

#
Oh. You are not yet even using the 'int Charselect field. You do not even have any code to add the actor that is to eat the candy in the class. Replace the 'setCharselect' method (lines 7 through 13) with the following method:
public void setSelection(Actor selected)
{
    addObject(selected, 50, 540);
}
That should be a starting point, at least.
joanne_wm joanne_wm

2014/12/10

#
ok, now half of the game errors is solved. There is one final one here: regarding the code to prepare the characters in the SelectionWorld
 addObject(new Selector(new 'randomname'()), 80, 100); 
it said cannot find symbol class 'selector' {which is referring to the new 'Selector' selector} so here's the character code:
  Actor selection;  
  
    public Taeyeon(Actor actor)  
    {  
        selection = actor;  
        GreenfootImage img = new GreenfootImage(actor.getImage());  
        GreenfootImage text = new GreenfootImage(actor.getClass().getName(), 24, null, null);  
        GreenfootImage image = new GreenfootImage(80, 100);  
        img.scale(80, 80);  
        image.drawImage(img, 0, 0);  
        image.drawImage(text, 40-text.getWidth()/2, 76);  
        setImage(image);  
    }  
public void act()
{

 if (Greenfoot.mouseClicked(this))  
        {  
            L4_SpaceWorld spaceWorld = new L4_SpaceWorld();  
            spaceWorld.setSelection(selection);  
            Greenfoot.setWorld(spaceWorld);  
        }      
    }
so what's wrong with it?
danpost danpost

2014/12/10

#
Looks like you renamed it 'Taeyeon'. Change the line to this:
addObject(new Taeyeon(new 'randomname'()), 80, 100);
joanne_wm joanne_wm

2014/12/11

#
So since all the character codes are the same, all I have to do is to:
AddObject(new Taeyeon(new Taeyeon ()), 80, 100);
And change the name to other actors as needed
danpost danpost

2014/12/11

#
If all the character codes are the same, then you only need one class that the image can be set differently for each 'apparent' different character.
joanne_wm joanne_wm

2014/12/12

#
but how will i do that?
danpost danpost

2014/12/12

#
Instead of passing an Actor to each Selector object created, just pass the different images (or the Strings used to create the images). In the act of the Selector class, if clicked create a new space world and call setSelected on it passing the image of that Selector object. The setSelected method can set the image of the Player object ('Irene', 'Joy', whichever).
joanne_wm joanne_wm

2014/12/31

#
how would i pass the different images? sorry for that long reply i wasn't on wifi for some time but can i just pass it on separately?
danpost danpost

2014/12/31

#
Maybe it is best to leave it as passing the actors to the Taeyeon class as you need more than just the image. You should be using lines, for example, like these:
addObject(new Taeyeon(new Irene()), 80, 100);
addObject(new Taeyeon(new Joy()), 160, 100);
for preparing the actors in your selection world.
joanne_wm joanne_wm

2015/1/1

#
ok, got that, but the thing is now its saying the typed out dimensions doesn't match with the original size e.g. for Irene class, the actual size of the actual image is 426x673, so i typed out
addObject(new Taeyeon(new Irene()), 426, 673);
here's what the ? mark problem box looks like
danpost danpost

2015/1/1

#
I do not have access to that link. The two numbers in your 'addObject' statement are for where you want the actor to be located in the wold; they have nothing to do with the size of the image.
joanne_wm joanne_wm

2015/1/2

#
heres the link instead of: image link ? mark problem
danpost danpost

2015/1/2

#
joanne_wm wrote...
heres the link instead of: image link ? mark problem
That is the link that I do not have access to. I was able to acquire the url by quoting your earlier post. But, it says the page is unavailable.
There are more replies on the next page.
1
2
3
4