public void Update(GameTime gameTime, Camera gameCamera, VoxelWorld gameWorld)
        {
            foreach (Particle p in Particles.Where(part => part.Active))
            {
                p.Update(gameTime, gameWorld);
            }

            updateTime += gameTime.ElapsedGameTime.TotalMilliseconds;
            if (updateTime >= updateTargetTime)
            {
                updateTime = 0;

                parts = 0;
                foreach (Particle p in Particles.Where(part => part.Active))
                {
                    ParticleCube.Create(ref verts, ref indexes, p.Position, parts, p.Scale / 2, p.Color);
                    parts++;
                }
            }

            currentParticleCount = Particles.Count(part => part.Active);

            drawEffect.World = gameCamera.worldMatrix;
            drawEffect.View = gameCamera.viewMatrix;
            drawEffect.Projection = gameCamera.projectionMatrix;
        }
        public void Draw(Camera gameCamera)
        {
            foreach (Projectile p in Projectiles.Where(proj => proj.Type == ProjectileType.Laser1 || proj.Type == ProjectileType.Laser2 || proj.Type == ProjectileType.Laser3 || proj.Type == ProjectileType.Laser4))
            {
                //drawEffect.Alpha = 0.5f;
                drawEffect.World = gameCamera.worldMatrix *
                                   Matrix.CreateRotationX(MathHelper.PiOver2) *
                                   //Matrix.CreateRotationZ(-MathHelper.PiOver2) *
                                   p.Rotation *
                                   //Matrix.CreateScale(0.5f) *
                                   Matrix.CreateTranslation(p.Position);
                foreach (EffectPass pass in drawEffect.CurrentTechnique.Passes)
                {
                    pass.Apply();

                    graphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalColor>(PrimitiveType.TriangleList, projectileStrip.AnimChunks[(int)p.Type].VertexArray, 0, projectileStrip.AnimChunks[(int)p.Type].VertexArray.Length, projectileStrip.AnimChunks[(int)p.Type].IndexArray, 0, projectileStrip.AnimChunks[(int)p.Type].VertexArray.Length / 2);

                }
                //drawEffect.Alpha = 1f;
            }

            foreach (Projectile p in Projectiles.Where(proj => proj.Type == ProjectileType.Rocket))
            {
                drawEffect.World = gameCamera.worldMatrix *
                                   Matrix.CreateRotationX(MathHelper.PiOver2) *
                                   p.Rotation *
                                   Matrix.CreateScale(0.5f) *
                                   Matrix.CreateTranslation(p.Position);
                foreach (EffectPass pass in drawEffect.CurrentTechnique.Passes)
                {
                    pass.Apply();

                    graphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalColor>(PrimitiveType.TriangleList, projectileStrip.AnimChunks[4].VertexArray, 0, projectileStrip.AnimChunks[4].VertexArray.Length, projectileStrip.AnimChunks[4].IndexArray, 0, projectileStrip.AnimChunks[4].VertexArray.Length / 2);

                }
            }
        }
Esempio n. 3
0
        public void Update(GameTime gameTime, Camera gameCamera, VoxelWorld gameWorld, Hero gameHero, float scrollPos)
        {
            foreach (Powerup p in Powerups.Where(part => part.Active))
            {
                p.Update(gameTime, gameWorld, gameHero, scrollPos);
            }

            updateTime += gameTime.ElapsedGameTime.TotalMilliseconds;
            if (updateTime >= updateTargetTime)
            {
                updateTime = 0;

                parts = 0;
                foreach (Powerup p in Powerups.Where(part => part.Active))
                {
                    Vector3 topLeftFront = new Vector3(-1.0f, 1.0f, 0f) * 1f;
                    Vector3 bottomLeftFront = new Vector3(-1.0f, -1.0f, 0f) * 1f;
                    Vector3 topRightFront = new Vector3(1.0f, 1.0f, 0f) * 1f;
                    Vector3 bottomRightFront = new Vector3(1.0f, -1.0f, 0f) * 1f;
                    verts[(parts * 4) + 0] = new VertexPositionNormalTexture(p.Position + topLeftFront, Vector3.Normalize(topLeftFront), new Vector2(0, 0));
                    verts[(parts * 4) + 1] = new VertexPositionNormalTexture(p.Position + bottomLeftFront, Vector3.Normalize(bottomLeftFront), new Vector2(0, 1));
                    verts[(parts * 4) + 2] = new VertexPositionNormalTexture(p.Position + topRightFront, Vector3.Normalize(topRightFront), new Vector2(1, 0));
                    verts[(parts * 4) + 3] = new VertexPositionNormalTexture(p.Position + bottomRightFront, Vector3.Normalize(bottomRightFront), new Vector2(1, 1));

                    for (int i = 0; i < 6; i++) indexes[(parts * 6) + i] = (short)((parts * 4) + faceIndices[i]);

                    parts+=1;
                }
            }

            currentPowerupCount = Powerups.Count(part => part.Active);

            drawEffect.World = gameCamera.worldMatrix;
            drawEffect.View = gameCamera.viewMatrix;
            drawEffect.Projection = gameCamera.projectionMatrix;
        }
