class Rubynoid.Game { private var _paddle:MovieClip = null; public var _leftedge:Number = 0; public var _rightedge:Number = 0; public var _topedge:Number = 0; public var _bottomedge:Number = 0; public var _rightmax:Number = 0; public var _xdelta:Number = 0; private var _clickthisframe:Boolean = false; private var _keythisframe = false; private var _activeballs = []; private var _bricks = []; private var _board = []; private var __attachcounter:Number = 0; private var _brickcounter:Number = 0; private var _soundplayer:Rubynoid.SoundPlayer = null; public var Lives:Number = 4; function Game() { Mouse.addListener(this); Key.addListener(this); _soundplayer = new Rubynoid.SoundPlayer(); _soundplayer.includeSound( "stonebounce" ); _soundplayer.includeSound( "otherbounce" ); _soundplayer.includeSound( "shatter" ); } function PrepareLevel(paddle, leftedge, rightedge, topedge, leveldefinition) { _paddle = paddle; _leftedge = leftedge; _rightedge = rightedge; _topedge = topedge; _rightmax = (_rightedge - _paddle._width); _bottomedge = _paddle._parent._height; leveldefinition = leveldefinition || ""; BuildLevel( leveldefinition ); } function ResetBoard() { for(i=0; i<_bricks.length; i++) { if (_bricks[i]) { _bricks[i].removeMovieClip(); }; } _clickthisframe = false; _keythisframe = false; _bricks = []; _brickcounter = 0; _board.clear(); for(var i=0; i<25; i++) { _board[i] =[]; }; } function GameLoop() { var X = _root._xmouse; var currball, currballsound; var i,j,blockx,blocky; var boardcontent; var vhit, hhit; var lbx, lby, hbx, hby; if (X>_rightmax) { X = _rightmax; } if (X<_leftedge) { X = _leftedge; } _xdelta = X - this._paddle._x; this._paddle._x = X; for (var i = 0; i<_activeballs.length; i++) { currball = _activeballs[i]; currballsound = currball.runFrame( _clickthisframe ); if ( currballsound ) { _soundplayer.playSound(currballsound); }; if ( _paddle.hitTest( currball ) ) { currballsound = currball.bounceonpaddle(); if ( currballsound ) { _soundplayer.playSound(currballsound); }; continue; }; if(currball._y > _bottomedge) { RemoveBall(i); } else if (currball._y < 290) { blockx = Math.floor(((currball._x - 24)/ 12.0)); blocky = Math.floor(((currball._y - 24) / 12.0)); if ( currball._deltaY < 0 ) { lby = blocky-1; hby = blocky; } else { lby = blocky; hby = blocky + 1; } if ( currball._deltaX < 0 ) { lbx = blockx-1; hbx = blockx; } else { lbx = blockx; hbx = blockx + 1; } boardcontent = null; for(j=lby; j<=hby; j++) { if( _board[j] ) { for(i=lbx; i<=hbx; i++) { if( _board[j][i] == boardcontent ) { continue; } boardcontent = _board[j][i]; if( boardcontent ) { if ( currball.hitTest( boardcontent ) ) { vhit = (! ( (currball._y>=boardcontent._y) && (currball._y<=(boardcontent._y + boardcontent._height)) )); hhit = (! ( (currball._x>=boardcontent._x) && (currball._x<=(boardcontent._x + boardcontent._width)) )); currball.bounce( hhit, (vhit || (!hhit)) ); if ( ! boardcontent.Permanent ) { _bricks[ boardcontent.brickindex ] = null; _brickcounter--; _soundplayer.playSound("stonebounce"); } else { _soundplayer.playSound("otherbounce"); } boardcontent.ProcessHit(); return; }; } } } } } } if (_keythisframe) { if (_keythisframe == 'w') { return "Win Level"; }; } _clickthisframe = false; _keythisframe = false; if ( _brickcounter < 1 ) { return "Win Level"; } switch( _paddle.state ) { case "Normal": if (_activeballs.length < 1) { _paddle.gotoAndPlay("Explode"); _soundplayer.playSound( "shatter" ); } return null; case "Explode": return null; case "Gone": return "Lost Paddle"; } } function BuildLevel( levelstring ) { var i,row,ch,col,brick,dp; ResetBoard(); row=0; col=0; for(ch=0;ch=_activeballs.length) { return; } var ball = _activeballs[index]; _activeballs.splice(index,1); ball.removeMovieClip(); } function ClearBalls() { for (var i = 0; i<_activeballs.length; i++) { _activeballs[i].removeMovieClip(); } _activeballs = []; } function ResetBalls() { ClearBalls(); var ball = _paddle._parent.attachMovie("Rubynoid.Ball", ("rnBall"+__attachcounter++), _paddle._parent.getNextDepth(), {_game: this}); ball.setState("onPaddle"); _activeballs.push(ball); } function onMouseDown() { _clickthisframe = true; } function onKeyDown() { _keythisframe = String.fromCharCode( Key.getAscii() ); }; function getPaddle() { return _paddle; }; function dumpBoard() { var line, i, j; for(j=0; j<22; j++) { line = ""; for(i=0;i<20;i++) { line += (_board[j][i]) ? "X" : "."; } trace(line); } }; }