Frame 1
var CPMStarPoolID = 1580;
var CPMStarSubPoolID = 1;
System.security.allowDomain("server.cpmstar.com");
AdLoader = new MovieClipLoader();
AdLoader.loadClip((("http://server.cpmstar.com/adviewas2.swf?poolid=" + CPMStarPoolID) + "&subpoolid=") + CPMStarSubPoolID, adBox);
adBox._visible = true;
Frame 2
adBox._visible = true;
StartTime = new Date();
Frame 3
adBox._visible = true;
Rel1 = getBytesLoaded() / getBytesTotal();
Now = new Date();
LoadProgress = AdLoader.getProgress(adBox);
Rel2 = LoadProgress.bytesLoaded / LoadProgress.bytesTotal;
Rel = Math.min(Rel1, Rel2);
Loading.LoadingBar.gotoAndStop(Math.round(Rel * 100) + 1);
Loading.PercentageText = Math.round(Rel * 100) + "%";
if (Rel >= 1) {
Loading.gotoAndStop(2);
}
Frame 4
adBox._visible = true;
gotoAndPlay ("Preloader");
Frame 5
function CalcAngle(Xfrom, Yfrom, Xto, Yto) {
if ((Xfrom == Xto) and (Yfrom == Yto)) {
Angle = 0;
} else {
XDis = Math.abs(Xto - Xfrom);
YDis = Math.abs(Yto - Yfrom);
Angle = Math.atan(YDis / XDis);
if (Xto > Xfrom) {
if (Yto < Yfrom) {
Angle = halfPI - Angle;
} else {
Angle = halfPI + Angle;
}
} else if (Yto > Yfrom) {
Angle = (Math.PI + halfPI) - Angle;
} else {
Angle = (Math.PI + halfPI) + Angle;
}
if (Angle < 0) {
Angle = Angle + (Math.PI*2);
}
}
return(Angle);
}
function CalcDistance(Xfrom, Yfrom, Xto, Yto) {
xDistance = Math.abs(Xto - Xfrom);
yDistance = Math.abs(Yto - Yfrom);
LineDistance = Math.sqrt(Math.pow(xDistance, 2) + Math.pow(yDistance, 2));
return(LineDistance);
}
function NumberFormat(Num, AfterComa) {
var _local3 = Math.floor(Num);
var _local4 = Math.round((Num - _local3) * Math.pow(10, AfterComa));
var _local1 = _local3.toString();
var _local2 = new Array();
ss = _local1.length - 3;
while (ss >= 0) {
_local2.unshift(_local1.substr(ss, 3));
ss = ss - 3;
}
if ((ss < 0) and (ss > -3)) {
_local2.unshift(_local1.substr(0, ss + 3));
}
_local1 = _local2.join(".");
if (AfterComa > 0) {
_local1 = _local1 + ("," + _local4);
}
return(_local1);
}
function AngleDifference(Angle1, Angle2) {
Res = Angle2 - Angle1;
while (Res > Math.PI) {
Res = Res - dblPI;
}
while (Res < -3.14159265358979) {
Res = Res + dblPI;
}
return(Res);
}
function LineHitsLine(Line1, Line2) {
var _local1 = new Object();
if (Line1.a == Line2.a) {
_local1.x = Infinity;
_local1.y = Infinity;
} else {
if ((Line1.x == undefined) and (Line2.x == undefined)) {
if ((Line1.a != 0) and (Line2.a != 0)) {
_local1.x = (Line2.b - Line1.b) / (Line1.a - Line2.a);
_local1.y = (Line2.a * _local1.x) + Line2.b;
}
if (Line1.a == 0) {
_local1.y = Line1.b;
_local1.x = (Line2.b - _local1.y) / (-Line2.a);
}
if (Line2.a == 0) {
_local1.y = Line2.b;
_local1.x = (_local1.y - Line1.b) / Line1.a;
}
}
if (Line1.x != undefined) {
_local1.x = Line1.x;
_local1.y = (Line2.a * _local1.x) + Line2.b;
}
if (Line2.x != undefined) {
_local1.x = Line2.x;
_local1.y = (Line1.a * _local1.x) + Line1.b;
}
}
return(_local1);
}
function co2ab(x1, y1, x2, y2) {
var _local1 = new Object();
if (x1 == x2) {
_local1.x = x1;
} else {
_local1.a = (y2 - y1) / (x2 - x1);
_local1.b = y1 - (x1 * _local1.a);
}
return(_local1);
}
function ang2ab(x, y, Angle) {
var _local1 = new Object();
if ((Angle == 0) or (Angle == Math.PI)) {
_local1.x = x;
} else {
_local1.a = 1 / Math.tan(Angle);
_local1.b = y - (x * _local1.a);
}
return(_local1);
}
function SegmentHitsSegment(l1x1, l1y1, l1x2, l1y2, l2x1, l2y1, l2x2, l2y2) {
var _local11;
var _local10;
var _local1 = LineHitsLine(co2ab(l1x1, l1y1, l1x2, l1y2), co2ab(l2x1, l2y1, l2x2, l2y2));
_local1.x = Math.round(_local1.x * 1000000000) / 1000000000;
_local1.y = Math.round(_local1.y * 1000000000) / 1000000000;
_local11 = (((_local1.x >= Math.min(l1x1, l1x2)) and (_local1.x <= Math.max(l1x1, l1x2))) and (_local1.y >= Math.min(l1y1, l1y2))) and (_local1.y <= Math.max(l1y1, l1y2));
_local10 = (((_local1.x >= Math.min(l2x1, l2x2)) and (_local1.x <= Math.max(l2x1, l2x2))) and (_local1.y >= Math.min(l2y1, l2y2))) and (_local1.y <= Math.max(l2y1, l2y2));
if ((!_local11) or (!_local10)) {
_local1 = null;
}
return(_local1);
}
function CreateFormation() {
var _local1;
var _local2 = new Array();
var _local12 = new Array();
var _local4 = new Array();
var _local6 = new Array();
var _local5;
var _local3;
var _local7;
var _local8;
if (Game == 1) {
_local1 = 1;
while (_local1 <= 7) {
_local4[_local1 - 1] = {Num:_local1, Used:false, Type:2};
_local1++;
}
_local1 = 9;
while (_local1 <= 15) {
_local4[_local1 - 1] = {Num:_local1, Used:false, Type:1};
_local1++;
}
if (HasGame or (Mode != 3)) {
_local2[11] = 8;
_local4[7] = {Num:8, Used:true, Type:3};
_local2[1] = RandomBall(_local4, 2);
_local2[5] = RandomBall(_local4, 1);
_local1 = 1;
while (_local1 <= 15) {
if (_local2[_local1] == undefined) {
_local2[_local1] = RandomBall(_local4, 0);
}
_local1++;
}
if (Mode == 3) {
PL = "";
_local1 = 1;
while (_local1 <= 15) {
PL = PL + ("|" + _local2[_local1]);
_local1++;
}
Con.send("3" + PL);
}
}
if ((Mode == 3) and (!HasGame)) {
_local1 = 1;
while (_local1 <= 15) {
_local2[_local1] = ReceivedPositions[_local1];
_local1++;
}
}
_local8 = -(dblPI / 6);
_local1 = 0;
while (_local1 <= 4) {
_local6[_local1] = {x:FootString + (((Math.sin(_local8) * _local1) * BallRadius) * FormationSpace), y:VerticalMiddle - (((Math.cos(_local8) * _local1) * BallRadius) * FormationSpace)};
_local1++;
}
_local7 = 5;
_local3 = 1;
_local5 = 4;
_local1 = 0;
while (_local1 <= 14) {
_local12[_local1] = {Ball:_local2[_local1 + 1], x:_local6[_local5].x, y:_local6[_local5].y + (((_local3 - 1) * BallRadius) * FormationSpace)};
_local3++;
if (_local3 > _local7) {
_local3 = 1;
_local5--;
_local7--;
}
_local1++;
}
}
return(_local12);
}
function RandomBall(Arr, Type) {
var _local5;
var _local1;
var _local3;
_local1 = random(Arr.length);
_local3 = 0;
while ((Arr[_local1].Used or ((Arr[_local1].Type != Type) and (Type != 0))) and (_local3 < Arr.length)) {
_local1++;
if (_local1 >= Arr.length) {
_local1 = _local1 - Arr.length;
}
_local3++;
}
Arr[_local1].Used = true;
return(Arr[_local1].Num);
}
function BallsHit(a, c, b, d, e, g, f, h, Distance, AllowNegative) {
var _local1;
var _local2;
var _local5;
var _local3;
var _local7;
var _local6;
var _local4;
_local1 = Math.pow(b - f, 2) + Math.pow(d - h, 2);
_local2 = ((2 * (b - f)) * (a - e)) + ((2 * (d - h)) * (c - g));
_local5 = (Math.pow(a - e, 2) + Math.pow(c - g, 2)) - Math.pow(Distance, 2);
_local3 = Math.pow(_local2, 2) - ((4 * _local1) * _local5);
if (_local1 != 0) {
if (_local3 > 0) {
_local7 = ((-_local2) + Math.sqrt(_local3)) / (2 * _local1);
_local6 = ((-_local2) - Math.sqrt(_local3)) / (2 * _local1);
_local4 = Math.min(_local7, _local6);
}
if (_local3 == 0) {
_local4 = (-_local2) / (2 * _local1);
}
}
return(_local4);
}
function SwitchPlayers() {
if (SO.data.SoundOn and (!MuteSounds)) {
if ((Fault == 0) or (Fault == 4)) {
SwitchPlayerSound.start();
}
MuteSounds = false;
}
YourTurn = !YourTurn;
if (YourTurn) {
Player = Players[1];
Opponent = Players[2];
} else {
Opponent = Players[1];
Player = Players[2];
}
OpponentPhase = 0;
}
function CheckBallType(Num) {
if ((Num > 0) and (Num < 8)) {
return(2);
}
if (Num > 8) {
return(1);
}
if (Num == 0) {
return(0);
}
if (Num == 8) {
return(3);
}
}
function EndGame(WinLose) {
if (WinLose == 1) {
trace(Player.Name + " Wins");
Winner = Player;
}
if (WinLose == 2) {
trace(Opponent.Name + " Wins");
Winner = Opponent;
}
if ((Mode == 2) and (Winner == Players[1])) {
SO.data.CPUPlayers[SelectedOpponent].Won++;
SO.flush();
}
if (Mode == 3) {
if (Winner == Players[1]) {
Con.send("A");
} else {
Con.send("B");
}
}
Mouse.show();
gotoAndStop ("GameEnd");
}
function PlaceCueBall(X, Y) {
switch (PlaceCue) {
case 0 :
RemoveBall.removeMovieClip();
RemoveShadow.removeMovieClip();
NewCueBall = AddBall(0, HeadString, VerticalMiddle);
CueBall = Balls[NewCueBall];
PlaceCue = 1;
case 1 :
if (X < HeadString) {
CueX = HeadString;
CueY = Y;
if (CueY < (VerticalMiddle - HeadRadius)) {
CueY = VerticalMiddle - HeadRadius;
}
if (CueY > (VerticalMiddle + HeadRadius)) {
CueY = VerticalMiddle + HeadRadius;
}
} else {
Angle = CalcAngle(HeadString, VerticalMiddle, X, Y);
Distance = CalcDistance(HeadString, VerticalMiddle, X, Y);
if (Distance > HeadRadius) {
Distance = HeadRadius;
}
CueX = HeadString + (Math.sin(Angle) * Distance);
CueY = VerticalMiddle - (Math.cos(Angle) * Distance);
}
Angle = CalcAngle(HeadString, VerticalMiddle, CueX, CueY);
Distance = CalcDistance(HeadString, VerticalMiddle, CueX, CueY);
NowMoving = 1;
Steps = 0;
StartDistance = Distance;
do {
CueX = HeadString + (Math.sin(Angle) * Distance);
CueY = VerticalMiddle - (Math.cos(Angle) * Distance);
HitsAnotherBall = false;
for (b in Balls) {
if ((b != NewCueBall) and (CalcDistance(Balls[b].x, Balls[b].y, CueX, CueY) < BallDiameter)) {
HitsAnotherBall = true;
Steps++;
Distance = StartDistance + ((Steps * BallRadius) * NowMoving);
if (NowMoving == 1) {
NowMoving = -1;
} else {
NowMoving = 1;
}
break;
}
}
} while (HitsAnotherBall);
CueBall.Shadow._x = (CueBall.Symbol._x = (CueBall.x = CueX));
CueBall.Shadow._y = (CueBall.Symbol._y = (CueBall.y = CueY));
}
}
function UpdateBoards() {
if (YourTurn) {
PB1.gotoAndStop(2);
PB2.gotoAndStop(1);
} else {
PB1.gotoAndStop(1);
PB2.gotoAndStop(2);
}
BS1.gotoAndStop(Players[1].BallType + 1);
BS2.gotoAndStop(Players[2].BallType + 1);
BS1.Num = Players[1].PocketedBalls;
BS2.Num = Players[2].PocketedBalls;
ST1._visible = false;
ST2._visible = false;
PC1._visible = false;
PC2._visible = false;
if (HitTwice) {
if (YourTurn) {
ST1._visible = true;
} else {
ST2._visible = true;
}
}
if (CueBallPocketed) {
if (YourTurn) {
PC1._visible = true;
} else {
PC2._visible = true;
}
}
}
function GenerateBlocked(Ball) {
var _local2;
var _local12;
var _local3;
var _local5;
var _local7;
var _local6;
var _local8;
var _local10;
var _local4;
Ball.Blocked = new Array();
for (_local2 in Balls) {
if (Balls[_local2] != Ball) {
_local3 = CalcAngle(Ball.x, Ball.y, Balls[_local2].x, Balls[_local2].y);
_local5 = _local3 - halfPI;
_local7 = Balls[_local2].x + (Math.sin(_local5) * BallDiameter);
_local6 = Balls[_local2].y - (Math.cos(_local5) * BallDiameter);
_local8 = CalcAngle(Ball.x, Ball.y, _local7, _local6);
_local10 = CalcDistance(Ball.x, Ball.y, _local7, _local6);
_local4 = AngleDifference(_local3, _local8);
Ball.Blocked.push({Distance:_local10, Start:_local3 + _local4, End:_local3 - _local4});
}
}
}
function AngleFallsBetween(Angle, Start, End) {
while (Start > End) {
Start = Start - dblPI;
}
while (Angle >= dblPI) {
Angle = Angle - dblPI;
}
if (Angle < Start) {
while (Angle < Start) {
Angle = Angle + dblPI;
}
return(Angle <= End);
}
if (Angle > End) {
while (Angle > End) {
Angle = Angle - dblPI;
}
return(Angle >= Start);
}
return(true);
}
function MakeSimilar(Angle, SimilarTo) {
while ((Angle - SimilarTo) > dblPI) {
Angle = Angle - dblPI;
}
while ((SimilarTo - Angle) > dblPI) {
Angle = Angle + dblPI;
}
return(Angle);
}
function BorderReflection(TheBorder, SourceX, SourceY, TargetX, TargetY) {
var _local4 = co2ab(TheBorder.StartX, TheBorder.StartY, TheBorder.EndX, TheBorder.EndY);
var _local1 = LineHitsLine(ang2ab(SourceX, SourceY, TheBorder.Angle), _local4);
var _local5 = CalcDistance(SourceX, SourceY, _local1.x, _local1.y);
var _local3 = LineHitsLine(ang2ab(TargetX, TargetY, TheBorder.Angle), _local4);
var _local7 = CalcDistance(TargetX, TargetY, _local3.x, _local3.y);
var _local6 = _local5 / (_local7 + _local5);
var _local8 = _local1.x + ((_local3.x - _local1.x) * _local6);
var _local9 = _local1.y + ((_local3.y - _local1.y) * _local6);
var _local10 = {x:_local8, y:_local9};
return(_local10);
}
function BlockedReflection(Border, Start, End) {
if ((((Border == Borders[0]) or (Border == Borders[1])) or (Border == LongBorders[0])) and (Start.x < End.x)) {
return(true);
}
if ((Border == Borders[2]) and (Start.y < End.y)) {
return(true);
}
if ((((Border == Borders[3]) or (Border == Borders[4])) or (Border == LongBorders[1])) and (Start.x > End.x)) {
return(true);
}
if ((Border == Borders[5]) and (Start.y > End.y)) {
return(true);
}
return(false);
}
function Physics(Balls, Simulation) {
var _local18;
for (b in Balls) {
Balls[b].FullMoveX = (Balls[b].MoveX = Math.sin(Balls[b].Angle) * Balls[b].Speed);
Balls[b].FullMoveY = (Balls[b].MoveY = -(Math.cos(Balls[b].Angle) * Balls[b].Speed));
Balls[b].InitX = Balls[b].x;
Balls[b].InitY = Balls[b].y;
Balls[b].WasHit = 0;
Balls[b].Affected = true;
}
PrevProgress = (Progress = 0);
Hits = new Array();
do {
for (h in Hits) {
Hits[h].Distance = ((PrevProgress + (Hits[h].Distance * (1 - PrevProgress))) - Progress) / (1 - Progress);
}
PrevProgress = Progress;
b = 0;
while (b < (Balls.length - 1)) {
bb = b + 1;
while (bb < Balls.length) {
if (Balls[b].Affected or Balls[bb].Affected) {
Hitting = BallsHit(Balls[b].x, Balls[b].y, Balls[b].MoveX, Balls[b].MoveY, Balls[bb].x, Balls[bb].y, Balls[bb].MoveX, Balls[bb].MoveY, BallDiameter, false);
if (((Hitting != undefined) and (Hitting >= 0)) and (Hitting <= 1)) {
Hits.push({Ball1:b, Ball2:bb, Distance:Hitting, Type:1});
}
}
bb++;
}
b++;
}
for (b in Balls) {
if (Balls[b].Affected) {
for (br in Borders) {
if (Math.abs(AngleDifference(Balls[b].Angle, Borders[br].Angle)) > halfPI) {
HitBorder = SegmentHitsSegment(Borders[br].StartX, Borders[br].StartY, Borders[br].EndX, Borders[br].EndY, Balls[b].x, Balls[b].y, Balls[b].x + Balls[b].MoveX, Balls[b].y + Balls[b].MoveY);
if (HitBorder != null) {
FullDist = (1 - Progress) * Balls[b].Speed;
RealHit = CalcDistance(Balls[b].x, Balls[b].y, HitBorder.x, HitBorder.y);
Ds = RealHit / FullDist;
Hits.push({Ball:b, Distance:Ds, Type:2, HitX:HitBorder.x, HitY:HitBorder.y, Angle:Borders[br].Angle});
}
}
}
}
}
AllDone = Hits.length == 0;
if (Hits.length > 0) {
MinDist = Infinity;
for (h in Hits) {
if (Hits[h].Distance < MinDist) {
MinDist = Hits[h].Distance;
}
Hits[h].Active = true;
}
for (b in Balls) {
Balls[b].PrevX = Balls[b].x;
Balls[b].PrevY = Balls[b].y;
Balls[b].x = Balls[b].x + (Balls[b].MoveX * MinDist);
Balls[b].y = Balls[b].y + (Balls[b].MoveY * MinDist);
Balls[b].MoveX = Balls[b].MoveX * (1 - MinDist);
Balls[b].MoveY = Balls[b].MoveY * (1 - MinDist);
Balls[b].Affected = false;
}
Progress = Progress + ((1 - Progress) * MinDist);
Forces = new Array();
for (h in Hits) {
if (Hits[h].Distance == MinDist) {
if (Hits[h].Type == 1) {
b = Hits[h].Ball1;
bb = Hits[h].Ball2;
if (FirstHit == 0) {
if (Balls[b].Num == 0) {
FirstHit = Balls[bb].Num;
}
if (Balls[bb].Num == 0) {
FirstHit = Balls[b].Num;
}
}
Balls[b].Affected = true;
Balls[bb].Affected = true;
Balls[b].WasHit++;
Balls[bb].WasHit++;
BetweenBalls = CalcAngle(Balls[b].x, Balls[b].y, Balls[bb].x, Balls[bb].y);
AP = Math.cos(AngleDifference(Balls[b].Angle, BetweenBalls)) * Balls[b].Speed;
BP = Math.cos(AngleDifference(Balls[bb].Angle, BetweenBalls)) * Balls[bb].Speed;
Proj = AP - BP;
Forces.push({Ball:bb, Power:Proj, Angle:BetweenBalls});
Forces.push({Ball:b, Power:-Proj, Angle:BetweenBalls});
for (hh in Hits) {
if ((((((Hits[hh].Ball1 == b) or (Hits[hh].Ball2 == b)) or (Hits[hh].Ball == b)) or (Hits[hh].Ball1 == bb)) or (Hits[hh].Ball2 == bb)) or (Hits[hh].Ball == bb)) {
Hits[hh].Active = false;
}
}
BallsSound.push({Power:Proj, x:Balls[b].x + ((Balls[bb].x - Balls[b].x) / 2)});
}
if (Hits[h].Type == 2) {
Balls[Hits[h].Ball].Affected = true;
Balls[Hits[h].Ball].WasHit++;
Ang = Hits[h].Angle;
Balls[Hits[h].Ball].x = Hits[h].HitX;
Balls[Hits[h].Ball].y = Hits[h].HitY;
Power = -((Math.cos(AngleDifference(Balls[Hits[h].Ball].Angle, Ang)) * Balls[Hits[h].Ball].Speed) * 2);
Forces.push({Ball:Hits[h].Ball, Power:Power, Angle:Ang});
for (hh in Hits) {
if (((Hits[hh].Ball1 == Hits[h].Ball) or (Hits[hh].Ball2 == Hits[h].Ball)) or (Hits[hh].Ball == Hits[h].Ball)) {
Hits[hh].Active = false;
}
}
BordersSound.push({Power:Power, x:Balls[Hits[h].Ball].x});
}
}
}
for (h in Hits) {
if (!Hits[h].Active) {
Hits.splice(h, 1);
}
}
for (f in Forces) {
b = Forces[f].Ball;
Balls[b].FullMoveX = Balls[b].FullMoveX + (Math.sin(Forces[f].Angle) * Forces[f].Power);
Balls[b].FullMoveY = Balls[b].FullMoveY - (Math.cos(Forces[f].Angle) * Forces[f].Power);
Balls[b].MoveX = (1 - Progress) * Balls[b].FullMoveX;
Balls[b].MoveY = (1 - Progress) * Balls[b].FullMoveY;
Balls[b].Angle = CalcAngle(0, 0, Balls[b].FullMoveX, Balls[b].FullMoveY);
Balls[b].Speed = CalcDistance(0, 0, Balls[b].FullMoveX, Balls[b].FullMoveY);
}
}
} while (!AllDone);
AllStopped = true;
for (b in Balls) {
Balls[b].x = Balls[b].x + Balls[b].MoveX;
Balls[b].y = Balls[b].y + Balls[b].MoveY;
if ((Balls[b].y <= ((TopOffset + Border) + BallRadius)) and (((Balls[b].x >= Borders[0].StartX) and (Balls[b].x <= Borders[0].EndX)) or ((Balls[b].x >= Borders[1].StartX) and (Balls[b].x <= Borders[1].EndX)))) {
Balls[b].y = ((TopOffset + Border) + BallRadius) + 0.1;
}
if (((Balls[b].x >= ((740 - Border) - BallRadius)) and (Balls[b].y >= Borders[2].StartY)) and (Balls[b].y <= Borders[2].EndY)) {
Balls[b].x = ((740 - Border) - BallRadius) - 0.1;
}
if ((Balls[b].y >= (((TopOffset + 370) - Border) - BallRadius)) and (((Balls[b].x <= Borders[3].StartX) and (Balls[b].x >= Borders[3].EndX)) or ((Balls[b].x <= Borders[4].StartX) and (Balls[b].x >= Borders[4].EndX)))) {
Balls[b].y = (((TopOffset + 370) - Border) - BallRadius) - 0.1;
}
if (((Balls[b].x <= (Border + BallRadius)) and (Balls[b].y <= Borders[5].StartY)) and (Balls[b].y >= Borders[5].EndY)) {
Balls[b].x = (Border + BallRadius) + 0.1;
}
Balls[b].Speed = (Balls[b].Speed * 0.98) - 0.01;
if (Balls[b].Speed < 0.05) {
Balls[b].Speed = 0;
}
if (Balls[b].Speed > 0) {
AllStopped = false;
}
MovedX = Balls[b].x - Balls[b].InitX;
MovedY = Balls[b].y - Balls[b].InitY;
if (((Balls[b].Type == 1) or (Balls[b].Type == 2)) and ((MovedX != 0) or (MovedY != 0))) {
RotateBall(Balls[b], -(MovedY / 8), 0, MovedX / 8);
}
Balls[b].Speed = Balls[b].Speed * (1 - (Balls[b].WasHit * 0.1));
if (Mode == 3) {
Balls[b].x = Math.round(Balls[b].x * 1000) / 1000;
Balls[b].y = Math.round(Balls[b].y * 1000) / 1000;
}
if (!Simulation) {
Balls[b].Shadow._x = (Balls[b].Symbol._x = Balls[b].x);
Balls[b].Shadow._y = (Balls[b].Symbol._y = Balls[b].y);
}
NearPocket = 0;
if (Balls[b].y < (TopOffset + 47)) {
if (Balls[b].x < 260) {
NearPocket = 1;
}
if ((Balls[b].x >= 260) and (Balls[b].x <= 480)) {
NearPocket = 2;
}
if (Balls[b].x > 480) {
NearPocket = 3;
}
}
if (Balls[b].y > ((TopOffset + 370) - 47)) {
if (Balls[b].x < 260) {
NearPocket = 4;
}
if ((Balls[b].x >= 260) and (Balls[b].x <= 480)) {
NearPocket = 5;
}
if (Balls[b].x > 480) {
NearPocket = 6;
}
}
if (NearPocket > 0) {
DistanceToPocket = CalcDistance(Balls[b].x, Balls[b].y, Pockets[NearPocket].x, Pockets[NearPocket].y);
AngleFromPocket = CalcAngle(Pockets[NearPocket].x, Pockets[NearPocket].y, Balls[b].x, Balls[b].y);
Pocketed = false;
if (Math.abs(AngleDifference(AngleFromPocket, Pockets[NearPocket].Angle)) > halfPI) {
Pocketed = true;
if (DistanceToPocket > (16.97 - BallRadius)) {
Balls[b].Symbol._x = (Balls[b].x = Pockets[NearPocket].x + (Math.sin(AngleFromPocket) * (16.97 - BallRadius)));
Balls[b].Symbol._y = (Balls[b].y = Pockets[NearPocket].y - (Math.cos(AngleFromPocket) * (16.97 - BallRadius)));
}
} else if (DistanceToPocket <= 16.97) {
Pocketed = true;
}
if (Pocketed) {
PocketedNow.push(Balls[b].Num);
if (SO.data.SoundOn) {
PocketSound.setPan(Math.round((Pockets[NearPocket].x - 370) / 3.7));
PocketSound.start();
}
if (!Simulation) {
if (Balls[b].Num == 8) {
BlackIn = NearPocket;
}
Angle = Math.random() * dblPI;
Distance = Math.random() * 5;
DiffX = (Pockets[NearPocket].x + (Math.sin(Angle) * Distance)) - Balls[b].x;
DiffY = (Pockets[NearPocket].y - (Math.cos(Angle) * Distance)) - Balls[b].y;
Steps = 5;
MinDepth = Infinity;
for (bb in Balls) {
Depth = Balls[bb].Symbol.getDepth();
if (Depth < MinDepth) {
MinDepth = Depth;
}
}
Balls[b].Symbol.swapDepths(MinDepth);
FallingBalls.push({Symbol:Balls[b].Symbol, Shadow:Balls[b].Shadow, Col:new Color(Balls[b].Symbol), MoveX:DiffX / Steps, MoveY:DiffY / Steps, Steps:Steps});
if (Balls[b].Num == 0) {
CueBallPocketed = true;
RemoveBall = Balls[b].Symbol;
RemoveShadow = Balls[b].Shadow;
PlaceCue = 0;
}
}
Balls.splice(b, 1);
}
}
}
}
function SelectOpponent(num) {
SelectedOpponent = num;
Players[2].Name = Opponents[num].Name;
CPU.Skill = Opponents[num].Skill;
CPU.Accuracy = Opponents[num].Accuracy;
MDown = false;
SO.data.CPUPlayers[num].Played++;
SO.flush();
gotoAndPlay ("GameStart");
}
function InitTournament(Difficulty) {
TournamentType = Difficulty;
switch (Difficulty) {
case 1 :
MinCategory = 1;
MaxCategory = 4;
InitMatches = 4;
break;
case 2 :
MinCategory = 2;
MaxCategory = 7;
InitMatches = 8;
break;
case 3 :
MinCategory = 4;
MaxCategory = 10;
InitMatches = 16;
break;
case 4 :
MinCategory = 6;
MaxCategory = 13;
InitMatches = 32;
}
TotalCategories = (MaxCategory - MinCategory) + 1;
PeoplePerCategory = Math.ceil((InitMatches * 2) / TotalCategories);
Tourney = new Array();
TournamentSteps = Difficulty + 2;
t = 1;
while (t <= TournamentSteps) {
Tourney[t] = new Array();
t++;
}
c = MinCategory;
while (c <= MaxCategory) {
switch (c) {
case 1 :
Accuracy = 1;
Skill = 1;
break;
case 2 :
Accuracy = 1;
Skill = 2;
break;
case 3 :
Accuracy = 2;
Skill = 1;
break;
case 4 :
Accuracy = 2;
Skill = 2;
break;
case 5 :
Accuracy = 2;
Skill = 3;
break;
case 6 :
Accuracy = 3;
Skill = 2;
break;
case 7 :
Accuracy = 3;
Skill = 3;
break;
case 8 :
Accuracy = 3;
Skill = 4;
break;
case 9 :
Accuracy = 4;
Skill = 3;
break;
case 10 :
Accuracy = 4;
Skill = 4;
break;
case 11 :
Accuracy = 4;
Skill = 5;
break;
case 12 :
Accuracy = 5;
Skill = 4;
break;
case 13 :
Accuracy = 5;
Skill = 5;
}
TempCat = new Array();
CurrStage = 1;
cc = 0;
while (cc < TournamentCatagories[c].length) {
TempCat.push(TournamentCatagories[c][cc]);
cc++;
}
p = 1;
while (p <= PeoplePerCategory) {
CurrPart = random(TempCat.length);
Tourney[1].push({Name:TempCat[CurrPart], Accuracy:Accuracy, Skill:Skill, Lost:false});
if (Tourney[1].length >= ((InitMatches * 2) - 1)) {
break;
}
TempCat.splice(CurrPart, 1);
p++;
}
c++;
}
Tourney[1].unshift(Players[1]);
ChangesNum = random(Tourney[1].length * 200);
ch = 1;
while (ch <= ChangesNum) {
ChangePos = 1 + random(Tourney[1].length - 2);
Tmp = Tourney[1][ChangePos];
Tourney[1][ChangePos] = Tourney[1][ChangePos + 1];
Tourney[1][ChangePos + 1] = Tmp;
ch++;
}
CurrMatch = 0;
Frame3Squares = new Array();
Frame4Squares = new Array();
gotoAndPlay ("Tournament");
}
function DisplayExitDialogue() {
ExitScreen._visible = true;
MDown = false;
if (Mode != 3) {
Paused = true;
}
ExitScreen.WarningMessage._visible = (Mode == 3) and (!ExitFree._visible);
}
function UpdateSigns() {
if (SO.data.SoundOn) {
SoundSign.Txt = "SOUND: ON";
} else {
SoundSign.Txt = "SOUND: OFF";
}
if (SO.data.MusicOn) {
MusicSign.Txt = "MUSIC: ON";
} else {
MusicSign.Txt = "MUSIC: OFF";
}
}
function UpdateLoginCBs() {
if (SO.data.RememberLoginName) {
CBName.gotoAndStop(1);
} else {
CBName.gotoAndStop(2);
}
if (SO.data.RememberLoginPass) {
CBPass.gotoAndStop(1);
} else {
CBPass.gotoAndStop(2);
}
}
function LeaveLoginScreen() {
if (!SO.data.RememberLoginName) {
SO.data.LoginName = "";
}
if (!SO.data.RememberLoginPass) {
SO.data.LoginPass = "";
}
SO.flush();
}
function DisableAll(Level) {
if (Level == undefined) {
Level = _root;
}
var _local3;
for (_local3 in Level) {
if (Level[_local3] instanceof TextField) {
if (Level[_local3].type == "input") {
Level[_local3].type = "dynamic";
Level[_local3].selectable = false;
Disabled.push(Level[_local3]);
}
} else if (Level[_local3]._visible) {
if (Level[_local3].enabled) {
Level[_local3].enabled = false;
Disabled.push(Level[_local3]);
}
if (Level[_local3] instanceof MovieClip) {
DisableAll(Level[_local3]);
}
}
}
}
function EnableAll() {
var _local1;
for (_local1 in Disabled) {
if (Disabled[_local1] instanceof TextField) {
Disabled[_local1].selectable = true;
Disabled[_local1].type = "input";
} else {
Disabled[_local1].enabled = true;
}
}
Disabled = new Array();
}
function LoginSend(Data) {
if (!Connected) {
if (!Con.connect("sugar-free-games.com", 10003)) {
trace("Connection Failed");
OpenMB(10);
}
PendingData = Data;
OpenMB(1);
} else {
Con.send(Data);
OpenMB(2);
}
}
function EncodeSpecial(Text) {
var _local2;
while (_local2 = Text.indexOf("|") , _local2 != -1) {
Text = (Text.substring(0, _local2) + "[%s]") + Text.substr(_local2 + 1);
}
return(Text);
}
function DecodeSpecial(Text) {
var _local2;
while (_local2 = Text.indexOf("[%s]") , _local2 != -1) {
Text = (Text.substring(0, _local2) + "|") + Text.substr(_local2 + 4);
}
return(Text);
}
function OpenMB(Type) {
DisableAll();
MB._visible = true;
switch (Type) {
case 1 :
MB.gotoAndStop(1);
MB.Title = "CONNECTING";
break;
case 2 :
MB.gotoAndStop(1);
MB.AbortButt.enabled = true;
MB.Title = "SENDING/RECEIVING DATA";
break;
case 3 :
MB.gotoAndStop(2);
MB.Title = "ERROR";
MB.Text = "You cannot login to the server with an empty name. Please enter your name in \"LOG IN AS GUEST\" section and try again.";
MB.Butt1.Txt = "OK";
MB.Butt1.onPress = function () {
MB._visible = false;
EnableAll();
};
break;
case 4 :
MB.gotoAndStop(2);
MB.Title = "ERROR";
MB.Text = "The game you are trying to join is no longer available. Please try another game.";
MB.Butt1.Txt = "OK";
MB.Butt1.onPress = function () {
MB._visible = false;
EnableAll();
};
break;
case 5 :
MB.gotoAndStop(2);
MB.Title = "NOT ACCEPTED";
MB.Text = "The opponent has not accepted the game.";
MB.Butt1.Txt = "OK";
MB.Butt1.onPress = function () {
MB._visible = false;
EnableAll();
};
break;
case 6 :
MB.gotoAndStop(2);
MB.Title = "ERROR";
MB.Text = "You cannot use an empty name.\rType your name in \"Sign In\" section and try again.";
MB.Butt1.Txt = "OK";
MB.Butt1.onPress = function () {
MB._visible = false;
EnableAll();
};
break;
case 7 :
MB.gotoAndStop(2);
MB.Title = "ERROR";
MB.Text = "You cannot use an empty password.\rPlease type your password and try again.";
MB.Butt1.Txt = "OK";
MB.Butt1.onPress = function () {
MB._visible = false;
EnableAll();
};
break;
case 8 :
MB.gotoAndStop(2);
MB.Title = "ERROR";
MB.Text = "You cannot use this name because it's taken by another user. Please select a different name and try again.";
MB.Butt1.Txt = "OK";
MB.Butt1.onPress = function () {
MB._visible = false;
EnableAll();
Selection.setFocus("SignInName");
};
break;
case 9 :
MB.gotoAndStop(2);
MB.Title = "ERROR";
MB.Text = "Incorrect name/password.";
MB.Butt1.Txt = "OK";
MB.Butt1.onPress = function () {
MB._visible = false;
EnableAll();
Selection.setFocus("SignInName");
};
break;
case 10 :
MB.gotoAndStop(2);
MB.Title = "CONNECTION FAILED";
MB.Text = "Possible Solutions:\rTemporary Server Problem: Wait for a couple of minutes and try again.\rNo Internet Connection: Make sure you are connected to the Internet.\rPort Blocked: Adjust your firewall settings to allow traffic on port 10003.";
MB.Butt1.Txt = "OK";
MB.Butt1.onPress = function () {
MB._visible = false;
EnableAll();
};
}
}
function UpdateGames() {
var _local2;
var _local3;
AvGamesTxt = ((("AVAILABLE GAMES (" + (Math.floor(GamesListOffset / 8) + 1)) + "/") + (Math.floor((Games.length - 1) / 8) + 1)) + "):";
_local2 = 0;
while (_local2 <= 7) {
_local3 = _local2 + GamesListOffset;
if (_local3 < Games.length) {
this["I" + _local2]._visible = true;
if (Games[_local3].Rank == 0) {
this["I" + _local2].Name.gotoAndStop(2);
this["I" + _local2].RankSign.gotoAndStop(2);
delete this["I" + _local2].RankSign.onPress;
} else {
this["I" + _local2].Name.gotoAndStop(1);
this["I" + _local2].RankSign.gotoAndStop(1);
this["I" + _local2].RankSign.RankText = "Rank " + Games[_local3].Rank;
this["I" + _local2].RankSign.onPress = function () {
RequestInfo(this._parent.Index);
};
}
this["I" + _local2].Name.Text = Games[_local3].Name;
this["I" + _local2].Index = _local3;
if (Games[_local3].ID == YourID) {
this["I" + _local2].JoinButt._visible = false;
} else {
this["I" + _local2].JoinButt._visible = true;
this["I" + _local2].JoinButt.onPress = function () {
Con.send("2" + Games[this._parent.Index].ID);
Players[2].Name = this._parent.Name.Text;
MessageText = ("WAITING FOR " + this._parent.Name.Text.toUpperCase()) + "'S RESPONSE...";
gotoAndStop ("Waiting");
};
}
} else {
this["I" + _local2]._visible = false;
}
_local2++;
}
if (Games.length > (GamesListOffset + 8)) {
NextButt.enabled = true;
NextButt._alpha = 100;
} else {
NextButt.enabled = false;
NextButt._alpha = 40;
}
if (GamesListOffset > 0) {
PrevButt.enabled = true;
PrevButt._alpha = 100;
} else {
PrevButt.enabled = false;
PrevButt._alpha = 40;
}
}
function UpdatePoints() {
if (YouAreGuest) {
RI.gotoAndStop(2);
} else {
RI.gotoAndStop(1);
RI.PointsText = "Points: " + YourPoints;
RI.RankText = "Rank: " + PointsToRank(YourPoints);
}
}
function PointsToRank(Points) {
return(Math.floor(Math.sqrt(Points)) + 1);
}
function RequestInfo(ID) {
OpenMB(2);
Con.send("C" + ID);
}
halfPI = (Math.PI/2);
dblPI = (Math.PI*2);
Rad2Deg = 360 / dblPI;
Game = 1;
adBox._visible = false;
Connected = false;
var SO = SharedObject.getLocal("PoolSaved");
if (SO.data.SoundOn == undefined) {
SO.data.SoundOn = true;
}
if (SO.data.MusicOn == undefined) {
SO.data.MusicOn = true;
}
if (SO.data.RememberLoginName == undefined) {
SO.data.RememberLoginName = true;
}
if (SO.data.RememberLoginPass == undefined) {
SO.data.RememberLoginPass = true;
}
if (SO.data.CPUPlayers == undefined) {
SO.data.CPUPlayers = new Array();
i = 1;
while (i <= 9) {
SO.data.CPUPlayers[i] = {Played:0, Won:0};
i++;
}
}
if (SO.data.Player1Name == undefined) {
SO.data.Player1Name = "Player 1";
}
if (SO.data.Player2Name == undefined) {
SO.data.Player2Name = "Player 2";
}
if (SO.data.LoginName == undefined) {
SO.data.LoginName = SO.data.Player1Name;
}
if (SO.data.LoginPass == undefined) {
SO.data.LoginPass = "";
}
CPU = new Object();
Players = [undefined, {Name:SO.data.Player1Name}, {Name:SO.data.Player2Name}];
Opponents = [undefined, {Name:"Dodo Doodle", Skill:1, Accuracy:1}, {Name:"Lou Zer", Skill:1, Accuracy:2}, {Name:"John E.Z. Smith", Skill:2, Accuracy:2}, {Name:"Soso Machabeli", Skill:2, Accuracy:3}, {Name:"Sakamoto Okidoki", Skill:3, Accuracy:3}, {Name:"Michael Goodone", Skill:3, Accuracy:4}, {Name:"Jerry McTough", Skill:4, Accuracy:4}, {Name:"George S. Kika", Skill:4, Accuracy:5}, {Name:"Kent Beatme", Skill:5, Accuracy:5}];
TournamentCatagories = [undefined, ["John Smith", "Marco Van Hoosear", "Francesca Bianchi", "Vladimir Golubev", "Francisco Serrano", "Eithan Cohen", "Andrey Zoshenko", "Edna Goldberg", "Francois Guttier", "Friedrich Zimmermann"], ["Francesco Rossi", "Mario Rizzo", "Michael Sheppard", "Niclas Fleischer", "Cindy Fitzgerald", "Dmitry Petrov", "Jan Haasse", "Gustav Ericson", "Carl Larsen", "Jaanus Kallas"], ["Josef Kappel", "Lorenzo Ferrari", "Peter Jackson", "Anton Sidorov", "Jean Pasteur", "Knut Hansen", "Jozef Habich", "Yang Hu", "Petru Stoica", "Iwasawa Takashi"], ["Anna Klein", "Federico Esposito", "Marry White", "Olesia Kovach", "Claude Carol", "Peter Garborg", "Marat Bekmambetov", "Dimitris Fotopoulos", "Stefan Pascin", "Milan Markovic"], ["Lukas Bauer", "Filippo Ricci", "George Patton", "Bernardo Herrero", "Jacques Reno", "Jurgis Banionis", "Cemal Kaya", "Petr Krenek", "Martin Stanchev", "Stefan Sokolovic"], ["Jan Huber", "Stefano Romano", "Gregory Brown", "Ann Flynn", "Gregorio Vila", "Louis Maunier", "Thomas Van Houten", "Bohuslav Radok", "Maruyama Suzuki", "Sava Lazic"], ["Paul Farber", "Elisa Colombo", "Anthony Skinner", "Luis Schuster", "Antonio Torres", "Gabrielle Moulin", "Johan Brun", "Adam Kemula", "Timur Batyr", "Matija Simic"], ["Finn Schultz", "Stacy Johnson", "Jack Small", "Davide Russo", "Diego Hernandez", "Pierre Fourier", "Hans Kreuger", "Einar Scheving", "Sun Wang", "Dimitar Cheparinov"], ["Leon Koch", "Matteo Marino", "Nick Washington", "Heather McDonald", "David Blanco", "Bernard Van der Meer", "Wilhelm Jacobsen", "Ion Preda", "Georgios Kalomiris", "Peter Mitic"], ["Jonas Metzger", "Giuseppe Greco", "James Williams", "Pedro Jimenez", "Nils Bergman", "Lars Thomsen", "Andrius Kernagis", "Eugen Trailescu", "Yorgos Vamvakaris", "Svetomir Stojkov"], ["Simone Bruno", "Mark Evans", "David Ferguson", "Kevin Reilly", "Alain Dausset", "Kazimierz Godlewski", "Shimura Tokuhichi", "Konstantinos Georgiadis", "Filip Stupel", "Goran Nenadovic"], ["Vincenzo Gallo", "Alexander McQueen", "Douglas Gilmore", "Stewart O'Brien", "Richard Quinn", "Daniel Murray", "Tom Hayes", "Fred O'Neill", "Snorri Hauksson", "Tadeusz Brudzewski"], ["Luca Kaufmann", "Chris McNeely", "Robert Wilson", "Albert Scott", "Brad McMillan", "Bruce Boyle", "Steven O'Donnell", "Chung Lee", "Mehmet Batuk", "Jan Medek"]];
BallRadius = 9;
BallDiameter = BallRadius * 2;
StripeDivs = 10;
StripeStep = dblPI / StripeDivs;
StripeHeight = BallRadius / 2;
NumCircleDivs = 8;
LeftNC = 6;
RightNC = 2;
TopNC = 0;
BottomNC = 4;
NumCircleStep = dblPI / NumCircleDivs;
NumCircleRadius = BallRadius / 2.4;
OutsideRadius = BallRadius * 2;
FormationSpace = 2.1;
TopOffset = 65;
Border = 40;
TableLength = 740 - (Border * 2);
TableWidth = 370 - (Border * 2);
FootString = Border + (TableLength / 4);
HeadString = Border + (TableLength * 0.793);
VerticalMiddle = (TopOffset + Border) + (TableWidth / 2);
HeadRadius = 50;
HalfCornerMouth = 16;
PocketRadius = Math.sqrt(Math.pow(HalfCornerMouth + BallRadius, 2) * 2) / 2;
HalfSideMouth = PocketRadius + 1.776;
CornerOffset = (Border + 8) + HalfCornerMouth;
Top = (TopOffset + Border) + BallRadius;
Bottom = ((TopOffset + 370) - Border) - BallRadius;
Left = Border + BallRadius;
Right = (740 - Border) - BallRadius;
HalfPocket = 16.97;
MiddlePocketAngle = CalcAngle(HalfPocket, 20, HalfPocket + 3, 40);
HitPoint = LineHitsLine(co2ab(HalfPocket - BallRadius, 20, (HalfPocket + 3) - BallRadius, 40), co2ab(0, 40 + BallRadius, 10, 40 + BallRadius));
HalfMidMouth = HitPoint.x;
Corner2X = Border + (Math.sin(halfPI / 2) * BallRadius);
Corner2Y = 64 - (Math.cos(halfPI / 2) * BallRadius);
Borders = [{StartX:CornerOffset, StartY:Top, EndX:370 - HalfMidMouth, EndY:Top}, {StartX:370 + HalfMidMouth, StartY:Top, EndX:740 - CornerOffset, EndY:Top}, {StartX:Right, StartY:TopOffset + CornerOffset, EndX:Right, EndY:(TopOffset + 370) - CornerOffset}, {StartX:740 - CornerOffset, StartY:Bottom, EndX:370 + HalfMidMouth, EndY:Bottom}, {StartX:370 - HalfMidMouth, StartY:Bottom, EndX:CornerOffset, EndY:Bottom}, {StartX:Left, StartY:(TopOffset + 370) - CornerOffset, EndX:Left, EndY:TopOffset + CornerOffset}, {StartX:Corner2X, StartY:TopOffset + Corner2Y, EndX:0, EndY:(TopOffset + Corner2Y) - Corner2X}, {StartX:0, StartY:(TopOffset + Corner2X) - Corner2Y, EndX:Corner2Y, EndY:TopOffset + Corner2X}, {StartX:740 - Corner2Y, StartY:TopOffset + Corner2X, EndX:740, EndY:(TopOffset + Corner2X) - Corner2Y}, {StartX:740, StartY:(TopOffset + Corner2Y) - Corner2X, EndX:740 - Corner2X, EndY:TopOffset + Corner2Y}, {StartX:740, StartY:((TopOffset + 370) - Corner2X) + Corner2Y, EndX:740 - Corner2Y, EndY:(TopOffset + 370) - Corner2X}, {StartX:740 - Corner2X, StartY:(TopOffset + 370) - Corner2Y, EndX:740, EndY:((TopOffset + 370) - Corner2Y) + Corner2X}, {StartX:0, StartY:((TopOffset + 370) - Corner2Y) + Corner2X, EndX:Corner2X, EndY:(TopOffset + 370) - Corner2Y}, {StartX:Corner2Y, StartY:(TopOffset + 370) - Corner2X, EndX:0, EndY:((TopOffset + 370) - Corner2X) + Corner2Y}, {StartX:370 - HalfMidMouth, StartY:Top, EndX:(370 - HalfPocket) + BallRadius, EndY:TopOffset + 20}, {StartX:(370 - HalfPocket) + BallRadius, StartY:TopOffset + 20, EndX:(370 - HalfPocket) + BallRadius, EndY:TopOffset}, {StartX:(370 + HalfPocket) - BallRadius, StartY:TopOffset + 20, EndX:370 + HalfMidMouth, EndY:Top}, {StartX:(370 + HalfPocket) - BallRadius, StartY:TopOffset, EndX:(370 + HalfPocket) - BallRadius, EndY:TopOffset + 20}, {StartX:(370 - HalfPocket) + BallRadius, StartY:TopOffset + 370, EndX:(370 - HalfPocket) + BallRadius, EndY:TopOffset + 350}, {StartX:(370 - HalfPocket) + BallRadius, StartY:TopOffset + 350, EndX:370 - HalfMidMouth, EndY:Bottom}, {StartX:(370 + HalfPocket) - BallRadius, StartY:TopOffset + 350, EndX:(370 + HalfPocket) - BallRadius, EndY:TopOffset + 370}, {StartX:370 + HalfMidMouth, StartY:Bottom, EndX:(370 + HalfPocket) - BallRadius, EndY:TopOffset + 350}];
Borders.push({StartX:Borders[5].EndX, StartY:Borders[5].EndY, EndX:Borders[6].StartX, EndY:Borders[6].StartY});
Borders.push({StartX:Borders[7].EndX, StartY:Borders[7].EndY, EndX:Borders[0].StartX, EndY:Borders[0].StartY});
Borders.push({StartX:Borders[1].EndX, StartY:Borders[1].EndY, EndX:Borders[8].StartX, EndY:Borders[8].StartY});
Borders.push({StartX:Borders[9].EndX, StartY:Borders[9].EndY, EndX:Borders[2].StartX, EndY:Borders[2].StartY});
Borders.push({StartX:Borders[10].EndX, StartY:Borders[10].EndY, EndX:Borders[3].StartX, EndY:Borders[3].StartY});
Borders.push({StartX:Borders[2].EndX, StartY:Borders[2].EndY, EndX:Borders[11].StartX, EndY:Borders[11].StartY});
Borders.push({StartX:Borders[12].EndX, StartY:Borders[12].EndY, EndX:Borders[5].StartX, EndY:Borders[5].StartY});
Borders.push({StartX:Borders[4].EndX, StartY:Borders[4].EndY, EndX:Borders[13].StartX, EndY:Borders[13].StartY});
LongBorders = [{StartX:Borders[0].StartX, StartY:Borders[0].StartY, EndX:Borders[1].EndX, EndY:Borders[1].EndY, Angle:Math.PI}, {StartX:Borders[3].StartX, StartY:Borders[3].StartY, EndX:Borders[4].EndX, EndY:Borders[4].EndY, Angle:0}];
Pockets = [undefined, {x:30, y:TopOffset + 30, Angle:2.35619449019234, StartEnterX:Borders[6].StartX, StartEnterY:Borders[6].StartY, EndEnterX:Borders[7].EndX, EndEnterY:Borders[7].EndY}, {x:370, y:TopOffset + 20, Angle:Math.PI, StartEnterX:Borders[14].StartX, StartEnterY:Borders[14].StartY, EndEnterX:Borders[16].EndX, EndEnterY:Borders[16].EndY}, {x:710, y:TopOffset + 30, Angle:3.92699081698724, StartEnterX:Borders[8].StartX, StartEnterY:Borders[8].StartY, EndEnterX:Borders[9].EndX, EndEnterY:Borders[9].EndY}, {x:30, y:TopOffset + 340, Angle:(Math.PI/4), StartEnterX:Borders[13].StartX, StartEnterY:Borders[13].StartY, EndEnterX:Borders[12].EndX, EndEnterY:Borders[12].EndY}, {x:370, y:TopOffset + 350, Angle:0, StartEnterX:Borders[21].StartX, StartEnterY:Borders[21].StartY, EndEnterX:Borders[19].EndX, EndEnterY:Borders[19].EndY}, {x:710, y:TopOffset + 340, Angle:5.49778714378214, StartEnterX:Borders[11].StartX, StartEnterY:Borders[11].StartY, EndEnterX:Borders[10].EndX, EndEnterY:Borders[10].EndY}];
Pockets[1].ReflectBorders = [2, 3, 4];
Pockets[2].ReflectBorders = [3, 4];
Pockets[3].ReflectBorders = [3, 4, 5];
Pockets[4].ReflectBorders = [2, 0, 1];
Pockets[5].ReflectBorders = [0, 1];
Pockets[6].ReflectBorders = [0, 1, 5];
for (p in Pockets) {
ShiftX = Math.sin(Pockets[p].Angle + halfPI) * ((HalfPocket - BallRadius) - 1);
ShiftY = Math.cos(Pockets[p].Angle + halfPI) * ((HalfPocket - BallRadius) - 1);
Pockets[p].StartInsideX = Pockets[p].x + ShiftX;
Pockets[p].StartInsideY = Pockets[p].y - ShiftY;
Pockets[p].EndInsideX = Pockets[p].x - ShiftX;
Pockets[p].EndInsideY = Pockets[p].y + ShiftY;
}
for (b in Borders) {
Borders[b].Angle = CalcAngle(Borders[b].StartX, Borders[b].StartY, Borders[b].EndX, Borders[b].EndY) + halfPI;
}
MListener = new Object();
MListener.onMouseDown = function () {
MDown = true;
};
MListener.onMouseUp = function () {
MDown = false;
};
Mouse.addListener(MListener);
Powers = new Array();
i = 0;
while (i <= 60) {
Powers[i] = 0;
CurrSpeed = i;
while (CurrSpeed > 0) {
Powers[i] = Powers[i] + CurrSpeed;
CurrSpeed = (CurrSpeed * 0.98) - 0.01;
}
i++;
}
Disabled = new Array();
var Con = new XMLSocket();
Con.onConnect = function () {
Connected = true;
Con.send(PendingData);
OpenMB(2);
PingCounter = 0;
onEnterFrame = function () {
PingCounter++;
if ((!GameStarted) and (PingCounter >= 1500)) {
Con.send("X");
PingCounter = 0;
}
Now = new Date();
if (((GameStarted and (!YourTurn)) and ((PingCounter % 250) == 0)) and ((Now - LastMove) > 10000)) {
Con.send("F" + (LastActionNum + 1));
}
};
};
Con.onData = function (src) {
var _local1;
var _local2;
Command = src.substr(0, 1);
if (src.length > 1) {
_local2 = src.substr(1).split("|");
} else {
_local2 = null;
}
switch (Command) {
case "0" :
YourID = _local2[0];
YourPoints = Number(_local2[1]);
Games = new Array();
if (_local2.length > 3) {
_local1 = 2;
while (_local1 < _local2.length) {
Games.push({ID:_local2[_local1], Name:DecodeSpecial(_local2[_local1 + 1]), Rank:Number(_local2[_local1 + 2])});
_local1 = _local1 + 3;
}
}
LeaveLoginScreen();
MB._visible = false;
gotoAndStop ("Lobby");
break;
case "1" :
Games.push({ID:_local2[0], Name:DecodeSpecial(_local2[1]), Rank:Number(_local2[2])});
UpdateGames();
break;
case "2" :
for (_local1 in Games) {
if (Games[_local1].ID == _local2[0]) {
Games.splice(_local1, 1);
break;
}
}
UpdateGames();
break;
case "3" :
gotoAndStop ("Lobby");
GameNotAvailable = true;
break;
case "4" :
if (_local2[1] == "0") {
RankText = "guest";
} else {
RankText = "rank " + _local2[1];
}
Players[2].Name = _local2[0];
MessageText = ((_local2[0] + " (") + RankText) + ") wants to join your game.";
gotoAndStop ("AcceptOpponent");
break;
case "5" :
MDown = false;
YourTurn = true;
ReceivedPositions = new Array();
_local1 = 1;
while (_local1 < _local2.length) {
ReceivedPositions[_local1] = Number(_local2[_local1]);
_local1++;
}
gotoAndPlay ("GameStart");
break;
case "6" :
if ((!HasGame) and (!GameStarted)) {
IsDenied = true;
gotoAndStop ("Lobby");
}
break;
case "7" :
gotoAndStop ("OpponentLeft");
break;
case "8" :
if (Number(_local2[2]) == (LastActionNum + 1)) {
ReceivedHits.push({Angle:Number(_local2[0]), Power:Number(_local2[1])});
LastMove = new Date();
LastActionNum++;
}
if (Number(_local2[2]) > (LastActionNum + 1)) {
Con.send("F" + (LastActionNum + 1));
}
break;
case "9" :
if (Number(_local2[2]) == (LastActionNum + 1)) {
PlaceCueBall(Number(_local2[0]), Number(_local2[1]));
PlaceCue = 3;
CueBallPocketed = false;
UpdateBoards();
LastMove = new Date();
LastActionNum++;
}
if (Number(_local2[2]) > (LastActionNum + 1)) {
Con.send("F" + (LastActionNum + 1));
}
break;
case "A" :
OpenMB(8);
break;
case "B" :
OpenMB(9);
break;
case "C" :
YourPoints = Number(_local2[0]);
UpdatePoints();
break;
case "D" :
InfoArray = new Array();
_local1 = 0;
while (_local1 < _local2.length) {
InfoArray[_local1] = _local2[_local1];
_local1++;
}
gotoAndStop ("InfoPage");
break;
case "E" :
Con.close();
Connected = false;
gotoAndStop ("Disconnected");
break;
case "F" :
if (Number(_local2[0]) > (LastActionNum + 1)) {
Con.send("F" + (LastActionNum + 1));
} else {
if (Actions[Number(_local2[0])] == undefined) {
break;
}
Con.send(Actions[Number(_local2[0])]);
}
}
};
Frame 6
adBox._visible = false;
this.createEmptyMovieClip("BallHitsBallControl", this.getNextHighestDepth());
BallHitsBallSound = new Sound(BallHitsBallControl);
BallHitsBallSound.attachSound("ballhitsball");
this.createEmptyMovieClip("BallHitsBorderControl", this.getNextHighestDepth());
BallHitsBorderSound = new Sound(BallHitsBorderControl);
BallHitsBorderSound.attachSound("ballhitsborder");
this.createEmptyMovieClip("CueControl", this.getNextHighestDepth());
CueSound = new Sound(CueControl);
CueSound.attachSound("cue");
this.createEmptyMovieClip("PocketControl", this.getNextHighestDepth());
PocketSound = new Sound(PocketControl);
PocketSound.attachSound("pocket");
FaultSound = new Sound(this);
FaultSound.attachSound("fault");
SwitchPlayerSound = new Sound(this);
SwitchPlayerSound.attachSound("switchplayer");
WinSound = new Sound(this);
WinSound.attachSound("win");
LoseSound = new Sound(this);
LoseSound.attachSound("lose");
ClickSound = new Sound(this);
ClickSound.attachSound("click");
stop();
Frame 7
adBox._visible = false;
stop();
B1.Txt = "MULTIPLAYER";
B1.onPress = function () {
Mode = 3;
gotoAndStop ("MultiplayerLogin");
};
B2.Txt = "2 PLAYERS";
B2.onPress = function () {
Mode = 1;
gotoAndStop ("SetPlayerNames");
};
B3.Txt = "VS. CPU: SINGLE GAME";
B3.onPress = function () {
Mode = 2;
gotoAndStop ("OpponentSelect");
};
B4.Txt = "VS. CPU: TOURNAMENT";
B4.onPress = function () {
Mode = 2;
gotoAndStop ("TournamentSelect");
};
B5.Txt = "INSTRUCTIONS";
B5.onPress = function () {
gotoAndStop ("Instructions");
};
B6.Txt = "TOP ONLINE PLAYERS";
B6.onPress = function () {
getURL ("http://www.sugar-free-games.com/sfgpool.php", "_blank");
};
B7.Txt = "MORE BILLIARDS GAMES";
B7.onPress = function () {
getURL ("http://www.sugar-free-games.com/billiards.php", "_blank");
};
B8.Txt = "PLAY AND DOWNLOAD THIS GAME\rAT SUGAR-FREE-GAMES.COM";
B8.onPress = function () {
getURL ("http://www.sugar-free-games.com/showgame.php?game=2441", "_blank");
};
B9.Txt = "OTHER GREAT GAMES AT\rSUGAR-FREE-GAMES.COM";
B9.onPress = function () {
getURL ("http://www.sugar-free-games.com", "_blank");
};
PlayerName.text = SO.data.Player1Name;
Players[1].Name = SO.data.Player1Name;
this.onEnterFrame = function () {
if (eval (Selection.getFocus()) != PlayerName) {
Selection.setFocus("PlayerName");
} else {
delete this.onEnterFrame;
}
};
PlayerName.onChanged = function () {
SO.data.Player1Name = PlayerName.text;
Players[1].Name = PlayerName.text;
};
PlayerName.onKillFocus = function () {
SO.flush();
};
Frame 8
adBox._visible = false;
Players[1].Name = SO.data.Player1Name;
Players[2].Name = SO.data.Player2Name;
this.onEnterFrame = function () {
if (((Player1N.text != SO.data.Player1Name) or (Player2N.text != SO.data.Player2Name)) or (eval (Selection.getFocus()) != Player2N)) {
Player1N.text = SO.data.Player1Name;
Player2N.text = SO.data.Player2Name;
Selection.setFocus("Player2N");
} else {
delete this.onEnterFrame;
}
};
Player1N.onChanged = function () {
SO.data.Player1Name = Player1N.text;
Players[1].Name = Player1N.text;
};
Player2N.onChanged = function () {
SO.data.Player2Name = Player2N.text;
Players[2].Name = Player2N.text;
};
Player1N.onKillFocus = (Player2N.onKillFocus = function () {
SO.flush();
});
PlayButt.Txt = "PLAY";
PlayButt.onPress = function () {
MDown = false;
gotoAndPlay ("GameStart");
};
BackButt.Txt = "BACK";
BackButt.onPress = function () {
gotoAndStop ("MainMenu");
};
Frame 9
adBox._visible = false;
Butt1.Txt = "8 BALL RULES";
Butt1.onPress = function () {
gotoAndStop ("Rules");
};
Butt2.Txt = "MAIN MENU";
Butt2.onPress = function () {
gotoAndStop ("MainMenu");
};
Frame 10
adBox._visible = false;
Butt1.Txt = "INSTRUCTIONS";
Butt1.onPress = function () {
gotoAndStop ("Instructions");
};
Butt2.Txt = "MAIN MENU";
Butt2.onPress = function () {
gotoAndStop ("MainMenu");
};
Frame 11
adBox._visible = false;
stop();
ItsATourney = true;
TS1.Name = "TOURNEY FOR DUMMIES";
TS2.Name = "SCHOOL TOURNAMENT";
TS3.Name = "LOCAL COMPETITION";
TS4.Name = "WORLD CHAMPIONSHIP";
TS1.onPress = function () {
InitTournament(1);
};
TS2.onPress = function () {
InitTournament(2);
};
TS3.onPress = function () {
InitTournament(3);
};
TS4.onPress = function () {
InitTournament(4);
};
FromGame = false;
Butt.Txt = "TO MAIN MENU";
Butt.onPress = function () {
gotoAndStop ("MainMenu");
};
Frame 12
adBox._visible = false;
AllPairs = new Array();
PlayButton.Txt = "PLAY";
StartFrom = (-((InitMatches * 350) / 2)) + 100;
t = 1;
while (t <= TournamentSteps) {
AllPairs[t] = new Array();
CurrStageMatches = (InitMatches * 2) / Math.pow(2, t - 1);
i = 0;
while (i <= (CurrStageMatches - 1)) {
if (!(AllPairs[t][Math.floor(i / 2)] instanceof Object)) {
AllPairs[t][Math.floor(i / 2)] = new Object();
}
TourneyScreen.TSquareSample.duplicateMovieClip((("TS" + t) + "x") + i, TourneyScreen.getNextHighestDepth());
TourneyScreen[(("TS" + t) + "x") + i].gotoAndStop(1);
if (Tourney[t][i] != undefined) {
TourneyScreen[(("TS" + t) + "x") + i].Name = Tourney[t][i].Name;
}
if (t != 1) {
StartPair = AllPairs[t - 1][Math.floor(i / 2) * 2];
EndPair = AllPairs[t - 1][(Math.floor(i / 2) * 2) + 1];
BetweenPairs = StartPair.Square1._x + ((EndPair.Square2._x - StartPair.Square1._x) / 2);
}
if ((i % 2) == 0) {
if (t == 1) {
TourneyScreen[(("TS" + t) + "x") + i]._x = StartFrom + (Math.floor(i / 2) * 350);
} else {
TourneyScreen[(("TS" + t) + "x") + i]._x = BetweenPairs - 75;
}
AllPairs[t][Math.floor(i / 2)].Square1 = TourneyScreen[(("TS" + t) + "x") + i];
AllPairs[t][Math.floor(i / 2)].Player1 = Tourney[t][i];
} else {
if (t == 1) {
TourneyScreen[(("TS" + t) + "x") + i]._x = (StartFrom + (Math.floor(i / 2) * 350)) + 150;
} else {
TourneyScreen[(("TS" + t) + "x") + i]._x = BetweenPairs + 75;
}
AllPairs[t][Math.floor(i / 2)].Square2 = TourneyScreen[(("TS" + t) + "x") + i];
AllPairs[t][Math.floor(i / 2)].Player2 = Tourney[t][i];
}
TourneyScreen[(("TS" + t) + "x") + i]._y = -(t * 150);
i++;
}
t++;
}
for (i in Frame3Squares) {
TourneyScreen[Frame3Squares[i]].gotoAndStop(3);
}
for (i in Frame4Squares) {
TourneyScreen[Frame4Squares[i]].gotoAndStop(4);
}
HalfHeight = 30;
TourneyScreen.createEmptyMovieClip("Draw", TourneyScreen.getNextHighestDepth());
TourneyScreen.Draw.lineStyle(0.5, 4465152, 100);
t = 1;
while (t <= (TournamentSteps - 1)) {
i = 0;
while (i < AllPairs[t].length) {
TourneyScreen.Draw.moveTo(AllPairs[t][i].Square1._x, AllPairs[t][i].Square1._y - HalfHeight);
TourneyScreen.Draw.lineTo(AllPairs[t][i].Square1._x, (AllPairs[t][i].Square1._y - HalfHeight) - 5);
TourneyScreen.Draw.lineTo(AllPairs[t][i].Square2._x, (AllPairs[t][i].Square2._y - HalfHeight) - 5);
TourneyScreen.Draw.lineTo(AllPairs[t][i].Square2._x, AllPairs[t][i].Square2._y - HalfHeight);
Middle = AllPairs[t][i].Square1._x + ((AllPairs[t][i].Square2._x - AllPairs[t][i].Square1._x) / 2);
NextLevelPair = AllPairs[t + 1][Math.floor(i / 2)];
if ((i % 2) == 0) {
NextLevelSquare = NextLevelPair.Square1;
NextLSX = NextLevelSquare._x - 74;
} else {
NextLevelSquare = NextLevelPair.Square2;
NextLSX = NextLevelSquare._x + 74;
}
TourneyScreen.Draw.moveTo(Middle, (AllPairs[t][i].Square1._y - HalfHeight) - 5);
TourneyScreen.Draw.lineTo(Middle, NextLevelSquare._y);
TourneyScreen.Draw.lineTo(NextLSX, NextLevelSquare._y);
i++;
}
t++;
}
TourneyScreen.FinalSign._x = 0;
TourneyScreen.FinalSign._y = AllPairs[TournamentSteps][0].Square1._y - 100;
TourneyScreen.TSquareSample._visible = false;
TourneyScreen._x = (220 - AllPairs[CurrStage][0].Square1._x) + ((AllPairs[CurrStage][0].Square2._x - AllPairs[CurrStage][0].Square1._x) / 2);
TourneyScreen._y = (250 - AllPairs[CurrStage][0].Square1._y) + ((AllPairs[CurrStage][0].Square2._y - AllPairs[CurrStage][0].Square1._y) / 2);
Phase = 1;
PlayButton._visible = false;
PlayButton.onPress = function () {
CPU.Skill = AllPairs[CurrStage][0].Player2.Skill;
CPU.Accuracy = AllPairs[CurrStage][0].Player2.Accuracy;
Players[2].Name = AllPairs[CurrStage][0].Player2.Name;
MDown = false;
FromGame = true;
gotoAndPlay ("GameStart");
};
ScreenX = TourneyScreen._x;
ScreenY = TourneyScreen._y;
ScreenOffsetX = (ScreenOffsetY = 0);
Mouse.show();
Frame 13
adBox._visible = false;
switch (Phase) {
case 1 :
if (FromGame) {
Tourney[CurrStage + 1].push(Players[1]);
AllPairs[CurrStage + 1][Math.floor(CurrMatch / 2)].Player1 = Players[1];
AllPairs[CurrStage + 1][Math.floor(CurrMatch / 2)].Square1.Name = Players[1].Name;
AllPairs[CurrStage][CurrMatch].Square1.gotoAndStop(3);
AllPairs[CurrStage][CurrMatch].Square2.gotoAndStop(4);
Frame3Squares.push(AllPairs[CurrStage][CurrMatch].Square1._name);
Frame4Squares.push(AllPairs[CurrStage][CurrMatch].Square2._name);
FromGame = false;
Phase = 2;
} else if (AllPairs[CurrStage][CurrMatch].Player1 != Players[1]) {
Player1Score = (AllPairs[CurrStage][CurrMatch].Player1.Skill + (AllPairs[CurrStage][CurrMatch].Player1.Accuracy * 2)) + random(3);
Player2Score = (AllPairs[CurrStage][CurrMatch].Player2.Skill + (AllPairs[CurrStage][CurrMatch].Player2.Accuracy * 2)) + random(3);
if (Player1Score > Player2Score) {
MatchWinner = AllPairs[CurrStage][CurrMatch].Player1;
AllPairs[CurrStage][CurrMatch].Square1.gotoAndStop(3);
AllPairs[CurrStage][CurrMatch].Square2.gotoAndStop(4);
Frame3Squares.push(AllPairs[CurrStage][CurrMatch].Square1._name);
Frame4Squares.push(AllPairs[CurrStage][CurrMatch].Square2._name);
} else {
MatchWinner = AllPairs[CurrStage][CurrMatch].Player2;
AllPairs[CurrStage][CurrMatch].Square2.gotoAndStop(3);
AllPairs[CurrStage][CurrMatch].Square1.gotoAndStop(4);
Frame3Squares.push(AllPairs[CurrStage][CurrMatch].Square2._name);
Frame4Squares.push(AllPairs[CurrStage][CurrMatch].Square1._name);
}
Tourney[CurrStage + 1].push(MatchWinner);
if (SO.data.SoundOn) {
ClickSound.start();
}
if ((CurrMatch % 2) == 0) {
AllPairs[CurrStage + 1][Math.floor(CurrMatch / 2)].Player1 = MatchWinner;
AllPairs[CurrStage + 1][Math.floor(CurrMatch / 2)].Square1.Name = MatchWinner.Name;
} else {
AllPairs[CurrStage + 1][Math.floor(CurrMatch / 2)].Player2 = MatchWinner;
AllPairs[CurrStage + 1][Math.floor(CurrMatch / 2)].Square2.Name = MatchWinner.Name;
}
Phase = 2;
} else {
AllPairs[CurrStage][0].Square1.gotoAndStop(2);
AllPairs[CurrStage][0].Square2.gotoAndStop(2);
PlayButton._visible = true;
if (Key.isDown(37)) {
ScreenOffsetX = ScreenOffsetX + 10;
}
if (Key.isDown(39)) {
ScreenOffsetX = ScreenOffsetX - 10;
}
if (Key.isDown(38)) {
ScreenOffsetY = ScreenOffsetY + 10;
}
if (Key.isDown(40)) {
ScreenOffsetY = ScreenOffsetY - 10;
}
}
break;
case 2 :
if (CurrMatch < (AllPairs[CurrStage].length - 1)) {
CurrMatch++;
} else {
CurrMatch = 0;
CurrStage++;
}
NextPair = AllPairs[CurrStage][CurrMatch];
MoveToX = (220 - AllPairs[CurrStage][CurrMatch].Square1._x) + ((AllPairs[CurrStage][CurrMatch].Square2._x - AllPairs[CurrStage][CurrMatch].Square1._x) / 2);
MoveToY = (250 - AllPairs[CurrStage][CurrMatch].Square1._y) + ((AllPairs[CurrStage][CurrMatch].Square2._y - AllPairs[CurrStage][CurrMatch].Square1._y) / 2);
Steps = 10;
StepX = (MoveToX - TourneyScreen._x) / Steps;
StepY = (MoveToY - TourneyScreen._y) / Steps;
Counter = 0;
Phase = 3;
break;
case 3 :
Counter++;
if (Counter >= 10) {
Counter = 0;
AllPairs[CurrStage][CurrMatch].Square1.gotoAndStop(2);
AllPairs[CurrStage][CurrMatch].Square2.gotoAndStop(2);
Phase = 4;
}
break;
case 4 :
ScreenX = ScreenX + StepX;
ScreenY = ScreenY + StepY;
Counter++;
if (Counter < Steps) {
break;
}
Phase = 1;
}
TourneyScreen._x = ScreenX + ScreenOffsetX;
TourneyScreen._y = ScreenY + ScreenOffsetY;
Frame 14
adBox._visible = false;
gotoAndPlay ("TournamentCycle");
Frame 15
adBox._visible = false;
stop();
i = 1;
while (i <= 9) {
this["OS" + i].Name = Opponents[i].Name;
this["OS" + i].SkillStars.gotoAndStop(Opponents[i].Skill);
this["OS" + i].AccuracyStars.gotoAndStop(Opponents[i].Accuracy);
this["OS" + i].Played = NumberFormat(SO.data.CPUPlayers[i].Played, 0);
this["OS" + i].Won = SO.data.CPUPlayers[i].Won;
this["OS" + i].Ind = i;
this["OS" + i].onPress = function () {
SelectOpponent(this.Ind);
};
i++;
}
Mouse.show();
ItsATourney = false;
Butt.Txt = "TO MAIN MENU";
Butt.onPress = function () {
gotoAndStop ("MainMenu");
};
Frame 16
adBox._visible = false;
IsDenied = false;
GameNotAvailable = false;
CancelButt.Txt = "CANCEL";
MB._visible = false;
GamesListOffset = 0;
CancelButt.onPress = function () {
LeaveLoginScreen();
if (Connected) {
Connected = false;
Con.close();
delete onEnterFrame;
}
gotoAndStop ("MainMenu");
};
GuestLoginButt.Txt = "LOG IN AS GUEST";
GuestLoginButt.onPress = function () {
if (GuestName.text.length == 0) {
OpenMB(3);
} else {
LoginSend("0" + EncodeSpecial(GuestName.text));
}
YourName = GuestName.text;
YouAreGuest = true;
};
SignInButt.Txt = "SIGN IN";
SignInButt.onPress = function () {
YourName = SignInName.text;
Players[1].Name = SignInName.text;
YouAreGuest = false;
if (SignInName.text.length == 0) {
OpenMB(6);
} else if (SignInPass.text.length == 0) {
OpenMB(7);
} else {
LoginSend((("6" + EncodeSpecial(SignInName.text)) + "|") + EncodeSpecial(SignInPass.text));
}
};
RegisterButt.Txt = "REGISTER THIS NAME";
RegisterButt.onPress = function () {
YourName = SignInName.text;
Players[1].Name = SignInName.text;
YouAreGuest = false;
if (SignInName.text.length == 0) {
OpenMB(6);
} else if (SignInPass.text.length == 0) {
OpenMB(7);
} else {
LoginSend((("7" + EncodeSpecial(SignInName.text)) + "|") + EncodeSpecial(SignInPass.text));
}
};
UpdateLoginCBs();
CBName.onPress = function () {
SO.data.RememberLoginName = !SO.data.RememberLoginName;
SO.flush();
UpdateLoginCBs();
};
CBPass.onPress = function () {
SO.data.RememberLoginPass = !SO.data.RememberLoginPass;
SO.flush();
UpdateLoginCBs();
};
if (SO.data.RememberLoginName) {
SignInName.text = SO.data.LoginName;
}
if (SO.data.RememberLoginPass) {
SignInPass.text = SO.data.LoginPass;
}
SignInName.onChanged = function () {
if (SO.data.RememberLoginName) {
SO.data.LoginName = SignInName.text;
}
};
SignInPass.onChanged = function () {
if (SO.data.RememberLoginPass) {
SO.data.LoginPass = SignInPass.text;
}
};
GuestName.onChanged = function () {
SO.data.Player1Name = GuestName.text;
Players[1].Name = GuestName.text;
};
GuestName.text = SO.data.Player1Name;
Frame 17
adBox._visible = false;
gotoAndStop ("MultiplayerLogin");
Frame 18
this.onEnterFrame = function () {
if (adBox._visible) {
adBox._visible = false;
}
};
AdLoader.loadClip((("http://server.cpmstar.com/adviewas2.swf?poolid=" + CPMStarPoolID) + "&subpoolid=") + CPMStarSubPoolID, adBox);
adBox._visible = false;
GameStarted = false;
HasGame = false;
MB._visible = false;
CreateButt.Txt = "CREATE GAME";
CreateButt.onPress = function () {
Con.send("1");
MessageText = "WAITING FOR AN OPPONENT TO JOIN..";
HasGame = true;
gotoAndStop ("Waiting");
};
CancelButt.Txt = "LOG OUT";
CancelButt.onPress = function () {
Con.close();
Connected = false;
delete onEnterFrame;
gotoAndStop ("MainMenu");
};
UpdateGames();
PrevButt.onPress = function () {
GamesListOffset = GamesListOffset - 8;
UpdateGames();
};
NextButt.onPress = function () {
GamesListOffset = GamesListOffset + 8;
UpdateGames();
};
if (IsDenied) {
OpenMB(5);
IsDenied = false;
}
if (GameNotAvailable) {
OpenMB(4);
GameNotAvailable = false;
}
UpdatePoints();
NameText = YourName;
if (YouAreGuest) {
StatButt._visible = false;
} else {
StatButt.onPress = function () {
RequestInfo(YourID);
};
}
Frame 19
this.onEnterFrame = function () {
if (!adBox._visible) {
adBox._visible = true;
}
};
CancelButt.Txt = "CANCEL";
CancelButt.onPress = function () {
Con.send("5");
gotoAndStop ("Lobby");
};
Frame 20
adBox._visible = false;
Mouse.show();
MessageText = "THE OPPONENT HAS LEFT THE GAME";
OKButt.Txt = "OK";
OKButt.onPress = function () {
if (HasGame) {
MessageText = "WAITING FOR AN OPPONENT TO JOIN...";
gotoAndStop ("Waiting");
} else {
gotoAndStop ("Lobby");
}
};
GameStarted = false;
Frame 21
adBox._visible = false;
OKButt.Txt = "OK";
OKButt.onPress = function () {
gotoAndStop ("MainMenu");
};
Frame 22
this.onEnterFrame = function () {
if (adBox._visible) {
adBox._visible = false;
}
};
AcceptButt.Txt = "ACCEPT";
AcceptButt.onPress = function () {
MDown = false;
YourTurn = false;
gotoAndPlay ("GameStart");
};
DenyButt.Txt = "REJECT";
DenyButt.onPress = function () {
Con.send("4");
MessageText = "WAITING FOR AN OPOPNENT TO JOIN...";
gotoAndStop ("Waiting");
};
Frame 23
adBox._visible = false;
MonthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
NameText = InfoArray[0];
InfoArray[1] = Number(InfoArray[1]);
R = PointsToRank(InfoArray[1]);
RankText = "Rank: " + R;
PointsText = "Points: " + NumberFormat(InfoArray[1], 0);
PointsNextLevelText = "Needed for the next rank: " + NumberFormat(Math.pow(R, 2) - InfoArray[1], 0);
PlayedText = "Games Played: " + NumberFormat(Number(InfoArray[2]), 0);
WonText = "Games Won: " + NumberFormat(Number(InfoArray[3]), 0);
LostText = "Games Lost: " + NumberFormat(Number(InfoArray[4]), 0);
Now = new Date();
InFlashFormat = Number(InfoArray[5]) * 1000;
Reg = new Date();
Reg.setTime(InFlashFormat);
RegisteredText = ((((((("Registered: " + MonthNames[Reg.getMonth()]) + " ") + Reg.getDate()) + " ") + Reg.getFullYear()) + " (") + Math.floor((Now - InFlashFormat) / 86400000)) + " days ago)";
i = 0;
while (i < 10) {
InArr = 6 + (i * 2);
if ((InArr < InfoArray.length) and (InfoArray[InArr] != "")) {
this["Game" + i] = "vs. " + InfoArray[InArr];
if (InfoArray[InArr + 1] == "1") {
this["Game" + i] = this["Game" + i] + " (won)";
} else {
this["Game" + i] = this["Game" + i] + " (lost)";
}
} else {
this["Game" + i] = "";
}
i++;
}
BackButt.Txt = "BACK";
BackButt.onPress = function () {
gotoAndStop ("Lobby");
};
Frame 24
adBox._visible = false;
Butt1.Txt = "PLAY THIS GAME AT\rSUGAR-FREE-GAMES.COM";
Butt1.onPress = function () {
getURL ("http://www.sugar-free-games.com/showgame.php?game=2441", "_blank");
};
Butt2.Txt = "BACK";
Butt2.onPress = function () {
gotoAndStop(GoBack);
};
Frame 25
function RotateBall(Ball, XRot, YRot, ZRot) {
var x;
var y;
var z;
var InitX;
var Visible;
var Arr;
var a;
var Nexti;
var TopLineStart;
var TopLineEnd;
var BottomLineStart;
var BottomLineEnd;
var i;
var MidX;
var MidZ;
var ConnectEnds;
var AngleToMid;
var To;
var VarName;
var StartFrom;
Ball.XRot = Ball.XRot + XRot;
Ball.YRot = Ball.YRot + YRot;
Ball.ZRot = Ball.ZRot + ZRot;
Ball.XRot = Ball.XRot % dblPI;
Ball.ZRot = Ball.ZRot % dblPI;
Ball.YRot = Ball.YRot % dblPI;
Ball.Symbol.Stripe.clear();
Ball.Symbol.Stripe.lineStyle(0, 0, 0);
var TopLine = new Array();
var BottomLine = new Array();
var NumCircle = new Array();
i = 0;
while (i < Ball.Points.length) {
x = (Math.sin(YRot) * Ball.Points[i].z) + (Math.cos(YRot) * Ball.Points[i].x);
z = (Math.cos(YRot) * Ball.Points[i].z) - (Math.sin(YRot) * Ball.Points[i].x);
y = (Math.sin(XRot) * z) + (Math.cos(XRot) * Ball.Points[i].y);
z = (Math.cos(XRot) * z) - (Math.sin(XRot) * Ball.Points[i].y);
InitX = x;
x = (Math.sin(ZRot) * y) + (Math.cos(ZRot) * x);
y = (Math.cos(ZRot) * y) - (Math.sin(ZRot) * InitX);
Visible = y >= 0;
if (Ball.Points[i].Type == 3) {
NumCircle.push({x:x, y:y, z:z, Visible:Visible});
}
if (Ball.Points[i].Type == 1) {
TopLine.push({x:x, y:y, z:z, Visible:Visible});
}
if (Ball.Points[i].Type == 2) {
BottomLine.push({x:x, y:y, z:z, Visible:Visible});
}
Ball.Points[i].x = x;
Ball.Points[i].y = y;
Ball.Points[i].z = z;
i++;
}
if (Ball.Type == 1) {
StartFrom = 1;
} else {
StartFrom = 3;
}
a = StartFrom;
while (a <= 3) {
if (a == 1) {
Arr = "TopLine";
}
if (a == 2) {
Arr = "BottomLine";
}
if (a == 3) {
Arr = "NumCircle";
}
this[Arr + "Start"] = undefined;
this[Arr + "End"] = undefined;
i = 0;
while (i < eval (Arr).length) {
if (i < (eval (Arr).length - 1)) {
Nexti = i + 1;
} else {
Nexti = 0;
}
if (eval (Arr)[i].Visible != eval (Arr)[Nexti].Visible) {
if (eval (Arr)[Nexti].Visible) {
To = eval (Arr)[i];
this[Arr + "Start"] = i;
VarName = Arr + "StartAngle";
eval (Arr)[i].StartEnd = 1;
} else {
To = eval (Arr)[Nexti];
this[Arr + "End"] = Nexti;
VarName = Arr + "EndAngle";
eval (Arr)[Nexti].StartEnd = 2;
}
AngleToMid = CalcAngle(0, 0, To.x, To.z);
this[VarName] = AngleToMid;
}
i++;
}
if ((this[Arr + "Start"] == undefined) and (!eval (Arr)[0].Visible)) {
this[Arr + "Exists"] = false;
} else {
this[Arr + "Exists"] = true;
}
a++;
}
if (Ball.Type == 1) {
Ball.Symbol.Stripe.beginFill(Ball.StripeColor);
if ((this.TopLineStart == undefined) and this.TopLineExists) {
this.TopLineEnd = (this.TopLineStart = Math.floor(StripeDivs / 2));
this.TopLineStartAngle = (this.TopLineEndAngle = CalcAngle(0, 0, TopLine[this.TopLineStart].x, TopLine[this.TopLineStart].z));
}
if ((this.BottomLineEnd == undefined) and this.BottomLineExists) {
this.BottomLineEnd = (this.BottomLineStart = Math.floor(StripeDivs / 2));
this.BottomLineStartAngle = (this.BottomLineEndAngle = CalcAngle(0, 0, BottomLine[this.BottomLineStart].x, BottomLine[this.BottomLineStart].z));
}
if (this.TopLineExists) {
ConnectEnds = this.TopLineStart == this.TopLineEnd;
Ball.Symbol.Stripe.moveTo(TopLine[this.TopLineStart].x, TopLine[this.TopLineStart].z);
i = 0;
while (i < StripeDivs) {
Nexti = this.TopLineStart + i;
if (Nexti >= TopLine.length) {
Nexti = Nexti - TopLine.length;
}
if (TopLine[Nexti].Visible or (TopLine[Nexti].StartEnd > 0)) {
Ball.Symbol.Stripe.lineTo(TopLine[Nexti].x, TopLine[Nexti].z);
}
i++;
}
if (ConnectEnds) {
Ball.Symbol.Stripe.lineTo(TopLine[this.TopLineEnd].x, TopLine[this.TopLineEnd].z);
}
if (this.BottomLineExists) {
FillGap(this.TopLineEndAngle, this.BottomLineEndAngle, Ball.Symbol.Stripe);
} else {
FillGap(this.TopLineStartAngle, this.TopLineEndAngle, Ball.Symbol.Stripe);
}
} else {
Ball.Symbol.Stripe.moveTo(BottomLine[this.BottomLineStart].x, BottomLine[this.BottomLineStart].z);
}
if (this.BottomLineExists) {
ConnectEnds = this.BottomLineStart == this.BottomLineEnd;
i = 0;
while (i < StripeDivs) {
Nexti = this.BottomLineEnd - i;
if (Nexti < 0) {
Nexti = Nexti + BottomLine.length;
}
if (BottomLine[Nexti].Visible or (BottomLine[Nexti].StartEnd > 0)) {
Ball.Symbol.Stripe.lineTo(BottomLine[Nexti].x, BottomLine[Nexti].z);
}
i++;
}
if (ConnectEnds) {
Ball.Symbol.Stripe.lineTo(BottomLine[this.BottomLineStart].x, BottomLine[this.BottomLineStart].z);
}
if (this.TopLineExists) {
FillGap(this.BottomLineStartAngle, this.TopLineStartAngle, Ball.Symbol.Stripe);
} else {
FillGap(this.BottomLineStartAngle, this.BottomLineEndAngle, Ball.Symbol.Stripe);
}
}
Ball.Symbol.Stripe.endFill();
}
if (((Ball.Type == 1) or (Ball.Type == 2)) and this.NumCircleExists) {
Ball.Symbol.Stripe.beginFill(14540236);
if (this.NumCircleStart == undefined) {
this.NumCircleEnd = (this.NumCircleStart = 0);
}
Ball.Symbol.Stripe.moveTo(NumCircle[this.NumCircleStart].x, NumCircle[this.NumCircleStart].z);
i = 0;
while (i < NumCircleDivs) {
Nexti = i + this.NumCircleStart;
if (Nexti >= NumCircle.length) {
Nexti = Nexti - NumCircle.length;
}
if (NumCircle[Nexti].Visible) {
Ball.Symbol.Stripe.lineTo(NumCircle[Nexti].x, NumCircle[Nexti].z);
}
i++;
}
if (this.NumCircleStart != this.NumCircleEnd) {
FillGap(this.NumCircleEndAngle, this.NumCircleStartAngle, Ball.Symbol.Stripe);
}
Ball.Symbol.Stripe.endFill();
if (Ball.Points[0].y > 0) {
Ball.Symbol.Num._visible = true;
NCRot = CalcAngle(NumCircle[BottomNC].x, NumCircle[BottomNC].z, NumCircle[TopNC].x, NumCircle[TopNC].z);
NCVert = CalcDistance(NumCircle[BottomNC].x, NumCircle[BottomNC].z, NumCircle[TopNC].x, NumCircle[TopNC].z);
NCHor = CalcDistance(NumCircle[LeftNC].x, NumCircle[LeftNC].z, NumCircle[RightNC].x, NumCircle[RightNC].z);
Ball.Symbol.Num._rotation = NCRot * Rad2Deg;
Ball.Symbol.Num._yscale = (NCVert / (NumCircleRadius * 2)) * 100;
Ball.Symbol.Num._xscale = (NCHor / (NumCircleRadius * 2)) * 100;
Ball.Symbol.Num._x = Ball.Points[0].x;
Ball.Symbol.Num._y = Ball.Points[0].z;
} else {
Ball.Symbol.Num._visible = false;
}
} else {
Ball.Symbol.Num._visible = false;
}
}
function FillGap(StartAngle, EndAngle, Symbol) {
var _local5;
var _local2;
var _local1;
var _local4;
var _local3;
_local4 = AngleDifference(StartAngle, EndAngle);
if (_local4 == 0) {
_local4 = dblPI;
}
if (_local4 < 0) {
_local4 = dblPI + _local4;
}
_local3 = Math.abs(Math.ceil(_local4 / 1));
_local5 = _local4 / _local3;
_local1 = 0;
while (_local1 <= _local3) {
_local2 = StartAngle + (_local1 * _local5);
Symbol.lineTo(Math.sin(_local2) * OutsideRadius, -(Math.cos(_local2) * OutsideRadius));
_local1++;
}
}
function DrawPoint(Draw, x, y) {
Draw.moveTo(x - 0.5, y);
Draw.lineTo(x + 0.5, y);
Draw.moveTo(x, y - 0.5);
Draw.lineTo(x, y + 0.5);
}
function AddBall(BallNum, x, y) {
var _local1;
var _local8;
var _local3;
var _local2;
_local2 = Balls.length;
BallSymbolIndex++;
BallsClip.BallSample.duplicateMovieClip("B" + BallSymbolIndex, BallsClip.getNextHighestDepth());
Shadows.ShadowSample.duplicateMovieClip("S" + BallSymbolIndex, Shadows.getNextHighestDepth());
Balls[_local2] = new Object();
Balls[_local2].Shadow = Shadows["S" + BallSymbolIndex];
Balls[_local2].Symbol = BallsClip["B" + BallSymbolIndex];
Balls[_local2].Points = new Array();
Balls[_local2].XRot = 0;
Balls[_local2].YRot = 0;
Balls[_local2].ZRot = 0;
if (BallNum == 0) {
Balls[_local2].BGColor = 14540236 /* 0xDDDDCC */;
Balls[_local2].Type = 3;
}
if (Game == 1) {
switch (BallNum) {
case 1 :
Balls[_local2].BGColor = 14526976 /* 0xDDAA00 */;
break;
case 2 :
Balls[_local2].BGColor = 221;
break;
case 3 :
Balls[_local2].BGColor = 14483456 /* 0xDD0000 */;
break;
case 4 :
Balls[_local2].BGColor = 8913032 /* 0x880088 */;
break;
case 5 :
Balls[_local2].BGColor = 14509568 /* 0xDD6600 */;
break;
case 6 :
Balls[_local2].BGColor = 34816;
break;
case 7 :
Balls[_local2].BGColor = 8921600 /* 0x882200 */;
break;
case 8 :
Balls[_local2].BGColor = 2236962 /* 0x222222 */;
break;
case 9 :
Balls[_local2].StripeColor = 14526976 /* 0xDDAA00 */;
break;
case 10 :
Balls[_local2].StripeColor = 221;
break;
case 11 :
Balls[_local2].StripeColor = 14483456 /* 0xDD0000 */;
break;
case 12 :
Balls[_local2].StripeColor = 8913032 /* 0x880088 */;
break;
case 13 :
Balls[_local2].StripeColor = 14509568 /* 0xDD6600 */;
break;
case 14 :
Balls[_local2].StripeColor = 34816;
break;
case 15 :
Balls[_local2].StripeColor = 8921600 /* 0x882200 */;
}
if ((BallNum > 0) and (BallNum <= 8)) {
Balls[_local2].Type = 2;
}
if (BallNum > 8) {
Balls[_local2].Type = 1;
Balls[_local2].BGColor = 14540236 /* 0xDDDDCC */;
}
} else {
Balls[_local2].Type = 3;
}
Balls[_local2].BGCol = new Color(Balls[_local2].Symbol.BG);
Balls[_local2].BGCol.setRGB(Balls[_local2].BGColor);
_local3 = Math.sqrt(Math.pow(BallRadius, 2) - Math.pow(StripeHeight, 2));
if ((Balls[_local2].Type == 1) or (Balls[_local2].Type == 2)) {
Balls[_local2].Symbol.Num._visible = true;
Balls[_local2].Symbol.Num.gotoAndStop(BallNum);
Balls[_local2].Points[0] = {x:0, y:BallRadius, z:0, Type:4};
_local8 = Math.sqrt(Math.pow(BallRadius, 2) - Math.pow(NumCircleRadius, 2));
_local1 = 0;
while (_local1 < NumCircleDivs) {
Balls[_local2].Points[_local1 + 1] = {x:Math.sin(_local1 * NumCircleStep) * NumCircleRadius, y:_local8, z:-(Math.cos(_local1 * NumCircleStep) * NumCircleRadius), Type:3};
_local1++;
}
} else {
Balls[_local2].Symbol.Num._visible = false;
}
if (Balls[_local2].Type == 1) {
_local1 = 0;
while (_local1 < StripeDivs) {
Balls[_local2].Points[(_local1 + NumCircleDivs) + 1] = {x:Math.sin(_local1 * StripeStep) * _local3, y:Math.cos(_local1 * StripeStep) * _local3, z:-StripeHeight, Type:1};
Balls[_local2].Points[((_local1 + StripeDivs) + NumCircleDivs) + 1] = {x:Math.sin(_local1 * StripeStep) * _local3, y:Math.cos(_local1 * StripeStep) * _local3, z:StripeHeight, Type:2};
_local1++;
}
}
Balls[_local2].Shadow._x = (Balls[_local2].Symbol._x = (Balls[_local2].x = x));
Balls[_local2].Shadow._y = (Balls[_local2].Symbol._y = (Balls[_local2].y = y));
Balls[_local2].Speed = 0;
Balls[_local2].Angle = 0;
Balls[_local2].Num = BallNum;
RotateBall(Balls[_local2], 0, Math.random() * dblPI, 0);
return(_local2);
}
function DrawPoint(x, y, Col) {
Draw.lineStyle(1, Col, 100);
Draw.moveTo(x - 1, y);
Draw.lineTo(x + 1, y);
Draw.moveTo(x, y - 1);
Draw.lineTo(x, y + 1);
}
delete onEnterFrame;
adBox._visible = false;
MusicSign._visible = false;
SFGLogo.onPress = function () {
getURL ("http://www.sugar-free-games.com", "_blank");
};
if (Mode != 3) {
YourTurn = false;
}
if ((Mode == 3) and YourTurn) {
Cue._visible = false;
}
MusteSounds = true;
SwitchPlayers();
HitTwice = false;
FirstHit = 0;
BlackIn = 0;
LastActionNum = 0;
Actions = new Array();
GameStarted = true;
ReceivedHits = new Array();
UpdateSigns();
SoundSign.onPress = function () {
SO.data.SoundOn = !SO.data.SoundOn;
UpdateSigns();
SO.flush();
MDown = false;
};
MusicSign.onPress = function () {
SO.data.MusicOn = !SO.data.MusicOn;
UpdateSigns();
SO.flush();
MDown = false;
};
ExitButt.onPress = function () {
DisplayExitDialogue();
};
ExitScreen._visible = false;
PleaseWait._visible = false;
AllStopped = false;
Power = 0;
Cue.Inside._y = BallRadius;
CueBallPocketed = false;
PocketedNow = new Array();
PrevAllStopped = true;
if (CPU.Skill < 3) {
CPU.MaxLevels = 1;
} else {
CPU.MaxLevels = 2;
}
Players[1].BallType = 0;
Players[2].BallType = 0;
Players[1].PocketedBalls = 0;
Players[2].PocketedBalls = 0;
PC1._visible = false;
PC2._visible = false;
Balls = new Array();
BallSymbolIndex = -1;
BallsClip.BallSample._visible = false;
Shadows.ShadowSample._visible = false;
Formation = CreateFormation();
AddBall(0, HeadString, VerticalMiddle);
CueBall = Balls[0];
i = 0;
while (i <= 14) {
AddBall(Formation[i].Ball, Formation[i].x, Formation[i].y);
i++;
}
FallingBalls = new Array();
UpdateBoards();
Player1Name = Players[1].Name;
Player2Name = Players[2].Name;
Message = "";
this.createEmptyMovieClip("Draw", this.getNextHighestDepth());
Draw.lineStyle(1, 16711680, 100);
ExitFree._visible = false;
LastMove = new Date();
Frame 26
adBox._visible = false;
if (!Paused) {
BallsSound = new Array();
BordersSound = new Array();
if (!AllStopped) {
Physics(Balls, false);
if (SO.data.SoundOn and (BallsSound.length > 0)) {
TotalPower = 0;
TotalX = 0;
for (bh in BallsSound) {
TotalPower = TotalPower + BallsSound[bh].Power;
TotalX = TotalX + BallsSound[bh].x;
}
AverageX = TotalX / BallsSound.length;
BallHitsBallSound.setVolume(Math.round(TotalPower * 1.5));
BallHitsBallSound.setPan(Math.round((AverageX - 370) / 3.5));
BallHitsBallSound.start();
}
if (SO.data.SoundOn and (BordersSound.length > 0)) {
TotalPower = 0;
TotalX = 0;
for (bh in BordersSound) {
TotalPower = TotalPower + BordersSound[bh].Power;
TotalX = TotalX + BordersSound[bh].x;
}
AverageX = TotalX / BordersSound.length;
BallHitsBorderSound.setVolume(Math.round(TotalPower * 1.5));
BallHitsBorderSound.setPan(Math.round((AverageX - 370) / 3.5));
BallHitsBorderSound.start();
}
}
for (b in FallingBalls) {
FallingBalls[b].Symbol._x = FallingBalls[b].Symbol._x + FallingBalls[b].MoveX;
FallingBalls[b].Symbol._y = FallingBalls[b].Symbol._y + FallingBalls[b].MoveY;
FallingBalls[b].Shadow._x = FallingBalls[b].Symbol._x;
FallingBalls[b].Shadow._y = FallingBalls[b].Symbol._y;
Brightness = 20 + (FallingBalls[b].Steps * 16);
FallingBalls[b].Col.setTransform({ra:Brightness, rb:0, ga:Brightness, gb:0, ba:Brightness, bb:0});
FallingBalls[b].Steps--;
if (FallingBalls[b].Steps == 0) {
FallingBalls.splice(b, 1);
}
}
if (AllStopped) {
if (!PrevAllStopped) {
Message = "";
Fault = 0;
if (Game == 1) {
if (PocketedNow.length == 0) {
if (HitTwice) {
HitTwice = false;
} else {
Fault = 4;
}
}
if ((Player.BallType > 0) and (CheckBallType(FirstHit) != Player.BallType)) {
Fault = 1;
}
if (PocketedNow.length > 0) {
HitTwice = false;
if (!((PocketedNow.length == 1) and (PocketedNow[0] == 0))) {
Message = Player.Name + " pockets ";
}
MessageAddition = "";
i = 0;
while (i < PocketedNow.length) {
if ((Player.BallType == 0) and (((PocketedNow[i] > 0) and (PocketedNow[i] < 8)) or (PocketedNow[i] > 8))) {
if (PocketedNow[i] < 8) {
Player.BallType = 2;
Opponent.BallType = 1;
MessageAddition = (Player.Name + "'s balls are solids.") + "\r";
} else {
Player.BallType = 1;
Opponent.BallType = 2;
MessageAddition = (Player.Name + "'s balls are stripes.") + "\r";
}
}
if ((Player.BallType != 0) and (CheckBallType(PocketedNow[i]) == Player.BallType)) {
Player.PocketedBalls++;
} else {
Fault = 3;
}
if ((Player.BallType != 0) and (CheckBallType(PocketedNow[i]) == Opponent.BallType)) {
Opponent.PocketedBalls++;
}
if ((Player.PocketedBalls == 7) and (Player.BallType != 3)) {
Player.BallType = 3;
MessageAddition = MessageAddition + ((Player.Name + " goes on 8.") + "\r");
}
if ((Opponent.PocketedBalls == 7) and (Opponent.BallType != 3)) {
Opponent.BallType = 3;
MessageAddition = MessageAddition + ((Opponent.Name + " goes on 8.") + "\r");
}
if (PocketedNow[i] != 0) {
Message = Message + PocketedNow[i];
if ((i < (PocketedNow.length - 1)) and (!((i == (PocketedNow.length - 2)) and (PocketedNow[i + 1] == 0)))) {
Message = Message + ", ";
}
}
i++;
}
if (!((PocketedNow.length == 1) and (PocketedNow[0] == 0))) {
Message = Message + ".\r";
}
Message = Message + MessageAddition;
if (CueBallPocketed) {
Fault = 2;
}
}
if ((BlackIn > 0) and (Fault == 0)) {
EndGame(1);
}
if ((BlackIn > 0) and (Fault > 0)) {
EndGame(2);
}
if (BlackIn == 0) {
if (Fault > 0) {
if (((Fault != 4) and (Opponent.BallType != 3)) and (Opponent.BallType != 0)) {
HitTwice = true;
}
if (Fault != 4) {
Message = Message + "FAULT!!! ";
id(SO.data.SoundOn);
FaultSound.start();
}
if (Fault == 1) {
Message = Message + ((Player.Name + " scratches.") + "\r");
}
if (Fault == 2) {
Message = Message + (((((Player.Name + " pockets the cue ball.") + "\r") + Opponent.Name) + ", place the cue ball.") + "\r");
}
if (Fault == 3) {
Message = Message + ((Player.Name + " pockets an opponent's ball.") + "\r");
}
SwitchPlayers();
}
}
PocketedNow = new Array();
}
FirstHit = 0;
BlackIn = 0;
}
UpdateBoards();
if (YourTurn or (Mode == 1)) {
if (CueBallPocketed) {
PlaceCueBall(_xmouse, _ymouse);
if (MDown) {
PlaceCue = 3;
}
if (PrevMDown and (!MDown)) {
CueBallPocketed = false;
UpdateBoards();
if (Mode == 3) {
LastActionNum++;
Actions[LastActionNum] = (((("9" + _xmouse) + "|") + _ymouse) + "|") + LastActionNum;
Con.send(Actions[LastActionNum]);
LastMove = new Date();
}
}
} else {
Cue._visible = true;
Angle = CalcAngle(CueBall.x, CueBall.y, _xmouse, _ymouse);
Cue._x = CueBall.x;
Cue._y = CueBall.y;
Rot = Angle * Rad2Deg;
Cue._rotation = Rot;
Cue.Inside.gotoAndStop(Math.round(Rot));
if (MDown) {
if (!PrevMDown) {
Power = 0;
}
Power = Power + 3;
if (Power > 100) {
Power = 100;
}
Cue.Inside._y = BallRadius + Power;
} else if (PrevMDown and (!ExitScreen._visible)) {
if (Mode == 3) {
Angle = Math.round(Angle * 10000) / 10000;
}
CueBall.Angle = Angle;
CueBall.Speed = Power;
Cue.Inside._y = BallRadius;
AllStopped = false;
if (Mode == 3) {
LastActionNum++;
Actions[LastActionNum] = (((("8" + Angle) + "|") + Power) + "|") + LastActionNum;
Con.send(Actions[LastActionNum]);
LastMove = new Date();
}
if (SO.data.SoundOn) {
CueSound.setVolume(Math.round(Power * 1.5));
CueSound.setPan(Math.round((CueBall.x - 370) / 3.5));
CueSound.start();
}
}
}
} else {
PleaseWait._visible = true;
if (Mode == 3) {
if (ReceivedHits.length > 0) {
Angle = ReceivedHits[0].Angle;
Power = ReceivedHits[0].Power;
OpponentPhase = 4;
ReceivedHits.shift();
}
}
if (Mode == 2) {
if (OpponentPhase == 0) {
if (CueBallPocketed) {
Ang = Math.random() * dblPI;
Dis = random(50);
PlaceCueBall(HeadString + (Math.sin(Ang) * Dis), VerticalMiddle - (Math.cos(Ang) * Dis));
PlaceCue = 3;
CueBallPocketed = false;
UpdateBoards();
}
Targets = new Array();
i = 0;
while (i <= CPU.MaxLevels) {
Targets[i] = new Array();
i++;
}
p = 1;
while (p < Pockets.length) {
if ((p == 2) or (p == 5)) {
PVal = -10;
PM = 0.9;
OutsideMiddle = true;
} else {
PVal = 0;
PM = 1;
OutsideMiddle = false;
}
Targets[0].push({StartX:Pockets[p].StartEnterX, StartY:Pockets[p].StartEnterY, EndX:Pockets[p].EndEnterX, EndY:Pockets[p].EndEnterY, Pocket:Pockets[p], Points:PVal, PowerMultiplier:PM, OutsideMiddle:OutsideMiddle, Type:2});
Targets[0].push({StartX:Pockets[p].StartInsideX, StartY:Pockets[p].StartInsideY, EndX:Pockets[p].EndInsideX, EndY:Pockets[p].EndInsideY, Pocket:Pockets[p], Points:10, OutsideMiddle:false, Type:2});
p++;
}
CurrLevel = 0;
OpponentPhase = 1;
for (b in Balls) {
BType = CheckBallType(Balls[b].Num);
Balls[b].Hitable = ((Player.BallType != 0) and (BType == Player.BallType)) or (((Player.BallType == 0) and (BType >= 1)) and (BType <= 2));
}
for (b in Balls) {
Balls[b].Blocked = new Array();
}
b = 0;
while (b < (Balls.length - 1)) {
bb = b + 1;
while (bb < Balls.length) {
if ((Balls[b] != CueBall) and (Balls[bb] != CueBall)) {
DistanceBetweenBalls = CalcDistance(Balls[b].x, Balls[b].y, Balls[bb].x, Balls[bb].y);
if (DistanceBetweenBalls < (BallDiameter * 2)) {
AngleBetweenBalls = CalcAngle(Balls[b].x, Balls[b].y, Balls[bb].x, Balls[bb].y);
AngleDiff = Math.acos((DistanceBetweenBalls / 2) / BallDiameter);
Balls[b].Blocked.push({Start:AngleBetweenBalls - AngleDiff, End:AngleBetweenBalls + AngleDiff, Ball:Balls[bb]});
RevAngle = AngleBetweenBalls + Math.PI;
while (RevAngle > dblPI) {
RevAngle = RevAngle - dblPI;
}
Balls[bb].Blocked.push({Start:RevAngle - AngleDiff, End:RevAngle + AngleDiff, Ball:Balls[b]});
}
}
bb++;
}
b++;
}
TriedToHitAnything = false;
b = 0;
t = 0;
Operations = 0;
PossibleHits = new Array();
}
if (OpponentPhase == 1) {
while (true) {
FoundAWay = false;
if ((((((Balls[b] != Targets[CurrLevel][t].Ball) and (Targets[CurrLevel][t] instanceof Object)) and ((b == Targets[CurrLevel][t].DesignatedBall) or (Targets[CurrLevel][t].Type != 3))) and (Balls[b].Hitable or (CurrLevel != 0))) and ((Balls[b] == CueBall) or (CurrLevel != CPU.MaxLevels))) and ((Balls[b].Hitable or (Balls[b] == CueBall)) or (CurrLevel != (CPU.MaxLevels - 1)))) {
Blocked = false;
StartAngle = CalcAngle(Balls[b].x, Balls[b].y, Targets[CurrLevel][t].StartX, Targets[CurrLevel][t].StartY);
EndAngle = CalcAngle(Balls[b].x, Balls[b].y, Targets[CurrLevel][t].EndX, Targets[CurrLevel][t].EndY);
while (StartAngle > EndAngle) {
StartAngle = StartAngle - dblPI;
}
AngleToStart = Targets[CurrLevel][t].AngleToStart;
AngleToEnd = Targets[CurrLevel][t].AngleToEnd;
if (Targets[CurrLevel][t].Type == 2) {
SPDifference = Math.abs(AngleDifference(Targets[CurrLevel][t].Pocket.Angle, StartAngle));
EPDifference = Math.abs(AngleDifference(Targets[CurrLevel][t].Pocket.Angle, EndAngle));
}
if (!((Targets[CurrLevel][t].Type == 2) and (((!Targets[CurrLevel][t].OutsideMiddle) and ((SPDifference <= halfPI) or (EPDifference <= halfPI))) or (Targets[CurrLevel][t].OutsideMiddle and ((SPDifference <= 2.19911485751286) or (EPDifference <= 2.19911485751286)))))) {
Operations++;
StartDistance = CalcDistance(Balls[b].x, Balls[b].y, Targets[CurrLevel][t].StartX, Targets[CurrLevel][t].StartY);
EndDistance = CalcDistance(Balls[b].x, Balls[b].y, Targets[CurrLevel][t].EndX, Targets[CurrLevel][t].EndY);
TargetStartX = Targets[CurrLevel][t].StartX;
TargetStartY = Targets[CurrLevel][t].StartY;
TargetEndX = Targets[CurrLevel][t].EndX;
TargetEndY = Targets[CurrLevel][t].EndY;
if (Targets[CurrLevel][t].Type == 1) {
AngleFromTarget = CalcAngle(Targets[CurrLevel][t].Ball.x, Targets[CurrLevel][t].Ball.y, Balls[b].x, Balls[b].y);
DistanceToTarget = CalcDistance(Targets[CurrLevel][t].Ball.x, Targets[CurrLevel][t].Ball.y, Balls[b].x, Balls[b].y);
Alpha = Math.acos(BallDiameter / DistanceToTarget);
StartLimit = AngleFromTarget + Alpha;
EndLimit = AngleFromTarget - Alpha;
if ((((StartLimit != undefined) and (EndLimit != undefined)) and (Targets[CurrLevel][t].AngleToStart != undefined)) and (Targets[CurrLevel][t].AngleToEnd != undefined)) {
Blocked = true;
FixStart = false;
FixEnd = false;
StartFallsBetween = AngleFallsBetween(Targets[CurrLevel][t].AngleToStart, EndLimit, StartLimit);
EndFallsBetween = AngleFallsBetween(Targets[CurrLevel][t].AngleToEnd, EndLimit, StartLimit);
if (StartFallsBetween and EndFallsBetween) {
Blocked = false;
}
if (EndFallsBetween and (!StartFallsBetween)) {
FixStart = true;
}
if (StartFallsBetween and (!EndFallsBetween)) {
FixEnd = true;
}
if (AngleFallsBetween(StartLimit, Targets[CurrLevel][t].AngleToEnd, Targets[CurrLevel][t].AngleToStart) and AngleFallsBetween(EndLimit, Targets[CurrLevel][t].AngleToEnd, Targets[CurrLevel][t].AngleToStart)) {
FixStart = true;
FixEnd = true;
}
if (FixStart) {
AngleToStart = StartLimit;
TargetStartX = Targets[CurrLevel][t].Ball.x + (Math.sin(StartLimit) * BallDiameter);
TargetStartY = Targets[CurrLevel][t].Ball.y - (Math.cos(StartLimit) * BallDiameter);
NewStartAngle = CalcAngle(Balls[b].x, Balls[b].y, TargetStartX, TargetStartY);
NewStartAngle = MakeSimilar(NewStartAngle, StartAngle);
StartAngle = NewStartAngle;
Blocked = false;
}
if (FixEnd) {
AngleToEnd = EndLimit;
TargetEndX = Targets[CurrLevel][t].Ball.x + (Math.sin(EndLimit) * BallDiameter);
TargetEndY = Targets[CurrLevel][t].Ball.y - (Math.cos(EndLimit) * BallDiameter);
NewEndAngle = CalcAngle(Balls[b].x, Balls[b].y, TargetEndX, TargetEndY);
NewEndAngle = MakeSimilar(NewEndAngle, EndAngle);
EndAngle = NewEndAngle;
Blocked = false;
}
if (FixStart or FixEnd) {
while (StartAngle > EndAngle) {
StartAngle = StartAngle - dblPI;
}
StartDistance = CalcDistance(Balls[b].x, Balls[b].y, TargetStartX, TargetStartY);
EndDistance = CalcDistance(Balls[b].x, Balls[b].y, TargetEndX, TargetEndY);
Blocked = false;
}
}
}
if (!Blocked) {
bb = 0;
while (bb < Balls.length) {
Balls[bb].AngleFromCurrent = CalcAngle(Balls[b].x, Balls[b].y, Balls[bb].x, Balls[bb].y);
Balls[bb].DistanceFromCurrent = CalcDistance(Balls[b].x, Balls[b].y, Balls[bb].x, Balls[bb].y);
Balls[bb].DistanceFromTarget = CalcDistance(Targets[CurrLevel][t].Ball.x, Targets[CurrLevel][t].Ball.y, Balls[bb].x, Balls[bb].y);
bb++;
}
bb = 0;
while (bb < Balls.length) {
if ((bb != b) and (Balls[bb] != Targets[CurrLevel][t].Ball)) {
Perp = StartAngle + halfPI;
XShift = Math.sin(Perp) * BallDiameter;
YShift = Math.cos(Perp) * BallDiameter;
HitPoint = SegmentHitsSegment(Balls[b].x, Balls[b].y, TargetStartX, TargetStartY, Balls[bb].x - XShift, Balls[bb].y + YShift, Balls[bb].x + XShift, Balls[bb].y - YShift);
if (((HitPoint.x != undefined) and (CalcDistance(Balls[bb].x, Balls[bb].y, HitPoint.x, HitPoint.y) < BallDiameter)) or ((CalcDistance(TargetStartX, TargetStartY, Balls[bb].x, Balls[bb].y) < BallDiameter) and (Targets[CurrLevel][t].Type != 1))) {
AngleShift = Math.asin(BallDiameter / Balls[bb].DistanceFromCurrent);
NewStartAngle = Balls[bb].AngleFromCurrent + AngleShift;
while (NewStartAngle < StartAngle) {
NewStartAngle = NewStartAngle + dblPI;
}
StartAngle = NewStartAngle;
NewStartAngle = MakeSimilar(NewStartAngle, StartAngle);
TargetStartX = Balls[b].x + (Math.sin(StartAngle) * StartDistance);
TargetStartY = Balls[b].y - (Math.cos(StartAngle) * StartDistance);
if (StartAngle > EndAngle) {
break;
}
}
}
bb++;
}
bb = 0;
while (bb < Balls.length) {
if ((bb != b) and (Balls[bb] != Targets[CurrLevel][t].Ball)) {
Perp = EndAngle - halfPI;
XShift = Math.sin(Perp) * BallDiameter;
YShift = Math.cos(Perp) * BallDiameter;
HitPoint = SegmentHitsSegment(Balls[b].x, Balls[b].y, TargetEndX, TargetEndY, Balls[bb].x - XShift, Balls[bb].y + YShift, Balls[bb].x + XShift, Balls[bb].y - YShift);
if (((HitPoint.x != undefined) and (CalcDistance(Balls[bb].x, Balls[bb].y, HitPoint.x, HitPoint.y) < BallDiameter)) or ((CalcDistance(TargetEndX, TargetEndY, Balls[bb].x, Balls[bb].y) < BallDiameter) and (Targets[CurrLevel][t].Type != 1))) {
AngleShift = Math.asin(BallDiameter / Balls[bb].DistanceFromCurrent);
NewEndAngle = Balls[bb].AngleFromCurrent - AngleShift;
while (NewEndAngle > EndAngle) {
NewEndAngle = NewEndAngle - dblPI;
}
NewEndAngle = MakeSimilar(NewEndAngle, EndAngle);
EndAngle = NewEndAngle;
TargetEndX = Balls[b].x + (Math.sin(EndAngle) * EndDistance);
TargetEndY = Balls[b].y - (Math.cos(EndAngle) * EndDistance);
if (EndAngle < StartAngle) {
break;
}
}
}
bb++;
}
for (br in Borders) {
if ((Targets[CurrLevel][t].Border != br) or (Targets[CurrLevel][t].Type != 3)) {
StartHitPoint = SegmentHitsSegment(Balls[b].x, Balls[b].y, TargetStartX, TargetStartY, Borders[br].StartX, Borders[br].StartY, Borders[br].EndX, Borders[br].EndY);
EndHitPoint = SegmentHitsSegment(Balls[b].x, Balls[b].y, TargetEndX, TargetEndY, Borders[br].StartX, Borders[br].StartY, Borders[br].EndX, Borders[br].EndY);
Point2 = undefined;
if (StartHitPoint.x != undefined) {
Point2 = SegmentHitsSegment(TargetStartX, TargetStartY, TargetEndX, TargetEndY, Borders[br].StartX, Borders[br].StartY, Borders[br].EndX, Borders[br].EndY);
if ((Point2.x != undefined) and (EndHitPoint.x == undefined)) {
TargetStartX = Point2.x;
TargetStartY = Point2.y;
} else {
TargetStartX = Borders[br].EndX;
TargetStartY = Borders[br].EndY;
}
NewStartAngle = CalcAngle(Balls[b].x, Balls[b].y, TargetStartX, TargetStartY);
while (NewStartAngle < StartAngle) {
NewStartAngle = NewStartAngle + dblPI;
}
NewStartAngle = MakeSimilar(NewStartAngle, StartAngle);
StartAngle = NewStartAngle;
}
if (EndHitPoint.x != undefined) {
if (Point2 == undefined) {
Point2 = SegmentHitsSegment(TargetStartX, TargetStartY, TargetEndX, TargetEndY, Borders[br].StartX, Borders[br].StartY, Borders[br].EndX, Borders[br].EndY);
}
if ((Point2.x != undefined) and (StartHitPoint.x == undefined)) {
TargetEndX = Point2.x;
TargetEndY = Point2.y;
} else {
TargetEndX = Borders[br].StartX;
TargetEndY = Borders[br].StartY;
}
NewEndAngle = CalcAngle(Balls[b].x, Balls[b].y, TargetEndX, TargetEndY);
while (NewEndAngle > EndAngle) {
NewEndAngle = NewEndAngle - dblPI;
}
NewEndAngle = MakeSimilar(NewEndAngle, EndAngle);
EndAngle = NewEndAngle;
}
}
}
StartAngle = MakeSimilar(StartAngle, EndAngle);
if (((StartAngle <= EndAngle) and ((EndAngle - StartAngle) <= Math.PI)) and (!Blocked)) {
if (Targets[CurrLevel][t].Type == 1) {
AngleToStart = CalcAngle(Targets[CurrLevel][t].Ball.x, Targets[CurrLevel][t].Ball.y, TargetStartX, TargetStartY);
AngleToEnd = CalcAngle(Targets[CurrLevel][t].Ball.x, Targets[CurrLevel][t].Ball.y, TargetEndX, TargetEndY);
while (AngleToEnd > AngleToStart) {
AngleToEnd = AngleToEnd - dblPI;
}
CurrX = Targets[CurrLevel][t].Ball.x;
CurrY = Targets[CurrLevel][t].Ball.y - BallRadius;
a = 0.01;
while (a <= dblPI) {
PrevX = CurrX;
PrevY = CurrY;
CurrX = Targets[CurrLevel][t].Ball.x + (Math.sin(a) * BallRadius);
CurrY = Targets[CurrLevel][t].Ball.y - (Math.cos(a) * BallRadius);
IsBlocked = false;
for (bl in Targets[CurrLevel][t].Ball.Blocked) {
if ((Targets[CurrLevel][t].Ball.Blocked[bl].Ball != Balls[b]) and AngleFallsBetween(a, Targets[CurrLevel][t].Ball.Blocked[bl].Start, Targets[CurrLevel][t].Ball.Blocked[bl].End)) {
IsBlocked = true;
break;
}
}
a = a + 0.01;
}
for (bl in Targets[CurrLevel][t].Ball.Blocked) {
if (((Targets[CurrLevel][t].Ball.Blocked[bl].Ball != Balls[b]) and AngleFallsBetween(AngleToStart, Targets[CurrLevel][t].Ball.Blocked[bl].Start, Targets[CurrLevel][t].Ball.Blocked[bl].End)) or (AngleFallsBetween(Targets[CurrLevel][t].Ball.Blocked[bl].Start, AngleToEnd, AngleToStart) and AngleFallsBetween(Targets[CurrLevel][t].Ball.Blocked[bl].End, AngleToEnd, AngleToStart))) {
NewAngleToStart = Targets[CurrLevel][t].Ball.Blocked[bl].Start;
while (NewAngleToStart > AngleToStart) {
NewAngleToStart = NewAngleToStart - dblPI;
}
NewAngleToStart = MakeSimilar(NewAngleToStart, AngleToStart);
AngleToStart = NewAngleToStart;
}
if (AngleFallsBetween(AngleToEnd, Targets[CurrLevel][t].Ball.Blocked[bl].Start, Targets[CurrLevel][t].Ball.Blocked[bl].End)) {
NewAngleToEnd = Targets[CurrLevel][t].Ball.Blocked[bl].End;
while (NewAngleToEnd < AngleToEnd) {
NewAngleToEnd = NewAngleToEnd + dblPI;
}
NewAngleToEnd = MakeSimilar(NewAngleToEnd, AngleToEnd);
AngleToEnd = NewAngleToEnd;
}
}
if (AngleToStart < AngleToEnd) {
Blocked = true;
} else {
TargetStartX = Targets[CurrLevel][t].Ball.x + (Math.sin(AngleToStart) * BallDiameter);
TargetStartY = Targets[CurrLevel][t].Ball.y - (Math.cos(AngleToStart) * BallDiameter);
TargetEndX = Targets[CurrLevel][t].Ball.x + (Math.sin(AngleToEnd) * BallDiameter);
TargetEndY = Targets[CurrLevel][t].Ball.y - (Math.cos(AngleToEnd) * BallDiameter);
NewStartAngle = CalcAngle(Balls[b].x, Balls[b].y, TargetStartX, TargetStartY);
StartAngle = MakeSimilar(NewStartAngle, StartAngle);
NewEndAngle = CalcAngle(Balls[b].x, Balls[b].y, TargetEndX, TargetEndY);
EndAngle = MakeSimilar(NewEndAngle, EndAngle);
}
}
if (!Blocked) {
FoundAWay = true;
if (Balls[b] == CueBall) {
if (Targets[CurrLevel][t].Ball.Hitable or (Targets[CurrLevel][t].Type == 3)) {
PossibleHits.push({Type:1, Ball:CueBall, Start:StartAngle, End:EndAngle, Points:0, Next:Targets[CurrLevel][t], Distance:(StartDistance + EndDistance) / 2});
}
} else {
RevStart = StartAngle + Math.PI;
RevEnd = EndAngle + Math.PI;
NewStartX = Balls[b].x + (Math.sin(RevEnd) * BallDiameter);
NewStartY = Balls[b].y - (Math.cos(RevEnd) * BallDiameter);
NewEndX = Balls[b].x + (Math.sin(RevStart) * BallDiameter);
NewEndY = Balls[b].y - (Math.cos(RevStart) * BallDiameter);
Targets[CurrLevel + 1].push({StartX:NewStartX, StartY:NewStartY, EndX:NewEndX, EndY:NewEndY, Ball:Balls[b], Next:Targets[CurrLevel][t], AngleToStart:RevEnd, AngleToEnd:RevStart, Distance:(StartDistance + EndDistance) / 2, Type:1});
}
}
}
}
}
if (((CPU.Skill > 3) and (!FoundAWay)) or (CPU.Skill == 5)) {
Operations++;
ReflectBorders = new Array();
if (Targets[CurrLevel][t].Type == 1) {
if (AngleFallsBetween(Targets[CurrLevel][t].AngleToStart, 4.71238898038469, halfPI)) {
ReflectBorders.push(0, 1);
} else {
ReflectBorders.push(3, 4);
}
if (AngleFallsBetween(Targets[CurrLevel][t].AngleToStart, 0, Math.PI)) {
ReflectBorders.push(2);
} else {
ReflectBorders.push(5);
}
if (AngleFallsBetween(Targets[CurrLevel][t].AngleToEnd, 4.71238898038469, halfPI)) {
ReflectBorders.push(0, 1);
} else {
ReflectBorders.push(3, 4);
}
if (AngleFallsBetween(Targets[CurrLevel][t].AngleToEnd, 0, Math.PI)) {
ReflectBorders.push(2);
} else {
ReflectBorders.push(5);
}
rb = 0;
while (rb < (ReflectBorders.length - 1)) {
rb2 = rb + 1;
while (rb2 < ReflectBorders.length) {
if (ReflectBorders[rb] == ReflectBorders[rb2]) {
ReflectBorders.splice(rb2, 1);
rb2--;
}
rb2++;
}
rb++;
}
}
if (Targets[CurrLevel][t].Type == 2) {
for (rb in Targets[CurrLevel][t].Pocket.ReflectBorders) {
ReflectBorders[rb] = Targets[CurrLevel][t].Pocket.ReflectBorders[rb];
}
}
for (rb in ReflectBorders) {
TargetStartX = Targets[CurrLevel][t].StartX;
TargetStartY = Targets[CurrLevel][t].StartY;
TargetEndX = Targets[CurrLevel][t].EndX;
TargetEndY = Targets[CurrLevel][t].EndY;
TheBorder = Borders[ReflectBorders[rb]];
Start = BorderReflection(TheBorder, Balls[b].x, Balls[b].y, TargetStartX, TargetStartY);
End = BorderReflection(TheBorder, Balls[b].x, Balls[b].y, TargetEndX, TargetEndY);
ToStart = CalcAngle(Start.x, Start.y, TargetStartX, TargetStartY);
ToEnd = CalcAngle(End.x, End.y, TargetEndX, TargetEndY);
Blocked = (Math.abs(AngleDifference(TheBorder.Angle, ToStart)) > halfPI) or (Math.abs(AngleDifference(TheBorder.Angle, ToEnd)) > halfPI);
if (!Blocked) {
StartDistance = CalcDistance(Start.x, Start.y, TargetStartX, TargetStartY);
EndDistance = CalcDistance(End.x, End.y, TargetStartX, TargetStartY);
MinX = Math.min(TheBorder.StartX, TheBorder.EndX);
MaxX = Math.max(TheBorder.StartX, TheBorder.EndX);
MinY = Math.min(TheBorder.StartY, TheBorder.EndY);
MaxY = Math.max(TheBorder.StartY, TheBorder.EndY);
StartOut = false;
if (Start.x < MinX) {
StartOut = true;
Start.x = MinX;
}
if (Start.x > MaxX) {
StartOut = true;
Start.x = MaxX;
}
if (Start.y < MinY) {
StartOut = true;
Start.y = MinY;
}
if (Start.y > MaxY) {
StartOut = true;
Start.y = MaxY;
}
EndOut = false;
if (End.x < MinX) {
EndOut = true;
End.x = MinX;
}
if (End.x > MaxX) {
EndOut = true;
End.x = MaxX;
}
if (End.y < MinY) {
EndOut = true;
End.y = MinY;
}
if (End.y > MaxY) {
EndOut = true;
End.y = MaxY;
}
}
if ((!StartOut) or (!EndOut)) {
for (bb in Balls) {
if ((bb != b) and (Balls[bb] != CueBall)) {
Perp = CalcAngle(Start.x, Start.y, Balls[bb].x, Balls[bb].y) + halfPI;
XShift = Math.sin(Perp) * BallDiameter;
YShift = Math.cos(Perp) * BallDiameter;
HitPoint = SegmentHitsSegment(Start.x, Start.y, TargetStartX, TargetStartY, Balls[bb].x - XShift, Balls[bb].y + YShift, Balls[bb].x + XShift, Balls[bb].y - YShift);
if (((HitPoint.x != undefined) and (CalcDistance(Balls[bb].x, Balls[bb].y, HitPoint.x, HitPoint.y) < BallDiameter)) or ((Targets[CurrLevel][t].Ball != Balls[bb]) and (CalcDistance(TargetStartX, TargetStartY, Balls[bb].x, Balls[bb].y) < BallDiameter))) {
ShiftPointX = Balls[bb].x + XShift;
ShiftPointY = Balls[bb].y - YShift;
Start = BorderReflection(TheBorder, Balls[b].x, Balls[b].y, ShiftPointX, ShiftPointY);
Blocked = BlockedReflection(TheBorder, Start, End);
if (Blocked) {
break;
}
NewAngle = CalcAngle(Start.x, Start.y, ShiftPointX, ShiftPointY);
TargetStartX = Start.x + (Math.sin(NewAngle) * StartDistance);
TargetStartY = Start.y - (Math.cos(NewAngle) * StartDistance);
}
if (!Blocked) {
HitPoint = SegmentHitsSegment(End.x, End.y, TargetEndX, TargetEndY, Balls[bb].x - XShift, Balls[bb].y + YShift, Balls[bb].x + XShift, Balls[bb].y - YShift);
if (((HitPoint.x != undefined) and (CalcDistance(Balls[bb].x, Balls[bb].y, HitPoint.x, HitPoint.y) < BallDiameter)) or ((Targets[CurrLevel][t].Ball != Balls[bb]) and (CalcDistance(TargetEndX, TargetEndY, Balls[bb].x, Balls[bb].y) < BallDiameter))) {
ShiftPointX = Balls[bb].x - XShift;
ShiftPointY = Balls[bb].y + YShift;
End = BorderReflection(TheBorder, Balls[b].x, Balls[b].y, ShiftPointX, ShiftPointY);
Blocked = BlockedReflection(TheBorder, Start, End);
if (Blocked) {
break;
}
NewAngle = CalcAngle(Start.x, Start.y, ShiftPointX, ShiftPointY);
TargetEndX = Start.x + (Math.sin(NewAngle) * EndDistance);
TargetEndY = Start.y - (Math.cos(NewAngle) * EndDistance);
}
}
}
}
if (!Blocked) {
BordersToCheck = new Array();
if (((Targets[CurrLevel][t].Pocket == Pockets[2]) or (Targets[CurrLevel][t].Pocket == Pockets[5])) or (Targets[CurrLevel][t].Type != 2)) {
br = 0;
while (br <= 5) {
BordersToCheck.push(Borders[br]);
br++;
}
} else {
BordersToCheck.push(Borders[2]);
BordersToCheck.push(Borders[5]);
BordersToCheck.push(LongBorders[0]);
BordersToCheck.push(LongBorders[1]);
}
}
if (!Blocked) {
for (br in BordersToCheck) {
if (((BordersToCheck[br] != TheBorder) and (!((BordersToCheck[br] == LongBorders[0]) and ((TheBorder == Borders[0]) or (TheBorder == Borders[1]))))) and (!((BordersToCheck[br] == LongBorders[1]) and ((TheBorder == Borders[3]) or (TheBorder == Borders[4]))))) {
StartHitPoint = SegmentHitsSegment(Start.x, Start.y, TargetStartX, TargetStartY, BordersToCheck[br].StartX, BordersToCheck[br].StartY, BordersToCheck[br].EndX, BordersToCheck[br].EndY);
EndHitPoint = SegmentHitsSegment(End.x, End.y, TargetEndX, TargetEndY, BordersToCheck[br].StartX, BordersToCheck[br].StartY, BordersToCheck[br].EndX, BordersToCheck[br].EndY);
Point2 = undefined;
if (StartHitPoint.x != undefined) {
Point2 = SegmentHitsSegment(TargetStartX, TargetStartY, TargetEndX, TargetEndY, BordersToCheck[br].StartX, BordersToCheck[br].StartY, BordersToCheck[br].EndX, BordersToCheck[br].EndY);
if ((Point2.x != undefined) and (EndHitPoint.x == undefined)) {
TargetStartX = Point2.x;
TargetStartY = Point2.y;
} else {
TargetStartX = BordersToCheck[br].EndX;
TargetStartY = BordersToCheck[br].EndY;
}
Start = BorderReflection(TheBorder, Balls[b].x, Balls[b].y, TargetStartX, TargetStartY);
Blocked = BlockedReflection(TheBorder, Start, End);
if (Blocked) {
break;
}
}
if ((EndHitPoint.x != undefined) and (!Blocked)) {
if (Point2 == undefined) {
Point2 = SegmentHitsSegment(TargetStartX, TargetStartY, TargetEndX, TargetEndY, BordersToCheck[br].StartX, BordersToCheck[br].StartY, BordersToCheck[br].EndX, BordersToCheck[br].EndY);
}
if ((Point2.x != undefined) and (StartHitPoint.x == undefined)) {
TargetEndX = Point2.x;
TargetEndY = Point2.y;
} else {
TargetEndX = BordersToCheck[br].StartX;
TargetEndY = BordersToCheck[br].StartY;
}
End = BorderReflection(TheBorder, Balls[b].x, Balls[b].y, TargetEndX, TargetEndY);
Blocked = BlockedReflection(TheBorder, Start, End);
if (Blocked) {
break;
}
}
}
}
}
if (!Blocked) {
Targets[CurrLevel].push({Type:3, Border:ReflectBorders[rb], StartX:End.x, StartY:End.y, EndX:Start.x, EndY:Start.y, DesignatedBall:b, Distance:(StartDistance + EndDistance) / 2, Next:Targets[CurrLevel][t]});
}
}
}
}
}
t++;
if ((Operations >= 20) or (t >= Targets[CurrLevel].length)) {
Operations = 0;
break;
}
}
if (t >= Targets[CurrLevel].length) {
t = 0;
b++;
if (b >= Balls.length) {
b = 0;
CurrLevel++;
if (CurrLevel > CPU.MaxLevels) {
OpponentPhase = 2;
}
}
}
}
if (OpponentPhase == 2) {
if (CPU.Skill > 1) {
for (h in PossibleHits) {
PossibleHits[h].Score = 0;
CurrPoint = PossibleHits[h];
TotalDistance = PossibleHits[h].Distance;
Hits = 1;
Divider = 1;
PrevTarget = CueBall;
Multiplier = 1;
while (CurrPoint.Next instanceof Object) {
if (CurrPoint.PowerMultiplier != undefined) {
Multiplier = Multiplier * CurrPoint.PowerMultiplier;
}
CurrPoint = CurrPoint.Next;
if (CurrPoint.Points != undefined) {
PossibleHits[h].Score = PossibleHits[h].Score + CurrPoint.Points;
}
if (CurrPoint.Distance != undefined) {
TotalDistance = TotalDistance + CurrPoint.Distance;
}
AvX = CurrPoint.StartX + ((CurrPoint.EndX - CurrPoint.StartX) / 2);
AvY = CurrPoint.StartY + ((CurrPoint.EndY - CurrPoint.StartY) / 2);
if (CurrPoint.Type == 3) {
Hits++;
}
if ((CurrPoint.AngleToStart != undefined) and (CurrPoint.AngleToEnd != undefined)) {
Hits++;
AverageAngle = CurrPoint.AngleToStart + ((CurrPoint.AngleToEnd - CurrPoint.AngleToStart) / 2);
while (AverageAngle > dblPI) {
AverageAngle = AverageAngle - dblPI;
}
AngleToHit = CalcAngle(PrevTarget.x, PrevTarget.y, AvX, AvY);
AngleDiff = AngleDifference(AngleToHit, AverageAngle + Math.PI);
Divider = Divider * Math.abs(Math.cos(AngleDiff));
}
if (CurrPoint.Type == 1) {
PrevTarget = CurrPoint.Ball;
} else {
PrevTarget = {x:CurrPoint.StartX + ((CurrPoint.EndX - CurrPoint.StartX) / 2), y:CurrPoint.StartY + ((CurrPoint.EndY - CurrPoint.StartY) / 2)};
}
}
if (TotalDistance >= Powers[60]) {
PossibleHits[h].Power = 60;
} else {
p = 1;
while (p <= 59) {
if ((Powers[p - 1] < TotalDistance) and (Powers[p + 1] > TotalDistance)) {
PossibleHits[h].Power = p + 1;
break;
}
p++;
}
}
PossibleHits[h].Power = PossibleHits[h].Power / Divider;
PossibleHits[h].Power = PossibleHits[h].Power * Multiplier;
PossibleHits[h].Power = PossibleHits[h].Power / Math.pow(0.95, Hits);
PossibleHits[h].Power = PossibleHits[h].Power + 2;
if (PossibleHits[h].Power == undefined) {
PossibleHits[h].Power = 20 + random(40);
}
}
}
if (PossibleHits.length > 0) {
for (i in PossibleHits) {
Range = PossibleHits[i].End - PossibleHits[i].Start;
if (Range > Math.PI) {
Tmp = PossibleHits[i].Start;
PossibleHits[i].Start = PossibleHits[i].End;
PossibleHits[i].End = Tmp;
Range = dblPI - Range;
}
PossibleHits[i].Score = PossibleHits[i].Score + (Range * 100);
if (CPU.Skill > 1) {
if (PossibleHits[i].Power > 60) {
PossibleHits[i].Score = PossibleHits[i].Score - (PossibleHits[i].Power / 5);
} else {
PossibleHits[i].Score = PossibleHits[i].Score - (PossibleHits[i].Power / 20);
}
}
PossibleHits[i].Average = PossibleHits[i].Start + (Range / 2);
}
PossibleHits.sortOn("Score", 18);
PHCounter = 0;
AbsCounter = 0;
InitLength = PossibleHits.length;
if (CPU.Skill > 4) {
do {
CheckBalls = new Array();
PocketedNow = new Array();
for (b in Balls) {
CheckBalls[b] = new Object();
CheckBalls[b].x = Balls[b].x;
CheckBalls[b].y = Balls[b].y;
if (Balls[b] == CueBall) {
CheckBalls[b].Speed = Math.min(PossibleHits[0].Power, 60);
CheckBalls[b].Angle = PossibleHits[0].Average;
} else {
CheckBalls[b].Speed = 0;
CheckBalls[b].Angle = 0;
}
CheckBalls[b].Num = Balls[b].Num;
}
CAS = false;
while (!CAS) {
Physics(CheckBalls, true);
CAS = true;
for (b in CheckBalls) {
if (CheckBalls[b].Speed > 0) {
CAS = false;
break;
}
}
}
Flt = false;
Nothing = false;
if ((!TriedToHitAnything) and (PocketedNow.length == 0)) {
Flt = true;
Nothing = true;
PossibleHits.shift();
PHCounter--;
}
CurrType = Player.BallType;
for (pn in PocketedNow) {
BT = CheckBallType(PocketedNow[pn]);
if ((BT == 3) and (CurrType != 3)) {
Flt = true;
Nothing = true;
PossibleHits.shift();
PHCounter--;
break;
}
if (((CurrType > 0) and (BT != CurrType)) or (((CurrType == 0) and (BT != 1)) and (BT != 2))) {
Flt = true;
PossibleHits[0].Score = PossibleHits[0].Score - 10000;
if (CurrType == 3) {
PossibleHits.shift();
PHCounter--;
Nothing = true;
}
} else {
PossibleHits[0].Score = PossibleHits[0].Score + 9000;
if (CurrType == 0) {
CurrType = BT;
}
}
}
if (Flt and (!Nothing)) {
if (PossibleHits[0].Score > -1000) {
MvHit = PossibleHits.shift();
PossibleHits.push(MvHit);
PHCounter++;
} else {
PossibleHits.shift();
PHCounter--;
}
}
if ((PHCounter >= PossibleHits.length) or (PossibleHits.length == 0)) {
PossibleHits.sortOn("Score", 18);
break;
}
if (!Flt) {
break;
}
AbsCounter++;
} while (AbsCounter <= InitLength);
}
PocketedNow = new Array();
FirstHit = 0;
AllStopped = true;
if (PossibleHits.length > 0) {
if (CPU.Skill == 5) {
SelHit = PossibleHits[0];
} else {
SelHit = PossibleHits[Math.min(random(6 - CPU.Skill), PossibleHits.length - 1)];
}
Angle = SelHit.Average;
if (CPU.Skill > 1) {
Power = SelHit.Power;
if (((CPU.Skill > 2) and (Player.BallType == 0)) or ((Player.BallType == 3) and (Opponent.BallType == 3))) {
Power = Power * 2;
}
if (TriedToHitAnything) {
Power = Power * 2;
}
if (Power > 60) {
Power = 60;
}
} else {
Power = 20 + random(40);
}
}
}
OpponentPhase = 3;
if ((PossibleHits.length == 0) and TriedToHitAnything) {
trace("No Hits");
if (CPU.Skill < 3) {
Angle = Math.random() * dblPI;
} else {
for (bl in Balls) {
TP = CheckBallType(Balls[b].Num);
if (((Player.BallType > 0) and (TP == Player.BallType)) or (((Player.BallType == 0) and (TP > 0)) and (TP < 3))) {
Angle = CalcAngle(CueBall.x, CueBall.y, Balls[b].x, Balls[b].y);
break;
}
}
}
Power = 10 + random(20);
}
if ((PossibleHits.length == 0) and (!TriedToHitAnything)) {
trace("*******Trying to hit anything");
Targets[CPU.MaxLevels] = new Array();
for (b in Balls) {
if (Balls[b].Hitable) {
AngleToBall = CalcAngle(CueBall.x, CueBall.y, Balls[b].x, Balls[b].y);
Perp = AngleToBall + halfPI;
XShift = Math.sin(Perp) * BallDiameter;
YShift = Math.cos(Perp) * BallDiameter;
Targets[CPU.MaxLevels].push({StartX:Balls[b].x - XShift, StartY:Balls[b].y + YShift, EndX:Balls[b].x + XShift, EndY:Balls[b].y - YShift, Ball:Balls[b], AngleToStart:dblPI, AngleToEnd:0, Type:1});
}
}
CurrLevel = CPU.MaxLevels;
b = 0;
t = 0;
Operations = 0;
OpponentPhase = 1;
TriedToHitAnything = true;
}
}
if (OpponentPhase == 3) {
PowerError = (5 - CPU.Accuracy) * 3;
Power = Power + ((PowerError * 1.5) - ((Math.random() * PowerError) * 2));
Power = Math.round(Power);
if ((!Power) > 0) {
Power = 20 + random(40);
}
if (((!Angle) > 0) and (Angle != 0)) {
Angle = Math.random() * dblPI;
}
if (Power > 60) {
Power = 60;
}
if (Power < 2) {
Power = 2;
}
switch (CPU.Accuracy) {
case 5 :
if (CPU.Skill == 5) {
AngleError = 0;
} else {
AngleError = 0.001;
}
break;
case 4 :
AngleError = 0.005;
break;
case 3 :
AngleError = 0.01;
break;
case 2 :
AngleError = 0.03;
break;
case 1 :
AngleError = 0.09;
}
Angle = Angle + (AngleError - ((Math.random() * AngleError) * 2));
PleaseWait._visible = false;
OpponentPhase = 4;
}
}
if (OpponentPhase == 4) {
PleaseWait._visible = false;
Cue._visible = true;
Cue._x = CueBall.x;
Cue._y = CueBall.y;
Rot = Angle * Rad2Deg;
Cue._rotation = Rot;
Cue.Inside.gotoAndStop(Math.round(Rot));
CurrPower = CurrPower + 2;
Cue.Inside._y = BallRadius + CurrPower;
if (CurrPower >= Power) {
CueBall.Angle = Angle;
CueBall.Speed = Power;
Cue.Inside._y = BallRadius;
AllStopped = false;
OpponentPhase = 0;
if (SO.data.SoundOn) {
CueSound.setVolume(Math.round(Power * 1.5));
CueSound.setPan(Math.round((CueBall.x - 370) / 3.5));
CueSound.start();
}
}
}
}
PrevMDown = MDown;
} else {
Cue._visible = false;
}
}
if (((((_ymouse >= TopOffset) and (_ymouse <= (TopOffset + 370))) and (!CueBallPocketed)) and (!Paused)) and (!ExitScreen._visible)) {
Mouse.hide();
Cursor._visible = true;
Cursor._x = _xmouse;
Cursor._y = _ymouse;
} else {
Mouse.show();
Cursor._visible = false;
}
PrevAllStopped = AllStopped;
if (Mode == 3) {
Now = new Date();
PrevStatus = ExitFree._visible;
ExitFree._visible = ((!YouAreGuest) and (!YourTurn)) and ((Now - LastMove) >= 60000);
if ((!PrevStatus) and ExitFree._visible) {
Con.send("D");
}
if (PrevStatus and (!ExitFree._visible)) {
Con.send("E");
}
}
Frame 27
adBox._visible = false;
gotoAndPlay ("Cycle");
Frame 28
adBox._visible = false;
GameStarted = false;
HasGame = false;
Mouse.show();
Butt.Txt = "CONTINUE";
TitleText = Winner.Name.toUpperCase() + " WINS!";
if (Mode == 2) {
if (ItsATourney) {
if (Winner == Players[1]) {
if (CurrStage == (AllPairs.length - 1)) {
gotoAndStop ("WinTourney");
} else {
if (SO.data.SoundOn) {
WinSound.start();
}
MessageText = ("You won the game against " + Players[2].Name) + " and can proceed to the next game. Congratulations!";
Butt.onPress = function () {
gotoAndPlay ("Tournament");
};
}
} else {
if (SO.data.SoundOn) {
LoseSound.start();
}
MessageText = "You lost the game and have been eliminated from the tournament. Sorry.";
Butt.onPress = function () {
gotoAndStop ("MainMenu");
};
}
} else {
Butt.onPress = function () {
gotoAndStop ("OpponentSelect");
};
}
}
if ((Mode == 2) or (Mode == 3)) {
if (Winner == Players[1]) {
WinLose.gotoAndStop(1);
if (!ItsATourney) {
MessageText = "You won this game. Congratulations!";
}
if (SO.data.SoundOn and ((!ItsATourney) or (Mode != 2))) {
WinSound.start();
}
} else {
WinLose.gotoAndStop(2);
if (!ItsATourney) {
MessageText = "You lost this game. Sorry.";
}
if (SO.data.SoundOn) {
LoseSound.start();
}
}
} else {
WinLose.gotoAndStop(1);
MessageText = ("Congratulations " + Winner.Name) + "!";
Butt.onPress = function () {
gotoAndStop ("MainMenu");
};
}
if (Mode == 3) {
Butt.onPress = function () {
gotoAndStop ("Lobby");
};
}
Frame 29
adBox._visible = false;
gotoAndStop ("MainMenu");
Frame 30
adBox._visible = false;
WinScreen.gotoAndStop(TournamentType);
ContButt.Txt = "TO MAIN MENU";
ContButt.onPress = function () {
gotoAndStop ("MainMenu");
};
Symbol 14 MovieClip Frame 1
stop();
Symbol 16 MovieClip Frame 1
stop();
Symbol 22 MovieClip Frame 1
stop();
Symbol 22 MovieClip Frame 2
Butt.Txt = "PLAY";
Butt.onPress = function () {
_parent.gotoAndPlay("InitStuff");
};
Symbol 44 Button
on (press) {
getURL ("http://www.sugar-free-games.com", "_SELF");
}
Symbol 53 MovieClip Frame 100
_parent.gotoAndStop("MainMenu");
Symbol 134 MovieClip Frame 1
AbortButt.Txt = "ABORT CONNECTION";
AbortButt.onPress = function () {
_root.Con.close();
_root.Connected = false;
_root.MB._visible = false;
_root.gotoAndStop("MultiplayerLogin");
_root.EnableAll();
};
Symbol 145 MovieClip Frame 1
JoinButt.Txt = "JOIN";
Symbol 271 MovieClip Frame 1
YesButt.Txt = "YES";
YesButt.onPress = function () {
_parent.Paused = false;
if ((_parent.Mode == 1) or (_parent.Mode == 2)) {
_parent.gotoAndStop("MainMenu");
}
if (_parent.Mode == 3) {
_parent.Con.send("5");
_parent.gotoAndStop("Lobby");
}
};
NoButt.Txt = "NO";
NoButt.onPress = function () {
_parent.Paused = false;
_parent.MDown = false;
_parent.ExitScreen._visible = false;
};
Symbol 294 MovieClip Frame 2
DayNames = ["Sunday", "Monday", "Tuesday", "Wednsday", "Thursday", "Friday", "Saturday"];
MonthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
Name = _parent.Players[1].Name;
Time = new Date();
Day = Time.getDate();
if (((Day % 10) == 1) and ((Day < 10) or (Day > 20))) {
Ending = "st";
}
if (((Day % 10) == 2) and ((Day < 10) or (Day > 20))) {
Ending = "nd";
}
if (((Day % 10) == 3) and ((Day < 10) or (Day > 20))) {
Ending = "rd";
}
if (((Day % 10) > 3) or ((Day % 10) == 0)) {
Ending = "th";
}
DateTxt = ((((((DayNames[Time.getDay()] + ", ") + MonthNames[Time.getMonth()]) + " ") + Day) + Ending) + " ") + Time.getFullYear();
Symbol 294 MovieClip Frame 3
DayNames = ["Sunday", "Monday", "Tuesday", "Wednsday", "Thursday", "Friday", "Saturday"];
MonthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
Name = _parent.Players[1].Name;
Time = new Date();
Day = Time.getDate();
if (((Day % 10) == 1) and ((Day < 10) or (Day > 20))) {
Ending = "st";
}
if (((Day % 10) == 2) and ((Day < 10) or (Day > 20))) {
Ending = "nd";
}
if (((Day % 10) == 3) and ((Day < 10) or (Day > 20))) {
Ending = "rd";
}
if (((Day % 10) > 3) or ((Day % 10) == 0)) {
Ending = "th";
}
DateTxt = ((((((DayNames[Time.getDay()] + ", ") + MonthNames[Time.getMonth()]) + " ") + Day) + Ending) + " ") + Time.getFullYear();