PDA

View Full Version : game stage area question


diggz
11-04-2007, 10:36 AM
Morning!

I am hoping that someone may be able to put me right with this problem I have with an fla that I am working with.

It is basically a ball-pop type game (you know the sort, move the paddle to bounce the ball into the blocks) - it all works fine and as it should apart from one detail. At the moment the "ball" moves around a space that is determined by co-ordinates in the AS
gGameRect = [121, 106, 840, 600];


and this makes the ball bounce back into play when it reaches any of the above positions (or lose a life if it goes past 600).

What I am trying to do is make the ball recognise 100% height and width of the stage/screen. So regardless of the user browser window size it will bounce back from the edges of it rather than the set size as defined above.

I have tried a few different ideas but none work - so am hoping that someone here will be able to see where I can do it and hopefully be able to tell me what I need to change to make it work at full screen.

Here is the full script from the frame:
function moveTheBalls()
{
x = 1;
for (;;)
{
if (theNumberOfBalls < x)
{
return;
}

thisBall = theBallsList["ball" + x];
if (!thisBall == 0)
{
thisBall.moveBall();
}

++x;
}

}

function newBallList(startBallNum)
{
this["ball" + startBallNum] = new newBall("ball" + startBallNum);
}

function addNewBall()
{
++theNumberOfBalls;
++theCurBallNum;
theBallsList["ball" + theNumberOfBalls] = new newBall("ball" + theNumberOfBalls);
}

function maketargetList(numOfTiles)
{
i = 0;
for (;;)
{
if (i >= numOfTiles)
{
return;
}

gTargetList[i] = String("tile" + (i + 1));
++i;
}

}

function newBall(instName)
{
duplicateMovieClip("ball", instName, 16384 + theNumberOfBalls);
this.name = instName;
this.MovieClip = _root[instName];
this.MovieClip._x = gBallBaseLoc[0];
this.MovieClip._y = gBallBaseLoc[1];
this.deltaX = getRandom(-5, 5);
this.deltaY = -10;
this.HitNum = 0;
}

function resetGame()
{
maketargetList(gTileNum);
resetTiles();
}

function resetTiles()
{
i = 0;
for (;;)
{
if (i >= gTileNum)
{
return;
}

var thisTile = gTargetList[i];
_root[thisTile]._x = _root[thisTile].startX;
++i;
}

}

function checkForXtraBall(theBallName)
{
var xtraBallNum = xtraBallList.length;
i = 0;
for (;;)
{
if (i >= xtraBallNum)
{
return;
}

if (theBallName == xtraBallList[i])
{
return 1;
}

++i;
}

}

function getRandom(x, y)
{
return Math.round(Math.random() * (y - x)) + x;
}

Mouse.hide(false);
gameOn = 1;
theScore = 0;
gBallBaseLoc = [200, 300];
gThePaddle = [_root.paddle, _root.paddle2];
gGameRect = [121, 106, 840, 600];
gHMax = pGameRect[2] - 5;
gTileNum = 32;
gTargetList = [];
maketargetList(gTileNum);
theNumberOfBalls = 1;
theCurBallNum = 1;
theBallsList = new newBallList(theNumberOfBalls);
ballsLeft = 2;
xtraBallList = ["tile16", "tile18", "tile30"];
_root.resetTiles();
newBall.prototype.moveBall = function ()
{
this.MovieClip._x = this.MovieClip._x + this.deltaX;
this.MovieClip._y = this.MovieClip._y + this.deltaY;
if (this.MovieClip._y<120) {
this.flipY();
}

var theTileNum = gTargetList.length;
i = 0;
while (i < theTileNum)
{
var thisTile = gTargetList[i];
if (this.MovieClip.hitTest(_root[thisTile]))
{
this.increaseSpeed();
theScore = theScore + 10 * theCurBallNum;
_root[thisTile]._x = _root[thisTile]._x + -1000;
gTargetList.splice(i, 1);
this.flipY();
if (checkForXtraBall(thisTile))
{
addNewBall();
}

if (gTargetList.length == 0)
{
resetGame();
}

break;
}

++i;
}

thisPad = 0;
while (thisPad < 2)
{
var thePaddle = gThePaddle[thisPad];
if (this.MovieClip.hitTest(thePaddle) && 0 < this.deltaY)
{
this.paddleHit(thePaddle);
}

++thisPad;
}

if (gGameRect[3] + 20 < this.MovieClip._y)
{
theBallsList[this.name] = 0;
removeMovieClip(this.MovieClip);
--theCurBallNum;
if (0 >= theCurBallNum)
{
--ballsLeft;
if (ballsLeft < 0)
{
ballsLeft = 0;
gameOn = 0;
gotoAndStop("play");
}
else
{
addNewBall();
}


}

}

if (this.MovieClip._x < gGameRect[0] || gGameRect[2] < this.MovieClip._x)
{
this.flipX();
}

}
;
newBall.prototype.serveBall = function ()
{
this.MovieClip._x = gBallBaseLoc[0];
this.MovieClip._y = gBallBaseLoc[1];
this.deltaX = getRandom(-5, 5);
this.deltaY = -10;
}
;
newBall.prototype.flipY = function ()
{
this.deltaY = this.deltaY * -1;
}
;
newBall.prototype.flipX = function ()
{
this.deltaX = this.deltaX * -1;
}
;
newBall.prototype.paddleHit = function (thePaddle)
{
this.deltaX = (this.MovieClip._x - thePaddle._x) / 4;
this.flipY();
this.MovieClip._y = Math.min(this.MovieClip._y, thePaddle._y + 10);
}
;
newBall.prototype.increaseSpeed = function ()
{
if (this.deltaY < -18 || 18 < this.deltaY)
{
return;
}

++this.hitNum;
if (3 < this.hitNum)
{
this.hitNum = 0;
if (0 < this.deltaY)
{
++this.deltaY;
return;
}

--this.deltaY;
}

}
;


Does anyone know which lines I need to change and to what???

The above script contains the only references to stage size in the actual fla itself - but I can post up the fla if any needs it.

Hope that my faith in the clever bods that frequent this site holds true and that someone can offer me some much needed advice.

Thanks in anticipation ;-)
D

MonkeyBiscuits
11-05-2007, 12:47 PM
I've done something similar before, but don't have the code on me - basically what you need to do is something along the lines of having a wrapper swf, which is displayed in the html page at 100% height and width, which then loads your current swf in (with scaling for the loaded movie set to false to preserve your components in their correct sizes), then from the the loaded swf reference the dimensions of the first wrapper swf which was loaded by the html at 100% width and height, to get the full size of the stage and use that as your boundary.

I didn't explain that very well, but hopefully you get the picture. Post back if you have any problems.

diggz
12-19-2007, 10:21 AM
...I have been struggling with this for some time now - but seem to have got so far but no further! :confused:

I have attached a folder with the ballpop game in it and also the layout it needs to work within. The game is "ballpop.fla" and the layout is the "LIQUIDlayout.fla" - the movie clip that I want the game to work in is shown on the stage and is called "CENTREpages" which is shown on the stage.

I have tried a number of methods but I can't get the game to play within a movieclip and still recognise the centered commands when the stage is resized.

Anyone think they can take a look for me and maybe point me in the right directions - I have sooo much about target paths and the like that my head hurts!!!

...here's hoping!

diggz
12-19-2007, 03:11 PM
...or does anyone know how or if this ballpop can be changed to always stay dead centre to the stage or play within a movie clip that will sit centrally?

...hope so...

...maybe...

...anyone?