コード例 #1
0
 // folow a player if the player comes in the kill zone
 public void follow(PlayerWithWeapon p)
 {
     if (inChaseZone(p))
     {
         Vector2 direction = p.position - this.position;
         direction.Normalize();
         this.position += direction * Velocity;
     }
 }
コード例 #2
0
        // inChaseZone sees if the player is in the kill zone
        // if so it takes approproate action
        public bool inChaseZone(PlayerWithWeapon p)
        {
            float distance = Math.Abs(Vector2.Distance(this.WorldOrigin, p.CentrePos));

            if (distance <= chaseRdaius)
            {
                return(true);
            }
            return(false);
        }
コード例 #3
0
        public override void Update(GameTime gametime)
        {
            if (InputEngine.CurrentPadState.IsConnected)
            {
                if (InputEngine.CurrentPadState.ThumbSticks.Right.Length() > 0)

                {
                    Vector2 previousTilePos = TilePosition;
                    // Thumbstick moves in the opposite direction for Y hence adjust with  new Vector2(1,-1)
                    Vector2 Movement = Vector2.Normalize(InputEngine.CurrentPadState.ThumbSticks.Right) * new Vector2(1, -1) * smoothingFactor;

                    //InputEngine.CurrentPadState.ThumbSticks.Left / new Vector2(FrameWidth, FrameHeight)
                    //                    + _cam.CamPos / new Vector2(FrameWidth, FrameHeight);
                    Rectangle LocalviewBound = new Rectangle(((_cam.CamPos) / new Vector2(FrameWidth, FrameHeight)).ToPoint(),
                                                             new Point((_cam.View.Width) / FrameWidth, (_cam.View.Height) / FrameHeight));

                    // Get the player from the Game components
                    PlayerWithWeapon player = (PlayerWithWeapon)Game.Components.Where(p => p.GetType() == typeof(PlayerWithWeapon)).FirstOrDefault();
                    // Make sure the site stays in the local view range
                    if (!LocalviewBound.Contains((TilePosition + Movement).ToPoint()))
                    {
                        TilePosition = previousTilePos;
                    }
                    // Make sure the site
                    else if (player != null && !player.Range.Contains((PixelPosition + Movement * new Vector2(FrameWidth, FrameHeight)).ToPoint()))
                    {
                        TilePosition = previousTilePos;
                    }

                    else
                    {
                        TilePosition += Movement;
                    }
                    //Tileposition = Vector2.Clamp(Tileposition, _cam.CamPos,
                    //    new Vector2(_cam.View.Bounds.Width, _cam.View.Bounds.Height));
                }
            }
            else if (_cam != null)
            {
                TilePosition = InputEngine.MousePosition / new Vector2(FrameWidth, FrameHeight)
                               + _cam.CamPos / new Vector2(FrameWidth, FrameHeight);
            }

            base.Update(gametime);
        }
コード例 #4
0
        private void setupPlayer()
        {
            List<TileRef> playerFrames = new List<TileRef>();
            playerFrames.Add(new TileRef(15, 0, 0));
            playerFrames.Add(new TileRef(16, 0, 0));
            playerFrames.Add(new TileRef(17, 0, 0));
            playerFrames.Add(new TileRef(18, 0, 0));
            playerFrames.Add(new TileRef(19, 0, 0));
            playerFrames.Add(new TileRef(20, 0, 0));
            playerFrames.Add(new TileRef(21, 0, 0));

            player = new PlayerWithWeapon(new Vector2(0, 0), new Vector2(tileMap.GetLength(1),tileMap.GetLength(0)),
                            playerFrames,
                            64, 64, 1.0f); // Default stopped

            player.setFrameSet(DIRECTION.UP, playerFrames);
            player.setFrameSet(DIRECTION.DOWN,
                new List<TileRef> {
                    new TileRef(15, 1, 0),
                    new TileRef(16, 1, 0),
                    new TileRef(17, 1, 0),
                    new TileRef(18, 1, 0),
                    new TileRef(19, 1, 0),
                    new TileRef(20, 1, 0),
                    new TileRef(21, 1, 0),
            });
            player.setFrameSet(DIRECTION.LEFT,
                new List<TileRef> {
                    new TileRef(16, 2, 0),
                    new TileRef(16, 3, 0),
                    new TileRef(16, 4, 0),
                    new TileRef(16, 5, 0),
                    new TileRef(16, 6, 0),
                    new TileRef(16, 7, 0),
                    new TileRef(16, 8, 0),
            });
            player.setFrameSet(DIRECTION.RIGHT,
                new List<TileRef> {
                    new TileRef(15, 2, 0),
                    new TileRef(15, 3, 0),
                    new TileRef(15, 4, 0),
                    new TileRef(15, 5, 0),
                    new TileRef(15, 6, 0),
                    new TileRef(15, 7, 0),
                    new TileRef(15, 8, 0),
            });
        }
