protected override void OnMouseButtonDown(MouseButtonEvent e) { if (Session == null) { return; } camera.OnMouseButtonDown(e); if (e.Handled) { return; } var sc = ToAbsolute(e.Position); var mc = Geometry.ScreenToMap(sc); var gob = Session.Scene.GetObjectAt(sc); if (placeGob != null) { Placed.Raise(new MapPlaceEvent(e, placeGob.Position)); Session.Objects.RemoveLocal(placeGob); placeGob = null; } else { MapClick.Raise(new MapClickEvent(e, mc, e.Position, gob)); } e.Handled = true; }
private void DoBonusAction(Gob host) { if (Game.NetworkMode == NetworkMode.Client) return; if (host.Owner != null) host.Owner.ArenaStatistics.BonusesCollected++; var gameAction = BonusAction.Create<BonusAction>(_bonusActionTypeName, host, gob => { }); if (gameAction == null) return; Gob.CreateGob<ArenaMessage>(Game, (CanonicalString)"bonusmessage", gob => { gob.ResetPos(Pos, Vector2.Zero, Gob.DEFAULT_ROTATION); gob.Owner = host.Owner; gob.Message = gameAction.BonusText; gob.IconName = gameAction.BonusIconName; if (host.Owner != null) gob.DrawColor = host.Owner.Color; Game.DataEngine.Arena.Gobs.Add(gob); }); var playerOwner = host.Owner as Player; if (playerOwner != null) playerOwner.Messages.Add(new PlayerMessage("You collected " + gameAction.BonusText, playerOwner.Color)); if (host.Owner != null) Game.Stats.Send(new { Bonus = _bonusActionTypeName.Value, Player = Game.Stats.GetStatsString(host.Owner), Pos = Pos, BirthPos = BirthPos, }); }
/// <summary> /// Displays the grid. /// </summary> void OnGUI() { if (_ObjectManager.gameState.displayGrid) { foreach (Node node in nodes) { if (node.isBuildable) { Vector3 posVector = Camera.main.WorldToScreenPoint(node.unityPosition); GUI.DrawTexture(new Rect(posVector.x, Screen.height - posVector.y, nodeSize.x, nodeSize.y), gridTexture); } } } foreach (EnemyBase Gob in _ObjectManager.ThingsWithHealthBars()) { //Health Bar float healthRatio = (((float)Gob.Health) / ((float)Gob.maxHealth)); if (healthRatio != 1) { Vector2 objSize = Gob.GetPixelSize(); float width = Gob.healthBarSize.x; float height = Gob.healthBarSize.y; width = width * healthRatio; Vector3 wantedPos = Camera.main.WorldToScreenPoint(Gob.transform.position); GUI.color = new Color(2 * (1 - healthRatio), 2 * healthRatio, 0); GUI.DrawTexture(new Rect(wantedPos.x - width / 2, Screen.height - wantedPos.y - objSize.y / 2, width, height), healthTexture); } } }
public override void onUpdate() { Vector gravity = new Vector(0, 1); Vector acc = Vector.Zero; Vector friction = new Vector(.08f, 0); if ((plr.Position - Gob.Position).Length < 1400) { bool isPlayerOnRight = (plr.X - Gob.X) > 0; if (isPlayerOnRight) { acc += Vector.UnitX * (.4f + (surface.Y < .2 ? .5f : 0)); } else { acc -= Vector.UnitX * (.4f + (surface.Y < .2 ? .5f : 0)); } if (surface.Y > .8f) { jumping = true; acc -= gravity * Math.Min(23, Math.Max(Gob.Y - plr.Y, 0)); } } acc += gravity; Gob.Velocity += acc; Gob.Velocity -= new Vector(Gob.Velocity.X * friction.X, Gob.Velocity.Y * friction.Y); Gob.Position += Gob.Velocity; Collisions <Wall> wallColls = Gob.currentCollisions <Wall>(); surface = Vector.Zero; foreach (Collision <Wall> c in wallColls) { Gob.Position -= c.MTV; Gob.Velocity = c.Normal.Perpendicular * c.Normal.Perpendicular.dot(Gob.Velocity); if (c.Normal.Y > .8f) { surface = c.Normal; jumping = false; } } if (Gob.Bounds.getCollisionInfo(plr.Bounds) != null) { Gob.close(); } }
public override ISprite MakeInstance(Gob owner, byte[] state) { var flags = state != null ? new BitArray(state) : new BitArray(0); var parts = Parts.Where(p => p.Id < 0 || flags.IsSet(p.Id)); return(new StaticSprite(parts)); }
public CollisionArea(string name, IGeomPrimitive area, Gob owner, CollisionAreaType type, CollisionMaterialType collisionMaterial) { _type = type; _collisionMaterial = collisionMaterial; _name = name; _area = area; _owner = owner; if (owner != null && owner.IsRegistered) Initialize(); }
public override ISprite MakeInstance(Gob owner, byte[] state) { var flags = state != null ? new BitArray(state) : new BitArray(0); var ps = Parts.Where(p => p.Id < 0 || flags.IsSet(p.Id)); var fs = GenerateFrames(flags); return(new AnimSprite(ps, fs)); }
public void Unplace() { if (Session == null) { throw new InvalidOperationException(); } Session.Objects.RemoveLocal(placeGob); placeGob = null; }
public GobTrackerItem(Gob gob, Gob trackerGob, string texture) { if (gob == null) throw new ArgumentNullException("GobTrackerItem.Gob must not be null"); Gob = gob; StickToBorders = true; RotateTowardsTarget = true; ShowWhileTargetOnScreen = false; ScaleByDistance = true; Texture = texture; TrackerGob = trackerGob; }
private void setControlPointsVisibility(bool visible) { Gob.setControlPointVisibility(visible, Gob.ControlPointRight); Gob.setControlPointVisibility(visible, Gob.ControlPointRightTop); Gob.setControlPointVisibility(visible, Gob.ControlPointTop); Gob.setControlPointVisibility(visible, Gob.ControlPointLeftTop); Gob.setControlPointVisibility(visible, Gob.ControlPointLeft); Gob.setControlPointVisibility(visible, Gob.ControlPointLeftBot); Gob.setControlPointVisibility(visible, Gob.ControlPointBot); Gob.setControlPointVisibility(visible, Gob.ControlPointRightBot); }
public void Setup() { _player1 = new Player(null, "Player 1", CanonicalString.Null, CanonicalString.Null, CanonicalString.Null, new UI.PlayerControls()); _player2 = new Player(null, "Player 2", CanonicalString.Null, CanonicalString.Null, CanonicalString.Null, new UI.PlayerControls()); _arena = new Arena(); _source = new Gob { ID = 1, Owner = _player1, MaxDamageLevel = 100, Arena = _arena, Pos = Vector2.Zero }; _hostileGob1 = new Gob { ID = 2, Owner = _player2, MaxDamageLevel = 100, Arena = _arena }; _hostileGob2 = new Gob { ID = 3, Owner = _player2, MaxDamageLevel = 100, Arena = _arena }; _neutralGob = new Gob { ID = 4, Owner = null, MaxDamageLevel = 100, Arena = _arena }; _friendlyGob = new Gob { ID = 5, Owner = _player1, MaxDamageLevel = 100, Arena = _arena }; _targetSelector = new TargetSelector(700); }
public override void onUpdate() { Collisions <Wall> walls = Gob.currentCollisions <Wall>(); if (walls.Count > 0) { int index = 0; if (walls[index].Gob == lastWall) { index = walls.Count - 1; } Gob.Velocity = walls[index].Normal.Perpendicular * Gob.Speed; lastWall = walls[index].Gob; onWall = true; } else if (onWall) { Gob.Position -= Gob.Velocity; Gob.Velocity = Gob.Velocity.Perpendicular; Gob.Position += Gob.Velocity.Unit; onWall = false; } else { Gob.Velocity = Vector.UnitY; } // //check for line of sight to target // GameObject target = Objects.getObject(Gob.Target); // if (target != null && onWall){ // Vector toTarget = target.Position - Gob.Position; // float length = toTarget.Length; // if (toTarget.Length < 800){ // // // toTarget = toTarget.Unit; // // RayCollisions<Wall> rayColls = Gob.currentRayCollisions<Wall>(toTarget); // if (rayColls.Count > 0 && rayColls[0].Length > length){ // Log.debug("See you. " + rayColls[0].Length + "/" + length); // onWall = false; // Gob.Position += Gob.Velocity.Perpendicular; // Gob.Velocity = Gob.Velocity.Perpendicular; // Gob.Position += Gob.Velocity; // // } // // } // } Gob.Position += Gob.Velocity; }
public MapClickEvent( MouseButton button, KeyModifiers mods, Point2D mapCoord, Point2D screenCoord, Gob gob) { Button = button; MapCoord = mapCoord; ScreenCoord = screenCoord; Gob = gob; Modifiers = mods; }
/// <summary> /// Returns an estimate of the current mood of a position for a gob. /// Mood is not measured in any specific units. Returned values are mutually comparable; /// the larger the return value, the better the mood is. /// </summary> private static float GetMood(Gob gob, Vector2 pos) { const float MOOD_DISTANCE_MIN = 400; const float MOOD_DISTANCE_MAX = 2000; var constituents = from minion in gob.Game.DataEngine.Minions where minion != gob let distance = Vector2.Distance(pos, minion.Pos) let sign = gob.IsFriend(minion) ? 1 : -1 let amplitude = MathHelper.Clamp(1 - (distance - MOOD_DISTANCE_MIN) / (MOOD_DISTANCE_MAX - MOOD_DISTANCE_MIN), 0, 1) select sign * amplitude; return constituents.Sum(); }
public override void onUpdate() { Color c = Gob.Sprite.Color; c.A = (c.A * Gob.Decay) / (Gob.Decay + 1); Gob.Sprite.Color = c; Gob.Y -= .3f; if (c.A < 1) { Gob.close(); } //Gob.Position += Gob.Dir * Gob.Speed; }
private void CreateShot(Gob source, int sourceBoneIndex, Gob target, int chainIndex) { var birthPos = source.GetNamedPosition(sourceBoneIndex); Gob.CreateGob<Lightning>(Owner.Game, _shotTypeName, shot => { shot.ResetPos(birthPos, Vector2.Zero, Gob.DEFAULT_ROTATION); shot.Owner = PlayerOwner; shot.Shooter = source; shot.ShooterBoneIndex = sourceBoneIndex; shot.Target = target; shot.ChainIndex = chainIndex; Arena.Gobs.Add(shot); }); }
public void Setup() { _shooter = new Gobs.Ship { Pos = new Vector2(0, 0), Rotation = 0 }; _gob1 = new MockGob { Name = "Gob1", Pos = new Vector2(100, 0) }; _gob2 = new MockGob { Name = "Gob2", Pos = new Vector2(200, 0) }; _gob3 = new MockGob { Name = "Gob3", Pos = new Vector2(300, 0) }; _gob4 = new MockGob { Name = "Gob4", Pos = new Vector2(0, 100) }; _gob5 = new MockGob { Name = "Gob5", Pos = new Vector2(0, 200) }; _gob6 = new MockGob { Name = "Gob6", Pos = new Vector2(-100, 0) }; _gob7 = new MockGob { Name = "Gob7", Pos = new Vector2(0, -100) }; _potentialTargets = new[] { _gob1, _gob2, _gob3, _gob4, _gob5, _gob6 }; _gun = new LightningGun(); _gun.AttachTo(_shooter, GobUtils.ShipDevice.OwnerHandleType.PrimaryWeapon); }
public static List<Peng> CreatePengs(IEnumerable<CanonicalString> typeNames, Gob leader) { var result = new List<Peng>(); foreach (var typeName in typeNames) { Gob.CreateGob<Peng>(leader.Game, typeName, peng => { peng.ResetPos(leader.Pos, Vector2.Zero, Gob.DEFAULT_ROTATION); peng.Leader = leader; leader.Arena.Gobs.Add(peng); result.Add(peng); }); } return result; }
public void Activate(Gob owner) { Owner = owner; _pengs = new List<Peng>(); foreach (var name in _pengNames) { Gob.CreateGob<Peng>(Owner.Game, name, peng => { peng.Emitter.Pause(); peng.Leader = Owner; Owner.Arena.Gobs.Add(peng); _pengs.Add(peng); }); } }
public override ISprite MakeInstance(Gob owner, byte[] state) { var rnd = new Random(owner?.Id ?? RandomUtils.GetSeed()); var parts = new List <SpritePart>(); parts.AddRange(Parts.Where(x => x.Id == -1)); for (int i = 0; i < num; i++) { var s = strands[rnd.Next(strands.Length)]; var cx = (int)(rnd.NextGaussian() * neg.Hitbox.Width / 2); var cy = (int)(rnd.NextGaussian() * neg.Hitbox.Height / 2); var offset = Geometry.MapToScreen(cx, cy).Sub(s.Width / 2, s.Height); parts.Add(new SpritePart(s.Image, offset, s.Z, s.SubZ)); } return(new StaticSprite(parts)); }
public override ISprite MakeInstance(Gob owner, byte[] state) { var reader = new BinaryDataReader(state); var value = reader.ReadInt32(); var displayPlus = reader.ReadByte() != 0; var str = value.ToString(); if (displayPlus && value > 0) { str = "+" + str; } var color = UnpackColor(reader.ReadUInt16()); return(new FloatText(str, Fonts.LabelText, color)); }
public void Place(ISprite sprite, bool snapToTile, int?radius) { if (Session == null) { throw new InvalidOperationException(); } placeOnTile = snapToTile; placeRadius = radius ?? -1; placeGob = new Gob(-1); placeGob.SetSprite(new Delayed <ISprite>(sprite)); var mc = Geometry.ScreenToMap(ToAbsolute(Host.MousePosition)); placeGob.Position = placeOnTile ? Geometry.Tilify(mc) : mc; Session.Objects.AddLocal(placeGob); }
public override void onUpdate() { Gob.Acceleration = Vector.UnitY; Vector vX = Gob.A; if (!goingToA) { vX = Gob.B; } float d = (vX.X - Gob.X); if (Math.Abs(d) < 10) { goingToA = !goingToA; } float x = Math.Sign(d); Gob.Acceleration += Vector.UnitX * x * 2; Gob.Velocity += Gob.Acceleration; Gob.Velocity -= Gob.Velocity * .1f; Gob.Position += Gob.Velocity; vis.Position = Gob.Position + new Vector(0, -75); vis.Sprite.Scale = new Vector(x, 1) * 1.5f; //if (Gob.Velocity.X != 0){ a.advanceFrame(); //} var wallColls = Gob.currentCollisions <Wall>(); foreach (var wallColl in wallColls) { Gob.Position -= wallColl.MTV; } }
/// <summary> /// Displays the grid. /// </summary> void OnGUI() { foreach (EnemyBase Gob in _ObjectManager.ThingsWithHealthBars()) { //Health Bar float healthRatio = (((float)Gob.Health) / ((float)Gob.maxHealth)); if (healthRatio != 1) { Vector2 objSize = Gob.GetPixelSize(); float width = Gob.healthBarSize.x; float height = Gob.healthBarSize.y; width = width * healthRatio; Vector3 wantedPos = Camera.main.WorldToScreenPoint(Gob.transform.position); GUI.color = new Color(2 * (1 - healthRatio), 2 * healthRatio, 0); GUI.DrawTexture(new Rect(wantedPos.x - width / 2, Screen.height - wantedPos.y - objSize.y / 2, width, height), healthTexture); } } }
/// <summary> /// Positions a minion (e.g. a ship) using any of the spawn areas in the arena. /// </summary> public static void PositionNewMinion(Gob minion, Arena arena) { Func<IGeomPrimitive, int, IEnumerable<Vector2>> getRandomPoses = (area, count) => Enumerable.Range(0, count) .Select(x => arena.GetFreePosition(LARGE_GOB_PHYSICAL_RADIUS, area)); var spawnPoses = arena.Gobs.All<SpawnPlayer>() .SelectMany(spawn => getRandomPoses(spawn._spawnArea, 5)); var poses = spawnPoses.Any() ? spawnPoses : getRandomPoses(new Rectangle(Vector2.Zero, arena.Dimensions), 20); var posesWithThreats = poses .Select(pos => new { pos, mood = GetMood(minion, pos) }) .ToList() .OrderByDescending(x => x.mood) .ToList(); var bestMood = posesWithThreats[0].mood; var bestSpawns = posesWithThreats.TakeWhile(x => x.mood == bestMood).ToList(); var bestPos = bestSpawns[RandomHelper.GetRandomInt(bestSpawns.Count)].pos; minion.ResetPos(bestPos, Vector2.Zero, Gob.DEFAULT_ROTATION); }
public void Setup() { Spectator.CreateStatsData = spectator => new MockStats(); Coroner.ResetPhraseSets(); _avengers = new Team("Avengers", null); _player1 = new Player(null, "Player 1", CanonicalString.Null, CanonicalString.Null, CanonicalString.Null, new UI.PlayerControls()); _player2 = new Player(null, "Player 2", CanonicalString.Null, CanonicalString.Null, CanonicalString.Null, new UI.PlayerControls()); _player3 = new Player(null, "Player 3", CanonicalString.Null, CanonicalString.Null, CanonicalString.Null, new UI.PlayerControls()); _player4 = new Player(null, "Player 4", CanonicalString.Null, CanonicalString.Null, CanonicalString.Null, new UI.PlayerControls()); _player1.AssignTeam(_avengers); _player4.AssignTeam(_avengers); _arena = new Arena(); _gob1 = new Gob { Owner = _player1, MaxDamageLevel = 100, Arena = _arena }; _gob1DamagedBy2 = new Gob { Owner = _player1, MaxDamageLevel = 100, Arena = _arena }; _gob2 = new Gob { Owner = _player2, MaxDamageLevel = 100, Arena = _arena }; _gob2Nature = new Gob { Owner = null }; _gob4 = new Gob { Owner = _player4, MaxDamageLevel = 100, Arena = _arena }; _arena.TotalTime = TimeSpan.FromSeconds(10); _gob1DamagedBy2.InflictDamage(10, new DamageInfo(_gob2)); }
public void Setup() { _arena = new Arena(); _avengers = new Team("Avengers", null); _player1 = new Player(null, "Player 1", CanonicalString.Null, CanonicalString.Null, CanonicalString.Null, new UI.PlayerControls()); _player2 = new Player(null, "Player 2", CanonicalString.Null, CanonicalString.Null, CanonicalString.Null, new UI.PlayerControls()); _player3 = new Player(null, "Player 3", CanonicalString.Null, CanonicalString.Null, CanonicalString.Null, new UI.PlayerControls()); _player2.AssignTeam(_avengers); _player3.AssignTeam(_avengers); _gob1 = new Gob { ID = 10, Owner = _player1, MaxDamageLevel = 100, Arena = _arena }; _gob1DamagedBy2 = new Gob { ID = 11, Owner = _player1, MaxDamageLevel = 100, Arena = _arena }; _gob2 = new Gob { ID = 2, Owner = _player2, MaxDamageLevel = 100, Arena = _arena }; _gob3 = new Gob { ID = 3, Owner = _player3, MaxDamageLevel = 100, Arena = _arena }; _gobNature = new Gob { ID = 4, Owner = null, MaxDamageLevel = 100, Arena = _arena }; _info1Hit1 = new DamageInfo(_gob1).Bind(_gob1); _info2Hit1 = new DamageInfo(_gob2).Bind(_gob1); _info3Hit2 = new DamageInfo(_gob3).Bind(_gob2); _infoNatureHit1 = new DamageInfo(_gobNature).Bind(_gob1); _arena.TotalTime = TimeSpan.FromSeconds(10); _gob1DamagedBy2.InflictDamage(10, new DamageInfo(_gob2)); _info1DamagedBy2 = DamageInfo.Unspecified.Bind(_gob1DamagedBy2); }
public override void onUpdate() { if (Gob.Selected != null) { Vector mousePos = WhiskeyControl.InputManager.MousePosition; mousePos = WhiskeyControl.ActiveCamera.getGameCoordinate(mousePos); ObjectControlPoint cp = Gob.ControlPointLightRadius; Gob.setControlPointVisibility(Gob.Selected.Light.Visible, cp); cp.Position = Gob.Position + (Gob.Selected.Light.Radius / 2) * Vector.UnitX; cp.X = cp.Position.X; cp.Y = cp.Position.Y; if (WhiskeyControl.InputManager.isNewMouseDown(Whiskey2D.Core.Inputs.MouseButtons.Left) && Gob.Selected.Light.Visible) { if (Gob.ControlPointLightRadius.Bounds.vectorWithin(mousePos)) { dragging = true; startDrag = Gob.Selected.Position; } } if (dragging && Gob.Selected.Light.Visible) { Vector diff = mousePos - startDrag; Gob.Selected.Light.Radius = diff.Length * 2; if (!WhiskeyControl.InputManager.isMouseDown(Whiskey2D.Core.Inputs.MouseButtons.Left)) { dragging = false; } } } }
public static GameObject CreateDecal(SDecalInfo Info) { Material sharedMat = GameObject.Instantiate(CGame.WorldResources.DecalMat); GameObject Gob = null; if (Info.mType == CDecal.EDecalType.TEXT) { Gob = new GameObject("decal"); TextMesh textMesh = Gob.AddComponent <TextMesh>(); Gob.GetComponent <MeshRenderer>().material = sharedMat; sharedMat.SetTexture("_MainTex", CGame.WorldResources.DecalFontA.material.GetTexture("_MainTex")); sharedMat.SetFloat("_Add", 1.0f); textMesh.font = CGame.WorldResources.DecalFontA; textMesh.text = Info.mText; textMesh.characterSize = 0.2f; textMesh.fontSize = 54; textMesh.color = new Color(1.0f, 1.0f, 1.0f, 1.0f); textMesh.anchor = TextAnchor.MiddleCenter; } else if (Info.mType == CDecal.EDecalType.IMAGE) { Gob = GameObject.CreatePrimitive(PrimitiveType.Quad); Gob.name = "decal"; Gob.GetComponent <MeshRenderer>().material = sharedMat; sharedMat.SetTexture("_MainTex", CGame.PrimaryResources.GetDecalImage(Info.mVisualId)); } Gob.transform.localPosition = Info.mPosition; Gob.transform.rotation = Info.mRotation; Gob.transform.localScale = new Vector3(Info.mSize.x, Info.mSize.y, 1.0f); sharedMat.SetColor("_Color", Info.mColor); Gob.AddComponent <Item>().Init(sharedMat); return(Gob); }
public override void onUpdate() { Collisions <Player> colls = Gob.currentCollisions <Player>(); foreach (Collision <Player> coll in colls) { if (coll.Gob is Player) { Player plr = (Player)coll.Gob; Gob.Acceleration += new Vector(.01f * plr.Velocity.X, .1f * plr.Velocity.Y); } } if (Gob.Wave == true) { //Gob.Velocity += new Vector(0, waveAmplitude * (float)Math.Sin(waveFrequency * waveActuator)); waveActuator += .01f; } bool hasNeighbors = (Gob.RightNode != null && Gob.LeftNode != null); Gob.Velocity += new Vector(hasNeighbors ? Gob.Acceleration.X : 0, Gob.Acceleration.Y); if (Gob.Velocity.Length > 30) { Gob.Velocity = 30 * Gob.Velocity.Unit; } Gob.Position += Gob.Velocity; Gob.Acceleration = Vector.Zero; //} }
public override void onUpdate() { Vector dir = Input.MousePosition - new Vector(ScreenWidth / 2, ScreenHeight / 2); target.Position = Input.MouseGamePosition; mouse.Position = Input.MouseGamePosition; Vector start = Gob.GunTipPosition - Gob.Position; //dir = Input.MouseGamePosition - start; //mouse.Position = Gob.Position + dir.UnitSafe * 200; RayCollisions <Wall> rayColls = Gob.currentRayCollisions <Wall>(start, dir); RayCollision rc = null; if (rayColls.Count > 0) { rc = rayColls[0]; target.Position = rc.ContactPoint; } RayCollisions <Badguy> badguyColls = Gob.currentRayCollisions <Badguy>(start, dir); if (badguyColls.Count > 0) { if (rc == null || rc.Length > badguyColls[0].Length) { rc = badguyColls[0]; target.Position = rc.ContactPoint; } } if (rc != null) { Gob.LookAngle = rc.RayDirection.Angle - (float)Math.PI / 2; } if (rayColls.Count > 0) { target.Position = rc.ContactPoint; Vector screenPos = Level.Camera.getScreenCoordinate(Gob.GunTipPosition); Bounds b = new Bounds(Vector.Zero, new Vector(ScreenWidth, ScreenHeight), 0); RayCollisionInfo info = b.getRayCollisionInfo(screenPos, (rc.RayDirection)); if (info != null) { screenPos = info.ContactPoint; screenPos = Level.Camera.getGameCoordinate(screenPos); if ((screenPos - Gob.GunTipPosition).Length < (Gob.GunTipPosition - target.Position).Length) { target.Position = screenPos; } } } if (Input.isNewMouseDown(MouseButtons.Left) && rc != null) { laserSound.duplicate().play(); //laserSound.Pan = 0; if (rc is RayCollision <Badguy> ) { RayCollision <Badguy> brc = (RayCollision <Badguy>)rc; brc.Gob.close(); } float height = (Rand.Instance.nextFloat() * 20 - 10); Tracer tracer = new Tracer(Level); tracer.Light.Visible = true; float scaleAmt = .9f - (Rand.Instance.nextFloat() * .45f); scaleAmt = 1; tracer.Sprite.Scale = new Vector((rc.Length - 0) * scaleAmt / 10f, .5f + (Rand.Instance.nextFloat() * .3f - .15f)); tracer.Sprite.Rotation = rc.RayDirection.Angle; tracer.Position = (rc.ContactPoint + rc.RayStart) / 2; tracer.Sprite.Color = Rand.Instance.nextColorVariation(Color.DarkOrange, .1f, .1f, .1f, .2f); //tracer.Position += rc.RayDirection * (0 + ((1 - scaleAmt) * (rc.Length)/2 * (Rand.Instance.nextFloat() * 2 - 1))); tracer.Position += rc.RayDirection.Perpendicular * height; tracer.Decay = 5; tracer = new Tracer(Level); tracer.Light.Visible = true; //scaleAmt = .9f - (Rand.Instance.nextFloat()*.45f); //scaleAmt = (scaleAmt + 0) / 2; tracer.Sprite.Scale = new Vector((rc.Length - 0) * scaleAmt / 10f, .2f + (Rand.Instance.nextFloat() * .3f - .15f)); tracer.Sprite.Rotation = rc.RayDirection.Angle; tracer.Position = (rc.ContactPoint + rc.RayStart) / 2; tracer.Sprite.Color = Rand.Instance.nextColorVariation(Color.White, .1f, .1f, .1f, 0); tracer.Decay = 4; //tracer.Position += rc.rayDirection * (0 + ((1 - scaleAmt) * (rc.Length)/2 * (Rand.Instance.nextFloat() * 2 - 1))); //tracer.Position += -rc.RayDirection * (rc.Length/2 - tracer.Sprite.ImageSize.X/2); tracer.Position += rc.RayDirection.Perpendicular * height; tracer.Dir = rc.RayDirection; tracer.Speed = 1f; SpriteEffect fx = new SpriteEffect(Level); fx.Effect = "smokePlume3"; fx.Position = rc.ContactPoint - rc.RayDirection * 10; fx.Sprite.Scale *= .4f; fx.Frames = Vector.One * 4; fx.Speed = 2; fx.Sprite.Color = Color.Orange; fx.Light.Visible = true; fx.Light.Radius = 256f; float f = 256f; fx.OnUpdate = (a) => { f *= .95f; fx.Light.Radius = f; }; fx = new SpriteEffect(Level); fx.Effect = "muzzle"; fx.Position = rc.RayStart - rc.RayDirection * 10; fx.Frames = new Vector(4, 2); fx.Speed = 2; fx.Sprite.Scale *= .4f; fx.Sprite.Rotation = rc.RayDirection.Angle; fx.Sprite.Color = Color.Orange; } }
public override void onUpdate() { Vector dir = Input.MousePosition - Level.Camera.getScreenCoordinate(Gob.Position); dir = Vector.Zero; if (Input.isKeyDown(Keys.Right)) { dir.X += 1; } if (Input.isKeyDown(Keys.Left)) { dir.X -= 1; } if (Input.isKeyDown(Keys.Up)) { dir.Y -= 1; } if (Input.isKeyDown(Keys.Down)) { dir.Y += 1; } if (dir.Equals(Vector.Zero)) { dir.X = Math.Sign(Gob.Velocity.X); } dir = dir.UnitSafe; Gob.LookAngle = dir.Angle - (float)Math.PI / 2; Vector start = Gob.GunTipPosition - Gob.Position; RayCollisions <Wall> rayColls = Gob.currentRayCollisions <Wall>(start, dir); RayCollision rc = null; if (rayColls.Count > 0) { rc = rayColls[0]; target.Position = rc.ContactPoint; } RayCollisions <Drone> badguyColls = Gob.currentRayCollisions <Drone>(start, dir); if (badguyColls.Count > 0) { if (rc == null || rc.Length > badguyColls[0].Length) { rc = badguyColls[0]; target.Position = rc.ContactPoint; } } RayCollisions <Worm> badguyCollsWorms = Gob.currentRayCollisions <Worm>(start, dir); if (badguyCollsWorms.Count > 0) { if (rc == null || rc.Length > badguyCollsWorms[0].Length) { rc = badguyCollsWorms[0]; target.Position = rc.ContactPoint; } } RayCollisions <FlyBug> badguyCollsBugs = Gob.currentRayCollisions <FlyBug>(start, dir); if (badguyCollsBugs.Count > 0) { if (rc == null || rc.Length > badguyCollsBugs[0].Length) { rc = badguyCollsBugs[0]; target.Position = rc.ContactPoint; } } if (rayColls.Count > 0) { target.Position = rc.ContactPoint; Vector screenPos = Level.Camera.getScreenCoordinate(Gob.GunTipPosition); Bounds b = new Bounds(Vector.Zero, new Vector(ScreenWidth, ScreenHeight), 0); RayCollisionInfo info = b.getRayCollisionInfo(screenPos, (rc.RayDirection)); if (info != null) { screenPos = info.ContactPoint; screenPos = Level.Camera.getGameCoordinate(screenPos); if ((screenPos - Gob.GunTipPosition).Length < (Gob.GunTipPosition - target.Position).Length) { target.Position = screenPos; } } } bool space = Input.isNewKeyDown(Keys.LeftShift) || Input.isNewKeyDown(Keys.RightControl); if (space) { Log.debug("space"); } if (space && rc != null) { Log.debug("shoot"); laserSound.duplicate().setVolume(.4f).play(); //laserSound.Pan = 0; if (rc is RayCollision <Drone> ) { RayCollision <Drone> brc = (RayCollision <Drone>)rc; brc.Gob.close(); } // if (rc is RayCollision<Worm>){ // RayCollision<Worm> brc = (RayCollision<Worm>) rc; // brc.Gob.close(); // } if (rc is RayCollision <FlyBug> ) { RayCollision <FlyBug> brc = (RayCollision <FlyBug>)rc; brc.Gob.close(); } float height = (Rand.Instance.nextFloat() * 20 - 10); Tracer tracer = new Tracer(Level); tracer.Light.Visible = true; float scaleAmt = .9f - (Rand.Instance.nextFloat() * .45f); scaleAmt = 1; tracer.Sprite.Scale = new Vector((rc.Length - 0) * scaleAmt / 10f, .5f + (Rand.Instance.nextFloat() * .3f - .15f)); tracer.Sprite.Rotation = rc.RayDirection.Angle; tracer.Position = (rc.ContactPoint + rc.RayStart) / 2; tracer.Sprite.Color = Rand.Instance.nextColorVariation(Color.DarkOrange, .1f, .1f, .1f, .2f); //tracer.Position += rc.RayDirection * (0 + ((1 - scaleAmt) * (rc.Length)/2 * (Rand.Instance.nextFloat() * 2 - 1))); tracer.Position += rc.RayDirection.Perpendicular * height; tracer.Decay = 5; tracer = new Tracer(Level); tracer.Light.Visible = true; //scaleAmt = .9f - (Rand.Instance.nextFloat()*.45f); //scaleAmt = (scaleAmt + 0) / 2; tracer.Sprite.Scale = new Vector((rc.Length - 0) * scaleAmt / 10f, .2f + (Rand.Instance.nextFloat() * .3f - .15f)); tracer.Sprite.Rotation = rc.RayDirection.Angle; tracer.Position = (rc.ContactPoint + rc.RayStart) / 2; tracer.Sprite.Color = Rand.Instance.nextColorVariation(Color.White, .1f, .1f, .1f, 0); tracer.Decay = 4; //tracer.Position += rc.rayDirection * (0 + ((1 - scaleAmt) * (rc.Length)/2 * (Rand.Instance.nextFloat() * 2 - 1))); //tracer.Position += -rc.RayDirection * (rc.Length/2 - tracer.Sprite.ImageSize.X/2); tracer.Position += rc.RayDirection.Perpendicular * height; tracer.Dir = rc.RayDirection; tracer.Speed = 1f; SpriteEffect fx = new SpriteEffect(Level); fx.Effect = "smokePlume3"; fx.Position = rc.ContactPoint - rc.RayDirection * 10; fx.Sprite.Scale *= .4f; fx.Frames = Vector.One * 4; fx.Speed = 2; fx.Sprite.Depth = .3f; fx.Sprite.Color = Color.Orange; fx.Light.Visible = true; fx.Light.Radius = 256f; float f = 256f; fx.OnUpdate = (a) => { f *= .95f; fx.Light.Radius = f; }; fx = new SpriteEffect(Level); fx.Effect = "muzzle"; fx.Position = rc.RayStart - rc.RayDirection * 10; fx.Frames = new Vector(4, 2); fx.Speed = 2; fx.Sprite.Scale *= .4f; fx.Sprite.Rotation = rc.RayDirection.Angle; fx.Sprite.Color = Color.Orange; } }
private bool IsReachable(Gob gob) { return !IsFriend(gob) && !gob.IsHidden && _potentialTargets.Contains(gob); }
public override void onUpdate() { //Config conf = Objects.getObject<Config>("Config"); if (Input.isNewKeyDown(Keys.Escape)) { GameManager.SetLevel("MainMenu.state"); } Gob.Acceleration = Vector.Zero; Vector friction = new Vector(.08f, 0); if (Input.isKeyDown(Keys.A)) { Gob.Acceleration -= Vector.UnitX; } if (Input.isKeyDown(Keys.D)) { Gob.Acceleration += Vector.UnitX; } if (Input.isKeyDown(Keys.O)) { surface = Vector.UnitY; jumping = false; } if (Input.isNewKeyDown(Keys.W)) { if (surface.Y > .8f) { jumping = true; jumpCounter = 40; int jumpPower = 12; if (Gob.InWater) { jumpPower = 12; } Gob.Velocity = new Vector(Gob.Velocity.X, 0); Gob.Acceleration = -gravity * jumpPower; doubleJumped = false; SpriteEffect fx = new SpriteEffect(Level); fx.Position = Gob.Position + Vector.UnitY * Gob.Bounds.Size.Y / 4; fx.Effect = "smokeJump"; fx.Frames = Vector.One * 4; fx.Sprite.Scale *= .3f; fx.Speed = 4; } else if (((jumping && !doubleJumped) || (surface.Y < .8f && !jumping)) && !Gob.InWater) { jumpCounter = 40; doubleJumped = true; jumping = true; int jumpPower = 12; Gob.Acceleration = -gravity * jumpPower; Gob.Velocity = new Vector(Gob.Velocity.X, 0); SpriteEffect fx = new SpriteEffect(Level); Vector xD = Vector.UnitX * Gob.Sprite.FrameWidth; if (Gob.Velocity.X < 0) { xD *= -1; } fx.Position = Gob.Position - (Vector.UnitY * Gob.Bounds.Size.Y / 2) - xD; fx.Sprite.Rotation = 1.57f; fx.Effect = "jump"; fx.Frames = new Vector(4, 2); fx.Sprite.Scale *= .3f; fx.Sprite.Depth = Gob.Sprite.Depth + .01f; fx.Speed = 4; } } if (Input.isKeyDown(Keys.W)) { if (jumping && jumpCounter > 0) { Gob.Acceleration -= gravity * .02f * jumpCounter; jumpCounter--; } } surface = Vector.Zero; Gob.InWater = false; var waterBlocks = Gob.currentCollisions <WaterBlock>(); if (waterBlocks.Count > 0) { Gob.InWater = true; if (Gob.Y > waterBlocks[0].Gob.Bounds.Top) { Gob.Acceleration -= gravity * 1.2f; if (Gob.Velocity.Y > 0) { Gob.Velocity *= .8f; } } //if (Gob.Velocity.Y < 0 || Math.Abs(Gob.Y - waterBlocks[0].Gob.Bounds.Top) < 50){ // Log.debug("can jump from water"); surface = Vector.UnitY; //jumping = false; //} // if (waterBlocks[0].Gob.Bounds.Top > Gob.Bounds.Top){ // surface = Vector.UnitY; // } } Gob.Acceleration += gravity; Gob.Velocity += Gob.Acceleration; if (Gob.Velocity.Length > 55) { Gob.Velocity = 55 * Gob.Velocity.Unit; } Gob.Velocity -= new Vector(Gob.Velocity.X * friction.X, Gob.Velocity.Y * friction.Y); Gob.Sprite.Scale = new Vector(70 + Math.Abs(Gob.Velocity.X * 15), 256); Gob.Position += Gob.Velocity; Collisions <Wall> wallColls = Gob.currentCollisions <Wall>(); foreach (Collision <Wall> c in wallColls) { Gob.Position -= c.MTV; Gob.Velocity = c.Normal.Perpendicular * c.Normal.Perpendicular.dot(Gob.Velocity); if (c.Gob.Speed != 0) { Gob.Position += c.Gob.Velocity; } if (c.Normal.Y > .8f) { surface = c.Normal; jumping = false; } } if (waterBlocks.Count > 0) { //if (Gob.Y < waterBlocks[0].Gob.Bounds.Top + 10){ //surface = Vector.UnitY; //} } Collisions <WaterNode> wColls = Gob.currentCollisions <WaterNode>(); if (wColls.Count != 0 && waterNodes == 0) { Vector feet = Gob.Position + Vector.UnitY * Gob.Bounds.Size.Y; //feet.Y += wColls[0].Gob.Velocity.Y; float vel = -2f * (Gob.Velocity - wColls[0].Gob.Velocity).Length; vel = Math.Max(-25, vel); WaterParticle.makeSplash(feet, 20, new Vector(0, vel), 1, 1.2f, false); } else if (wColls.Count == 0 && waterNodes != 0) { Vector feet = Gob.Position + Vector.UnitY * Gob.Bounds.Size.Y / 2; float vel = -1.2f * (Gob.Velocity).Length; vel = Math.Max(-10, vel); WaterParticle.makeSplash(feet, 8, new Vector(0, vel), 1, 2, false); } foreach (Collision <WaterNode> coll in wColls) { coll.Gob.Acceleration += new Vector(0f * Gob.Velocity.X, .05f * Gob.Velocity.Y); } waterNodes = wColls.Count; }
/// <summary> /// Copies the gob's runtime state from another gob. /// </summary> /// <param name="runtimeState">The gob whose runtime state to imitate.</param> protected override void SetRuntimeState(Gob runtimeState) { base.SetRuntimeState(runtimeState); TriangleCount = _indexData.Length / 3; }
public SoundInstance CreateSound(string soundName, Gob parentGob) { return CreateSound(soundName, () => GetPos(parentGob), () => GetMove(parentGob)); }
private Vector2? GetMove(Gob gob) { return gob == null ? (Vector2?)null : gob.Move; }
private void GobCreation(Gob gob, int createCount, int i, int emitType, ref List<Particle> particles) { // Find out emission parameters. // We have to loop because some choices of parameters may not be wanted. int maxAttempts = 20; bool attemptOk = false; for (int attempt = 0; !attemptOk && attempt < maxAttempts; ++attempt) { bool lastAttempt = attempt == maxAttempts - 1; attemptOk = true; int random = RandomHelper.GetRandomInt(); float directionAngle, rotation; Vector2 directionUnit, pos, move; switch (Peng.ParticleCoordinates) { case Peng.CoordinateSystem.Peng: RandomHelper.GetRandomCirclePoint(_radius, -_sprayAngle, _sprayAngle, out pos, out directionUnit, out directionAngle); move = _initialVelocity.GetValue(0, random) * directionUnit; switch (_facingType) { case FacingType.Directed: rotation = 0; break; case FacingType.Forward: rotation = directionAngle; break; case FacingType.Random: rotation = RandomHelper.GetRandomFloat(0, MathHelper.TwoPi); break; default: throw new Exception("SprayEmitter: Unhandled particle facing type " + _facingType); } break; case Peng.CoordinateSystem.Game: { float posWeight = (i + 1) / (float)createCount; var startPos = Peng.OldDrawPos; var endPos = Peng.Pos + Peng.DrawPosOffset; var iPos = Vector2.Lerp(startPos, endPos, posWeight); var drawRotation = Peng.Rotation + Peng.DrawRotationOffset; RandomHelper.GetRandomCirclePoint(_radius, drawRotation - _sprayAngle, drawRotation + _sprayAngle, out pos, out directionUnit, out directionAngle); pos += iPos; move = Peng.Move + _initialVelocity.GetValue(0, random) * directionUnit; // HACK: 'move' will be added to 'pos' in PhysicalUpdater during this same frame pos -= move * (float)Peng.Game.GameTime.ElapsedGameTime.TotalSeconds; switch (_facingType) { case FacingType.Directed: rotation = Peng.Rotation; break; case FacingType.Forward: rotation = directionAngle; break; case FacingType.Random: rotation = RandomHelper.GetRandomFloat(0, MathHelper.TwoPi); break; default: throw new Exception("SprayEmitter: Unhandled particle facing type " + _facingType); } } break; case Peng.CoordinateSystem.FixedToPeng: pos = Vector2.Zero; move = Vector2.Zero; rotation = 0; directionAngle = 0; break; default: throw new ApplicationException("SprayEmitter: Unhandled peng coordinate system " + Peng.ParticleCoordinates); } // Set the thing's parameters. if (emitType < TextureNames.Length) { var particle = new Particle { Alpha = 1, Move = move, PengInput = Peng.Input, Pos = pos, Random = random, Direction = directionAngle, DirectionVector = Vector2.UnitX.Rotate(directionAngle), Rotation = rotation, Scale = 1, Texture = Peng.Game.Content.Load<Texture2D>(TextureNames[emitType]), }; particles.Add(particle); } else { // Bail out if the position is not free for the gob. if (!lastAttempt && !Peng.Arena.IsFreePosition(new Circle(pos, Gob.SMALL_GOB_PHYSICAL_RADIUS))) { attemptOk = false; continue; } gob.Owner = Peng.Owner; gob.ResetPos(pos, move, rotation); Peng.Arena.Gobs.Add(gob); } } }
public MapClickEvent(MouseButtonEvent e, Point2D mapCoord, Point2D screenCoord, Gob gob) : this(e.Button, e.Modifiers, mapCoord, screenCoord, gob) { }
private void GobRemovedFromArenaHandler(Gob gob) { if (!gob.IsRelevant) return; _pendingGobDeletionMessage =_pendingGobDeletionMessage ?? new GobDeletionMessage(); _pendingGobDeletionMessage.GobIDs.Add(gob.ID); }
public void AddGob(Gob gob) { _gobTypeNames.Add(gob.TypeName); _layerIndices.Add(gob.Arena.Layers.IndexOf(gob.Layer)); Write(gob, SerializationModeFlags.AllFromServer); }
private Vector2 GetTrackerPos(Gob trackerGob) { if (trackerGob != null) return trackerGob.Pos + trackerGob.DrawPosOffset; return _viewport.CurrentLookAt; }
public virtual void SendHit(Gob hitter, Gob target, Vector2? pos = null) { }
public abstract ISprite MakeInstance(Gob owner, byte[] state);
private void Hit(Gob gob, float damage) { gob.InflictDamage(damage, new DamageInfo(this)); GobHelper.CreatePengs(_hitEffects, gob); Game.Stats.SendHit(this, gob); }
/// <summary> /// Attaches the thruster to a gob. Call this method right after creating the gob. /// </summary> public void Activate(Gob owner) { if (owner == null) throw new ArgumentNullException("owner"); Owner = owner; _exhaustEngines = CreateExhaustEngines(); if (HasSound) { _thrusterSound = Owner.Game.SoundEngine.CreateSound(_runningSound, Owner); _thrusterTurnSound = Owner.Game.SoundEngine.CreateSound("LowEngine", Owner); } }
private Vector2? GetPos(Gob gob) { return gob == null ? (Vector2?)null : gob.Pos; }
public ISprite GetSprite(string resName, Gob owner, byte[] state = null) { var maker = Get <SpriteMaker>(resName); return(maker.MakeInstance(owner, state)); }
private Color SpectatorColor(Gob gob, Func<Color> otherwise) { return gob == null || gob.Owner == null ? otherwise() : gob.Owner.Color; }
public override void onUpdate() { if (WhiskeyControl.InputManager.isNewMouseDown(Whiskey2D.Core.Inputs.MouseButtons.Left)) { Vector mousePos = WhiskeyControl.InputManager.MousePosition; mousePos = WhiskeyControl.ActiveCamera.getGameCoordinate(mousePos); //check if selection already exists. If so, check for controlPoints { Gob.Selected = null; Gob.Sprite.Color = Color.Transparent; //GameManager.Controller.SelectedGob = null; List <InstanceDescriptor> objs = Gob.CurrentLevel.getInstances();//GameManager.Objects.getAllObjectsNotOfType<EditorGameObject>(); float highestDepth = 0; foreach (InstanceDescriptor obj in objs) { if (!obj.Layer.Locked && obj.Layer.Visible) { if (obj.Sprite != null && obj.Bounds.vectorWithin(mousePos) || new Bounds(obj.Position - Vector.One * 8, Vector.One * 16, 0).vectorWithin(mousePos) || obj == Gob.ControlPointObject && ( Gob.isSelectingControlPoint(mousePos)) ) { if (obj.Sprite.Depth > highestDepth) { Gob.Selected = obj; highestDepth = obj.Sprite.Depth; Gob.ControlPointObject = Gob.Selected; SelectionManager.Instance.SelectedInstance = obj; } //break; } } } if (Gob.Selected == null) { SelectionManager.Instance.SelectedInstance = null; } } } if (Gob.Selected != null) { //Sprite clone = new Sprite(Gob.Selected.Sprite); // Gob.Sprite = clone; Gob.Sprite.Color = Gob.CurrentLevel.BackgroundColorCompliment; Gob.Sprite.Rotation = Gob.Selected.Sprite.Rotation; //Color c = Gob.Sprite.Color; //c.A = 128; //Gob.Sprite.Color = c; Gob.Sprite.Depth = Gob.Selected.Sprite.Depth / 2; Gob.Position = Gob.Selected.Position; Gob.Sprite.Scale = Gob.Selected.Bounds.Size + new Vector(12); } else if (Gob.Unselect) { Gob.Unselect = false; Gob.Sprite.Color = Color.Transparent; } }
private float GetAcceleration(Gob gob, float impulse) { var force = impulse * AssaultWingCore.TargetFPS; return force / gob.Mass; }
protected override void SetRuntimeState(Gob runtimeState) { base.SetRuntimeState(runtimeState); ModelName = _propModelName; }
private bool IsAvoidable(Gob gob) { return IsFriend(gob) && gob is FloatingBullet; }
public override void onUpdate() { //Config conf = Objects.getObject<Config>("Config"); Gob.Acceleration = Vector.Zero; Vector friction = new Vector(.08f, 0); if (Input.isKeyDown(Keys.A)) { Gob.Acceleration -= Vector.UnitX; } if (Input.isKeyDown(Keys.D)) { Gob.Acceleration += Vector.UnitX; } if (Input.isNewKeyDown(Keys.W)) { if (surface.Y > .8f) { jumping = true; jumpCounter = 40; Gob.Acceleration -= gravity * 12; doubleJumped = false; SpriteEffect fx = new SpriteEffect(Level); fx.Position = Gob.Position + Vector.UnitY * Gob.Bounds.Size.Y / 4; fx.Effect = "smokeJump"; fx.Frames = Vector.One * 4; fx.Sprite.Scale *= .3f; fx.Speed = 4; } else if (jumping && !doubleJumped) { jumpCounter = 40; doubleJumped = true; Gob.Acceleration -= gravity * 12; SpriteEffect fx = new SpriteEffect(Level); fx.Position = Gob.Position + Vector.UnitY * Gob.Bounds.Size.Y / 4; fx.Effect = "smokeJump"; fx.Frames = Vector.One * 4; fx.Sprite.Scale *= .3f; fx.Speed = 4; } } if (Input.isKeyDown(Keys.W)) { if (jumping && jumpCounter > 0) { Gob.Acceleration -= gravity * .02f * jumpCounter; jumpCounter--; } } Gob.Acceleration += gravity; Gob.Velocity += Gob.Acceleration; if (Gob.Velocity.Length > 55) { Gob.Velocity = 55 * Gob.Velocity.Unit; } Gob.Velocity -= new Vector(Gob.Velocity.X * friction.X, Gob.Velocity.Y * friction.Y); Gob.Sprite.Scale = new Vector(50 + Math.Abs(Gob.Velocity.X * 15), 256); Gob.Position += Gob.Velocity; Collisions <Wall> wallColls = Gob.currentCollisions <Wall>(); surface = Vector.Zero; foreach (Collision <Wall> c in wallColls) { Gob.Position -= c.MTV; Gob.Velocity = c.Normal.Perpendicular * c.Normal.Perpendicular.dot(Gob.Velocity); if (c.Normal.Y > .8f) { surface = c.Normal; jumping = false; } } }
private void DoDamageOverTime(Gob target) { var action = BonusAction.Create<DamageBuffBonusAction>(_damageEffectTypeName, target, gob => { }); if (action != null) action.Owner = Owner; }
/// <summary> /// Chooses a target, preferring those that are /// 1. enemies or at least not friends, and /// 2. straight ahead, and /// 3. close /// </summary> /// <param name="filter">Gobs that map to false are ignored as potential targets.</param> public Gob ChooseTarget(IEnumerable<Gob> candidates, Gob source, float direction, Func<Gob, bool> filter = null) { var targets = from gob in candidates where !gob.Disabled && gob != source && !gob.IsHidden let distanceSquared = Vector2.DistanceSquared(gob.Pos, source.Pos) where distanceSquared <= MaxRange * MaxRange let ownerWeight = gob.IsFriend(source) ? FriendlyWeight : gob.Owner == null ? NeutralWeight : HostileWeight let relativePos = (gob.Pos - source.Pos).Rotate(-direction) let targetAngle = Math.Abs(relativePos.Angle()) where targetAngle <= MaxAngle let totalWeight = ownerWeight * (1 + (float)Math.Sqrt(distanceSquared) * (1 + AngleWeight * targetAngle)) where totalWeight < float.MaxValue orderby totalWeight ascending select gob; return filter != null ? targets.FirstOrDefault(filter) : targets.FirstOrDefault(); }
public Layouter(Gob owner) { this.owner = owner; }
public override void onUpdate() { Vector mousePos = WhiskeyControl.InputManager.MousePosition; mousePos = WhiskeyControl.ActiveCamera.getGameCoordinate(mousePos); mousePos = new Vector((int)mousePos.X, (int)mousePos.Y); if (WhiskeyControl.InputManager.isNewMouseDown(Whiskey2D.Core.Inputs.MouseButtons.Left)) { //make sure no control points are being selected if (!Gob.isSelectingControlPoint(mousePos)) { List <InstanceDescriptor> objs = Gob.CurrentLevel.getInstances(); float highestDepth = 0f; foreach (InstanceDescriptor obj in objs) { if (!obj.Layer.Locked && obj.Layer.Visible) { if (obj.Sprite != null && obj.Bounds.vectorWithin(mousePos) || new Bounds(obj.Position - Vector.One * 8, Vector.One * 16, 0).vectorWithin(mousePos)) { if (obj.Sprite.Depth > highestDepth) { highestDepth = obj.Sprite.Depth; Gob.Dragging = obj; grabOffset = Gob.Dragging.Position - mousePos; //break; } } } } } } if (Gob.Dragging != null) { //WhiskeyControl.Controller.SelectedGob = Gob.Dragging; SelectionManager.Instance.SelectedInstance = Gob.Dragging; Gob.Dragging.Position = mousePos + grabOffset; if (WhiskeyControl.InputManager.isKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift)) { Vector topLeft = Gob.Dragging.Bounds.TopLeft; topLeft = GridManager.Instance.snap(topLeft); Gob.Dragging.Position = topLeft + Gob.Dragging.Sprite.ScaledOffset; } Gob.Dragging.X = Gob.Dragging.Position.X; Gob.Dragging.Y = Gob.Dragging.Position.Y; if (!WhiskeyControl.InputManager.isMouseDown(Whiskey2D.Core.Inputs.MouseButtons.Left)) { Gob.Dragging = null; } } }