예제 #1
0
        public override void Update(World world, GameTime gameTime)
        {
            foreach (Entity e in world.entities)
            {
                if (e is Wall)
                {
                    Wall wall = (Wall)e;
                    // if (Intersects(rec2, wall.rectangle))
                    if (rec.Intersect(wall.rectangle))
                    {
                        world.ToKill.Add(this);
                    }
                }
                else if (isEnemy)
                {
                    if (e is MainHero && isEnemy)
                    {
                        MainHero h = (MainHero)e;
                        //  if (Intersects(rec2, h.rectangle))
                        if (rec.Intersect(h.rectangle))
                        {
                            h.health -= damage; damageHeroSound.Play();
                            world.ToKill.Add(this);
                            damageHeroSound.Play(0.8f, 0f, 0f);
                        }
                    }
                }
                else
                {
                    if (e is Enemy && !isEnemy)
                    {
                        Enemy en = (Enemy)e;
                        // if (Intersects(rec2, en.rectangle))
                        if (rec.Intersect(en.rectangle))
                        {
                            en.health -= damage;
                            world.ToKill.Add(this);
                            damageMonSound.Play(1f, 0f, 0f);
                        }
                    }
                }
            }

            position += direction * speed;
            rec.r.X   = (int)position.X; rec.r.Y = (int)position.Y;


            currentExistingTime += (float)gameTime.ElapsedGameTime.TotalMilliseconds;

            if (currentExistingTime >= existingTime)
            {
                world.ToKill.Add(this);
            }
            //else
            //{
            //    rec2 = new RectangleV2(direction, 60, 25, position);
            //    rectangle.X = (int)position.X; rectangle.Y = (int)position.Y;

            //}
        }
예제 #2
0
파일: World.cs 프로젝트: 4ku/ShooterGame
 public World(Game1 game)
 {
     this.game = game;
     kspast    = Keyboard.GetState();
     entities  = new List <Entity>();
     ToKill    = new List <Entity>();
     ToAdd     = new List <Entity>();
     camera    = new Camera(game.GraphicsDevice.Viewport);
     new TexturePack(game); //проинициализировали все текстуры
     Hero = new Robot(robot, new Vector2(WinWIDTH / 2, WinHEIGHT / 2));
     entities.Add(Hero);
 }
