Exemplo n.º 1
0
 public Walls(World world, Rectangle screenBounds, Ball ball, Paddle paddle)
 {
     _world = world;
     _screenBounds = screenBounds;
     _ball = ball;
     _paddle = paddle;
 }
Exemplo n.º 2
0
        // Add paddle to game

        private void CreatePaddle()
        {
            paddle = new Paddle
            {
                LocationX = 350,
                LocationY = 550
            };
            canvas.Children.Add(paddle);
        }
Exemplo n.º 3
0
 public Ball(Paddle paddle, Content content, InputCommands inputCommands)
     : base(content.Load<Image>("Ball"), Rectangle.Zero)
 {
     this.paddle = paddle;
     fireBallSound = content.Load<Sound>("PaddleBallStart");
     collisionSound = content.Load<Sound>("BallCollision");
     UpdateOnPaddle();
     RegisterFireBallCommand(inputCommands);
 }
Exemplo n.º 4
0
 public Breakout(SpriteBatch spriteBatch)
 {
     this.spriteBatch = spriteBatch;
     this.screenWidth = spriteBatch.GraphicsDevice.Viewport.Width;
     this.screenHeight = spriteBatch.GraphicsDevice.Viewport.Height;
     this.paddle = new Paddle(screenWidth, screenHeight);
     this.wall = new Wall(screenWidth, screenHeight);
     this.ball = new Ball(paddle, wall, screenWidth, screenHeight);
 }
Exemplo n.º 5
0
		public Ball(Paddle paddle)
			: base(new Material(ShaderFlags.Position2DColoredTextured,"Ball"), Rectangle.Zero)
		{
			this.paddle = paddle;
			fireBallSound = ContentLoader.Load<Sound>("PaddleBallStart");
			collisionSound = ContentLoader.Load<Sound>("BallCollision");
			UpdateOnPaddle();
			RegisterFireBallCommand();
			Start<RunBall>();
			RenderLayer = 5;
		}
Exemplo n.º 6
0
        public Block(World world, Rectangle screenBounds, int x, int y, Player player, Ball ball, Paddle paddle)
        {
            _world = world;
            _screenBounds = screenBounds;
            _x = x;
            _y = y;
            _player = player;
            _ball = ball;
            _paddle = paddle;

            DieTime = TimeSpan.FromSeconds(0.4);
        }
Exemplo n.º 7
0
        public Level(World world, Rectangle screenBounds, Player player)
        {
            _paddle = new Paddle(world, screenBounds);
            _ball = new Ball(world, _paddle, player);
            _walls = new Walls(world, screenBounds, _ball, _paddle);

            // TODO: Load level from file/resource
            for (int y = 0; y < 5; y++)
            {
                for (int x = 0; x < 10; x++)
                {
                    _blocks.Add(new Block(world, screenBounds, x, y, player, _ball, _paddle));
                }
            }
        }
Exemplo n.º 8
0
 private void GameRestart()
 {
     _ball            = new Ball();
     _controller      = new Paddle();
     gameOver.Visible = false;
 }
Exemplo n.º 9
0
 void resetGame()
 {
     gamestate = 2;
     Player    = null;
 }
Exemplo n.º 10
0
 /*
  |--------------------------------------------------------------------------
  | ANCHOR Create Paddle
  |--------------------------------------------------------------------------
  */
 private void CreatePaddle()
 {
     this.paddle = new Paddle(this, 450, 750, 200, 10);
 }
Exemplo n.º 11
0
 public Ball(World world, Paddle paddle, Player player)
 {
     _world  = world;
     _paddle = paddle;
     _player = player;
 }
        private static void Main(string[] args)
        {
            using (var w = new GameWindow(800,600))
              {

            w.Mouse.IsVisible = false;

            var imageDict = new Dictionary<GameResourceType, Bitmap>();
            imageDict[GameResourceType.Background] = new Bitmap("..\\Content\\background.png");
            imageDict[GameResourceType.Ball] = new Bitmap("..\\Content\\ball1.png");
            imageDict[GameResourceType.Paddle] = new Bitmap("..\\Content\\paddle.png");
            imageDict[GameResourceType.Brick] = new Bitmap("..\\Content\\brick.png");

            var ballList = new List <Ball>();

            System.Threading.Tasks.Task.Factory.StartNew(
              ()=>{for(int j = 1; j < 100; j++)
            {
              lock(ballList)
              {
                for(int i = 0; i < 150; i++)
                {
                  ballList.Add(new Ball());
                }
              }
              System.Threading.Thread.Sleep(1750);
            }});
            var paddle = new Paddle();

            while (w.IsRunning) {

              paddle.X = w.Mouse.X - 64;

              w.DrawBitmap(imageDict[GameResourceType.Background],0,0);

              w.DrawBitmap(imageDict[GameResourceType.Paddle], (int)paddle.X, (int)paddle.Y);

              lock (ballList)
              {
            foreach (var b in ballList.Where(x => !x.IsDead))
            {

              b.Process(1);
              w.DrawBitmap(imageDict[GameResourceType.Ball], (int)b.X, (int)b.Y);

              if(Rectangle.IsOverlapped(b as Rectangle, paddle as Rectangle)|| Rectangle.IsOverlapped(paddle, b))
              {
                b.Y = paddle.Y-b.H;
                b.VY = -b.VY;
              }

            }
              }
              if(w.Keyboard[System.Windows.Forms.Keys.Escape])
            break;

              w.Update();
            }

              }
        }
