Example #1
0
        internal void Initialize(Vector2 position,
                                 Vector2 acceleration, float mass, TimeSpan lifeTime)
        {
            phy = new ParticleObject(position, acceleration, mass);

            this.lifeTime = lifeTime;
        }
Example #2
0
    //-------------------------------------
    // Collision Methods - Particle Objects
    //-------------------------------------
    /// <summary>
    /// Separate the 2 objects from the information got from the collision.
    /// If ob2 is null only ob1 is moved out. Be careful to pass the right currPoint and projPoint.
    /// </summary>
    private void SeparateParticleObjects(ParticleObject ob1, Vector3 currPoint, Vector3 projPoint, ParticleObject ob2 = null)
    {
        // Update particles to move out
        float[] c1      = this.ComputeParticlesCoefficients(ob1, currPoint);
        float   lambda1 = this.ComputeLambda(c1);

        if (ob2 == null)
        {
            Logger.Instance.DebugInfo("1 Dynamic Sphere", "COLLISION");
            // Update the dynamic object
            for (int i = 0; i < 4; i++)
            {
                ob1.particles[i].position = ob1.particles[i].position + (lambda1 * c1[i] * (projPoint - currPoint)) * ob1.particles[i].invMass;
            }
            Logger.Instance.DebugParticleCoefficients(currPoint, c1, "COEFFICIENTS");
        }
        else
        {
            // In case both are dynamic have to push them in opposite directions.
            Logger.Instance.DebugInfo("2 Dynamic Spheres", "COLLISION");
            float[] c2      = this.ComputeParticlesCoefficients(ob1, projPoint);
            float   lambda2 = this.ComputeLambda(c2);

            // Update the dynamic object
            for (int i = 0; i < 4; i++)
            {
                ob1.particles[i].position = ob1.particles[i].position + (lambda1 * c1[i] * (projPoint - currPoint) * 0.5f) * ob1.particles[i].invMass;
                ob2.particles[i].position = ob2.particles[i].position + (lambda2 * c2[i] * (currPoint - projPoint) * 0.5f) * ob2.particles[i].invMass;
            }
            Logger.Instance.DebugParticleCoefficients(currPoint, c1, "COEFFICIENTS 1");
            Logger.Instance.DebugParticleCoefficients(projPoint, c2, "COEFFICIENTS 2");
        }
    }
Example #3
0
        public Vector2 CalculateAppliedForce(ParticleObject particle)
        {
            Vector2 apply = Vector2.Zero;

            if (range > 0)
            {
                float dist = Vector2.Distance(position, this.position);

                if (dist < range)
                {
                    Vector2 objDirect = Vector2.Normalize(position);

                    if (objDirect.X <= -direction.X || objDirect.Y >= -direction.Y)
                    {
                        float f = (force / range) * dist;

                        apply = direction * f;
                    }
                }
            }
            else
            {
                apply = direction * force;
            }

            return(apply);
        }
Example #4
0
        internal void Draw(ParticleObject po, ref Matrix4 viewProjection)
        {
            lock (po)
            {
                GL.Uniform4(mUniform_TintColor, ref po._tint);
                Matrix4 mvp = po._modelMatrix * viewProjection;
                GL.UniformMatrix4(mUniform_MVP, false, ref mvp);

                GL.ActiveTexture(TextureUnit.Texture0);
                GL.BindTexture(TextureTarget.Texture2D, po._info.Texture);
                GL.Uniform1(mUniform_Texture, 0);

                GL.Uniform1(mUniform_AnimationState, po._frame);
                GL.Uniform1(mUniform_AnimationStates, po._info.Images);

                GeoMesh mesh = po._model.Meshes.Values.ElementAt(0);
                GL.BindVertexArray(mesh.VAO);
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, mesh.VBOIndex);
                GL.DrawElements(mesh.Primitive, mesh.IndexCount, DrawElementsType.UnsignedInt, 0);
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);

                GL.BindTexture(TextureTarget.Texture2D, 0);
                GL.BindVertexArray(0);
            }
        }
Example #5
0
        public void loadLayer()
        {
            particleRenderer = new ParticleRenderer();
            Rt = new RenderTarget2D(GameLoop.gameInstance.GraphicsDevice, GameSettings.Default.resolutionWidth, GameSettings.Default.resolutionHeight);

            foreach (LevelObject lo in loList)
            {
                lo.LoadContent();

                if (lo is ParticleObject)
                {
                    ParticleObject p = (ParticleObject)lo;
                    particleRenderer.addParticleObjects(p);
                }
            }

            particleRenderer.initializeParticles();

            //Effects.Add(e0);

            if (Effects == null)
            {
                Effects = new List <EffectObject>();
            }

            foreach (EffectObject eo in Effects)
            {
                //eo.Initialise();
                eo.LoadContent();
            }
        }
Example #6
0
        public void Dispose()
        {
            startParticle.Remove();
            connectingParticle.Remove();

            startParticle      = null;
            connectingParticle = null;
        }
Example #7
0
        /// <summary>
        /// Destroys the PhysicsComponent.
        /// </summary>
        public override void Destroy()
        {
            particlePhysics.Remove();
            particlePhysics = null;

            collisionObject.Destroy();
            collisionObject = null;

            base.Destroy();
        }
Example #8
0
 /// <summary>
 /// Fügt ein neues Partikelobjekt hinzu
 /// </summary>
 /// <param name="g">Objekt</param>
 public void AddParticleObject(ParticleObject g)
 {
     lock (_particleObjects)
     {
         if (!_particleObjects.Contains(g))
         {
             _particleObjectsTBA.Add(g);
         }
     }
 }
Example #9
0
    /// <summary>
    /// Add a new particle object to the list of objects that get updated in the simulation.
    /// </summary>
    /// <param name="rigidBody"></param>
    /// =================
    /// Particle Object
    /// =================
    public void AddParticleObject(ParticleObject pObject)
    {
        if (ParticleObjects == null)
        {
            ParticleObjects = new List <ParticleObject>();
        }
        ParticleObjects.Add(pObject);

        Logger.Instance.DebugInfo("Added a particle object!");
    }
Example #10
0
        /// <summary>
        /// Calculates the force to be applied to an object.
        /// </summary>
        /// <param name="particle">The particle to get the applied forces for.</returns>
        internal static Vector2 AccumulateForces(ParticleObject particle)
        {
            Vector2 force = Vector2.Zero;

            for (int i = 0; i < forces.Count; i++)
            {
                force += forces[i].CalculateAppliedForce(particle);
            }

            return(force);
        }
Example #11
0
        /// <summary>
        /// Creates a new Spring force.
        /// </summary>
        /// <param name="startParticle">The ParticleObject determining the start of the Spring.</param>
        /// <param name="connectingParticle">The ParticleObject detemining the end of the Spring.</param>
        /// <param name="springStiffness">The stiffness of the Spring.</param>
        /// <param name="springLenght">The lenght of the Spring.</param>
        /// <param name="springFriction">The amount of friction to be applied to the Spring.</param>
        public Spring(ParticleObject startParticle,
                      ParticleObject connectingParticle, float springStiffness,
                      float springLenght, float springFriction)
        {
            this.startParticle      = startParticle;
            this.connectingParticle = connectingParticle;

            springConstant    = springStiffness;
            this.springLenght = springLenght;
            frictionConstant  = springFriction;
        }
Example #12
0
        /// <summary>
        /// Creates a new ProjectileObject.
        /// </summary>
        /// <param name="id">The ID of the ProjectileObject.</param>
        /// <param name="bounds">The bounds of the ProjectileObject.</param>
        /// <param name="acceleration">The initial acceleration of the ProjectileObject.</param>
        /// <param name="mass">The mass of the ProjectileObject.</param>
        public ProjectileObject(string id, Rectangle bounds,
                                Vector2 acceleration, float mass)
        {
            collide = new CollisionObject(id + "Collide", bounds);

            particle = new ParticleObject(new Vector2(bounds.Center.X,
                                                      bounds.Center.Y), acceleration, mass);

            particle.AttachedToID = collide.ID;

            particle.OnUpdate  += new OnParticleUpdateEvent(Update);
            collide.OnCollided += new CollisionEvent(Collided);
        }
