Esempio n. 1
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.
            //font = Content.Load<SpriteFont>("SpriteFont1");

            // TODO: use this.Content to load your game content here
            spriteSheet = Content.Load <Texture2D>("spritesheet");
            debugSquare = Content.Load <Texture2D>("Square");

            Dictionary <string, Rectangle[]> textures = Load.Sprites();

            ship = new Ship(uiController, spriteSheet, textures["ship"]);
            phyicsField.addPhysicsBody(ship);

            Random ran = new Random();

            for (int i = 0; i <= 10; i++)
            {
                Astroids roid = new Astroids(spriteSheet, textures["planetoid"][0], uiController, 50, 50, Vector2.Zero);
                roid.pos.X = ran.Next(100, screenWidth - 100);
                roid.pos.Y = ran.Next(100, screenHeight - 100);
                phyicsField.addPhysicsBody(roid);

                roid.update();
            }
        }
Esempio n. 2
0
    public int part_one(string input)
    {
        var astroids = Astroids.Parse(input);

        return(astroids
               .Max(station => Astroids.Relations(station, astroids)
                    .Select(r => r.Angle)
                    .Distinct()
                    .Count()));
    }
Esempio n. 3
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            // TODO: Add your drawing code here

            //DEBUG
            if (IS_DEBUG_MODE)
            {
                spriteBatch.Begin();

                //Asteroids
                List <PhysicsBody> roids = phyicsField.physBodies;
                for (int i = 0; i < roids.Count; i++)
                {
                    PhysicsBody body = roids[i];
                    if (body is Astroids)
                    {
                        Astroids roid = (Astroids)body;
                        spriteBatch.Draw(debugSquare, new Rectangle(
                                             (int)(roid.image.absX + roid.image.sizeX * roid.image.anchorPointX) - roid.image.offsetX + roid.rect.X,
                                             (int)(roid.image.absY + roid.image.sizeY * roid.image.anchorPointY) - roid.image.offsetY + roid.rect.Y,
                                             roid.rect.Width, roid.rect.Height
                                             ), Color.Beige);
                    }
                }

                //Bad boys

                //Sinistar

                //Ship
                spriteBatch.Draw(debugSquare, new Rectangle(
                                     (int)(ship.image.absX + ship.image.sizeX * ship.image.anchorPointX) - ship.image.offsetX + ship.rect.X,
                                     (int)(ship.image.absY + ship.image.sizeY * ship.image.anchorPointY) - ship.image.offsetY + ship.rect.Y,
                                     ship.rect.Width, ship.rect.Height
                                     ), Color.Red);

                spriteBatch.End();
            }

            //////////////
            uiController.drawElements();
            base.Draw(gameTime);
        }
Esempio n. 4
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            #region Objects
            astroids = new Astroids();
            players = new Players();
            players.AddPlayers(new Player(new Spacecraft(new Vector2(graphics.GraphicsDevice.Viewport.Width / 2, graphics.GraphicsDevice.Viewport.Height / 2)), 3, new KeyBatch()), new Player(new Vector2(graphics.GraphicsDevice.Viewport.Width / 2 - 100, graphics.GraphicsDevice.Viewport.Height / 2), new KeyBatch(Keys.W, Keys.A, Keys.D, Keys.Q, Keys.E, Keys.T, Keys.Y)));
            #endregion

            #region Visuals
            messages = new Messages();
            explosions = new Explosions();
            #endregion

            #region Game Control
            previousKeyboardState = Keyboard.GetState();
            gameOver = false;
            paused = false;
            level = 1;
            #endregion

            base.Initialize();
        }
Esempio n. 5
0
    public int part_two(string input)
    {
        var astroids = Astroids.Parse(input);
        var station  = astroids
                       .OrderByDescending(s =>
                                          Astroids.Relations(s, astroids)
                                          .Select(r => r.Angle)
                                          .Distinct()
                                          .Count())
                       .FirstOrDefault();

        var relations = Astroids.Relations(station, astroids)
                        .OrderBy(r => r.Angle)
                        .ThenBy(r => r.Distance)
                        .ToArray();

        var      vaporized = new HashSet <Point>();
        var      started   = false;
        var      postion   = 0;
        Relation last      = default;

        while (vaporized.Count < 200)
        {
            var relation = relations[postion++];
            started |= relation.Angle >= Math.PI / 2;

            if (started && last.Angle != relation.Angle && vaporized.Add(relation.Astroid))
            {
                last = relation;
            }
            if (postion >= relations.Length)
            {
                postion = 0;
            }
        }
        return(last.Astroid.X * 100 + last.Astroid.Y);
    }