Esempio n. 1
0
        public override void DoCollide(bool x, bool y, bool z, Vector3 checkPosition, Hero gameHero, VoxelWorld gameWorld, bool withPlayer)
        {
            gameWorld.Explode(checkPosition, 5f);

            Die();

            base.DoCollide(x, y, z, checkPosition, gameHero, gameWorld, withPlayer);
        }
Esempio n. 2
0
        public override void Update(GameTime gameTime, VoxelWorld gameWorld, Hero gameHero)
        {
            Rotation += rotSpeed;

            if(Helper.Random.Next(10)==1) ParticleController.Instance.Spawn(new Vector3(Helper.RandomPointInCircle(new Vector2(Position.X, Position.Y), 0f, 4f), Position.Z), Vector3.Zero, 0.3f, new Color(Color.Gray.ToVector3() * Helper.RandomFloat(0.4f, 0.8f)), 1000, false);

            base.Update(gameTime, gameWorld, gameHero);
        }
Esempio n. 3
0
        public override void Update(GameTime gameTime, VoxelWorld gameWorld, Hero gameHero)
        {
            barrelRot = Helper.TurnToFace(new Vector2(Position.X, Position.Y), new Vector2(gameHero.Position.X, gameHero.Position.Y), barrelRot, 1f, 0.1f);

            barrelRot = Inverted ? MathHelper.Clamp(barrelRot, 0.5f, MathHelper.Pi-0.5f) : MathHelper.Clamp(barrelRot, -MathHelper.Pi + 0.5f, -0.5f);
            //f(Helper.Random.Next(10)==1) ParticleController.Instance.Spawn(new Vector3(Helper.RandomPointInCircle(new Vector2(Position.X, Position.Y), 0f, 4f), Position.Z), Vector3.Zero, 0.3f, new Color(Color.Gray.ToVector3() * Helper.RandomFloat(0.4f, 0.8f)), 1000, false);

            base.Update(gameTime, gameWorld, gameHero);
        }
Esempio n. 4
0
        public void Update(GameTime gameTime, Hero gameHero, VoxelWorld gameWorld, float scrollPos)
        {
            Time += gameTime.ElapsedGameTime.TotalMilliseconds;

            if (affectedByGravity) Speed.Z += GRAVITY;

            CheckCollisions(gameHero, gameWorld);

            Position += Speed;

            if (Owner is Hero && Position.X > scrollPos + 75f) Active = false;

            Color c;
            switch (Type)
            {
                case ProjectileType.Rocket:

                    foreach(Enemy e in EnemyController.Instance.Enemies.OrderBy(en => Vector3.Distance(en.Position,Position)))
                    {
                        if (e.Position.X < scrollPos - 75f || !e.Active) continue;
                        target = e;
                        break;
                    }

                    if(target!=null)
                    {
                        if (target.Position.X > Position.X) Speed.X += 0.03f;
                        if (target.Position.X < Position.X) Speed.X -= 0.03f;
                        if (target.Position.Y > Position.Y) Speed.Y += 0.03f;
                        if (target.Position.Y < Position.Y) Speed.Y -= 0.03f;
                        Rotation = Matrix.CreateRotationZ(Helper.V2ToAngle(new Vector2(Speed.X, Speed.Y)));
                        Speed = Vector3.Clamp(Speed, new Vector3(-1f, -1f, 0f), new Vector3(1f, 1f, 0f));

                    }

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

                    break;

            }

            if (Time >= Life)
            {
                if (Type == ProjectileType.Rocket)
                {
                    ParticleController.Instance.SpawnExplosion(Position);
                }
                Active = false;
            }
        }
Esempio n. 5
0
        public void Update(GameTime gameTime, VoxelWorld gameWorld, Hero gameHero, float scrollPos)
        {
            Position += Speed;
            if(Position.X < scrollPos - 75f) Active = false;

            if (Vector3.Distance(gameHero.Position, Position) < 25f) Position = Vector3.Lerp(Position, gameHero.Position, 0.05f);
            if (Vector3.Distance(gameHero.Position, Position) < 10f) Position = Vector3.Lerp(Position, gameHero.Position, 0.1f);

            if(Vector3.Distance(gameHero.Position, Position) < 3f)
            {
                gameHero.XP += 0.15f;
                Active = false;
            }
        }
Esempio n. 6
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;
        }
        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. 8
