Ejemplo n.º 1
0
        public new void Apply()
        {
            var self = (this as Attack);

            if (null == _creature)
            {
                _creature = WorldMap.Creatures.OrderBy((c) => (WorldMap.GetDistance(self.Location, c.Location)))
                            .FirstOrDefault((c) => ((WorldMap.GetDistance(self.Location, c.Location) <= self.Range) && c.ID != Creator.ID &&
                                                    !c.Is("dead")));
            }
            Duration -= 1; //decay in 20 frames at 40fps.
            if (Duration <= 0)
            {
                //self._isApplied = true;
                self.Remove = true;
            }

            if (null == _creature)
            {
                this.Location = WorldMap.GetMoveLocation(this.Location, this.Direction, this.Speed);
                return;
            }

            if (WorldMap.GetDistance(self.Location, _creature.Location) <= self.Range)
            {
                self._creature.Set("hurt");
                self._creature.Health -= Damage;
                self._creature.Set("hurt");
                if (self._creature.Health <= 0 && !(self._creature.Is("dead")))
                {
                    self._creature.Set("dead", 4);
                    Creator.Kills += 1;
                }
                //self.Remove = true;
            }
            if (!Piercing)
            {
                self._isApplied = true;
            }
        }
Ejemplo n.º 2
0
 public Vector2 GetMoveLocation(Vector2 v, double angle, double distance)
 {
     return(WorldMap.GetMoveLocation(v, angle, distance));
 }
Ejemplo n.º 3
0
        private Vector3 HandleKeyboard()
        {
            var           player   = worldMap.Player;
            KeyboardState kbdState = Keyboard.GetState();

            if (kbdState.IsKeyDown(Keys.LeftShift))
            {
                Console.WriteLine("viewport: x{0} y{1}", worldMap.Viewport.X, worldMap.Viewport.Y);
            }

            float xshift = 0;
            float yshift = 0;
            float zshift = 0;

            //worldMap.Player.Unset("attacking");
            player.Get("attacking", player.Get("attacking") - 0.1f);
            if (kbdState.IsKeyDown(Keys.Z) && !player.Is("attacking"))
            {
                var loc = WorldMap.GetMoveLocation(player.Location, player.Direction, player.Range);
                worldMap.Player.Set("attacking", 0.5f);
                worldMap.Forces.Add(new Attack()
                {
                    Visual    = Force.Visuals.Beam,
                    Sound     = Force.Sounds.Beam,
                    Creator   = worldMap.Player,
                    WorldMap  = worldMap,
                    Damage    = player.Attack / 2,
                    Location  = loc,
                    Range     = player.Range,
                    Duration  = 40,
                    Direction = (float)player.Direction,
                    Speed     = 10,
                    Piercing  = true
                });
                if (!player.Is("slowed"))
                {
                    player.Set("slowed", player.Speed);
                    player.Speed = player.Speed / 2;
                }
                startTime = -1;
                engine.PlaySound("beam");
            }

            if (kbdState.IsKeyDown(Keys.X) && !player.Is("attacking"))
            {
                worldMap.Player.Set("attacking", 1.2f);
                worldMap.Forces.Add(new Attack()
                {
                    Visual   = Force.Visuals.Test2,
                    Sound    = Force.Sounds.Default,
                    Creator  = worldMap.Player,
                    WorldMap = worldMap,
                    Damage   = 4 * player.Attack,
                    Location = player.Location,
                    Range    = player.Range * 1.5f,
                    Duration = 20,
                    Speed    = 0
                });
                if (!player.Is("slowed"))
                {
                    player.Set("slowed", player.Speed);
                    player.Speed = player.Speed / 4;
                }
            }


            player.Set("usingCard", player.Get("usingCard") - 0.1f);
            if (kbdState.IsKeyDown(Keys.Space))
            {
                if (!player.Is("usingCard") && player.Cards.Count > 0)
                {
                    player.Set("usingCard");
                    var card = player.Cards.Dequeue();
                    if (null != card)
                    {
                        card.Apply(worldMap, worldMap.Player);
                        switch (card.Type)
                        {
                        case Card.Types.Heal:
                            engine.PlaySound("heal");
                            break;

                        case Card.Types.Sign:
                            engine.PlaySound("seal");
                            break;

                        default:
                            break;
                        }
                    }
                }
            }

            if (kbdState.IsKeyDown(Keys.Up))
            {
                yshift          += player.Speed / 100f;
                player.Direction = -Math.PI / 2;
            }

            if (kbdState.IsKeyDown(Keys.Down))
            {
                yshift          -= player.Speed / 100f;
                player.Direction = Math.PI / 2;
            }
            if (kbdState.IsKeyDown(Keys.Left))
            {
                xshift          -= player.Speed / 100f;
                player.Direction = Math.PI;
            }

            if (kbdState.IsKeyDown(Keys.Right))
            {
                xshift          += player.Speed / 100f;
                player.Direction = 0;
            }


            if (kbdState.IsKeyDown(Keys.PageUp))
            {
                zshift -= 0.01f;
            }

            if (kbdState.IsKeyDown(Keys.PageDown))
            {
                zshift += 0.01f;
            }


            if (kbdState.IsKeyDown(Keys.Enter))
            {
                if (kbdState.IsKeyDown(Keys.LeftAlt))
                {
                    graphics.IsFullScreen = !graphics.IsFullScreen;
                    if (!graphics.IsFullScreen)
                    {
                        graphics.PreferredBackBufferWidth  = 800;
                        graphics.PreferredBackBufferHeight = 480;
                    }
                    graphics.ApplyChanges();
                }
                if (player.Health <= 0 || worldMap.WinCondition)
                {
                    //player.Health = 100;
                    engine.Dispose();
                    engine = null;
                    this.LoadContent();
                }
            }
            return(new Vector3(xshift, yshift, zshift));
        }