public override ObjectStatePacket Update(long ticks) { if ((Target != null && Util.Distance(X, Y, Target.X, Target.Y) > CurrentUpgrade.Range) || !_game.Contains(Target)) { Target = null; } if (Target == null) { var nearest = _game.FindNearestObjectWithinRadius(this, X, Y, CurrentUpgrade.Range, typeof(Vehicle)); Target = nearest != null ? nearest.Object : null; } if (Target != null) { float ax, ay; Angles.AngleToDirection(Angle, out ax, out ay); float tdx = Target.X - X; float tdy = Target.Y - Y; int actualTargetAngle = Util.DeltasToAngle(tdx, tdy); float cp = CrossProduct(ax, ay, tdx, tdy); int adiff = Angles.Difference(_trackingTargetAngle, actualTargetAngle) / 2; if (cp < 0) { _trackingTargetAngle -= Math.Min(adiff, MaxAngleVelocity); } else { _trackingTargetAngle += Math.Min(adiff, MaxAngleVelocity); } //_trackingTargetAngle = actualTargetAngle; Angle = _trackingTargetAngle & 4095; } return null; }
public Hud(Game game) { _game = game; Renderer r = game.Application.Renderer; // _msgLine = new TextLine(r, r.Width-200, r.Height-PanelHeight/2-10, _basePriority); _gameLine = new TextLine(r, 8, 8, _basePriority); _rendererLine = new TextLine(r, 8, 28, _basePriority); _nextWaveLine = new TextLine(r, r.Width/2, r.Height/2-11, _basePriority+100); _showNextWaveLine = false; _toolbar = new HudToolbar(_game, r, _basePriority); _cursors[0] = new Sprite(_game.Config.GetWidgetTemplate("buildcursor"), Drawable.Flags.Colorize, _basePriority+40); _cursors[1] = new Sprite(null, Drawable.Flags.Colorize, _basePriority+41); _cursors[1][0].Frame = (byte)0; _selectionHighlight = new Sprite(_game.Config.GetWidgetTemplate("selhighlight"), 0, _basePriority); _upgradeButton = new Widget(_game.Config.GetWidgetTemplate("upgradebutton"), _game, _basePriority+1); _upgradeButton.SetFlags(WidgetFlags.LevelCoordinates); _sellButton = new Widget(_game.Config.GetWidgetTemplate("sellbutton"), _game, _basePriority+1); _sellButton.SetFlags(WidgetFlags.LevelCoordinates); _upgradeButton[0].Color = new Color4(1.0f, 1.0f, 1.0f, 0.65f); _upgradeButton[1].Color = new Color4(1.0f, 1.0f, 1.0f, 0.0f); _sellButton[0].Color = new Color4(1.0f, 1.0f, 1.0f, 0.65f); _sellButton[1].Color = new Color4(1.0f, 1.0f, 1.0f, 0.0f); _pointerCircle = new Circle(0, 0, 0, 300); _pointerCircle.Color.A = 0.4f; _selectedCircle = new Circle(0,0,0, _basePriority-2); _selectedCircle.Color.A = 0.4f; _bpullout = new HudBuildablePullout(_game, r,_basePriority); _mousePointerCollider = Collider.Point( 0, 0, delegate(Collider c, IEnumerable<ObjectAndDistance> objects) { var o = objects.FirstOrDefault(); if(o != null) _hoverObject = o.Object; }, null ); _mousePointerCollider.FilterType = typeof(Buildable); game.Application.Input.MouseDown += HandleMouseDown; game.Application.Input.KeyDown += HandleKeyDown; }
public void Remove(GameObject gob) { int startx = (int)(gob.X-gob.Radius) / _cellSize; int starty = (int)(gob.Y-gob.Radius) / _cellSize; int endx = (int)(gob.X+gob.Radius) / _cellSize; int endy = (int)(gob.Y+gob.Radius) / _cellSize; for(int y = starty; y <= endy; ++y) { for(int x = startx; x <= endx; ++x) { _grid[x + y * _gridWidth].Remove(gob); } } }
public ObjectAndDistance(GameObject obj, float distance) { Debug.Assert(obj != null); Distance = distance; Object = obj; }
public void RemoveObject(GameObject obj) { lock(_objectRemoveList) { _objectRemoveList.Add(obj); } }
public IEnumerable<ObjectAndDistance> FindObjectsWithinRadius(GameObject src, float x, float y, float radius, Type filterType) { var nearby = _spatialHash.GetNearby(x,y,radius); return from n in nearby let dist = Util.Distance(x,y,n.X,n.Y) where n != src && filterType.IsAssignableFrom(n.GetType()) && dist < radius select new ObjectAndDistance(n,dist); }
public ObjectAndDistance FindNearestObjectWithinRadius(GameObject src, float x, float y, float radius, Type filterType) { return FindObjectsWithinRadius(src,x,y,radius,filterType).OrderBy(o => o.Distance).FirstOrDefault(); }
public bool Contains(GameObject gob) { return _objects.Contains(gob); }
public void AddObject(GameObject obj) { lock(_objectAddList) { obj.Uid = _nextUid++; _objectAddList.Add(obj); } }