예제 #1
0
 public Vector2 CheckCollision(World world, GeometryType ignore)
 {
     float xMove = 0;
     GeometryBox collisionBox = new GeometryBox();
     collisionBox.rect = _bbox;
     if (world.Collides(_bbox, ignore, collisionBox, out collisionBox)) {
         xMove = 5 * Math.Sign(_bbox.X - collisionBox.rect.X);
     }
     _position += new Vector2(xMove, 0);
     _bbox.X += (int)xMove;
     return new Vector2(xMove, 0);
 }
예제 #2
0
        public Player(string defLocation, Texture2D texture, Vector2 position, World world, PlayerIndex index)
            : base(texture)
        {
            _playerDef = new Dictionary<string, float>();
            _animations = new Dictionary<string, KeyValuePair<int, int>>();
            XmlDocument doc = new XmlDocument();
            doc.Load(defLocation);
            XmlNode playerNode = doc.SelectSingleNode("player");
            foreach (XmlNode node in playerNode.ChildNodes) {
                XmlAttributeCollection xac = node.Attributes;

                if (node.Name == "animation") {
                    _animations.Add(xac["id"].Value,
                        new KeyValuePair<int,int>(int.Parse(xac["start"].Value), int.Parse(xac["end"].Value)));
                    continue;
                }

                _playerDef.Add(node.Name, float.Parse(xac["value"].Value, CultureInfo.InvariantCulture));
            }

            Position = position;

            List<Texture2D> textures = new List<Texture2D>();
            textures.Add(Resource<Texture2D>.Get("StreetFighter"));
            _spriteSheet = new SpriteSheet(textures, new Vector2(256, 256));
            _spriteSheetID = 0;
            _world = world;
            UndeadlyFrames = -1;
            _body = new Body(position - COL_OFFSET, COL_SIZE);
            _onGround = false;
            _hitboxes = Resource<Dictionary<Vector3, List<CollisionBox>>>.Get("TestHitboxes").ToDictionary(e => e.Key, e => e.Value.ToList());
            // Register player for hitboxes.
            for (int j = 0; j < _hitboxes.Count; j++) {
                for (int i = 0; i < _hitboxes[_hitboxes.Keys.ElementAt(j)].Count; i++) {
                    var box = _hitboxes[_hitboxes.Keys.ElementAt(j)][i];
                    box.player = this;
                    _hitboxes[_hitboxes.Keys.ElementAt(j)][i] = box;
                }
            }

            _health = 100f;
            _geomID = -1;
            if (index == PlayerIndex.One) {
                _geomType = GeometryType.Player1;
                _geomIgnore = GeometryType.Player2;
            } else {
                _geomType = GeometryType.Player2;
                _geomIgnore = GeometryType.Player1;
            }
        }
예제 #3
0
        public Vector2 MoveTo(Vector2 position, World world, out int hcol, out int vcol, GeometryType ignore)
        {
            Vector2 delta = position - _position;
            hcol = 0;
            vcol = 0;

            while (delta.LengthSquared() > 0.1f) {
                float dX = Math.Sign(delta.X);
                if (Math.Abs(delta.X) < 1) dX = delta.X;
                delta.X -= dX;

                float dY = Math.Sign(delta.Y);
                if (Math.Abs(delta.Y) < 1) dY = delta.Y;
                delta.Y -= dY;

                _bbox.X += (int)Math.Round(dX);
                if (world.Collides(_bbox, ignore)) {
                    _bbox.X -= (int)Math.Round(dX);
                    hcol = Math.Sign(dX);
                    delta.X = 0;
                    dX = 0;
                }

                _position.X += dX;

                _bbox.Y += (int)Math.Round(dY);

                if (world.Collides(_bbox, ignore)) {
                    _bbox.Y -= (int)Math.Round(dY);
                    vcol = Math.Sign(dY);
                    delta.Y = 0;
                    dY = 0;
                }

                _position.Y += dY;
            }

            return _position;
        }
예제 #4
0
        public override void Init(Viewport viewport)
        {
            base.Init(viewport);
            _world = new World();
            _world.Register(new Rectangle(-600, 680, 2400, 100));
            _world.Register(new Rectangle(-700, 0, 200, 720));
            _world.Register(new Rectangle(1700, 0, 200, 720));
            _inputManager = new InputManager();

            _debug = false;

            _player = new Player("Ryu.xml", _game.Content.Load<Texture2D>("PlayerTemp"), new Vector2(300, 500), _world, PlayerIndex.One);
            _player2 = new Player("Ryu.xml", _game.Content.Load<Texture2D>("PlayerTemp"), new Vector2(800, 500), _world, PlayerIndex.Two);
            //_player3 = new Player("Ryu.xml",_game.Content.Load<Texture2D>("PlayerTemp"), new Vector2(500, 100), _world, PlayerIndex.Three);
            _barLeft = Resource<Texture2D>.Get("BarLeft");
            _barRight = Resource<Texture2D>.Get("BarRight");
            _bar = Resource<Texture2D>.Get("Bar");
            _camera = new Camera(viewport, new Vector2(640, 360));
            _camera.Zoom = 1f;
            _kb = Keyboard.GetState();
            _bg1 = Resource<Texture2D>.Get("BG1");
            _bg2 = Resource<Texture2D>.Get("BG2");
            _rightCollisionIndex = -1;
            _leftCollisionIndex = -1;
        }