Пример #1
0
        public static Vector2 ReflectCircular(Vector2 batIntersection, Bat bat, Ball ball)
        {
            float length = ball.Direction.Length();
            Line  normalFromBatAtBallIntersection = new Line()
            {
                Position  = batIntersection,
                Direction = new Vector2(0, 1),
            };
            float  radius           = (bat.Size.X + ball.Size.X) / 2f;
            Circle virtualBatCircle = new Circle()
            {
                Position = new Vector2((bat.Position.X - ball.Size.X) + radius, bat.Position.Y - ball.Size.Y),
                Radius   = radius,
            };
            Vector2?secondIntersection;
            Vector2?directionVectorEndPoint = GetIntersectionPoint(normalFromBatAtBallIntersection, virtualBatCircle, out secondIntersection);

            if (directionVectorEndPoint.HasValue == false)
            {
                throw new Exception();
            }

            Vector2 result = directionVectorEndPoint.Value - virtualBatCircle.Position;

            result.Normalize();
            return(result * length);
        }
Пример #2
0
 private void CheckBallCollision(Ball ball, Bat bat)
 {
     if (SplashKit.BitmapCircleCollision(bat.CollisionBitmap, bat.X, bat.Y, ball.Circle))
     {
         this.OnCollideWithBat(EventArgs.Empty);
         Console.WriteLine(ball.GetType().Name + " hit " + bat.GetType().Name);
     }
 }
Пример #3
0
        public Game(int width, int height)
        {
            using (Stream stream = File.OpenRead(Path.GetFullPath("maps/level-definition.json")))
                using (StreamReader sr = new StreamReader(stream))
                    Levels = JsonConvert.DeserializeObject <string[]>(sr.ReadToEnd());
            BoundaryCoordinates = new Vector2(width, height);
            NextLevel();

            Bat = new Bat(width / 2f, height - 20, 400, Bat.Kinds.Regular);
        }
Пример #4
0
 public Ball(Window w, Color color, Bat bat)
 {
     _bat            = bat;
     MainColor       = color;
     Radius          = Constants.BallRadius;
     X               = bat.X + bat.Width / 2;
     Y               = bat.Y - Radius;
     Circle.Center.X = X;
     Circle.Center.Y = Y;
     Circle.Radius   = Radius;
 }
Пример #5
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);

            // TODO: use this.Content to load your game content here
            m_increasespeed          = new Timer();
            m_increasespeed.Interval = 10000; // 10000;
            m_increasespeed.Elapsed += new ElapsedEventHandler(m_increasespeed_Elapsed);

            m_superballtimer          = new Timer();
            m_superballtimer.Interval = 20000;
            m_superballtimer.Elapsed += new ElapsedEventHandler(m_superballtimer_Elapsed);

            BatTexture        = Content.Load <Texture2D>("bat");
            BallTexture       = Content.Load <Texture2D>("ball");
            SuperBallTexture  = Content.Load <Texture2D>("superball");
            BrickRedTexture   = Content.Load <Texture2D>("brickred");
            BrickGreenTexture = Content.Load <Texture2D>("brickgreen");
            BrickBlueTexture  = Content.Load <Texture2D>("brickblue");

            LogoTex = Content.Load <Texture2D>("Breakout");

            SoundLevelUp = Content.Load <SoundEffect>("applause");
            SoundBounce1 = Content.Load <SoundEffect>("boing");
            SoundBounce2 = Content.Load <SoundEffect>("boing2");
            SoundDing    = Content.Load <SoundEffect>("ding");

            Song1 = Content.Load <Song>("DJ Logikk - Random Stuff That Happens - EP - 02 Zirco");
            MediaPlayer.Play(Song1);
            m_playingmusic = true;

            m_player1bat = new Bat(BatTexture);
            m_ball       = new Ball(BallTexture);

            ReconfigureScreen();

            font = Content.Load <SpriteFont>("SpriteFont1");

            DoHighScoreTable();

            m_musicvolume      = 0.20f;
            MediaPlayer.Volume = m_musicvolume; // 20% vol

            IsMouseVisible = false;
            m_gameinitted  = true;
        }
Пример #6
0
 public Kinds?Move(Bat bat, float elapsed)
 {
     Position += Direction * FallSpeed * elapsed;
     if (Position.Y > bat.Position.Y - Size.Y)
     {
         if (Position.X > bat.Position.X - Size.X && Position.X < bat.Position.X + bat.Size.X)
         {
             ListReference.Remove(this);
             return(Kind);
         }
     }
     if (Position.Y > bat.Position.Y)
     {
         ListReference.Remove(this);
     }
     return(null);
 }
Пример #7
0
        public GameArea()
        {
            topEdge    = new TopEdge(MaxX);
            bottomEdge = new BottomEdge(MaxX, MaxY);
            rightEdge  = new RightEdge(MaxX, MaxY);
            leftEdge   = new LeftEdge(MaxY);

            bat = new Bat();
            {
                bat.PositionX = MaxX / 2;
                bat.PositionY = MaxY - 2;
            }
            ball = new Ball();
            {
                ball.PositionX = bat.PositionX - 1;
                ball.PositionY = bat.PositionY - 1;
            }

            brickArray = new BrickArray();
        }
Пример #8
0
        public Breakout(Window w)
        {
            GameWindow = w;

            _border = new Border(w);

            Player = new Player(Constants.PlayerColor, w.Width / 2, w.Height * 0.95, 580, 5);

            _bats.Add(Player);

            Npc = new NPC(Constants.NPCColor, w.Width / 2, w.Height * 0.05, 1000, 5);

            _bats.Add(Npc);

            Wall = new Wall(w);

            PlayerBall = new Ball(w, Constants.PlayerBallColor, Player);

            NpcBall = new Ball(w, Constants.NPCBallColor, Npc);

            //_playerBall.HasLaunched(_player, EventArgs.Empty);
        }
Пример #9
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);

            var batTexture    = Content.Load <Texture2D>("Bat");
            var ballTexture   = Content.Load <Texture2D>("Ball");
            var font          = Content.Load <SpriteFont>("Font");
            var blockTextures = new List <Texture2D>()
            {
                { Content.Load <Texture2D>("block1") },
                { Content.Load <Texture2D>("block2") },
                { Content.Load <Texture2D>("block3") },
                { Content.Load <Texture2D>("block4") },
                { Content.Load <Texture2D>("block5") },
                { Content.Load <Texture2D>("block6") },
                { Content.Load <Texture2D>("block7") },
            };

            blocks = new Blocks(blockTextures);
            bat    = new Bat(batTexture)
            {
                input = new Input()
                {
                    Left  = Keys.Left,
                    Right = Keys.Right,
                }
            };
            ball = new Ball(ballTexture);
            live = new Live(font)
            {
                position = new Vector2(2, 2),
            };

            StartGame();
        }
Пример #10
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);

            // TODO: use this.Content to load your game content here
            m_increasespeed          = new Timer();
            m_increasespeed.Interval = 10000;
            m_increasespeed.Elapsed += new ElapsedEventHandler(m_increasespeed_Elapsed);

            m_player1bat = new Bat();
            m_ball       = new Ball();

            BatTexture   = Content.Load <Texture2D>("bat");
            BallTexture  = Content.Load <Texture2D>("ball");
            BrickTexture = Content.Load <Texture2D>("brick");

            ReconfigureScreen();

            font = Content.Load <SpriteFont>("SpriteFont1");

            // Initialise Plantronics head tracking...
            m_pltlabsapi = new PLTLabsAPI2(this);
        }