예제 #3
0
        /*  public override Fire New(int width, int height, Vector2 startpos, Vector2 endpos)
         * {
         *   return new LightsaberFire(width,  height, startpos,  endpos);
         * }*/
        /* public void Shoot(World world, GameTime gameTime, Vector2 startPos)
         * {
         *   MouseState ms = Mouse.GetState();
         *
         *   if (ms.LeftButton == ButtonState.Pressed && mspast.LeftButton == ButtonState.Released)
         *   {
         *       Vector2 endPos = new Vector2((int)startPos.X + (-WinWIDTH / 2) + ms.Position.X, startPos.Y + ms.Position.Y + (-WinHEIGHT / 2));
         *       LightsaberFire bul = new LightsaberFire(300, 8, startPos,endPos);
         *       bul.isEn = false;
         *       world.ToAdd.Add(bul);
         *
         *   }
         *   mspast = ms;
         *
         * }*/



        public override void Update(World world, GameTime gameTime)
        {
            mouseState = Mouse.GetState();
            if (!lightsaber.isEnemy && mouseState.LeftButton == ButtonState.Released)
            {
                world.ToKill.Add(this); lightsaber.created = false;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.E))
            {
                angle += (float)Math.PI / 30;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Q))
            {
                angle -= (float)Math.PI / 30;
            }

            /* Vector2 v = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));
             * v *= (float)Math.Sqrt(world.Hero.width * world.Hero.width / 4 + world.Hero.height * world.Hero.height / 4);
             * position = world.Hero.position+v;
             *   //rec.r.X = (int)position.X; rec.r.Y = (int)position.Y;
             *   direction = new Vector2(mouseState.Position.X + (-WinWIDTH / 2)-v.X, mouseState.Position.Y + (-WinHEIGHT / 2) - v.Y);
             *   rec = new RectangleV3(position, 0.5f, 0.5f, direction, width, height);*/

            foreach (Entity e in world.entities)
            {
                if (e is Wall)
                {
                    Wall wall = (Wall)e;
                    if (rec.Intersect(wall.rectangle))
                    {
                        world.ToKill.Add(this); lightsaber.created = false;
                    }
                }
                else if (e is Fire)
                {
                    Fire bul = (Fire)e;


                    if (rec.Intersect(bul.rec) && !(e is LightsaberFire))
                    {
                        float   cos = (direction.X * bul.direction.X + direction.Y * bul.direction.Y) / (bul.direction.Length() * direction.Length());
                        float   k   = cos * bul.direction.Length() / direction.Length();
                        Vector2 V1  = new Vector2(direction.X * k, direction.Y * k);
                        Vector2 V2  = new Vector2(); V2 = bul.direction - V1;
                        bul.direction = V1 - V2;
                        if (bul.speed != 0)
                        {
                            while (rec.Intersect(bul.rec))
                            {
                                bul.position += bul.direction * bul.speed;
                                bul.rec.r.X   = (int)bul.position.X; bul.rec.r.Y = (int)bul.position.Y;
                            }
                        }
                        bul.isEnemy = isEnemy;
                    }
                }
                else if (isEnemy)
                {
                    if (e is MainHero)
                    {
                        MainHero h = (MainHero)e;
                        if (rec.Intersect(h.rectangle))
                        {
                            h.health -= damage;
                            damageHeroSound.Play();
                            //world.ToKill.Add(this);
                        }
                    }
                }
                else if (!isEnemy)
                {
                    if (e is Enemy)
                    {
                        Enemy en = (Enemy)e;
                        if (rec.Intersect(en.rectangle))
                        {
                            damageMonSound.Play();
                            en.health -= damage;
                            //world.ToKill.Add(this);
                        }
                    }
                }
            }
            //  world.ToKill.Add(this);



            //for (int i = 0; i < bullets.Count; i++)
            //{


            //    // bul.CrRecV2();
            //    if (w.Intersects(bullets[i]))
            //    {
            //        float cos = (w.Velocity.X * bullets[i].Velocity.X + w.Velocity.Y * bullets[i].Velocity.Y) / (bullets[i].Velocity.Length() * w.Velocity.Length());
            //        float k = cos * bullets[i].Velocity.Length() / w.Velocity.Length();
            //        Vector2 V1 = new Vector2(w.Velocity.X * k, w.Velocity.Y * k);
            //        Vector2 V2 = new Vector2(); V2 = bullets[i].Velocity - V1;
            //        bullets[i].Velocity = V1 - V2;
            //        while (bullets[i].Intersects(w))
            //        {
            //            bullets[i].Pos += bullets[i].Velocity;
            //            bullets[i].CrRecV2();
            //        }
            //        bulletsHero.Add(bullets[i]);
            //        bullets.Remove(bullets[i]);

            //        i--;

            //    }

            //}
            //world.Intersects(); world.ToKill();
        }
예제 #4
0
        public override void Update(World world, GameTime gameTime)
        {
            foreach (Entity e in world.entities)
            {
                if (e is Wall)
                {
                    Wall wall = (Wall)e;
                    if (rec.Intersect(wall.rectangle))
                    {
                        world.ToKill.Add(this);
                    }
                }
                else if (isEnemy)
                {
                    if (e is MainHero)
                    {
                        MainHero h = (MainHero)e;
                        if (rec.Intersect(h.rectangle))
                        {
                            h.health -= damage;
                            damageHeroSound.Play(0.8f, 0f, 0f);
                            //world.ToKill.Add(this);
                        }
                    }
                }
                else
                {
                    if (e is Enemy)
                    {
                        Enemy en = (Enemy)e;
                        if (rec.Intersect(en.rectangle))
                        {
                            en.health -= damage;
                            damageMonSound.Play(0.8f, 0f, 0f);
                            //world.ToKill.Add(this);
                        }
                    }
                }
            }


            position            += direction * speed;
            currentExistingTime += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            rec.r.X              = (int)position.X; rec.r.Y = (int)position.Y;

            if (currentExistingTime >= existingTime)
            {
                world.ToKill.Add(this);
            }
            //else
            //{
            //    rec2 = new RectangleV2(velocity, width, height, position);
            //    rectangle.X = (int)position.X;
            //    rectangle.Y = (int)position.Y;
            //}

            if (fl == 1)
            {
                mrelc += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                if (currentExistingTime < existingTime && mrelc > mrel)
                {
                    mrelc = 0;
                    BlasterFire bl = (BlasterFire)Clone();
                    fl          = 0;
                    bl.position = startPosition;
                    bl.rec.r.X  = (int)startPosition.X; bl.rec.r.Y = (int)startPosition.Y;   //КЛОНИРОВАТЬ!!!!
                    world.ToAdd.Add(bl);
                }
            }
        }
예제 #5
0
 public Standart(MainHero Hero)
 {
     this.Hero = Hero;
 }