0
        public void Update(GameTime gameTime, Camera gameCamera, Hero gameHero, VoxelWorld gameWorld, float scrollPos, float scrollSpeed)
        {
            for(int i=Spawns.Count-1;i>=0;i--)
            {
                if (gameWorld.ToScreenSpace(Spawns[i].Location.Center.X, Spawns[i].Location.Center.Y, 5).X < (int)scrollPos + 75)
                {
                    if (Spawns[i].Properties.Contains("IsWave"))
                    {
                        Wave w;
                        switch (Spawns[i].Properties["IsWave"])
                        {
                            case "Line":
                                w = new Wave(gameWorld.ToScreenSpace(Spawns[i].Location.Center.X, Spawns[i].Location.Center.Y, 10), WaveType.Line, (EnemyType)Enum.Parse(typeof(EnemyType), Spawns[i].Name), Convert.ToInt16(Spawns[i].Properties["Count"]), Spawns[i].Properties);

                                break;
                            default:
                                w = new Wave(gameWorld.ToScreenSpace(Spawns[i].Location.Center.X, Spawns[i].Location.Center.Y, 10), WaveType.Circle, (EnemyType)Enum.Parse(typeof(EnemyType), Spawns[i].Name), Convert.ToInt16(Spawns[i].Properties["Count"]), Spawns[i].Properties);

                                break;
                        }
                        Waves.Add(w);
                    }
                    else
                    {
                        Spawn((EnemyType)Enum.Parse(typeof(EnemyType), Spawns[i].Name), gameWorld.ToScreenSpace(Spawns[i].Location.Center.X, Spawns[i].Location.Center.Y, 10), Spawns[i].Properties);
                    }
                    Spawns.RemoveAt(i);
                }
            }

            for(int i=Enemies.Count-1;i>=0;i--) Enemies[i].Update(gameTime, gameWorld, gameHero);

            Enemies.RemoveAll(en => !en.Active || en.Position.X<scrollPos-110f);

            foreach (Wave w in Waves) w.Update(gameTime, scrollSpeed);

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

            if (gameHero.CollisionBox.Intersects(boundingSphere)) { gameHero.DoHit(Position, null); }

            if (Speed.Y < 0f)
            {
                for (float a = -MathHelper.PiOver2 - radiusSweep; a < -MathHelper.PiOver2 + radiusSweep; a += 0.02f)
                {
                    checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        DoCollide(false, true, false, checkPos, gameHero, world, false);
                    }

                }
            }
            if (Speed.Y > 0f)
            {
                for (float a = MathHelper.PiOver2 - radiusSweep; a < MathHelper.PiOver2 + radiusSweep; a += 0.02f)
                {
                    checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        DoCollide(false, true, false, checkPos, gameHero, world, false);
                    }
                    //if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, true); break; }
                }
            }
            if (Speed.X < 0f)
            {
                for (float a = -MathHelper.Pi - radiusSweep; a < -MathHelper.Pi + radiusSweep; a += 0.02f)
                {
                    checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        DoCollide(true, false, false, checkPos, gameHero, world, false);
                    }
                    //if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, true); break; }
                }
            }
            if (Speed.X > 0f)
            {
                for (float a = -radiusSweep; a < radiusSweep; a += 0.02f)
                {
                    checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight);
                    checkVoxel = world.GetVoxel(checkPos);
                    if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type)))
                    {
                        DoCollide(true, false, false, checkPos, gameHero, world, false);
                    }
                    //if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, true); break;}
                }
            }
        }
Esempio n. 10
0
        public virtual void Update(GameTime gameTime, VoxelWorld gameWorld, Hero gameHero)
        {
            CheckCollisions(gameWorld, gameHero);

            Position += Speed;

            animTime += gameTime.ElapsedGameTime.TotalMilliseconds;
            if (animTime >= animTargetTime)
            {
                animTime = 0;

                CurrentFrame++;
                if (CurrentFrame == numFrames) CurrentFrame = 0;
            }

            boundingSphere = new BoundingSphere(Position, 3f);

            if (hitAlpha > 0f) hitAlpha -= 0.1f;
            if (Health <= 0f) Die();

            currentAttackTime += gameTime.ElapsedGameTime.TotalMilliseconds;
            if (currentAttackTime >= attackRate) DoAttack();
        }
Esempio n. 11
0
 public virtual void DoCollide(bool x, bool y, bool z, Vector3 checkPosition, Hero gameHero, VoxelWorld gameWorld, bool withPlayer)
 {
     if (x) Speed.X = 0;
     if (y) Speed.Y = 0;
     if (z) Speed.Z = 0;
 }
