Пример #1
0
        public MapEntity GetFacingEntity()
        {
            Vector2   coords = GetFacingCoords();
            MapEntity target = MapManager.currentMap.entities.FirstOrDefault(v => v.X == coords.X && v.Y == coords.Y);

            return(target);
        }
Пример #2
0
        public void MoveTo(int x, int y)
        {
            if (_moving)
            {
                return;
            }

            if (x < X)
            {
                _facingDirection = Directions.LEFT;
            }
            else if (x > X)
            {
                _facingDirection = Directions.RIGHT;
            }
            else if (y < Y)
            {
                _facingDirection = Directions.UP;
            }
            else if (y > Y)
            {
                _facingDirection = Directions.DOWN;
            }

            if (!ephemeral)
            {
                // can't go out of bounds
                if (x < 0 || y < 0)
                {
                    return;
                }
                if (x >= MapManager.currentMap.width || y >= MapManager.currentMap.height)
                {
                    return;
                }

                // can't walk through walls
                if (MapManager.currentMap.IsTileSolid(x, y, Directions.DirectionToTileSide(_facingDirection)))
                {
                    return;
                }
                if (MapManager.currentMap.IsTileSolid(X, Y, _facingDirection))
                {
                    return;
                }

                // can't walk into other entities that aren't ephemeral
                MapEntity t = GetFacingEntity();
                if (t != null && !t.ephemeral)
                {
                    return;
                }
            }
            oldX = X;
            oldY = Y;
            _movementDistance = 0;
            _moving           = true;
            X = x;
            Y = y;
        }
Пример #3
0
 public bool Interact(MapEntity user)
 {
     if (InteractAction != null)
     {
         InteractAction(user);
     }
     return(true);
 }
Пример #4
0
        public void TryInteract()
        {
            MapEntity target = GetFacingEntity();

            if (target == null)
            {
                return;
            }
            target.Interact(this);
        }
Пример #5
0
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            GameWidth   = graphics.GraphicsDevice.Viewport.Width;
            GameHeight  = graphics.GraphicsDevice.Viewport.Height;

            arialFont = Content.Load <SpriteFont>("Arial");

            //thanks to Ken on StackExchange http://gamedev.stackexchange.com/questions/44015/
            texturePixel = new Texture2D(GraphicsDevice, 1, 1);
            texturePixel.SetData <Color>(new Color[] { Color.White });

            // TODO: use this.Content to load your game content here
            Tileset t = new Tilesets.Town16Test();

            t.Initialize(LoadTexture(t.texturePath));
            tilesets.Add(t);


            StateManager.currentState = StateManager.GetState(StateID.MainMenu);
            MapManager.currentMap     = MapManager.GetMap(MapID.Town);

            texturePlayer = LoadTexture("test_female1");

            playerMapEntity = new Entities.MapEntity();
            MapManager.currentMap.entities.Add(playerMapEntity);

            MapEntity randomNPC = new Entities.MapEntity();

            randomNPC.X = 1;
            randomNPC.Y = 0;
            randomNPC.InteractAction = delegate(MapEntity user) { randomNPC.MoveRight(); };

            MapManager.currentMap.entities.Add(randomNPC);

            aPandora      = new Actors.PartyActor();
            aPandora.name = "Pandora";
            aPandora.health.Set(300);
        }