public Ball(float minX, float maxX, float minY, float maxY, GameState gameState,ref Wall player1, ref Wall player2) { //Keep a reference to the gamestate around for updating the scores _gameState = gameState; //Limits for the ball to bounce _minX = minX; _maxX = maxX; _minY = minY; _maxY = maxY; reset(); //Must be called after the limits are set since it uses them! //The bats to check for collisions with _player1 = player1; _player2 = player2; //Look & feel //control.BackColor = _color; //control.Width = _radius; //control.Height = _radius; setHeightWidth(); //Preload the sound file //_beep.Load(); this.Drawer = new BallDrawer(this); }
public Crasher() { InitializeComponent(); this.SetStyle(ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true); gameState = new GameState(); settings = GameSettings.GetInstance(); Brick.Height = settings.BrickHeight; Brick.Width = settings.BrickWidth; Wall.Width = settings.WallWidth; Wall.Height = settings.WallHeight; Ball.Radius = settings.BallRadius; Ball.InitialSpeed = settings.BallInitialSpeed; settings.BallMaxX = (float)ClientSize.Width; settings.BallMaxY = (float)ClientSize.Height; //Create the bat Sprites - they need the keyboard controls and the gameplay area limits _player1 = new Wall(settings.PlayerDefaultX,Keys.Up,Keys.Down ,settings.MinPosition, (float)ClientSize.Height, Wall.Width, Wall.Height); //use this line for a second human player //_player2 = new Bat(player2Bat, ClientSize.Width - 30 - Bat.Width, Keys.P, Keys.L, 0, ClientSize.Height); //use this line for a computer player _player2 = new Wall((float)ClientSize.Width - settings.PlayerDefaultX - Wall.Width, settings.MinPosition, (float)ClientSize.Height, Wall.Width, Wall.Height); _ball_1 = new Ball(settings.BallMinX, (float)ClientSize.Width, settings.BallMinY, (float)ClientSize.Height, gameState, ref _player1, ref _player2); _player1.Ball = _ball_1; //Connect the AI player with the ball _player2.Ball = _ball_1; //Initialise and start the timer _lastTime = 0.0; _timer.Start(); Sprite shotGun = new ShotGun(_player1, _player2, _ball_1); Sprite shotGun2 = new ShotGun(_player1, _player2, _ball_1); _player1.Weapons.Add(shotGun); _player1.Weapons.Add(shotGun2); /* ((Weapon)shotGun).Use(); */ }