Esempio n. 12
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            font = Content.Load<SpriteFont>("font");
            hudTex = Content.Load<Texture2D>("hud");

            tilesSprite = new VoxelSprite(16, 16, 16);
            LoadVoxels.LoadSprite(Path.Combine(Content.RootDirectory, "tiles.vxs"), ref tilesSprite);

            gameMap = Content.Load<Map>("1");
            tileLayer = (TileLayer)gameMap.GetLayer("tiles");
            MapObjectLayer spawnLayer = (MapObjectLayer)gameMap.GetLayer("spawns");

            gameWorld = new VoxelWorld(gameMap.Width, 11, 1);

            for(int yy=0;yy<11;yy++)
                for(int xx=0;xx<12;xx++)
                    if(tileLayer.Tiles[xx,yy]!=null) gameWorld.CopySprite(xx*Chunk.X_SIZE, yy*Chunk.Y_SIZE, 0, tilesSprite.AnimChunks[tileLayer.Tiles[xx,yy].Index-1]);

            scrollColumn = 12;

            gameCamera = new Camera(GraphicsDevice, GraphicsDevice.Viewport);
            gameCamera.Position = new Vector3(0f, gameWorld.Y_SIZE * Voxel.HALF_SIZE, 0f);
            gameCamera.Target = gameCamera.Position;

            gameHero = new Hero();
            gameHero.LoadContent(Content, GraphicsDevice);

            enemyController = new EnemyController(GraphicsDevice);
            enemyController.LoadContent(Content, spawnLayer);
            projectileController = new ProjectileController(GraphicsDevice);
            projectileController.LoadContent(Content);
            particleController = new ParticleController(GraphicsDevice);
            powerupController = new PowerupController(GraphicsDevice);
            powerupController.LoadContent(Content);
            gameStarfield = new Starfield(GraphicsDevice);

            drawEffect = new BasicEffect(GraphicsDevice)
            {
                World = gameCamera.worldMatrix,
                View = gameCamera.viewMatrix,
                Projection = gameCamera.projectionMatrix,
                VertexColorEnabled = true,
            };
        }
Esempio n. 13
0
        public override void DoCollide(bool x, bool y, bool z, Vector3 checkPosition, Hero gameHero, VoxelWorld gameWorld, bool withPlayer)
        {
            //gameWorld.Explode(checkPosition, 5f);

            //Die();

            base.DoCollide(x, y, z, checkPosition, gameHero, gameWorld, withPlayer);
        }
Esempio n. 14
0
        void CheckCollisions(Hero gameHero, VoxelWorld gameWorld)
        {
            Vector3 worldSpace;
            switch (Type)
            {
                case ProjectileType.Laser1:
                case ProjectileType.Laser2:
                case ProjectileType.Laser3:
                case ProjectileType.Laser4:
                case ProjectileType.Rocket:
                    for (float d = 0f; d < 1f; d += 0.1f)
                    {
                        if (!Active) continue;

                        worldSpace = gameWorld.FromScreenSpace(Position + (d * ((Position + Speed) - Position)));
                        Voxel v = gameWorld.GetVoxel(Position + (d * ((Position + Speed) - Position)));

                        if (v.Active && Active)
                        {
                            if (v.Destructable >= 1 && Owner is Hero)
                            {
                                gameWorld.Explode(Position + (d * ((Position + Speed) - Position)), Type!= ProjectileType.Rocket?3f:5f);
                                gameWorld.Explode((Position + (d * ((Position + Speed) - Position))) + new Vector3(0f, 0f, -3f), Type != ProjectileType.Rocket ? 3f : 5f);
                                gameWorld.Explode((Position + (d * ((Position + Speed) - Position))) + new Vector3(0f, 0f, 3f), Type != ProjectileType.Rocket ? 3f : 5f);

                                //gameWorld.SetVoxelActive((int)worldSpace.X, (int)worldSpace.Y, (int)worldSpace.Z, false);
                                //for (int i = 0; i < 4; i++) ParticleController.Instance.Spawn(Position, new Vector3(-0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -((float)Helper.Random.NextDouble() * 0.5f)), 0.25f, new Color(v.SR, v.SG, v.SB), 1000, true);

                            }
                            Active = false;
                        }

                        if(Owner is Enemy)
                            if (!gameHero.Dead && gameHero.CollisionBox.Contains(Position + (d * ((Position + Speed) - Position))) == ContainmentType.Contains)
                            {
                                gameHero.DoHit(Position + (d * ((Position + Speed) - Position)), this);
                                Active = false;
                                if(Type== ProjectileType.Rocket) ParticleController.Instance.SpawnExplosion(Position);
                            }

                        if(Owner is Hero)
                            foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Active)) { if (e.boundingSphere.Contains(Position + (d * ((Position + Speed) - Position))) == ContainmentType.Contains) { e.DoHit(Position + (d * ((Position + Speed) - Position)), Speed, Damage); Active = false; if (Type == ProjectileType.Rocket) ParticleController.Instance.SpawnExplosion(Position); } }

                    }
                    break;
            }
        }