コード例 #5
0
        private void setupPlayer()
        {
            List<TileRef> playerFrames = new List<TileRef>();
            playerFrames.Add(new TileRef(15, 0, 0));
            playerFrames.Add(new TileRef(16, 0, 0));
            playerFrames.Add(new TileRef(17, 0, 0));
            playerFrames.Add(new TileRef(18, 0, 0));
            playerFrames.Add(new TileRef(19, 0, 0));
            playerFrames.Add(new TileRef(20, 0, 0));
            playerFrames.Add(new TileRef(21, 0, 0));

            player = new PlayerWithWeapon(new Vector2(0, 0), new Vector2(tileMap.GetLength(1),tileMap.GetLength(0)),
                            playerFrames,
                            64, 64, 0f); // Default stopped

            player.setFrameSet(DIRECTION.UP, playerFrames);
            player.setFrameSet(DIRECTION.DOWN,
                new List<TileRef> {
                    new TileRef(15, 1, 0),
                    new TileRef(16, 1, 0),
                    new TileRef(17, 1, 0),
                    new TileRef(18, 1, 0),
                    new TileRef(19, 1, 0),
                    new TileRef(20, 1, 0),
                    new TileRef(21, 1, 0),
            });
            player.setFrameSet(DIRECTION.LEFT,
                new List<TileRef> {
                    new TileRef(16, 2, 0),
                    new TileRef(16, 3, 0),
                    new TileRef(16, 4, 0),
                    new TileRef(16, 5, 0),
                    new TileRef(16, 6, 0),
                    new TileRef(16, 7, 0),
                    new TileRef(16, 8, 0),
            });
            player.setFrameSet(DIRECTION.RIGHT,
                new List<TileRef> {
                    new TileRef(15, 2, 0),
                    new TileRef(15, 3, 0),
                    new TileRef(15, 4, 0),
                    new TileRef(15, 5, 0),
                    new TileRef(15, 6, 0),
                    new TileRef(15, 7, 0),
                    new TileRef(15, 8, 0),
            });

            // Load the players newly created projectile
            player.loadProjectile(
                new Projectile(player.Tileposition,
                new List<TileRef>() // projectile tiles
                {
                    new TileRef(3,0,0),
                    new TileRef(4,0,0),
                    new TileRef(5,0,0),
                    new TileRef(6,0,0),
                },
                new List<TileRef>() // explosion tiles
                {
                    new TileRef(0,0,0),
                    new TileRef(1,0,0),
                    new TileRef(2,0,0),
                }, tileWidth, tileHeight, 0.5f));
        }
コード例 #6
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // assumes dirt is 0
            Texture2D dirt = Content.Load<Texture2D>("Tiles/se_free_dirt_texture");
            tileTextures.Add(dirt);

            Texture2D grass = Content.Load<Texture2D>("Tiles/se_free_grass_texture");
            tileTextures.Add(grass);

            Texture2D ground = Content.Load<Texture2D>("Tiles/se_free_ground_texture");
            tileTextures.Add(ground);

            _charactertx = Content.Load<Texture2D>("chaser");

            player = new PlayerWithWeapon(this, _charactertx, Vector2.Zero, 1);

            debug = Content.Load<SpriteFont>("debug");
            string[] backTileNames = { "free", "grass", "ground" };
            string[] impassibleTiles = {"free","ground"};
            string[] hiddenTileNames = { "NONE", "chest", "key" };

            _tManager.addLayer("hidden", hiddenTileNames, hiddenMap);
            int mapWidth = _tManager.Layers[0].MapWidth;
            _tManager.addLayer("background", backTileNames, tileMap);
            _tManager.ActiveLayer = _tManager.getLayer("background");
            _tManager.ActiveLayer.makeImpassable(impassibleTiles);
            _tManager.CurrentTile = new Tile();
            _tManager.CurrentTile.TileName = "Character";
            _tManager.CurrentTile.X = 6;
            _tManager.CurrentTile.Y = 3;
            player.CurrentTilePostion = _tManager.CurrentTile;

            _characterRect = new Rectangle(tileWidth * _tManager.CurrentTile.X, tileHeight * _tManager.CurrentTile.Y, tileWidth, tileHeight);
            // TODO: use this.Content to load your game content here
        }