コード例 #1
0
ファイル: BoxCollider.cs プロジェクト: soda5/Projekt2
        public void CheckCollision(BoxCollider other)
        {
            bool collision = false;

            if (X + Width <= other.X || other.X + other.Width <= X || Y + Height <= other.Y || other.Y + other.Height <= Y)
                collision = true;
            else
                collision = false;

            if(!collision)
            {
                if(!collidingColliders.Contains(other))
                {
                    collidingColliders.Add(other);

                    if (OnCollisionEnter != null)
                        OnCollisionEnter(other);
                }
                else
                {
                    if (OnCollisionStay != null)
                        OnCollisionStay(other);
                }
            }
            else
            {
                if(collidingColliders.Contains(other))
                {
                    collidingColliders.Remove(other);

                    if (OnCollisionExit != null)
                        OnCollisionExit(other);
                }
            }
        }
コード例 #2
0
ファイル: Player.cs プロジェクト: soda5/Projekt2
        public Player(Vector2 position)
        {
            Name = "Player";

            LoadSprite(GameManager.LoadTexture2D("Peter"));

            this.Position = position;

            map = (Map)GameManager.FindGameObject("Map");

            collider = new BoxCollider(this, (int)Position.X, (int)Position.Y, 1, 1);

            InputManager.OnKeyDown += OnKeyDown;
            InputManager.OnKeyPressed += OnKeyPressed;
        }
コード例 #3
0
ファイル: Potion.cs プロジェクト: soda5/Projekt2
        private void OnCollisionEnter(BoxCollider other)
        {
            if(other.Type is Player)
            {
                Player.Health += 20;

                GameManager.Destroy(this);
                CollisionManager.Destroy(collider);

                if(Game1.DebugMode)
                {
                    Debug.WriteLine("HP: " + Player.Health);
                }
            }
        }
コード例 #4
0
ファイル: Armor.cs プロジェクト: soda5/Projekt2
        private void OnCollisionEnter(BoxCollider other)
        {
            if(other.Type is Player)
            {
                Player.Defense += 1;

                GameManager.Destroy(this);
                CollisionManager.Destroy(collider);

                if(Game1.DebugMode == true)
                {
                    Debug.Write("Deine Rüstung hat sich um 1 erhöht");
                }
            }
        }
コード例 #5
0
ファイル: Item.cs プロジェクト: soda5/Projekt2
        public Item(Vector2 position, string atlasPath, string name)
        {
            Position = position;
            Name = name;

            ItemAtlas = GameManager.LoadTexture2D("Items");

            GameManager.AddGameObject(this);

            collider = new BoxCollider(this, (int)Position.X, (int)Position.Y, 1, 1);

            LoadFrame(atlasPath);

            SetFrame(Name);
        }
コード例 #6
0
ファイル: Pokemon.cs プロジェクト: soda5/Projekt2
        public Pokemon(Vector2 position, string texture, string name, int health, int defense, int attackPower, int xp, int init, string element, bool movement)
        {
            this.Position = position;
            this.Sprite = GameManager.Content.Load<Texture2D>(texture);
            this.Name = name;
            this.Health = health;
            this.Defense = defense;
            this.AttackPower = attackPower;
            this.Element = element;
            this.Init = init;
            this.Movement = movement;

            GameManager.AddGameObject(this);

            collider = new BoxCollider(this, (int)position.X, (int)position.Y, 1, 1);

            collider.OnCollisionEnter += OnCollisionEnter;
        }
コード例 #7
0
ファイル: CollisionManager.cs プロジェクト: soda5/Projekt2
 public static void Destroy(BoxCollider boxCollider)
 {
     deletedColliders.Add(boxCollider);
 }
コード例 #8
0
ファイル: CollisionManager.cs プロジェクト: soda5/Projekt2
 public static void AddCollider(BoxCollider collider)
 {
     colliders.Add(collider);
 }
コード例 #9
0
ファイル: Pokemon.cs プロジェクト: soda5/Projekt2
 private void OnCollisionEnter(BoxCollider other)
 {
     if (GameManager.GameState == "move" && other.Type is Player) // To prevent pokemon from fighting each other
         FightManager.Fight(this);
 }