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); } } }
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; }
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); } } }
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"); } } }
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); }
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; }
public static void Destroy(BoxCollider boxCollider) { deletedColliders.Add(boxCollider); }
public static void AddCollider(BoxCollider collider) { colliders.Add(collider); }
private void OnCollisionEnter(BoxCollider other) { if (GameManager.GameState == "move" && other.Type is Player) // To prevent pokemon from fighting each other FightManager.Fight(this); }