Exemplo n.º 13
0
        /*
         * Initiates logic.
         */
        protected override void Initialize()
        {
            graphics.PreferredBackBufferWidth = 640;
            graphics.PreferredBackBufferHeight = 420;
            graphics.IsFullScreen = false;
            graphics.ApplyChanges();
            Window.Title = "Breakout for Atari 2600 Replica";

            ball = new Ball();
            paddle = new Paddle();
            decoration = new Decoration();
            barX = 32.0f;
            barY = 114.0f;
            bars = new List<List<Bar>>();

            for (int i = 0; i < 6; i++)
            {
                bars.Add(new List<Bar>());
                for (int j = 0; j < 18; j++)
                {
                    bars[i].Add(new Bar(barX, barY, i));
                    barX += 32.0f;
                }
                barX = 32.0f;
                barY += 12.0f;
            }

            base.Initialize();
        }
Exemplo n.º 14
0
 /// <summary>
 /// Creates a new ball. The breakout game should only need once of these,
 /// unless I make it so more than one ball is active at a time.
 /// </summary>
 /// <param name="paddle">The Paddle which will hit the ball</param>
 /// <param name="screenWidth">Width of the screen for bounds checking.</param>
 /// <param name="screenHeight">Height of the screen for bounds checking.</param>
 public Ball(Paddle paddle, Wall wall, int screenWidth, int screenHeight)
 {
     this.state = State.Active;
     this.paddle = paddle;
     this.wall = wall;
     this.screenWidth = screenWidth;
     this.screenHeight = screenHeight;
     initialPosition = new Vector2(screenWidth / 2, screenHeight / 2);
 }
Exemplo n.º 15
0
 public BallInLevel(Paddle paddle, Level level)
     : base(paddle)
 {
     Level = level;
 }
Exemplo n.º 16
0
		public BallInLevel(Paddle paddle, Level level)
			: base(paddle)
		{
			Level = level;
		}
Exemplo n.º 17
0
 public BallInLevel(Paddle paddle, Content content, InputCommands inputCommands, Level level)
     : base(paddle, content, inputCommands)
 {
     Level = level;
 }
Exemplo n.º 18
0
        /// <summary>
        /// calculates collisions between the ball and a paddle, and finds the paddle surface that was hit
        /// </summary>
        /// <param name="paddle">the paddle that is being hit</param>
        /// <param name="newPosition">the position the ball has</param>
        /// <param name="newVelocity">the velocity the ball is trying to move with</param>
        /// <returns>the position, length and surface of the collision</returns>
        public CollisionReturn CollidesWithPaddle(Paddle paddle, Vector newPosition, Vector newVelocity)
        {
            Ray[] Vectors = new Ray[4]; // vector rays of moving ball
            Vectors[TopEdge] = new Ray(newPosition, newVelocity);
            Vectors[RightEdge] = new Ray(Vector.Add(newPosition, new Vector(Size.X, 0)), newVelocity);
            Vectors[BottomEdge] = new Ray(Vector.Add(newPosition, new Vector(0, Size.Y)), newVelocity);
            Vectors[LeftEdge] = new Ray(Vector.Add(newPosition, new Vector(Size.X, Size.Y)), newVelocity);

            CollisionReturn collisionReturn = new CollisionReturn(false);

            foreach (Ray ray in Vectors)
            {
                int edgeID = 0;
                foreach (Ray edge in paddle.Edges)
                {
                    RaycastReturn raycastReturn = Ray.Raycast(ray, edge);
                    if (raycastReturn.Intersects)
                    {
                        if (collisionReturn.Intersects)
                        {
                            if (raycastReturn.length < collisionReturn.length)
                            {
                                collisionReturn = new CollisionReturn(raycastReturn);
                                collisionReturn.Edge = edgeID;
                            }
                        }
                        else
                        {
                            collisionReturn = new CollisionReturn(raycastReturn);
                            collisionReturn.Edge = edgeID;
                        }
                    }
                    edgeID++;
                }
            }
            return collisionReturn;
        }
