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

2019/2/2

I've been working on a project in greenfoot and i need help on Character selection.

1
2
3
SniperRocks SniperRocks

2019/2/2

#
I dont know how to get it started, the only things ive done are the basics which is making the character moves & making the pictures. Its a fighting game im doing in my school. My partners and i are having troubles starting on it. I have 4 players (captain america, ironman, black panther, and hulk) and i want to know how would i click on on the pictures i have them on, onto the world aka the map. Idk if i can send the project here for anyone to figure it out but yeah, Please help me out.
danpost danpost

2019/2/2

#
SniperRocks wrote...
I have 4 players (captain america, ironman, black panther, and hulk) and i want to know how would i click on on the pictures i have them on, onto the world aka the map.
Okay, so you will need 4 objects that each depict a different type player for the user to choose from by a click on one of them. Group them in a field array:
private Actor[] icons = new Actor[4];
This basically assigns a value to each of the icons by its position in the array (the index). The icon objects can be simple Actor objects whose images are set to the various player images. I would use a simple Actor subclass as follows:
public class SimpleActor extends greenfoot.Actor {}
(that is the entire class). Here is an example of setting up an actor:
icons[0] = new SimpleActor();
icons[0].setImage((new Ironman()).getImage());
That is just one way you could set the images. Do similarly for the other three, just bump the index and use a different player image. Finally, check for clicks on them in the act method:
int selection = -1;
for (int i=0; i<icons.length; i++)
{
    if (Greenfoot.mouseClicked(icons[i]))
    {
        selection = i;
        break;
    }
}
if (selection > -1)
{
    // prepare game world here
}
SniperRocks SniperRocks

2019/2/2

#
How can i show you my project because i cant understand it like i get headaches from overthinking or when things dont work out on the code. Through email?
danpost danpost

2019/2/2

#
SniperRocks wrote...
How can i show you my project because i cant understand it like i get headaches from overthinking or when things dont work out on the code. Through email?
You can show what you tried here.
SniperRocks SniperRocks

2019/2/2

#
public selection() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(711, 400, 1); } public void act() { //if(Greenfoot.isKeyDown("n")) Greenfoot.setWorld(new map()); } public void keyCommands() { } // public void prepare() // { // for (int row=0; row<getHeight(); row++) for (int col=0; col<getWidth(); col++) // { // Actor actor = null; // while (!canPlace(actor, col, row)) // { // int which = Greenfoot.getRandomNumber(4); // if(which == 0) actor = new ironman(); // if(which == 1) actor = new captain(); // if(which == 2) actor = new blackpanther(); // if(which == 2) actor = new hulk(); // } // addObject(actor, col, row); // } // } thats what i have for my selection, which you can see idk what to get it started
SniperRocks SniperRocks

2019/2/2

#
i also have a playerone and its subclass are the 4 characters. I also have playertwo and its subclass are the same 4 characters just changed the name of it. its complicated
danpost danpost

2019/2/2

#
Try this:
public static Actor player;
public Actor[] icons;

public selection()
{
    super(711, 400, 1);
    prepare();
}

private void prepare()
{
    GreenfootImage[] images =
    {
        (new ironman()).getImage(),
        (new captain()).getImage(),
        (new blackpanther()).getImage(),
        (new hulk()).getImage()
    };
    icons = new Actor[images.length];
    for (int i=0; i<images.length; i++)
    {
        icons[i] = new SimpleActor();
        icons[i].setImage(images[i]);
        addObject(icons[i], 89+178*i, 300);
    }
}

public void act()
{
    if (!Greenfoot.mouseClicked(null)) return;
    int selected = -1;
    for (int i=0; i<icons.length; i++)
    {
        if (Greenfoot.mouseClicked(icons[i]))
        {
            selected = i;
            break;
        }
    }
    if (selected != -1)
    {
        switch (selected)
        {
            case 0:  player = new ironman(); break;
            case 1:  player= new captain(); break;
            case 2:  player= new blackpanther(); break;
            case 3:   player= new hulk; break;
        }
        Greenfoot.setWorld(new map());
    }
}
The map world will have to get the character:
Actor player = selection.player;
SniperRocks SniperRocks

2019/2/2

#
the only error i have is the SimpleActor, do i make a subclass in Actor? or World?
SniperRocks SniperRocks

2019/2/2

#
or make it a subclass under selection?
danpost danpost

2019/2/3

#
SniperRocks wrote...
the only error i have is the SimpleActor, do i make a subclass in Actor? or World?
I explained that in my first reply:
danpost wrote...
The icon objects can be simple Actor objects whose images are set to the various player images. I would use a simple Actor subclass as follows:
public class SimpleActor extends greenfoot.Actor {}
(that is the entire class).
SniperRocks SniperRocks

2019/2/3

#
So far it has worked, i can click on it and it does go on, but theres another problem. When i click on the character from the screen it works but it doesnt show up on the world aka the map. Any Solutions?
SniperRocks SniperRocks

2019/2/3

#
ima show you my map code
SniperRocks SniperRocks

2019/2/3

#
public class Arenaone extends World { private PlayerEntity playerone; private PlayerEntitytwo playertwo; private Timer timer; private int Timer = 0; GreenfootSound backgroundMusic = new GreenfootSound("battleone.mp3"); // private Bar healthBar; GreenfootSound punch = new GreenfootSound("ipunch.mp3"); //Actor player = selection.playerone; public Arenaone() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(711, 400, 1); playerone = new PlayerEntity(playerone.class); addObject(playerone, 123, 268); playertwo = new PlayerEntitytwo(playertwo.class); addObject(playertwo, 545, 267); timer = new Timer(); addObject(timer, 322, 50); addStones(); // if(timer>0) // { // timer -- ; // if(timer == 0) // Greenfoot.stop(); // } // Label pHealth = captain.getHealthLabel(); // pHealth.setLocation( 597,50 ); // healthBar = new Bar("", "Health", 100, 100); // healthBar.setTextColor(Color.white); // addObject(healthBar, 100, 30); // hulk = new PlayerEntity(hulk.class); // addObject(hulk, 123, 268); // backgroundMusic.playLoop(); } public void addStones() { for(int i = 0; i < 30; i++) { Stone floor = new Stone(); addObject(floor, 0 + (i * floor.getImage().getWidth()) , 351); } } }
danpost danpost

2019/2/3

#
SniperRocks wrote...
ima show you my map code
That is the Arenaone class code -- not the map class code.
SniperRocks SniperRocks

2019/2/3

#
i meant arenaone not maps, i apologize. But yeah it works on selection but how can i make it work to show up on arenaone
There are more replies on the next page.
1
2
3