private Visual GetIndicatorVisual(GameObject TargetObject, Vector focus, Vector viewSize) { int backWidth = GameProcess.Current_Game.gameMap.TileSize; int backHeight = 10; int fillPadding = 1; DrawingVisual visual = new DrawingVisual(); double percents = TargetObject.Life; int fillWidth = (int)((backWidth - fillPadding) * percents / 100); Vector position = CalculatePositionOnCanvas(TargetObject.AbsoluteCenter, viewSize, focus); Point rBackPoint = new Point(position.X - backWidth / 2, position.Y - backHeight / 2 - backWidth / 2); Point rFillPoint = new Point(rBackPoint.X + fillPadding, rBackPoint.Y + fillPadding); Rect rectBack = new Rect(rBackPoint, new Size(backWidth, backHeight)); Rect rectFill = new Rect(rFillPoint, new Size(fillWidth, backHeight - fillPadding * 2)); using (DrawingContext dc = visual.RenderOpen()) { dc.DrawRectangle(IndicatorBackBrush, IndicatorBorderPen, rectBack); dc.DrawRectangle(IndicatorFillBrush, IndicatorBorderPen, rectFill); } return visual; }
public LifeIndicator(GameObject gameObject, Int32 showtime) { TargetObject = gameObject; ShowTime = showtime; RestTime = showtime; //RestLife = TargetObject.Life; }
public override void Collide(GameObject gameObject, System.Windows.Vector direction, double overlap) { long summWeight = gameObject.GetWeight() + this.GetWeight(); this.LocalCenter -= direction * overlap * (gameObject.GetWeight() / summWeight); // MessageBox.Show("dd"); Damage(overlap * 2); }
/// <summary> /// Set component by type /// </summary> /// <param name="nObj"></param> public void SetComponentByType(GameObject nObj) { nObj.Parent = this; for (int i = 0; i < components.Count; i++) { if (components[i].GetType() == nObj.GetType()) { components[i] = nObj; return; } } this.AddComponent(nObj); if (ComponentsUpdated != null) ComponentsUpdated(this); }
/// <summary> /// /// </summary> /// <param name="gObject"></param> public void TryRemoveIndicator (GameObject gObject) { LifeIndicators.RemoveAll(x => x.TargetObject == gObject); }
/// <summary> /// /// </summary> /// <param name="gObject"></param> public void IndicateLifeChange(GameObject gObject) { foreach (LifeIndicator indicator in LifeIndicators) { if (indicator.TargetObject.Equals(gObject)) { indicator.Reset(); return; } } LifeIndicators.Add(new LifeIndicator(gObject, 1000)); }
/// <summary> /// This metod returns game objects to draw from map grid. When target object is in /// allowable sector, camera doesn't move. Otherway, it moves. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void UpdateFocus(GameObject gObject) { this.Focus = new Vector(UpdateFocusX(gObject.AbsoluteCenter.X), UpdateFocusY(gObject.AbsoluteCenter.Y)); }
public override bool Contains(GameObject obj) { return this.Equals(obj); }
public override void Collide(GameObject gameObject, Vector direction, double overlap) { Crash(); //base.Collide(gameObject, direction, overlap); }
public override void Collide(GameObject gameObject, Vector direction, double overlap) { if (gameObject.Name != "bullet") { /// LocalCenter += direction * overlap * 1.2; Engine.translateSpeed = new Vector(Engine.translateSpeed.X / 2, Engine.translateSpeed.Y / 2); /// } else { if(this.Name.ToLower() =="player") Damage(overlap * 0.1); else Damage(overlap * 0.5); } }
public void RegisterObject(GameObject gameObject) { //if(!chekingObjects.Contains(gameObject)) chekingObjects.Add(gameObject); }
/// <summary> /// This method check if this object contains someone primitive /// </summary> /// <param name="obj"></param> /// <returns></returns> public abstract Boolean Contains(GameObject obj);
/// <summary> /// /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Contains(GameObject obj) { if (this.Equals(obj)) return true; foreach (GameObject gObj in components) { if (gObj.Contains(obj)) return true; } return false; }
/// <summary> /// Remove one component /// </summary> /// <param name="gObj"></param> public void RemoveComponent(GameObject gObj) { components.Remove(gObj); if (ComponentsUpdated != null) ComponentsUpdated(this); }
/// <summary> /// Add new component /// </summary> /// <param name="gObj"></param> public void AddComponent(GameObject gObj) { components.Add(gObj); if (ComponentsUpdated != null) ComponentsUpdated(this); }
/// <summary> /// /// </summary> /// <param name="gameObject"></param> /// <param name="direction"></param> /// <param name="overlap"></param> public virtual void Collide(GameObject gameObject, Vector direction, double overlap) { }
public override void Collide(GameObject gameObject, System.Windows.Vector direction, double overlap) { base.Collide(gameObject, direction, overlap); Damage(overlap); }
public void UnRegisterObject(GameObject gameObject) { chekingObjects.Remove(gameObject); }