Hi Guys.
I’ve been learning flash over the last couple of weeks (using AS3) and have tried to write a game in it. However I’ve started to stumble on a problem I’m finding really confusing now. I’ve been making a bubble game where you shoot bubbles out and other bubbles and when you get a group of 3 or more bubbles, they explode (not a great explanation I know but the link to the swf should give you an idea). Right now it’s at the start of development, you can shoot bubbles upwards, but none will explode and there is only one bubble type. However I’m trying to get the physics right and the collisions are confusing me. Bubbles are colliding into each other in a funny way and I can’t figure out exactly how would be a good way of doing it.
Anyways heres a link to the swf:
[COLOR=#800080]http://www.imanagerlive.com/bubble.swf[/COLOR]
And here’s a link to the fla file
[COLOR=#0066cc]http://www.imanagerlive.com/bubbles1.zip[/COLOR]
I know I’ve done it a bit stupidly without using classes properly and having functions each on different layers, I think I just find it less confusing this way whilst im developing stuff…
Anyway I believe this to be where I’ve got big problems (The FLA file has all this code in and it’s probably easier to understand looking at that than this)…
function doBallMovement() /* When a ball is shot, this function is called */
{
var futureX=ballToFly.x+(sine[ballAngle]*ballSpeed);
var futureY=ballToFly.y+(cosine[ballAngle]*ballSpeed);
// Get what current array tile we're in - roughly
var xPos = Math.round(((futureX-gridStartX)/squareWidth));
var yPos = Math.round((futureY-accumulatedMovement-gridStartY-(squareHeight/2))/squareHeight);
var yPosTip = Math.round((ballToFly.y-accumulatedMovement-gridStartY-(squareHeight/2))/squareHeight);
if(((yPos>0)&&(yPos<gridHeight+extraVerticalBuffer))&& /* if we can collide, place it here THIS PART IS WRONG!! */
((xPos>0)&&(xPos<gridWidth)))
{
for(var i=xPos-1;i<xPos+1;i++)
{
if(bubbleGrid*[yPos]!=null)
{
if(bubbleGrid*[yPos].hitTestPoint(futureX,futureY))
{
if(bubbleGrid*[yPos+1]==null)
{
bubbleGrid*[yPos+1] = ballToFly;
snapToTile(i,yPos+1,bubbleGrid*[yPos+1]);
}
else
if(bubbleGrid*[yPos+2]==null)
{
bubbleGrid*[yPos+2] = ballToFly;
snapToTile(i,yPos+2,bubbleGrid*[yPos+2]);
}
setNext();
}
}
}
}
if(futureX<gridStartX) /*Bounce off the left */
{
ballAngle = 180-(ballAngle % 180);
while(ballAngle<0)
ballAngle+=360;
}
if(futureX>gridStartX+(gridWidth*squareWidth-(squareWidth/2))) /*Bounce off the right*/
{
ballAngle = 360-ballAngle;
while(ballAngle<0)
ballAngle+=360;
}
if(yPos<0)
return;
ballToFly.x=futureX;
ballToFly.y=futureY;
}
Many thanks in advance for any ideas people might have, I figure it can’t be too hard as there’s so many of these games around on the web…