Пример #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.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            testTexture   = Content.Load <Texture2D>("coloredSquare");
            tileSheet     = Content.Load <Texture2D>("basicTileSheet");
            blankParticle = Content.Load <Texture2D>("singleWhitePx");

            particleEngine = new ParticleEngine(blankParticle, 120);

            // TODO: use this.Content to load your game content here
        }
Пример #2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;

            tileHover   = false;
            newMouse    = Mouse.GetState();
            mouseRect.X = newMouse.X;
            mouseRect.Y = newMouse.Y;
            foreach (Tile t in drawn)   //check if a the mouse is hovering over a tile
            {
                if (mouseRect.Intersects(t.Hitbox))
                {
                    tileHover = true;
                }
            }

            #region Mouse-Specific Checking
            if (tileHover == false)
            {
                //place a new tile in the spot of the mouse when the mouse is clicked while not hovering and add it to the drawn list
                if (newMouse.LeftButton == ButtonState.Pressed && oldMouse.LeftButton == ButtonState.Released)
                {
                    Tile t = new Tile(false, false, false, false, tileSheet);
                    t.GetTilePosFromString("8");
                    t.X = newMouse.X - (t.Width / 2);
                    t.Y = newMouse.Y - (t.Height / 2);
                    drawn.Add(t);
                }
            }
            else
            {
                //run the particle engine if the mouse is clicked on top of a tile
                if (newMouse.LeftButton == ButtonState.Pressed && oldMouse.LeftButton == ButtonState.Released)
                {
                    //get all the tiles to feed into the engine and remove them from drawn
                    List <Tile> temp = new List <Tile>();
                    for (int current = drawn.Count; current > 0; current--)
                    {
                        if (drawn[current - 1] is Tile)
                        {
                            temp.Add((Tile)drawn[current - 1]);
                            drawn.Remove(drawn[current - 1]);
                        }
                    }

                    //actually start the engine
                    ParticleEngine tempPE = new ParticleEngine(blankParticle, 100);
                    tempPE.Run(temp);

                    //add the engine to current list of engines
                    particleEngines.Add(tempPE);
                }
            }
            #endregion

            for (int i = particleEngines.Count - 1; i >= 0; i--)
            {
                if (particleEngines[i].Duration < 0)
                {
                    particleEngines.RemoveAt(i);
                }
                else
                {
                    particleEngines[i].Continue();
                }
            }

            oldMouse = newMouse;

            base.Update(gameTime);
        }