Esempio n. 4
0
        void CheckCollisions(VoxelWorld world, Camera gameCamera)
        {
            float checkRadius = 3.5f;
            float radiusSweep = 0.1f;
            Vector2 v2Pos = new Vector2(Position.X, Position.Y);
            float checkHeight = Position.Z - 1f;
            Voxel checkVoxel;
            Vector3 checkPos;

            if (tempSpeed.Y < 0f)
            {
                for (float a = -MathHelper.PiOver2 - radiusSweep; a < -MathHelper.PiOver2 + radiusSweep; a += 0.02f)
                {
                    checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, collisionBoxSize.Y/2, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        tempSpeed.Y = 0f;
                    }
                    if (gameCamera.boundingFrustum.Contains(checkPos) == ContainmentType.Disjoint) tempSpeed.Y = 0;
                }
            }
            if (tempSpeed.Y > 0f)
            {
                for (float a = MathHelper.PiOver2 - radiusSweep; a < MathHelper.PiOver2 + radiusSweep; a += 0.02f)
                {
                    checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, collisionBoxSize.Y / 2, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        tempSpeed.Y = 0f;
                    }
                    if (gameCamera.boundingFrustum.Contains(checkPos) == ContainmentType.Disjoint) tempSpeed.Y = 0;
                }
            }
            if (tempSpeed.X < 0f)
            {
                for (float a = -MathHelper.Pi - radiusSweep; a < -MathHelper.Pi + radiusSweep; a += 0.02f)
                {
                    checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, collisionBoxSize.X / 2, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        tempSpeed.X = 0f;
                    }
                    if (gameCamera.boundingFrustum.Contains(checkPos) == ContainmentType.Disjoint) { tempSpeed.X -= Speed.X; break; }

                }
            }
            if (tempSpeed.X > 0f)
            {
                for (float a = -radiusSweep; a < radiusSweep; a += 0.02f)
                {
                    checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, collisionBoxSize.X / 2, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        tempSpeed.X = 0f;
                    }
                    if (gameCamera.boundingFrustum.Contains(checkPos) == ContainmentType.Disjoint) { tempSpeed.X -= Speed.X; break; }

                }
            }
        }
Esempio n. 5
0
        public void Update(GameTime gameTime, Camera gameCamera, VoxelWorld gameWorld, float scrollSpeed)
        {
            Vector2 v2Pos= new Vector2(Position.X,Position.Y);

            tempSpeed = Speed;
            tempSpeed.X += scrollSpeed;

            CollisionBox.Min = Position - (collisionBoxSize/2);
            CollisionBox.Max = Position + (collisionBoxSize/2);

            CheckCollisions(gameWorld, gameCamera);

            Position += tempSpeed;

            if(Helper.Random.Next(3)==1)
                ParticleController.Instance.Spawn(Position + new Vector3(-4f, 0f, 0f),
                                              new Vector3(Helper.RandomFloat(-0.5f, -0.3f), Helper.RandomFloat(-0.05f, 0.05f), 0f),
                                              0.3f,
                                              new Color(new Vector3(1f, Helper.RandomFloat(0f, 1.0f), 0f) * Helper.RandomFloat(0.5f, 1.0f)),
                                              1000,
                                              false);

            fireCooldown -= gameTime.ElapsedGameTime.TotalMilliseconds;
            rocketCooldown -= gameTime.ElapsedGameTime.TotalMilliseconds;

            if (hitAlpha > 0f) hitAlpha -= 0.1f;

            if (orbActive)
            {

                orbAngle += 0.1f;
                orbPosition = new Vector3(Helper.PointOnCircle(ref v2Pos, 15f, orbAngle), Position.Z);
                orbRotation += new Vector3(0.1f, -0.01f, 0.025f);

                foreach(Enemy e in EnemyController.Instance.Enemies)
                {
                    if (e.boundingSphere.Contains(new BoundingSphere(orbPosition,1.5f)) == ContainmentType.Intersects)
                    {
                        e.DoHit(orbPosition, Vector3.Zero, 3f);
                    }
                }
            }

            CheckLevelUp();

            drawEffect.Projection = gameCamera.projectionMatrix;
            drawEffect.View = gameCamera.viewMatrix;
        }
        public void Update(GameTime gameTime, Camera gameCamera, Hero gameHero, VoxelWorld gameWorld, float scrollPos)
        {
            foreach (Projectile p in Projectiles.Where(proj => proj.Active))
            {
                p.Update(gameTime, gameHero, gameWorld, scrollPos);
            }

            Projectiles.RemoveAll(proj => !proj.Active);

            drawEffect.World = gameCamera.worldMatrix;
            drawEffect.View = gameCamera.viewMatrix;
            drawEffect.Projection = gameCamera.projectionMatrix;
        }
Esempio n. 7
0
        public void Update(GameTime gameTime, Camera gameCamera)
        {
            X_SIZE = X_CHUNKS * Chunk.X_SIZE;
            Y_SIZE = Y_CHUNKS * Chunk.Y_SIZE;
            Z_SIZE = Z_CHUNKS * Chunk.Z_SIZE;

            redrawTime += gameTime.ElapsedGameTime.TotalMilliseconds;
            if (redrawTime > REDRAW_INTERVAL)
            {
                for(int i=0;i<1;i++)
                {
                    if (updateQueue.Count > 0)
                    {
                        redrawTime = 0;
                        Chunk uC = updateQueue.Dequeue();
                        uC.UpdateMesh();
                    }
                }
            }

            for (int y = 0; y < Y_CHUNKS; y++)
            {
                for (int x = 0; x < X_CHUNKS; x++)
                {
                    Chunk c = Chunks[x, y, 0];
                    if (c == null) continue;
                    if (!gameCamera.boundingFrustum.Intersects(c.boundingSphere))//.Transform(Matrix.CreateTranslation(-gameCamera.Position))))
                    {
                        if (c.Visible)
                        {
                            if (c.worldX * Chunk.X_SIZE * Voxel.SIZE < gameCamera.Position.X)
                            {
                                Chunks[x,y,0]=null;
                            }
                            else c.Visible = false;
                            //c.ClearMem();
                        }
                    }
                    else
                    {
                        if (!c.Visible)
                        {
                            c.Visible = true;
                            //if (c.Updated) c.UpdateMesh();
                            //c.UpdateMesh();
                        }
                    }
                }
            }
        }