PDA

View Full Version : Troubling destroying grid in Breakout knockoff



H4T
April 26th, 2004, 11:02 PM
I started creating a pong knockoff, then it kind of elaborated into a Breakout/Arkanoid knockoff, and I seem to have everything in order except

the Game Over / Play Again part
destroying the grid
I generate the grid through 2 for loops, and each block is assigned a unique name (block1-30 I think), I just don't know how to dynamically hitTest each one of those blocks so they can be unloaded/taken out of the movie when the ball hits it.

Here is the .fla, can someone please help me? (the grid code is in the top frame, as well as my apparantly unsuccessful attempt at detecting collisions within it.)

scdlt
April 26th, 2004, 11:57 PM
Here, I made this for my bricks game. Right now I don't have time to explain what I did, but I will try to remember to help. For now here is the code:


function checkCollisions() {
//get sides of ball
ballTop = ball._y-ball._height/2;
ballBottom = ball._y+ball._height/2;
ballLeft = ball._x-ball._width/2;
ballRight = ball._x-ball.width/2;
//assumelevel is done

//loop through bricks to see whether any were hit
for (i=1; i<=55; i++) {
brick = _root["a"+i];
//see whether brick is still around
if (brick._y != -100) {
if (brickHit(brick)) {
//brick hit so take away
brick._y += -100;
powerUps();
bricks++;
//revers ball
dy *= -1;
} else {
// brick stays
levelDone = false;
}
}
if(bricks == 55){
levelDone = true;
}
}
// sees ifall bricks are gone
if (levelDone) {
//starts new level
Mouse.show();
gotoAndPlay("winner");
//increase vertical speed
dy += 1;
if (dy>9) {
dy = 9;
}
}
}
function brickHit(brick){
//preform test on all four sides
if(ballTop <= brick._y + brick._height/2){
if(ballBottom >= brick._y - brick._height /2){
if(ballRight >= brick._x - brick._width/2){
if(ballLeft <= brick._x + brick._width /2){
return(true);
}
}
}
}
return(false);
}

H4T
April 27th, 2004, 05:29 PM
Hm, I still cannot get it to work. I customized the script to work for me, changed variable names. And my breakout game is sideways so I changed the X speed instead of Y on hit. But the ball still just passes right through all the blocks without doing a single thing...

Here's the code, this is on a frame



// Generate the grid
gridx = 6;
gridy = 39;
num = 0;

for(i=0; i<6; i++) {
for(j=0; j<5; j++) {
block.duplicateMovieClip("block"+num,num);
mc=this["block"+num];
mc._x = gridx*i + 350;
mc._y = gridy*j + 33;

TargetList[num] = String["block"+num];
num++;
}
}
block.unloadMovie();

// Collision detection for the grid
function checkCollisions() {
//get sides of ball
ballTop = ball._y-ball._height/2;
ballBottom = ball._y+ball._height/2;
ballLeft = ball._x-ball._width/2;
ballRight = ball._x-ball.width/2;
//assumelevel is done

//loop through bricks to see whether any were hit
for (i=1; i<=30; i++) {
block = _root["block"+i];
//see whether brick is still around
if (block._y != -100) {
if (blockHit(block)) {
//brick hit so take away
block._y += -100;
blocks++;
//revers ball
speedx *= -1;
} else {
// brick stays
levelDone = false;
}
}
if(blocks == 55){
levelDone = true;
}
}
// sees if all bricks are gone
if (levelDone) {
//starts new level
Mouse.show();
_root.text = "You Win!"
//increase vertical speed
speedy += 1;
if (speedy>9) {
speedy = 9;
}
}
}
function blockHit(block){
//preform test on all four sides
if(ballTop <= block._y + block._height/2){
if(ballBottom >= block._y - block._height /2){
if(ballRight >= block._x - block._width/2){
if(ballLeft <= block._x + block._width /2){
return(true);
}
}
}
}
return(false);
}

cr125rider
May 1st, 2004, 07:15 PM
Just an ided, but can you have a hit test with an array. I am new to Flash so this might not be proper syntax.

if (this, hitTest(["block" + array1]){

H4T
May 1st, 2004, 10:24 PM
Uhm, thats exactly what is going on...read the code above, the "block" is defined and placed into an array, and for loops retrieve and work with the array...

But I'm still getting now where, can some please help?