Having some trouble with manipulating arrays to my advantage here.
I'm creating a game similar to CRAZY TAXI (dunno if you've heard of it), a car game where you avoid oncoming cars on an ever extending road. I have decided to add some images (that of the Actor named "Question") that will randomly appear and travel down the road. I am currently storing the three locations in which they originate on the x-axis with an array, stored within the Actor Class:
public static int QuestionXPosition = {232,240,249};
The World class then executes this array.
Greenfoot.getRandomNumber(Probability);
if (RanNum == 0) {
Question question = new Question();
addObject(question, Question.QuestionXPosition, Question.ObjectYPosition);
}
if (RanNum == 1) {
Question question = new Question();
addObject(question, Question.QuestionXPosition, Question.ObjectYPosition);
}
if (RanNum == 2) {
Question question = new Question();
addObject(question, Question.QuestionXPosition, Question.ObjectYPosition);
}
I now want the images' linear direction of movement down the road to change according to where they originate. For example, the leftmost image should travel downwards diagonally to the left. The central image should travel straight down, whilst the rightmost image should travel downwards diagonally to the right.
I have a variable named XLocate which determines how much to the left or right the image travels as it descends down the road. The only trouble is adjusting this variable depending on which of the three locations the image takes (defined within the array).
I would really appreciate any ideas as to how I should adjust my code so that the variable XLocate alters according to what position is retrieved from the array, and also which class I should store the solution in... i.e. in the World or the Actor. Thankyou!