PDA

View Full Version : Stuck on arrays


Judah Smith
03-17-2008, 04:18 PM
Hi

I'm trying to make my first flash game. Reading 'Beiginning Flash Game Programming for Dummies' has got me so far, but I am now a bit stuck.

My game is a mix of pong and breakout. The player has to break down a wall in front of him by bouncing the ball off the bricks before getting the ball to the opponents side and making them do the same. For each brick the player destroys in his wall, he adds a brick to his opponents wall.

I have the pong bit working but I am a bit stuck on the arrays which will hold the players bricks and the opponents bricks.I have gotten a line of bricks for each of the player and the opponents brickArray but the opponent bricks seem to be sitting on top of the players bricks, despite me having given them two different start positions.

Could someone take a look at my code and tell me what I am doing wrong? Its probably very simple but I'm just not seeing it (n00b alert!).

I've also included a jpeg of the game which explains what I am trying to do.

Thanks

rrh
03-17-2008, 07:56 PM
You aren't handling depths properly.


//amount of bricks
var maxPlayerBricks = 13;
var maxOppBricks = 13;

//create player bricks
for (i=0; i<maxPlayerBricks; i++)
{
trace (i);
myGame.setPlayerArray(brick(attachMovie("playerBrick", "playerBrick"+i, i)),i);
}

//create opponent bricks
for (i=0; i<maxOppBricks; i++)
{
trace (i);
myGame.setOppArray(brick(attachMovie("oppBrick", "oppBrick"+i, i)),i);
}

The one uses depths 0 through 12, and then the other uses depths 0 through 12. There can only be one movieClip per depth.

Judah Smith
03-21-2008, 11:33 AM
Thanks rrh

I see that now, but I am new to arrays. Would it work if I change the i on opponent bricks to be ("maxPlayerBricks"+i)

Also, with all these i's floating around, which one would I change? I don't know which one refers to the layer (duh!)

Could you give me some clue as to the syntax I will need on the opponent brick setter to do this.

rrh
03-21-2008, 05:04 PM
The third parameter of attachMovie is depth.

maxPlayerBricks+i should work, not "maxPlayerBricks"+i because the "" marks turn it into a string instead of a variable.

Judah Smith
03-22-2008, 09:12 PM
Thanks again rrh. That worked a treat. It was an issue with layers, I'm learning all the time.

For my next trick, I need to have these bricks create a new row every time they reach the edge of the screen. Right now, they will keep forming in an endless line up to the maximum of the bricks (14 creates a complete row). What I need is the syntax that will get the brick array to automatically start drawing the second line when it gets to the edge of the screen.

My 2 thoughts were;
1) As I know that 14 blocks make a row, perhaps there is some syntax that can divide the maximum bricks by 14 and make that many rows. This seems ugly and would need hard-coding if ever the amount of bricks that make up a row ever changes

2) Some wizardry using stage.height. If I can get the bricks to recognise when they have gone beyond stage height and start another row, it would seem to be the most elegant solution. However, I'm not at all sure what the syntax would be.

I've included the up-to-date code (thanks rrh) and a screenshot of what I'm trying to achieve with this post.