Ejemplo n.º 1
0
        public void addParticles(int num)
        {
            for (int i = 0; i < num; i++)
            {
                Random RandomGenerator = new Random();

                float   randomXVelocity = 5;
                Vector2 mousePos        = camera.MouseToWorld();
                float   xPos            = mousePos.X;
                float   yPos            = mousePos.Y;

                if (xPos < drawingOffset)
                {
                    xPos = drawingOffset + 1;
                }
                else if (xPos > 800 - drawingOffset)
                {
                    xPos = 800 - drawingOffset - 1;
                }

                if (yPos < 0)
                {
                    yPos = 1;
                }
                else if (yPos > 500)
                {
                    yPos = 499;
                }

                BlobParticle theParticle = new BlobParticle(Game, new Vector2(xPos, yPos), theSprite, PhysicsOverlord.GetInstance().GetID(), particleRadius);
                theParticle.colour   = Color.Red;
                theParticle.velocity = new Vector2(5, 5);

                theParticles.Add(theParticle);
                SpatialGrid.GetInstance().AddObject(theParticle);

                particleCount++;
                currentNumParticles--;
            }
        }
Ejemplo n.º 2
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)
        {
            graphics.GraphicsDevice.Clear(Color.White);


            base.Draw(gameTime);

            spriteBatch.Begin();
            spriteBatch.DrawString(Content.Load <SpriteFont>("DebugFont"), "MOUSE: " + Mouse.GetState().ToString(), new Vector2(10, 10), Color.Red);
            spriteBatch.DrawString(Content.Load <SpriteFont>("DebugFont"), "MODE: " + ((state == GameState.gsEdit) ? "Edit" : "Simulate"), new Vector2(10, 30), (state == GameState.gsEdit) ? Color.Red : Color.Green);
            spriteBatch.DrawString(Content.Load <SpriteFont>("DebugFont"), "MOUSE WORLD: " + camera.MouseToWorld(), new Vector2(10, 50), Color.Red);
            spriteBatch.DrawString(Content.Load <SpriteFont>("DebugFont"), "CAMERA WORLD: " + camera.Position, new Vector2(10, 90), Color.Red);

            spriteBatch.End();
            // TODO: Add your drawing code here
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here
            //Vector2 mousePos = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
            //head.position = mousePos;
            if (game.state == GameState.gsSimulate)
            {
                KeyboardState aKeyboard = Keyboard.GetState();
                MouseState    aMouse    = Mouse.GetState();
                Vector2       mousePos  = camera.MouseToWorld();//new Vector2(aMouse.X, aMouse.Y);

                int     swimCount = 0;
                Boolean swimming  = false;

                if (head.status == ParasiteBodyPart.ParasiteStatus.swimming)
                {
                    swimCount++;
                }

                if (tail.status == ParasiteBodyPart.ParasiteStatus.swimming)
                {
                    swimCount++;
                }

                for (int i = 0; i < bodyparts.Count; i++)
                {
                    if (bodyparts[i].status == ParasiteBodyPart.ParasiteStatus.swimming)
                    {
                        swimCount++;
                    }
                }

                if (swimCount > (bodyparts.Count + 2) / 2)
                {
                    swimming = true;
                }


                Boolean applyGravity = true;

                if (!rigid)
                {
                    if (aKeyboard.IsKeyDown(Keys.Left))
                    {
                        head.velocity.X -= 0.2f;
                    }
                    else if (aKeyboard.IsKeyDown(Keys.Right))
                    {
                        head.velocity.X += 0.2f;
                    }

                    if (swimming)
                    {
                        if (aKeyboard.IsKeyDown(Keys.Up))
                        {
                            head.velocity.Y -= 0.2f;
                        }
                        else if (aKeyboard.IsKeyDown(Keys.Down))
                        {
                            head.velocity.Y += 0.2f;
                        }
                    }
                }

                if ((tail.Position - mousePos).Length() < 10 * bodyparts.Count && head.velocity.X < 1f && head.velocity.Y < 1f)
                {
                    tail.Position = mousePos;
                    //head.position = mousePos;

                    applyGravity = false;
                }

                if (aMouse.LeftButton == ButtonState.Pressed && (tail.Position - mousePos).Length() < 15)
                {
                    // LOCK all angles
                    if (rigid)
                    {
                        float maxDistance = theParasite.Count * 10;
                        float theDistance = (head.Position - tail.Position).Length();

                        // max distance between head/tail = theParasite.Count * defaultDistance.
                        // in this case, it is : 8 * 10 = 80.
                        head.IKPoint.distance = (theDistance / theParasite.Count);
                        tail.IKPoint.distance = (theDistance / theParasite.Count);
                        for (int i = 0; i < bodyparts.Count; i++)
                        {
                            bodyparts[i].IKPoint.distance = (theDistance / theParasite.Count);
                        }

                        launchForce = maxDistance - theDistance;
                    }
                    else
                    {
                        lockAngles();
                        rigid = true;
                    }
                }
                else
                {
                    if (rigid)
                    {
                        unlockAngles();

                        head.IKPoint.distance = head.IKPoint.defaultdistance;
                        tail.IKPoint.distance = tail.IKPoint.defaultdistance;
                        for (int i = 0; i < bodyparts.Count; i++)
                        {
                            bodyparts[i].IKPoint.distance = bodyparts[i].IKPoint.defaultdistance;
                        }

                        rigid = false;

                        if (launchForce > 0)
                        {
                            // Shoot him off!
                            head.velocity.X = (float)Math.Cos(tail.IKPoint.currentAngle) * launchForce;
                            head.velocity.Y = (float)Math.Sin(tail.IKPoint.currentAngle) * launchForce;
                        }
                    }
                }

                tail.Init();
                tail.UpdatePoint();

                if (applyGravity)
                {
                    tail.ApplyForce(tail.relativeGravity);
                }

                for (int i = 0; i < bodyparts.Count; i++)
                {
                    bodyparts[i].Init();
                    bodyparts[i].UpdatePoint();

                    if (bodyparts[i].status == ParasiteBodyPart.ParasiteStatus.swimming)
                    {
                        applyGravity = false;
                    }

                    if (applyGravity)
                    {
                        bodyparts[i].ApplyForce(bodyparts[i].relativeGravity);
                    }
                }

                head.Init();
                head.UpdatePoint();

                if (applyGravity)
                {
                    head.ApplyForce(head.relativeGravity);
                }

                //head.IKPoint.moveTo(mousePos.X, mousePos.Y);

                //head.velocity.Y += 0.2f;
            }
            //camera.Position = new Vector3(this.head.position, 0);
            base.Update(gameTime);
        }