Example #13
0
    public void OnCollisionEnter(Collision collisionObject)
    {
        Debug.Log("COLLIDED");
        GameObject     myAnimation;
        ParticleObject collidedWith = collisionObject.gameObject.GetComponent <ParticleObject>();

        int counter = 0;

        if (collidedWith.charge == 1)
        {
            if (this.charge == 1)
            {
                myAnimation = GameObject.Instantiate(col_1_anim_prefab, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                myAnimation.transform.position = this.transform.position;
                this.changeVelocity(new Vector3(this.velocity.x * -1, this.velocity.y * -1, this.velocity.z * -1));
                Debug.Log("Proton v Proton");
                counter += 1;
            }
            else if (this.charge == -1)
            {
                myAnimation = GameObject.Instantiate(col_2_anim_prefab, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                myAnimation.transform.position = this.transform.position;
                Debug.Log("Proton v Electron");
                this.changeVelocity(new Vector3((collidedWith.velocity.x + this.velocity.x) / 2,
                                                (collidedWith.velocity.y + this.velocity.y) / 2,
                                                (collidedWith.velocity.z + this.velocity.z) / 2));
                counter += 1;
            }
        }
        else if (collidedWith.charge == -1)
        {
            if (this.charge == 1)
            {
                myAnimation = GameObject.Instantiate(col_2_anim_prefab, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                myAnimation.transform.position = this.transform.position;
                this.changeVelocity(new Vector3((collidedWith.velocity.x + this.velocity.x) / 2,
                                                (collidedWith.velocity.y + this.velocity.y) / 2,
                                                (collidedWith.velocity.z + this.velocity.z) / 2));
                counter += 1;
            }
            else if (this.charge == -1)
            {
                myAnimation = GameObject.Instantiate(col_3_anim_prefab, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                myAnimation.transform.position = this.transform.position;
                this.changeVelocity(new Vector3(this.velocity.x * -1, this.velocity.y * -1, this.velocity.z * -1));
                Debug.Log("Electron v Electron");
                counter += 1;
            }
        }
        Debug.Log("Counter: " + counter.ToString());
    }
Example #14
0
        /// <summary>
        /// Creates a new PhysicsComponent.
        /// </summary>
        /// <param name="id">The ID of the PhysicsComponent.</param>
        /// <param name="bounds">The bounding area of the PhysicsComponent.</param>
        /// <param name="acceleration">The initial acceleration of the PhysicsComponent.</param>
        /// <param name="mass">The mass of the PhysicsComponent.</param>
        public PhysicsComponent(string id, Rectangle bounds,
                                Vector2 acceleration, float mass)
            : base(id)
        {
            collisionObject = new CollisionObject(id + "Collide", bounds);
            collisionObject.SetAttachedTo(ID);

            particlePhysics = new ParticleObject(new Vector2(bounds.Center.X,
                                                             bounds.Center.Y), acceleration, mass);

            particlePhysics.AttachedToID = collisionObject.ID;

            particlePhysics.OnUpdate   += new OnParticleUpdateEvent(ParticleUpdate);
            collisionObject.OnCollided += new CollisionEvent(Collided);
        }
Example #15
0
        private void SpawnParticles()
        {
            long now = GetCurrentTimeInMilliseconds();

            if (now - timestamp > 3000)
            {
                ParticleObject p = new ParticleObject(new Vector3(7, 2.5f, -5), new Vector3(5), ParticleType.BurstFirework2);
                AddParticleObject(p);

                Explosion e = new Explosion(new Vector3(3, 0, -5), 512, 0.5f, 5f, 3, ExplosionType.Dollar, new Vector4(1, 1, 0, 1));
                e.SetAnimationAlgorithm(ExplosionAnimation.WhirlwindUp);
                AddGameObject(e);

                timestamp = now;
            }
        }
Example #16
0
        public void loadLayer()
        {
            particleRenderer = new ParticleRenderer();

            foreach (LevelObject lo in loList)
            {
                lo.LoadContent();

                if (lo is ParticleObject)
                {
                    ParticleObject p = (ParticleObject)lo;
                    particleRenderer.addParticleObjects(p);
                }
            }

            particleRenderer.initializeParticles();
        }
Example #17
0
        /// <summary>
        /// Calculates the forec of the explosion at the position.
        /// </summary>
        /// <param name="position">The position of the object.</param>
        /// <returns>The calculated force.</returns>
        public Vector2 CalculateAppliedForce(ParticleObject particle)
        {
            Vector2 apply = Vector2.Zero;

            float dist = Vector2.Distance(impactArea.Center, particle.Position);

            if (dist < impactArea.Radius)
            {
                Vector2 direct = particle.Position - impactArea.Center;
                direct.Normalize();

                float f = (force / radius) * dist;

                apply = direct * f;
            }

            return(apply);
        }
Example #18
0
        protected override void Initialize()
        {
            List <Limb> limbs = refferenceSkeleton.Limbs;

            for (int i = 0; i < limbs.Count; i++)
            {
                collisionBodies.Add(new CollisionObject(ID +
                                                        limbs[i].Name + "Collide", GetBounds(limbs[i])));
            }

            GetArea();

            particle = new ParticleObject(
                GetPosition(), Vector2.Zero, mass, area);

            prevParticlePos = particle.Position;

            base.Initialize();
        }
Example #19
0
        public override void Act(KeyboardState kb, MouseState ms)
        {
            if (kb[Key.Escape])
            {
                CurrentWindow.SetWorld(new GameWorldStart());
                return;
            }

            long now = GetCurrentTimeInMilliseconds();

            if (now - _timeStamp > 3000)
            {
                ParticleObject smoke = new ParticleObject(new Vector3(-32.5f, 1, -22.5f), new Vector3(5, 5, 5), ParticleType.LoopSmoke1);
                smoke.SetColor(0.2f, 0.2f, 0.2f, 1);
                smoke.SetDuration(3.25f);
                AddParticleObject(smoke);
                _timeStamp = now;
            }

            if (now - _timeStampExp > _timeStampExpDiff)
            {
                Explosion ex = new Explosion(new Vector3(-35f, 4, -22.5f), 32, 1, 8, 2, ExplosionType.Cube, new Vector4(1, 1, 1, 1));
                //ex.SetAnimationAlgorithm(ExplosionAnimation.WindUp);
                AddGameObject(ex);

                _timeStampExp     = now;
                _timeStampExpDiff = HelperRandom.GetRandomNumber(3000, 10000);
                //_timeStampExpDiff = HelperRandom.GetRandomNumber(2000, 4000);
            }

            if (kb[Key.KeypadPlus])
            {
                _bloomradius        = HelperGeneral.Clamp(_bloomradius + 0.01f * KWEngine.DeltaTimeFactor, 0, 1);
                KWEngine.GlowRadius = _bloomradius;
                Console.WriteLine("Bloom radius: " + _bloomradius);
            }
            if (kb[Key.KeypadMinus])
            {
                _bloomradius        = HelperGeneral.Clamp(_bloomradius - 0.01f * KWEngine.DeltaTimeFactor, 0, 1);
                KWEngine.GlowRadius = _bloomradius;
                Console.WriteLine("Bloom radius: " + _bloomradius);
            }
        }
Example #20
0
 public void OnAwake()
 {
     if (Toolbox.Get <SceneController>().GetIsMainScene())
     {
         return;
     }
     _particleManager = Toolbox.Get <ParticleManager>();
     ManagerUpdate.AddTo(this);
     for (int i = 0; i < _particleCount; i++)
     {
         var particle = new ParticleObject();
         var obj      = Instantiate(_particles);
         particle.obj      = obj;
         particle.animator = obj.GetComponent <Animator>();
         particle.obj.SetActive(false);
         particle.transform = obj.transform;
         _freeParticles.Add(particle);
     }
 }
Example #21
0
        public void loadContentInEditor(GraphicsDeviceManager graphicsM, GraphicsDevice graphics, ContentManager content)
        {
            particleRenderer = new ParticleRenderer(graphicsM);
            particleRenderer.particleRenderer.LoadContent(content);
            this._graphicsM = graphicsM;
            this._contentM  = content;
            Rt = new RenderTarget2D(graphics, graphics.Viewport.Width, graphics.Viewport.Height);

            foreach (LevelObject lo in loList)
            {
                if (lo is DrawableLevelObject)
                {
                    DrawableLevelObject dlo = (DrawableLevelObject)lo;
                    try
                    {
                        dlo.loadContentInEditor(graphics);
                    }
                    catch (Exception e)
                    {
                        DebugLogManager.writeToLogFile("Wasn't able to load " + dlo.name + " in Layer " + this.name);
                    }
                }
                else if (lo is ParticleObject)
                {
                    ParticleObject p = (ParticleObject)lo;
                    particleRenderer.addParticleObjectsInEditor(p, content);
                }
            }

            particleRenderer.initializeParticlesInEditor(content);
            if (Effects == null)
            {
                Effects = new List <EffectObject>();
            }

            foreach (EffectObject eo in Effects)
            {
                //eo.Initialise();
                eo.loadContentInEditor(graphics, content);
            }
        }
Example #22
0
    /// <summary>
    /// Compute coefficients to use for moving the particles (SEE JAKOBSEN paper).
    /// This method should not be used for more than 4 particles.
    /// </summary>
    private float[] ComputeParticlesCoefficients(ParticleObject ob, Vector3 currPoint)
    {
        int numOfParticles = ob.particles.Length;

        float[] c = new float[numOfParticles];
        double[,] matrix = new double[4, numOfParticles];

        for (int j = 0; j < numOfParticles; j++)
        {
            Particle p = ob.particles[j];
            matrix[0, j] = (double)p.position.x;
            matrix[1, j] = (double)p.position.y;
            matrix[2, j] = (double)p.position.z;
            matrix[3, j] = (double)1;
        }
        //Logger.Instance.PrintMatrix(matrix, 4, 4);

        double[,] rhs = { { (double)currPoint.x }, { (double)currPoint.y }, { (double)currPoint.z }, { (double)1 } };
        //Logger.Instance.PrintMatrix(rhs, 4, 1, " RHS");

        double[,] x = Matrix.Solve(matrix, rhs);
        //Logger.Instance.PrintMatrix(x, 4, 1, "RESULT x");

        for (int i = 0; i < 4; i++)
        {
            c[i] = (float)x[i, 0];
        }

        // HACK: Faster but not accurate.
        //float maxDist = (ob.particles[0].position - currPoint).magnitude;
        //for (int i = 1; i < numOfParticles; i++)
        //{
        //    maxDist = Mathf.Max(maxDist, (ob.particles[i].position - currPoint).magnitude);
        //}

        //for (int i = 0; i < c.Length; i++)
        //{
        //    c[i] = 1 - ((ob.particles[i].position - currPoint).magnitude / maxDist);
        //}
        return(c);
    }
Example #23
0
        /// <summary>
        /// Creates a new Rope.
        /// </summary>
        /// <param name="id">The ID of the Rope.</param>
        /// <param name="drawLayer">The layer to draw the Rope on.</param>
        /// <param name="smoothness">The smoothnes of the Rope.</param>
        /// <param name="springsMass">The mass of each individual Spring in the Rope.</param>
        /// <param name="springsStiffness">The stiffness of each Spring.</param>
        /// <param name="springsFriction">The friction that each spring applies.</param>
        /// <param name="totalSpringLenght">The total lenght of the Rope.</param>
        /// <param name="pointOfConnection">The point from where the Rope will swing from.</param>
        /// <param name="textureFilepath">The texture filepath fgor each segment of the Rope.</param>
        /// <param name="normalMapFilepath">The normal map texture filepath for each segement of the Rope.</param>
        /// <param name="ropeThickness">The thickness of the Rope.</param>
        public Rope(string id, int drawLayer, int smoothness, float springsMass,
                    float springsStiffness, float springsFriction,
                    float totalSpringLenght, Vector2 pointOfConnection,
                    string textureFilepath, string normalMapFilepath, float ropeThickness)
        {
            this.id        = id;
            this.drawLayer = drawLayer;

            this.textureFilepath   = textureFilepath;
            this.normalMapFilepath = normalMapFilepath;
            this.ropeThickness     = ropeThickness;

            this.pointOfConnection = pointOfConnection;

            lenght = new Vector2(0, totalSpringLenght / smoothness);

            springs = new Spring[smoothness];
            sprites = new Sprite[smoothness];

            for (int i = 0; i < springs.Length; i++)
            {
                Spring spring;

                if (i == 0)
                {
                    ParticleObject start = new ParticleObject(pointOfConnection, Vector2.Zero, springsMass);
                    ParticleObject end   = new ParticleObject(pointOfConnection + lenght, Vector2.Zero, springsMass);

                    spring = new Spring(start, end, springsStiffness, lenght.Y, springsFriction);
                }
                else
                {
                    ParticleObject end = new ParticleObject(springs[i - 1].EndParticle.Position + lenght, Vector2.Zero, springsMass);

                    spring = new Spring(springs[i - 1].EndParticle, end, springsStiffness, lenght.Y, springsFriction);
                }

                springs[i] = spring;
            }
        }
Example #24
0
 public Vector2 CalculateAppliedForce(ParticleObject particle)
 {
     return(0.5f * frictionCoefficient *
            particle.SurfaceArea * fluidDensity * particle.Velocity);
 }
Example #25
0
 /// <summary>
 /// Called during initialization of particle object.
 /// </summary>
 /// <param name="particleObject"></param>
 public void AssignParticleObject(ParticleObject particleObject)
 {
     this.particleObject = particleObject;
 }
Example #26
0
 internal void RemoveParticleObject(ParticleObject g)
 {
     _particleObjectsTBR.Add(g);
 }
Example #27
0
	public void Play(ParticleObject particleObject, Vector3 position)
	{
		Game.Instantiate(particleObject, position, particleObject.transform.rotation);
	}
Example #28
0
 public Vector2 CalculateAppliedForce(ParticleObject particle)
 {
     return(particle.Velocity * friction);
 }
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            
            
            switch (currentState)
            {
                     
                #region Menu
		 
	            case States.Menu: 

                    //Platz für ein Menu
                    //Menu();
                    prewState = States.Menu;
                    currentState = States.Start;
                    break;

                    #endregion

                #region Start
                //Start: Objekte werden geladen, Kamera wird erstellt, danach Camto1
                case States.Start:

                    startObjects.LoadStartObjects(level.getLevel());

                    //Zeigt das Baumenü mit den Objekten und Texturen die der Spieler wählen kann, benötigt Name des Bildes
                    auswahlanzeige = startObjects.showObjects("Bau");
                    objWafC = startObjects.LoadObjWafC();

                    //setzt die Variable PosX1 auf die Position bevor er in den nächsten State wechselt
                    PosX1 = Scene.Camera.Position.X;
                    Zeit1 = gameTime.TotalGameTime.Milliseconds + gameTime.TotalGameTime.Seconds * 1000 + gameTime.TotalGameTime.Minutes * 60 * 1000; //Zeit zwischenspeichern
                    aktuallisiereZeit(gameTime);

                    //danach Kamera an Spielerposition 1 bewegen
                    prewState = States.Start;
                    currentState = States.Camto1;

                    break;

                #endregion

                #region Camto1
                //Camto1: Kamera wird an die Linke Position bewegt
                case States.Camto1:
                    aktuallisiereZeit(gameTime);
                    weiterSym.Visible = false;
                    detecting = false;  //Kinect deaktiviert

                    //Variable wird für nächste Schussphasen zurückgesetzt
                    firedWaffen = 0;                        
                    
                    //Kamera wird bewegt
                    cameraMovement.move(zeit,3000,PosX1, level.getSpieler1Pos());

                #region Übergangsbedingungen
                    //Wenn die Spielerposition 1 erreicht wurde startet die Bauphase/Schussphase
                    if (Scene.Camera.Position.X == level.getSpieler1Pos())
                    {
                        //setzt die Variable PosX1 auf die Position bevor er in den nächsten State wechselt 
                        PosX1 = Scene.Camera.Position.X;
                        Zeit1 = gameTime.TotalGameTime.Milliseconds + gameTime.TotalGameTime.Seconds * 1000 + gameTime.TotalGameTime.Minutes * 60 * 1000; //Zeit zwischenspeichern
                        aktuallisiereZeit(gameTime);

                        //Wenn wir aus der Startphase kommen, -> Bauphase 1
                        if (prewState == States.Start)
                        {
                            prewState = States.Camto1;
                            currentState = States.Bauphase1O;
                        }

                        //Wenn wir aus der Bauphase von Spieler2 kommen, -> Schussphase 1
                        else if (prewState == States.Bauphase2O)
                        {
                            prewState = States.Camto1;
                            currentState = States.Schussphase1;
                        }

                        //Wenn wir aus der Schussphase von Spieler2 kommen
                        else if (prewState == States.Schussphase2)
                        {
                            //Ist die Schussphase durch -> Bauphase 1
                            if (schussphasenDurch)
                            {
                                prewState = States.Camto1;
                                currentState = States.Schussphase1;
                                /* schussphasenDurch wird auf true gesetzt, damit nach der nächsten Schussphase wieder in die Bauphase gewechselt wird.
                                 * Schussphase2 sagt also schussphaseDurch= true, will aber erst noch Schussphase 1
                                 */

                            }
                            //sonst Schussphase 1
                            else
                            {
                                prewState = States.Camto1;
                                currentState = States.Bauphase1O;
                            }
                        }
                    } 
                #endregion

                    break;

                #endregion

                #region Objektemenüs
                case States.Bauphase2O:

                case States.Bauphase1O:
                    aktuallisiereZeit(gameTime);
                    detecting = true;               //Kinect aktiv
                    if (!weiterSym.Visible)
                    {
                        weiterSym.Visible = true;
                    }
                    float pos;
                    

                    #region Spieler &  Spielerposition
                    if (currentState == States.Bauphase1O)
                    {
                        gamer = spieler1;
                        pos = level.getSpieler1Pos();
                        weiterSym.Position = new Vector3(pos+1.13f, -0.7f, -2f);
                    }
                    else
                    {
                        gamer = spieler2;
                        pos = level.getSpieler2Pos();
                        weiterSym.Position = new Vector3(pos + 1.13f, -0.7f, -2f);
                    }
                    #endregion

                    #region Objekt erzeugen und mit Hand positionieren
                    if (!showWaffe)
                    {
                        if (getObj && objInHand == false && auswahl != 0 && auswahl < 5)    //"klick" und das Objekt wurde noch nicht erstellt und linke hand befindet sich auf auswahlfeld
                        {
                            objInHand = true;                                               //soll jetzt der Hand folgen
                            aktuellesObj = Objektverwaltung.createObj(auswahl, gamer, pos); //aktuelles Objekt wird erzeugt
                        }

                        if (objInHand)//Ausrichten des Obj
                        {
                            Vector3 rH = new Vector3(rightHand.Position.X, rightHand.Position.Y, -5f); //Handvektor ohne Tiefenveränderung
                            aktuellesObj.setPosition(rH);                 //Objektposition wird auf Handgelegt

                            Objektverwaltung.orientObj(aktuellesObj, leftHand.Position.X, leftHand.Position.Y);

                            rightHand.Visible = false;                  //Anzeige der rechten Hand deaktiviert
                        }

                        if (klick && objInHand == true)                //wenn sich ein Objekt in der Hand befindet und erneut geklickt wird
                        {
                            rightHand.Visible = true;                   //Rechte Hand wird wieder angezeigt
                            klick = false;
                            objInHand = false;                          //Bekommt nicht mehr die Posiotion der hand -> fällt

                            if (currentState == States.Bauphase1O)
                            {
                                prewState = States.Bauphase1O;              //Statewechsel
                                currentState = States.Bauphase1T;
                            }
                            else
                            {
                                prewState = States.Bauphase2O;
                                currentState = States.Bauphase2T;
                            }
                        }
                    }
                    #endregion

                    #region Waffe erzeugen und mit Hand positionieren
                    if (showWaffe)
                    {


                        if (getObj && objInHand == false && auswahl != 0 && auswahl < 5)    //"klick" und die Waffe wurde noch nicht erstellt und linke hand befindet sich auf auswahlfeld
                        {
                            objInHand = true;                                                   //soll jetzt der Hand folgen

                            aktuelleWaffe = Objektverwaltung.createWaffe(auswahl, gamer, rightHand.Position);  //aktuelles Objekt wird erzeugt
                            if (spieler1 == gamer)
                            {
                                spieler1.setWaffen(aktuelleWaffe);                                          //Waffe der Waffenliste des Spieler hinzufügen
                            }
                            else
                            {
                                spieler2.setWaffen(aktuelleWaffe);
                            }
                        }

                        
                        if (objInHand && showWaffe == true)                                              //Ausrichten der Waffe
                        {
                            Vector3 rH = new Vector3(rightHand.Position.X, rightHand.Position.Y, -5f);  //Handvektor ohne Tiefenveränderung
                            aktuelleWaffe.setPosition(rH);                                              //Waffenposition wird auf Handgelegt
                            
                            rightHand.Visible = false;                                                  //Anzeige der rechten Hand deaktiviert
                            
                        }

                        if (klick && objInHand)                                                         //wenn sich ein Objekt in der Hand befindet und erneut geklickt wird
                        {
                            rightHand.Visible = true;                                                   //Rechte Hand wird wieder angezeigt
                            klick = false;
                            objInHand = false;
                            
                        }

                    }
                    
                    #endregion

                    #region Wechsel von der Objekt zur Waffenauswahl
                    if (klick&&objInHand == false && auswahl == 5 && showWaffe == false) //"klick" und das Objekt wurde noch nicht erstellt und linke hand befindet sich auf auswahlfeld
                    {
                        showWaffe = true;
                    }
                    else if (klick && objInHand == false &&  auswahl == 5 && showWaffe)
                    {
                        showWaffe = false;
                    }
                    #endregion
                    
                    #region Übergangsbedingungen
                    //Wenn Spieler nicht ausreichend Geld hat (oder auf weiter Klickt => in Kinect realisiert)
                    if (gamer.getMoney() < level.getMinMoney() && objInHand == false)
                    {
                        PosX1 = Scene.Camera.Position.X;
                        Zeit1 = gameTime.TotalGameTime.Milliseconds + gameTime.TotalGameTime.Seconds * 1000 + gameTime.TotalGameTime.Minutes * 60 * 1000; //Zeit zwischenspeichern
                        aktuallisiereZeit(gameTime);

                        if (currentState == States.Bauphase1O)
                        {
                            prewState = States.Bauphase1O;
                            if (spieler2.getMoney() < level.getMinMoney() && spieler2.getMoney() < spieler1.getMoney())
                            {
                                currentState = States.Schussphase1;
                            }
                            else
                            {
                                currentState = States.Camto2;
                            }
                        }
                        else //Bauphase2O
                        {
                            prewState = States.Bauphase2O;
                            if (spieler1.getMoney() < spieler2.getMoney())
                            {
                                currentState = States.Schussphase2;
                            }
                            else
                            {
                                currentState = States.Camto1;
                            }
                        }
                    }
                    #endregion
                    
                    break;

                #endregion

                #region Texturenmenüs
                //Bauphase, Spiele 1, Objekte erstellen
                case States.Bauphase1T:
                case States.Bauphase2T:
                    aktuallisiereZeit(gameTime);
                    Objektverwaltung.firstMaterial(aktuellesObj, auswahl);
                    weiterSym.Visible = false;

                    if (currentState == States.Bauphase1T)
                    {
                        gamer = spieler1;
                    }
                    else 
                    {
                        gamer = spieler2;
                    }

                    if (klick) //Übergang wird mit klick erzeugt
                    {
                        #region Kosten dem Spieler abziehen
                        if (aktuellesObj.getMaterial() == "MHolz")
                        { } //kostenlos
                        else if (aktuellesObj.getMaterial() == "MStein")
                        {
                            gamer.setMoney(spieler1.getMoney() - 50);
                        }
                        else if (auswahl == 3)
                        {
                            gamer.setMoney(spieler1.getMoney() - 100);
                        }
                        else if (auswahl == 4)
                        {
                            gamer.setMoney(spieler1.getMoney() - 200);
                        }
                        #endregion

                        if (currentState == States.Bauphase1T)
                        {
                            prewState = States.Bauphase1T;
                            currentState = States.Bauphase1O;
                        }
                        else
                        {
                            prewState = States.Bauphase2T;
                            currentState = States.Bauphase2O;
                        }
                    }
                    break;

                #endregion

                #region Camto2
                //Kamera wird an die Rechte Positon bewegt
                case States.Camto2:
                    aktuallisiereZeit(gameTime);
                    detecting = false;               //Kinect deaktiviert
                    weiterSym.Visible = false;

                    //Variable wird für nächste Schussphasen zurückgesetzt
                    firedWaffen = 0; 

                    //Kamera wird bewegt
                    cameraMovement.move(zeit, 3000, PosX1, level.getSpieler2Pos());

                #region Übergangsbedingungen
                    //Wenn die Spielerposition 2 erreicht wurde startet die Bauphase/Schussphase
                    if (Scene.Camera.Position.X == level.getSpieler2Pos())
                    {
                        //setzt die Variable PosX1 auf die Position bevor er in den nächsten State wechselt 
                        PosX1 = Scene.Camera.Position.X;
                        Zeit1 = gameTime.TotalGameTime.Milliseconds + gameTime.TotalGameTime.Seconds * 1000 + gameTime.TotalGameTime.Minutes * 60 * 1000; //Zeit zwischenspeichern
                        aktuallisiereZeit(gameTime);

                        //Wenn wir aus der Bauphase1 kommen -> Bauphase 2 (ohne Geld, aber mehr Geld als Sp1 Schussphase2)
                        if (prewState == States.Bauphase1O)
                        {
                            //Spieler2 hat genug Geld zum Bauen
                            if (spieler2.getMoney() >= level.getMinMoney())
                            {
                                prewState = States.Camto2;
                                currentState = States.Bauphase2O;
                            }
                            //Spieler zwei hat nicht genug Geld aber mehr als Spieler1 -> Schussphase 2
                            else if (spieler2.getMoney() > spieler1.getMoney())
                            {
                                prewState = States.Camto2;
                                currentState = States.Schussphase2;
                            }
                        }
                        //Wenn wir aus der Schussphase1 kommen, muss Schussphase 2 starten 
                        else if (prewState == States.Schussphase1)
                        {
                            prewState = States.Camto2;
                            currentState = States.Schussphase2;
                        }

                    }
                #endregion

                    break;

                #endregion

                #region Schussphasen
                //Schussphasen
                case States.Schussphase2:
                case States.Schussphase1:

                    
                    aktuallisiereZeit(gameTime);
                    detecting = true;               //Kinect aktiv
                    weiterSym.Visible = false;
                    int xR;

                    if (currentState == States.Schussphase1)
                    {
                        gamer = spieler1;
                        xR = 1;
                    }
                    else
                    {
                        gamer = spieler2;
                        xR = -1;
                    }
                    #region Schussfunktion //shoot Funktion TODO: "auslagern"
                    if (gamer.getWaffen() != 0)
                    {   
                        aktuelleWaffe = Objektverwaltung.getWaffe(gamer, firedWaffen);
                        aktuelleWaffe.setWinkel(rightHand.Position.Y);//Setzt Winkel der Kanone in Waffen

                        if (klick==true)
                        {
                           float schusswinkel,x,y,velocity;
                           Vector3 spawnpoint = new Vector3 ( rightHand.Position.X+1,rightHand.Position.Y-1, rightHand.Position.Z); //Spawnposition nur Vorübergehend sollte am Objekt sein!
                           bullet = new SphereObject(new Vector3(aktuelleWaffe.getPosition().X, aktuelleWaffe.getPosition().Y,rightHand.Position.Z), 0.1f, 10, 10, 0.05f);
                           Vector3 shootdirection = new Vector3();
                           Scene.Add(bullet);
                            
                           schusswinkel = aktuelleWaffe.getWinkel();
                           x=(float)Math.Cos(schusswinkel);
                           y=(float)Math.Sin(schusswinkel);
                           shootdirection = new Vector3(x,y,0);
                           if (gamer == spieler1)
                           {
                               velocity = leftHand.Position.Y * 10f;
                               bullet.Physics.LinearVelocity = shootdirection * velocity;


                           }
                           else
                           {
                               velocity = leftHand.Position.Y * 10f;
                               shootdirection.X = shootdirection.X * (-1f);
                               bullet.Physics.LinearVelocity = shootdirection * velocity;
                           }


                           firedWaffen++;
                           bulletInAir = true;
                           
                           
                        }
        
                        
                        
                    }
                    
                    
                    if (bulletInAir)
                    {
                       
                        cameraMovement.chaseBullet(bullet.Position, cam.Position);
                        
                        bullet.Collided +=new EventHandler<CollisionArgs>(bulletCollidedHandler);

                        //Partikel Effekte FUNKTIONIERT NOCH NICHT
                        ParticleEffect effect = new ParticleEffect()
                        {
                            Emitters = new EmitterCollection()
                                {   
                                    new SphereEmitter
                                    {
                                        Name="Flame",
                                        Budget = 100,
                                        Term = 0.5f,
                                        ReleaseQuantity = 8,
                                        Enabled = true,
                                        ReleaseSpeed = new Range(5f,5f),
                                        ReleaseColour = new ColourRange
                                        {
                                            Red = new Range(0.9f,1f),
                                            Green = new Range(0.5f,0.5f),
                                            Blue = new Range(0f,0f),
                                        },
                                        ReleaseOpacity = new Range(1f,1f),
                                        ReleaseScale = new Range(2f,2f),
                                        ReleaseRotation = new RotationRange
                                        {
                                            Pitch = new Range(0f,0f),
                                            Yaw = new Range(0f,0f),
                                            Roll = new Range(-3.14f,3.14f),
                                        },
                                        ParticleTexture = Core.Content.Load<Texture2D>("Flames"),
                                        BlendMode = EmitterBlendMode.Add,
                                        Radius = 3f,
                                        Shell = true,
                                        Radiate = true,                        
                                        BillboardStyle = ProjectMercury.BillboardStyle.Spherical,
                                        Modifiers = new ModifierCollection
                                        {
                                            new OpacityInterpolator2
                                            {
                                                InitialOpacity = 0.5f,                                
                                                FinalOpacity = 0f,
                                            },
                                            new RotationModifier
                                            {
                                                RotationRate = new Vector3(0,0,1)
                                            }
                                        },
                                        Controllers = new ControllerPipeline
                                        {
                                            new CooldownController
                                            {
                                                CooldownPeriod = 0.02f,
                                            },
                                        }
                                    }
                                }
                        };

                        ParticleObject particle = new ParticleObject(bullet.Position, effect);
                        
                       


                    }
                    
                    #endregion

                    #region Übergangsbedingungen
                    //Wenn alle Waffen abgefeuert wurden...
                    if (firedWaffen == gamer.getWaffen())
                    {
                        //setzt die Variable PosX1 auf die Position bevor er in den nächsten State wechselt 
                        PosX1 = Scene.Camera.Position.X;
                        Zeit1 = gameTime.TotalGameTime.Milliseconds + gameTime.TotalGameTime.Seconds * 1000 + gameTime.TotalGameTime.Minutes * 60 * 1000; //Zeit zwischenspeichern
                        aktuallisiereZeit(gameTime);

                        //Wenn die Schussphase durch ist, beginnt die Bauphase
                        if (schussphasenDurch)
                        {
                            if (currentState == States.Schussphase1)
                            {
                                prewState = States.Schussphase1;
                                schussphasenDurch = false;
                                currentState = States.Bauphase1O;
                            }
                            else
                            {
                                prewState = States.Schussphase2;
                                schussphasenDurch = false;
                                currentState = States.Camto1;
                            }
                        }

                        //Sonst in die andere Schussphase wechseln
                        else
                        {
                            if (currentState == States.Schussphase1)
                            {
                                prewState = States.Schussphase1;
                                schussphasenDurch = true;           //nach der Schussphase2 ist die Schussphase beendet
                                currentState = States.Camto2;
                            }
                            else
                            {
                                prewState = States.Schussphase2;
                                schussphasenDurch = true;           //nach der Schussphase1 ist die Schussphase beendet
                                currentState = States.Camto1;
                            }
                        }
                    }

                    #endregion


                    break;

                #endregion

                #region End
                //Ende des Spiels
                case States.End:
                    //noch leer



                    //neues Spiel, alle vorherigen Objekte werden gelöscht
                    Scene.RemoveAllSceneObjects();  
                    break;

                #endregion

                
            }




            #region Objekt-/ Texturauswahl ein-/ausblenden
            if (currentState != States.Menu && currentState != States.Start && currentState != States.End)
            {
                if (currentState == States.Bauphase1O)
                {
                    if (showWaffe)
                    {
                        startObjects.einausblender(auswahlanzeige, objWafC, 11, zeit);
                    }
                    else
                    {
                        startObjects.einausblender(auswahlanzeige, objWafC, 1, zeit);
                    }
                }
                else if (currentState == States.Bauphase1T)
                {
                    showWaffe = false;
                    startObjects.einausblender(auswahlanzeige, objWafC, 12, zeit);
                }
                else if (currentState == States.Bauphase2O)
                {
                    if (showWaffe)
                    {
                        startObjects.einausblender(auswahlanzeige, objWafC, 21, zeit);
                    }
                    else
                    {
                        startObjects.einausblender(auswahlanzeige, objWafC, 2, zeit);
                    }
                }
                else if (currentState == States.Bauphase2T)
                {
                    showWaffe = false;
                    startObjects.einausblender(auswahlanzeige, objWafC, 22, zeit);
                }
                else
                {
                    startObjects.einausblender(auswahlanzeige, objWafC, 0, zeit);
                }
            }



            #endregion

            #region Kinect
            if (detecting)
            {
                if (Scene.Kinect.SkeletonDataReady)
                {
                    List<NOVA.Components.Kinect.Skeleton> skeletons = new List<NOVA.Components.Kinect.Skeleton>(Scene.Kinect.Skeletons);

                    //Aktives Skelett finden
                    foreach (NOVA.Components.Kinect.Skeleton skeleton in skeletons)
                    {
                        if (skeleton.TrackingState == SkeletonTrackingState.Tracked && skeleton.Joints.Count != 0)
                        {
                            //Box auf Hand, Klick auf Weiter
                           #region Detektion der rechten Hand

                            if (skeleton.Joints[JointType.HandRight].TrackingState == JointTrackingState.Tracked)
                            {
                                //Position der rechten Hand des Spielers in Bildschirmkoodinaten
                                Vector2 screenPos = skeleton.Joints[JointType.HandRight].ScreenPosition;
                                Vector2 normScreenPos = new Vector2(screenPos.X, screenPos.Y);
                                screenPos.X = screenPos.X * Scene.Game.Window.ClientBounds.Width;
                                screenPos.Y *= Scene.Game.Window.ClientBounds.Height;

                                //parallele Ebene zum Bildschirm erzeugen in der die Kugel transformiert wird
                                Plane plane2 = new Plane(Vector3.Forward, -4f);

                                //Weltkoordinatenpunk finden
                                Vector3 worldPos2 = Helpers.Unproject(screenPos, plane2);

                                #region Box auf Hand
                                //Position der Kugel setzen
                                rightHand.Position = worldPos2;
                                #endregion

                                #region getObj
                                if (normScreenPos.X >= 0.2f && normScreenPos.X <= 0.8f && normScreenPos.Y <= 0.1f)
                                {
                                    getObj = true;
                                }
                                else {getObj = false; }
                                #endregion

                                #region WEITER klick
                                //Wenn sich die rechte Hand in der oberen, rechten Ecke befindet & KLICK -> Klick auf WEITER
                                if (normScreenPos.X >= 0.9f && normScreenPos.Y >= 0.9f)
                                {
                                    //setzt die Variable PosX1 auf die Position bevor er in den nächsten State wechselt 
                                    PosX1 = Scene.Camera.Position.X;
                                    Zeit1 = gameTime.TotalGameTime.Milliseconds + gameTime.TotalGameTime.Seconds * 1000 + gameTime.TotalGameTime.Minutes * 60 * 1000; //Zeit zwischenspeichern
                                    aktuallisiereZeit(gameTime);

                                    if (currentState == States.Bauphase1O)
                                    {
                                        prewState = States.Bauphase1O;

                                        //wenn Spieler2 über genügend Geld zum bauen verfügt, Bauphase Spieler 2
                                        //Wenn Spieler2 mehr Geld besitzt fängt er die Schussphase2 an
                                        if (spieler2.getMoney() >= level.getMinMoney() || spieler2.getMoney() > spieler1.getMoney())
                                        {
                                            currentState = States.Camto2;
                                        }
                                        //wenn Spieler2 nicht über genügend Geld zum bauen verfügt, und Spieler1 mehr Geld hat beginnt Schussphase1
                                        else
                                        {
                                            currentState = States.Schussphase1;
                                        }

                                    }
                                    else if (currentState == States.Bauphase2O)
                                    {
                                        prewState = States.Bauphase2O;

                                        //Wenn Spieler2 mehr Geld besitzt fängt er die Schussphase2 an
                                        if (spieler2.getMoney() > spieler1.getMoney())
                                        {
                                            currentState = States.Schussphase2;
                                        }
                                        //sonst Spieler 1
                                        else
                                        {
                                            currentState = States.Camto1;
                                        }

                                    }
                                    else
                                    {
                                        return;
                                    }
                                }
                                #endregion

                                

                            }
                            #endregion

                            //Box auf Hand, Auswahl Textur/ Objekt
                            #region Detektion der linken Hand
                            if (skeleton.Joints[JointType.HandLeft].TrackingState == JointTrackingState.Tracked)
                            {
                                //Position der linken Hand des Spielers in Bildschirmkoodinaten
                                screenPos = skeleton.Joints[JointType.HandLeft].ScreenPosition;
                                Vector2 normScreenPos = new Vector2(screenPos.X, screenPos.Y);
                                screenPos.X = screenPos.X * Scene.Game.Window.ClientBounds.Width;
                                screenPos.Y *= Scene.Game.Window.ClientBounds.Height;

                                //parallele Ebene zum Bildschirm erzeugen in der die Kugel transformiert wird
                                Plane plane2 = new Plane(Vector3.Forward, -1f);

                                //Weltkoordinatenpunk finden
                                Vector3 worldPos2 = Helpers.Unproject(screenPos, plane2);

                                #region Box auf Hand
                                //Position der Kugel setzen
                                leftHand.Position = worldPos2;
                                #endregion

                                #region Auswahl Textur/ Objekt
                                auswahl = Auswahl.auswahl(normScreenPos);

                                #endregion
                            }
                           
                            #endregion

                            //Hintergrundsbild verschieben
                            #region Detektion des Kopfes
                            if (skeleton.Joints[JointType.Head].TrackingState == JointTrackingState.Tracked)
                            {
                                //Position des Kopfes des Spielers in Bildschirmkoodinaten
                                Vector2 screenPos = skeleton.Joints[JointType.Head].ScreenPosition;
                                Vector2 normScreenPos = new Vector2(screenPos.X / Scene.Game.Window.ClientBounds.Width, screenPos.Y / Scene.Game.Window.ClientBounds.Height);

                                //Hintergrund bewegen
                                startObjects.MoveBackground(normScreenPos.X - 0.5f, normScreenPos.Y - 0.5f);
                                


                            }
                            
                            #endregion

                        }
                    }

                }
            }
            else
            {
                
            }
            #endregion

            

            objState = currentState; //Am Ende jenden Updates wird der State angeglichen

            Objektverwaltung.refreshObj(spieler1,spieler2); //Entfernt Objekte ohne LP
         
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
      
        }
Example #30
0
    public static void AddParticle(GameObject newParticle)
    {
        ParticleObject particle = newParticle.GetComponent <ParticleObject>();

        _allParticles.Add(particle);
    }
Example #31
0
 /// <summary>
 /// Calculates the gravity to be applied to an object at a position.
 /// </summary>
 /// <param name="position">The position of the object.</param>
 public Vector2 CalculateAppliedForce(ParticleObject particle)
 {
     return(direction * gravity);
 }
Example #32
0
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            #region Kinect

            if (Scene.Kinect.SkeletonDataReady)
            {
                List<NOVA.Components.Kinect.Skeleton> skeletons = new List<NOVA.Components.Kinect.Skeleton>(Scene.Kinect.Skeletons);

                //Aktives Skelett finden
                foreach (NOVA.Components.Kinect.Skeleton skeleton in skeletons)
                {
                    if (skeleton.TrackingState == SkeletonTrackingState.Tracked && skeleton.Joints.Count != 0)
                    {
                        //Box auf Hand, Klick auf Weiter
                        #region Detektion der rechten Hand

                        if (skeleton.Joints[JointType.HandRight].TrackingState == JointTrackingState.Tracked)
                        {
                            //Position der rechten Hand des Spielers in Bildschirmkoodinaten
                            rHv2s = skeleton.Joints[JointType.HandRight].ScreenPosition;
                            rHv2s -= new Vector2(0, 10);
                            rHv2n.X = rHv2s.X / screenDim.X;
                            rHv2n.Y = rHv2s.Y / screenDim.Y;

                            Plane plane2 = new Plane(Vector3.Forward, -4f);

                            //Weltkoordinatenpunk finden
                            Vector3 worldPos2R = Helpers.Unproject(rHv2s, plane2, false);
                            rHv2w = new Vector2(worldPos2R.X, worldPos2R.Y);

                            #region Auswahl Textur/ Objekt
                            auswahl = Auswahl.auswahl(rHv2n);

                            #endregion

                            if (klickCounter<100)
                            {
                                klickCounter++;
                            }

                            try
                            {

                                if (skeleton.HandPointers[1].IsTracked == true)
                                {
                                    if (skeleton.HandPointers[1].HandEventType == InteractionHandEventType.GripRelease && klickCounter >= 100)
                                    {
                                        klickRH = true;
                                        klickCounter = 0;
                                    }
                                    else
                                    {
                                        klickRH = false;
                                    }

                                }
                            }
                            catch { };

                        }
                        #endregion

                        //Box auf Hand, Auswahl Textur/ Objekt
                        #region Detektion der linken Hand
                        if (skeleton.Joints[JointType.HandLeft].TrackingState == JointTrackingState.Tracked)
                        {
                            //Position der linken Hand des Spielers in Bildschirmkoodinaten
                            lHv2s = skeleton.Joints[JointType.HandLeft].ScreenPosition;
                            lHv2n.X = lHv2s.X / screenDim.X;
                            lHv2n.Y = lHv2s.Y / screenDim.Y;

                            //parallele Ebene zum Bildschirm erzeugen in der die Kugel transformiert wird
                            Plane plane2 = new Plane(Vector3.Forward, -4f);

                            //Weltkoordinatenpunk finden
                            Vector3 worldPos2L = Helpers.Unproject(lHv2s, plane2, false);
                            lHv2w = new Vector2(worldPos2L.X, worldPos2L.Y);
                          /*  try
                            {
                               // klickLH = (skeleton.HandPointers[1].HandEventType == InteractionHandEventType.Grip);
                            }
                            catch { };*/
                        }

                        #endregion

                        //Hintergrundsbild verschieben
                        if (bulletInAir == false)
                        {
                            #region Detektion des Kopfes
                            if (skeleton.Joints[JointType.Head].TrackingState == JointTrackingState.Tracked)
                            {
                                //Position des Kopfes des Spielers in Bildschirmkoodinaten
                                Vector2 screenPos = skeleton.Joints[JointType.Head].ScreenPosition;
                                Vector2 normScreenPos = new Vector2(screenPos.X / screenDim.X, screenPos.Y / screenDim.Y);

                                Vector3 realPos = skeleton.Joints[JointType.Head].WorldPosition;
                                //Hintergrund bewegen
                                startObjects.MoveBackground(normScreenPos.X - 0.5f, normScreenPos.Y - 0.5f);

                                //Kamera auf z-Achse bewegen
                                realPos = skeleton.Joints[JointType.Head].WorldPosition;

                                #region Zoom Funktionen
                                //ZOOM Funktionen
                                if (currentState == States.Schussphase1 || currentState == States.Schussphase2)
                                {
                                    if (gamer == spieler1)
                                    {
                                        cameraMovement.zoom(realPos.Z, 1, new Vector3(10f, 2f, 15f));
                                    }
                                    if (gamer == spieler2)
                                    {
                                        cameraMovement.zoom(realPos.Z, -1, new Vector3(10f, 2f, 15f));
                                    }
                                }
                                if (currentState == States.Bauphase1O || currentState == States.Bauphase1T || currentState == States.Bauphase2O || currentState == States.Bauphase2T)
                                {
                                    if (gamer == spieler1)
                                    {
                                        cameraMovement.zoom(realPos.Z, 1, new Vector3(1.5f, 0f, 4f));
                                    }
                                    if (gamer == spieler2)
                                    {
                                        cameraMovement.zoom(realPos.Z, -1, new Vector3(1.5f, 0f, 4f));
                                    }
                                }

                                #endregion

                            }
                            #endregion
                        }

                    }
                }

            }
            #endregion

            switch (currentState)
            {
                #region Start
                //Start: Objekte werden geladen, Kamera wird erstellt, danach Camto1
                case States.Start:

                    startObjects.LoadStartObjects(level.getLevel());

                    //setzt die Variable PosX1 auf die Position bevor er in den nächsten State wechselt
                    PosX1 = Scene.Camera.Position.X;
                    Zeit1 = gameTime.TotalGameTime.Milliseconds + gameTime.TotalGameTime.Seconds * 1000 + gameTime.TotalGameTime.Minutes * 60 * 1000; //Zeit zwischenspeichern
                    aktuallisiereZeit(gameTime);

                    //danach Kamera an Spielerposition 1 bewegen
                    currentState = States.Camto1;

                    break;

                #endregion

                #region Camto1
                //Camto1: Kamera wird an die Linke Position bewegt
                case States.Camto1:
                    aktuallisiereZeit(gameTime);

                    //Variable wird für nächste Schussphasen zurückgesetzt
                    firedWaffen = 0;

                    //Kamera wird bewegt
                    cameraMovement.move(zeit,3000,PosX1, level.getSpieler1Pos());

                #region Übergangsbedingungen
                    //Wenn die Spielerposition 1 erreicht wurde startet die Bauphase/Schussphase
                    if (Scene.Camera.Position.X == level.getSpieler1Pos())
                    {
                        //setzt die Variable PosX1 auf die Position bevor er in den nächsten State wechselt
                        PosX1 = Scene.Camera.Position.X;
                        Zeit1 = gameTime.TotalGameTime.Milliseconds + gameTime.TotalGameTime.Seconds * 1000 + gameTime.TotalGameTime.Minutes * 60 * 1000; //Zeit zwischenspeichern
                        aktuallisiereZeit(gameTime);

                        currentState = logik.uebergang(currentState, spieler1, spieler2, level);
                    }
                #endregion

                    break;

                #endregion

                #region Objektemenüs
                case States.Bauphase2O:

                case States.Bauphase1O:
                    aktuallisiereZeit(gameTime);
                    float pos;

                    #region Spieler &  Spielerposition
                    if (currentState == States.Bauphase1O)
                    {
                        gamer = spieler1;
                        pos = level.getSpieler1Pos();
                    }
                    else
                    {
                        gamer = spieler2;
                        pos = level.getSpieler2Pos();
                    }
                    #endregion

                    #region Objekt erzeugen und mit Hand positionieren
                    if (!showWaffe)
                    {
                        if (klickRH && !objInHand && auswahl != 0 &&auswahl < 5)    //"klick" und das Objekt wurde noch nicht erstellt und linke hand befindet sich auf auswahlfeld
                        {
                            klickRH = false;
                            objInHand = true;                                               //soll jetzt der Hand folgen
                            aktuellesObj = Objektverwaltung.createObj(auswahl, gamer, pos, rHv2s); //aktuelles Objekt wird erzeugt
                        }

                        if (objInHand)//Ausrichten des Obj
                        {
                            Vector3 rH = new Vector3(rHv2w.X, rHv2w.Y, -5f); //Handvektor ohne Tiefenveränderung
                            aktuellesObj.setPosition(rH);                 //Objektposition wird auf Handgelegt

                            Objektverwaltung.orientObj(aktuellesObj, lHv2w.X, lHv2w.Y);
                        }

                        if (klickRH && objInHand)                //wenn sich ein Objekt in der Hand befindet und erneut geklickt wird
                        {
                            klickRH = false;
                            objInHand = false;                          //Bekommt nicht mehr die Posiotion der hand -> fällt

                            if (currentState == States.Bauphase1O)
                            {
                                currentState = States.Bauphase1T;
                            }
                            else
                            {
                                currentState = States.Bauphase2T;
                            }
                        }
                    }
                    #endregion

                    #region Waffe erzeugen und mit Hand positionieren
                    if (showWaffe)
                    {
                        if (klickRH && !objInHand && auswahl != 0 && auswahl < 5)    //"klick" und die Waffe wurde noch nicht erstellt und linke hand befindet sich auf auswahlfeld
                        {
                            klickRH = false;
                            objInHand = true;                                                   //soll jetzt der Hand folgen

                            aktuelleWaffe = Objektverwaltung.createWaffe(auswahl, gamer, rHv2w);  //aktuelles Objekt wird erzeugt
                            if (spieler1 == gamer)
                            {
                                spieler1.setWaffen(aktuelleWaffe);                                          //Waffe der Waffenliste des Spieler hinzufügen
                            }
                            else
                            {
                                spieler2.setWaffen(aktuelleWaffe);
                            }
                        }

                        if (objInHand && showWaffe == true)                                              //Ausrichten der Waffe
                        {
                            Vector3 rH = new Vector3(rHv2w, -5f);                                       //Handvektor ohne Tiefenveränderung
                            aktuelleWaffe.getModelObject().Position = rH;                               //Waffenposition wird auf Handgelegt
                        }

                        if (klickRH && objInHand)                                                         //wenn sich ein Objekt in der Hand befindet und erneut geklickt wird
                        {
                            klickRH = false;
                            objInHand = false;
                        }
                    }

                    #endregion

                    #region Wechsel von der Objekt zur Waffenauswahl
                    if (klickRH && objInHand == false && auswahl == 5 && showWaffe == false) //"klick" und das Objekt wurde noch nicht erstellt und linke hand befindet sich auf auswahlfeld
                    {
                        klickRH = false;
                        showWaffe = true;
                    }
                    else if (klickRH && objInHand == false &&  auswahl == 5 && showWaffe)
                    {
                        klickRH = false;
                        showWaffe = false;
                    }
                    #endregion

                    #region Übergangsbedingungen
                    //Wenn Spieler nicht ausreichend Geld hat (oder auf weiter Klickt => in Kinect realisiert)
                    if (gamer.getMoney() < level.getMinMoney() && objInHand == false && (currentState == States.Bauphase1O ||currentState == States.Bauphase2O))
                    {
                        PosX1 = Scene.Camera.Position.X;
                        Zeit1 = gameTime.TotalGameTime.Milliseconds + gameTime.TotalGameTime.Seconds * 1000 + gameTime.TotalGameTime.Minutes * 60 * 1000; //Zeit zwischenspeichern
                        aktuallisiereZeit(gameTime);
                        showWaffe = false;

                        currentState = logik.uebergang(currentState, spieler1, spieler2, level);
                            }
                    #endregion

                    break;

                #endregion

                #region Texturenmenüs
                //Bauphase, Spiele 1, Objekte erstellen
                case States.Bauphase1T:
                case States.Bauphase2T:
                    aktuallisiereZeit(gameTime);
                    Objektverwaltung.firstMaterial(aktuellesObj, auswahl);

                    if (currentState == States.Bauphase1T)
                    {
                        gamer = spieler1;
                    }
                    else
                    {
                        gamer = spieler2;
                    }

                    if (klickRH) //Übergang wird mit klick erzeugt
                    {
                        klickRH = false;
                        #region Kosten dem Spieler abziehen
                        if (aktuellesObj.getMaterial() == "MHolz")
                        { } //kostenlos
                        else if (aktuellesObj.getMaterial() == "MStein")
                        {
                            DrawHelper.setmoney(gamer, -50, rHv2s);
                        }
                        else if (auswahl == 3)
                        {
                            DrawHelper.setmoney(gamer, -100, rHv2s);
                        }
                        else if (auswahl == 4)
                        {
                            DrawHelper.setmoney(gamer, -200, rHv2s);
                        }
                        #endregion

                        if (currentState == States.Bauphase1T)
                        {
                            currentState = States.Bauphase1O;
                        }
                        else
                        {
                            currentState = States.Bauphase2O;
                        }
                    }
                    break;

                #endregion

                #region Camto2
                //Kamera wird an die Rechte Positon bewegt
                case States.Camto2:
                    aktuallisiereZeit(gameTime);

                    //Variable wird für nächste Schussphasen zurückgesetzt
                    firedWaffen = 0;

                    //Kamera wird bewegt
                    cameraMovement.move(zeit, 3000, PosX1, level.getSpieler2Pos());

                #region Übergangsbedingungen
                    //Wenn die Spielerposition 2 erreicht wurde startet die Bauphase/Schussphase
                    if (Scene.Camera.Position.X == level.getSpieler2Pos())
                    {
                        //setzt die Variable PosX1 auf die Position bevor er in den nächsten State wechselt
                        PosX1 = Scene.Camera.Position.X;
                        Zeit1 = gameTime.TotalGameTime.Milliseconds + gameTime.TotalGameTime.Seconds * 1000 + gameTime.TotalGameTime.Minutes * 60 * 1000; //Zeit zwischenspeichern
                        aktuallisiereZeit(gameTime);

                        currentState = logik.uebergang(currentState, spieler1, spieler2, level);
                            }
                #endregion

                    break;

                #endregion

                #region Schussphasen
                //Schussphasen
                case States.Schussphase2:
                case States.Schussphase1:

                    aktuallisiereZeit(gameTime);
                    int xR;

                    if (currentState == States.Schussphase1)
                    {
                        gamer = spieler1;
                        xR = 1;
                    }
                    else
                    {
                        gamer = spieler2;
                        xR = -1;
                    }
                    #region Schussfunktion //shoot Funktion TODO: "auslagern"
                    if (gamer.getWaffen() != 0 && !bulletInAir)//Wenn der Spieler Waffen hat
                    {
                        aktuelleWaffe = Objektverwaltung.getWaffe(gamer, firedWaffen);
                        aktuelleWaffe.setWinkel(rHv2n.Y);//Setzt Winkel der Kanone in Waffen

                        if (klickRH)
                        {
                            klickRH = false;
                            float schusswinkel;
                            float x;
                            float y;
                            float velocity;

                            if (aktuelleWaffe.getType()=="Balliste")
                            {
                                Munition="Bolzen";
                            }
                            else if (aktuelleWaffe.getType() == "Kanone")
                            {
                                Munition = "Kugel";
                            }
                            else {
                                Munition = "Crap";
                            }
                            if (Munition =="Kugel")
                            { bullet = new SphereObject(new Vector3(aktuelleWaffe.getPosition().X, aktuelleWaffe.getPosition().Y+2.5f,aktuelleWaffe.getPosition().Z), 0.1f, 10, 10, 0.05f);
                              Scene.Add(bullet);
                            }
                            else if (Munition == "Bolzen")
                            {
                                bolzen = new ModelObject(new Vector3(aktuelleWaffe.getPosition().X, aktuelleWaffe.getPosition().Y + 0.5f, aktuelleWaffe.getPosition().Z), Quaternion.Identity, new Vector3(1, 1, 1), CollisionType.ExactMesh, "", "Bolzen", 0.05f);
                                Scene.Add(bolzen);
                            }

                            schusswinkel = aktuelleWaffe.getWinkel();
                            x=(float)Math.Cos(schusswinkel);
                            y=(float)Math.Sin(schusswinkel);
                            Vector3 shootdirection = new Vector3(x,y,0);

                            velocity = (1-lHv2n.Y) * 10f;
                            if (Munition == "Kugel")
                            {
                                bullet.Physics.LinearVelocity = shootdirection * velocity * xR;
                            }
                            else if (Munition == "Bolzen")
                            {
                                bolzen.Physics.LinearVelocity = shootdirection * velocity * xR;
                            }

                            firedWaffen++;
                            bulletInAir = true;
                        }
                    }

                    if (bulletInAir)
                    {
                        if (Munition == "Kugel")
                        {
                            cameraMovement.chaseBullet(bullet.Position, cam.Position);
                            bullet.Collided += new EventHandler<CollisionArgs>(bulletCollidedHandler);
                        }
                        else if (Munition == "Bolzen")
                        {
                            cameraMovement.chaseBullet(bolzen.Position, cam.Position);
                            bolzen.Collided += new EventHandler<CollisionArgs>(bulletCollidedHandler);
                        }

                        //Partikel Effekte FUNKTIONIERT NOCH NICHT
                        ParticleEffect effect = new ParticleEffect()
                        {
                            Emitters = new EmitterCollection()
                                {
                                    new SphereEmitter
                                    {
                                        Name="Flame",
                                        Budget = 100,
                                        Term = 0.5f,
                                        ReleaseQuantity = 8,
                                        Enabled = true,
                                        ReleaseSpeed = new Range(5f,5f),
                                        ReleaseColour = new ColourRange
                                        {
                                            Red = new Range(0.9f,1f),
                                            Green = new Range(0.5f,0.5f),
                                            Blue = new Range(0f,0f),
                                        },
                                        ReleaseOpacity = new Range(1f,1f),
                                        ReleaseScale = new Range(2f,2f),
                                        ReleaseRotation = new RotationRange
                                        {
                                            Pitch = new Range(0f,0f),
                                            Yaw = new Range(0f,0f),
                                            Roll = new Range(-3.14f,3.14f),
                                        },
                                        ParticleTexture = Core.Content.Load<Texture2D>("Flames"),
                                        BlendMode = EmitterBlendMode.Add,
                                        Radius = 3f,
                                        Shell = true,
                                        Radiate = true,
                                        BillboardStyle = ProjectMercury.BillboardStyle.Spherical,
                                        Modifiers = new ModifierCollection
                                        {
                                            new OpacityInterpolator2
                                            {
                                                InitialOpacity = 0.5f,
                                                FinalOpacity = 0f,
                                            },
                                            new RotationModifier
                                            {
                                                RotationRate = new Vector3(0,0,1)
                                            }
                                        },
                                        Controllers = new ControllerPipeline
                                        {
                                            new CooldownController
                                            {
                                                CooldownPeriod = 0.02f,
                                            },
                                        }
                                    }
                                }
                        };

                        ParticleObject particle = new ParticleObject(bullet.Position, effect);

                    }

                    #endregion

                    #region Übergangsbedingungen
                    //Wenn alle Waffen abgefeuert wurden...
                    if (firedWaffen == gamer.getWaffen())
                    {
                        //setzt die Variable PosX1 auf die Position bevor er in den nächsten State wechselt
                        PosX1 = Scene.Camera.Position.X;
                        Zeit1 = gameTime.TotalGameTime.Milliseconds + gameTime.TotalGameTime.Seconds * 1000 + gameTime.TotalGameTime.Minutes * 60 * 1000; //Zeit zwischenspeichern
                        aktuallisiereZeit(gameTime);

                        currentState = logik.uebergang(currentState, spieler1, spieler2, level);
                            }

                    #endregion

                    break;

                #endregion

                #region End
                //Ende des Spiels
                case States.End:
                    //noch leer

                    //neues Spiel, alle vorherigen Objekte werden gelöscht
                    Scene.RemoveAllSceneObjects();
                    break;

                #endregion

            }

            #region WEITER
            //Wenn sich die rechte Hand in der oberen, rechten Ecke befindet & KLICK -> Klick auf WEITER
            if (rHv2n.X >= 0.9f && rHv2n.Y >= 0.4f && rHv2n.Y <= 0.6f && klickRH)
            {
                klickRH = false;
                showWaffe = false;
                //setzt die Variable PosX1 auf die Position bevor er in den nächsten State wechselt
                PosX1 = Scene.Camera.Position.X;
                Zeit1 = gameTime.TotalGameTime.Milliseconds + gameTime.TotalGameTime.Seconds * 1000 + gameTime.TotalGameTime.Minutes * 60 * 1000; //Zeit zwischenspeichern
                aktuallisiereZeit(gameTime);

                currentState = logik.uebergang(currentState, spieler1, spieler2, level);
                    }
            #endregion

            #region Update Ende

            objState = currentState; //Am Ende jenden Updates wird der State angeglichen

            screenDim = new Vector2(Scene.Game.Window.ClientBounds.Width, Scene.Game.Window.ClientBounds.Height);

            Objektverwaltung.refreshObj(spieler1,spieler2); //Entfernt Objekte ohne LP

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

            #endregion
        }
Example #33
0
 internal override void Draw(ParticleObject po, ref Matrix4 viewProjection)
 {
     throw new NotImplementedException();
 }
Example #34
0
        private void AddParticleObject(ParticleObject loNew, Engine.Logic.PivotObject __parentObject = null)
        {
            _scene.AddObject(loNew);

            if (__parentObject != null)
            {
                loNew.SetGlobalPose(Matrix.Identity, true, __parentObject);
                _scene._objects.AddRule(__parentObject, loNew);
            }
        }