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

2013/6/20

Turn Based Fighting Game W/ Character Selection

PeanutButterPower PeanutButterPower

2013/6/20

#
I was planning to make a game where you select a character, and then fight against the computer (turn based). I have 2 questions about this: 1) How would i be able to make a character selection screen? Specifically, when you click on a characters image, their info should pop up on the screen and then you can select an opponent. 2) My second problem is with the attacks. There would be a bar in the bottom of the screen showing all of the available attacks that you could do. When you click on an attack, it uses that attack and ends your turn. I need help specifically with using the attack that is picked, playing an animation for that attack, and then ending the turn and have the computer pick a random attack. If anyone could help with this i would be really grateful. I dont want you to do it all for me, just point me in the right direction.
1) Have each character on the screen a subclass of the same class (Like "Character") and have in the super class a private object that displays all the info (maybe call the object "CharacterInfo"). Then write the code in the Character class that will add the info to the world when the character is clicked, and gets rid of any other CharacterInfo objects in the world already. Then in each Character subclass, all you have to do is define what is going to be in the CharacterInfo object. 2) You forgot to add question two...
PeanutButterPower PeanutButterPower

2013/6/20

#
I updated it with question 2
2) Well, you could have another object similar to CharacterInfo that would display the different attacks, and underline or point an arrow to the one you want to select. You can keep track of which one is selected by using a 2D array with ints or Strings. When one is selected, you could give it to the Character to play out that animation. There are several discussions on how to do both walking animations and animations in general on the site, so you should look at those. You could also use "bones" if you really wanted to, but those are more complicated, especially creating code to make an animation out of the "bones". And for the computer choosing a random attack, just use this:
Greenfoot.getRandomNumber(int numOfAttacks); //Will choose a random number from 0 to numOfAttacks
PeanutButterPower PeanutButterPower

2013/6/20

#
Thank you, i will try this out and see what happens :)
PeanutButterPower PeanutButterPower

2013/6/21

#
Actually, i dont really know much about 2d arrays, so could you give an example of that?
A 2D array is best thought of as an array of arrays. It's called a 2D array because if you line all the elements out, it's like a matrix (if you've taken algebra you'll know what that means) or a table of objects. A 2D array is declared like a normal array. You have an array of arrays, that have ints, doubles, Strings, or other objects. Most people will declare it in a way where you can see the objects laid out in columns and rows. Here's an example:
int[][] my2DArray = {
                                {1,   2,  3,  4,  5},
                                {6,   7,  8,  9,  10},
                                {11, 12, 13, 14, 15}
};

//Or

int[][] my2DArray = new int[3][5];
my2DArray[0][0] = 1;
my2DArray[0][1] = 2;
...
You can find the size of an array like this:
int widthOfArray = my2DArray[0].length;  //Assuming that all the arrays in the 2D array are the same length

int heightOfArray = my2DArray.length;
Which then in turn can be used in a for-loop:
//The following would print out all the elements in the 2D array in order, from top left, to bottom right

for (int i = 0; i < my2DArray.length; i++)
{
    for (int j = 0; j < my2DArray[0].length; j++)
        System.out.print(my2DArray[i][j] + " ");
    System.out.println();
}
I hoped that helped!
You need to login to post a reply.