Inheritance: IGameMessage
Example #1
0
        private void PlaceEntity(int index, GameEntity entity)
        {
            EntityPlacement info = _info.Entities[index];

            // can't respawn until the spawn point goes off screen
            _spawnable[index] = false;

            _respawnTracker.Track(info, entity);

            entity.Direction = info.direction;

            entity.Start(_stage);

            entity.GetComponent <PositionComponent>().SetPosition(new PointF(info.screenX, info.screenY));
            if (info.state != "Start")
            {
                StateMessage msg = new StateMessage(null, info.state);
                entity.SendMessage(msg);
            }

            _entities[index] = entity;
            Action remove = () => { };

            remove += () => {
                _entities[index] = null;
                entity.Removed  -= remove;
            };
            entity.Removed += remove;
        }
        public override void Message(IGameMessage msg)
        {
            StateMessage statemsg = msg as StateMessage;

            if (statemsg != null)
            {
                if (states.ContainsKey(statemsg.StateName))
                {
                    currentState = statemsg.StateName;
                    states[currentState].Initialize(Parent);
                    StateFrames = 0;
                }
            }
        }
Example #3
0
        public static Effect LoadSpawnEffect(XElement node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            string name      = node.RequireAttribute("name").Value;
            string statename = "Start";

            if (node.Attribute("state") != null)
            {
                statename = node.Attribute("state").Value;
            }
            XElement posNodeX = node.Element("X");
            XElement posNodeY = node.Element("Y");
            Effect   posEff   = null;

            if (posNodeX != null)
            {
                posEff = PositionComponent.ParsePositionBehavior(posNodeX, Axis.X);
            }
            if (posNodeY != null)
            {
                posEff += PositionComponent.ParsePositionBehavior(posNodeY, Axis.Y);
            }
            return(entity =>
            {
                GameEntity spawn = entity.Spawn(name);
                if (spawn == null)
                {
                    return;
                }
                StateMessage msg = new StateMessage(entity, statename);
                spawn.SendMessage(msg);
                if (posEff != null)
                {
                    posEff(spawn);
                }
            });
        }
Example #4
0
        public static Effect LoadSpawnEffect(XElement node)
        {
            if (node == null) throw new ArgumentNullException("node");

            string name = node.RequireAttribute("name").Value;
            string statename = "Start";
            if (node.Attribute("state") != null) statename = node.Attribute("state").Value;
            XElement posNodeX = node.Element("X");
            XElement posNodeY = node.Element("Y");
            Effect posEff = null;
            if (posNodeX != null)
            {
                posEff = PositionComponent.ParsePositionBehavior(posNodeX, Axis.X);
            }
            if (posNodeY != null) posEff += PositionComponent.ParsePositionBehavior(posNodeY, Axis.Y);
            return entity =>
            {
                GameEntity spawn = entity.Spawn(name);
                if (spawn == null) return;
                StateMessage msg = new StateMessage(entity, statename);
                spawn.SendMessage(msg);
                if (posEff != null) posEff(spawn);
            };
        }
        private void PlaceEntity(int index, GameEntity entity)
        {
            EntityPlacement info = _info.Entities[index];

            // can't respawn until the spawn point goes off screen
            _spawnable[index] = false;

            _respawnTracker.Track(info, entity);

            entity.Direction = info.direction;

            entity.Start(_stage);

            entity.GetComponent<PositionComponent>().SetPosition(new PointF(info.screenX, info.screenY));
            if (info.state != "Start")
            {
                StateMessage msg = new StateMessage(null, info.state);
                entity.SendMessage(msg);
            }

            _entities[index] = entity;
            Action remove = () => { };
            remove += () => {
                _entities[index] = null;
                entity.Removed -= remove;
            };
            entity.Removed += remove;
        }
Example #6
0
        private void BeginPlay()
        {
            Player.Start(this);
            Player.GetComponent<SpriteComponent>().Visible = true;

            StateMessage msg = new StateMessage(null, "Teleport");
            PlayerPos.SetPosition(new PointF(startX, 0));
            Player.SendMessage(msg);
            Action teleport = () => {};
            teleport += () =>
            {
                if (PlayerPos.Position.Y >= startY)
                {
                    PlayerPos.SetPosition(new PointF(startX, startY));
                    Player.SendMessage(new StateMessage(null, "TeleportEnd"));
                    GameThink -= teleport;
                    updateFunc = Update;
                }
            };
            GameThink += teleport;
        }