Exemplo n.º 19
0
 public Grid(Vector2f windowSize, ScoreBoard scoreBoard, List <Item> itemList, Paddle paddle, int startLevel)
 {
     level           = startLevel;
     array2D         = new Box[10, 5];
     this.windowSize = windowSize;
     buildMap(@"Levels/Level" + level + ".txt");
     this.board    = scoreBoard;
     this.itemList = itemList;
     this.paddle   = paddle;
 }
Exemplo n.º 20
0
        /// <summary>
        /// Put the paddle on the gameboard.
        /// </summary>
        private void initPaddle()
        {
            paddle = new Paddle(gameBoard);

            paddle.Draw();
        }
Exemplo n.º 21
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            _ballTexture = Content.Load<Texture2D>("ball");
            _brickTexture = Content.Load<Texture2D>("block");
            _paddleTexture = Content.Load<Texture2D>("Paddle");
            _gameBall = new Ball(new Vector2(200, 200), _ballTexture, new Vector2(5, 5));
            int[,] _map = new int[5,10]
            {
            {1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1}
            };
            _brickManager = new BrickManager(_map, _brickTexture, 5, 10);
            _brickManager.Init();

            _paddle = new Paddle(new Vector2(200, 400), _paddleTexture);
        }
Exemplo n.º 22
0
 public Ball(World world, Paddle paddle, Player player)
 {
     _world = world;
     _paddle = paddle;
     _player = player;
 }
Exemplo n.º 23
0
 /// <summary>
 /// sets up and begins new round
 /// </summary>
 /// <param name="form">the form being used for the game</param>
 public static void StartNew(Form form)
 {
     LeftMovement1 = false;
     RightMovement1 = false;
     LeftMovement2 = false;
     RightMovement2 = false;
     LastPlayerHit = Player.Player1;
     LabelLevels.Text = "Levels Completed: " + LevelsCompleted.ToString();
     UpdateScores();
     Balls = new List<Ball>();
     Blocks = new List<Block>();
     FormSize = new Vector(form.Size.Width, form.Size.Height - 100);
     PictureBox paddle1 = new PictureBox();
     form.Controls.Add(paddle1);
     if (CurrentMode == GameMode.Coop || CurrentMode == GameMode.Versus) // 2 player
     {
         PictureBox paddle2 = new PictureBox();
         form.Controls.Add(paddle2);
         PaddleObject2 = new Paddle(paddle2, new Vector(FormSize.X * 0.75f, FormSize.Y));
         PaddleObject1 = new Paddle(paddle1, new Vector(FormSize.X * 0.25f, FormSize.Y));
     }
     else // 1 player
     {
         PaddleObject1 = new Paddle(paddle1, new Vector(FormSize.X * 0.5f, FormSize.Y));
         PaddleObject2 = null;
     }
     currentForm = form;
     BallsInPlay = 0;
     AddBall();
     int blockRows = ((CurrentMode == GameMode.Classic) ? DefaultBlockRows : BlockRows);
     int blockColumns = ((CurrentMode == GameMode.Classic) ? DefaultBlockColumns : BlockColumns);
     int blockWidth = (int)FormSize.X / blockColumns;
     int blockHeight = (int)FormSize.Y / 3 / blockRows;
     const int blockFrame = 4;
     for (int x = 0; x < blockColumns; x++)
     {
         for (int y = 0; y < blockRows; y++)
         {
             float rowPercentage = (float)y / (float)blockRows;
             PictureBox newPictureBox = new PictureBox();
             newPictureBox.BackColor = Color.FromArgb((int)Math.Round(255 * Math.Max(0, 1 - rowPercentage * 2), 0), (int)Math.Round(255 * (1 - 2 * Math.Abs(0.5f - rowPercentage)), 0), (int)Math.Round(255 * Math.Max(0, rowPercentage * 2 - 1), 0));
             currentForm.Controls.Add(newPictureBox);
             Vector newBlockPosition = new Vector(x * blockWidth + blockFrame * 0.5f, y * blockHeight + blockFrame * 0.5f);
             Vector newBlockSize = new Vector(blockWidth - blockFrame, blockHeight - blockFrame);
             Block newBlock = new Block(newPictureBox, newBlockPosition, newBlockSize);
             newBlock.Points = 50 + 50 * (blockRows - y);
         }
     }
     gameThread = new Thread(GameThread);
     gameThread.IsBackground = true;
     gameThread.Start();
     form.Disposed += delegate { gameThread.Abort(); };
     InPlay = true;
 }
Exemplo n.º 24
0
        public Block(World world, Rectangle screenBounds, int x, int y, Player player, Ball ball, Paddle paddle)
        {
            _world        = world;
            _screenBounds = screenBounds;
            _x            = x;
            _y            = y;
            _player       = player;
            _ball         = ball;
            _paddle       = paddle;

            DieTime = TimeSpan.FromSeconds(0.4);
        }