public virtual void Advance() { if (invincibility.Value() > 0) { invincibility -= Game.TIMESTEP; } position = Game.instance.GetWrappedPosition(position); transform.position = new Vector3(position.x.ToFloat(), position.y.ToFloat()); }
public FVector Rotate(FInt angle) { FInt oldAngle = FInt.Atan(x, y); FInt newAngle = oldAngle + angle; FInt length = FInt.Sqrt(x * x + y * y); x = FInt.Cos(newAngle) * length; y = FInt.Sin(newAngle) * length; return this; }
public override void Damage(int damage) { health -= damage; if (health <= 0) { Game.instance.KillEnemy(this); return; } invincibility += new FInt(0.4f); }
// Normalize this vector public FVector Normalize() { FInt length = FInt.Sqrt(x * x + y * y); if (length.Value() == 0) { return this; } x = x / length; y = y / length; return this; }
public void Setup(InputModule input, FInt startx, FInt starty, int team, string name) { this.input = input; position.x = startx; position.y = starty; this.team = team + 1; playerName = name; transform.position = new Vector3(startx.ToFloat(), starty.ToFloat()); sword.Setup(this); }
// Helper that applies normal damage and shield leech (affected by leechFactor). static public object Act_ShieldLeech_Helper(NetBattlefield bf, NetQueueItem q, FInt leechFactor) { NetSkill ns = q.GetNetSkill(bf); NetCard owner = bf.GetCardByID(ns.OwnerCardID); NetCard target = null; if (NetType.IsNullOrEmpty(q.Targets)) { return(null); } FInt damage = owner.GetSkillCastingStrength(ns); int shieldLeeched = 0; // Primary targets. foreach (var v in q.Targets.value) { target = bf.ConvertPositionIDToCard(v); if (target != null) { target.ReciveNormalDamage(damage, bf, q, v); shieldLeeched += (damage * leechFactor).ToInt(); } } // Secondary targets. if (!NetType.IsNullOrEmpty(q.SecondaryTargets)) { damage *= 0.5f; foreach (var v in q.SecondaryTargets.value) { target = bf.ConvertPositionIDToCard(v); if (target != null) { target.ReciveNormalDamage(damage, bf, q, v); shieldLeeched += (damage * leechFactor).ToInt(); } } } if (shieldLeeched > 0) { FInt currentShields = owner.GetCA_SHIELD(); owner.SetCA_SHIELD(currentShields + shieldLeeched); } return(null); }
public override void RunAction(Character character) { // End the action after the designated number of frames has elapsed: if (Systems.timer.Frame > character.status.actionEnds) { this.EndAction(character); return; } Physics physics = character.physics; physics.velocity.X = FInt.Create(character.status.actionNum1); physics.velocity.Y = FInt.Create(character.status.actionNum2); }
public static FInt Sqrt(FInt f) { byte numberOfIterations = 8; if (f.RawValue > 0x64000) { numberOfIterations = 12; } if (f.RawValue > 0x3e8000) { numberOfIterations = 16; } return(Sqrt(f, numberOfIterations)); }
public void CollisionDetection() { Character ch = this.character; Physics phys = ch.physics; // Setup Character phys.StopX(); phys.StopY(); // Reset the Character's Velocity phys.MoveToPos(600, 300); // Reset the Character's Position phys.SetGravity(FInt.Create(0)); phys.intend = FVector.Create(3, 3); // Setup Shroom Shroom shroom = new Shroom(this.roomScene, (byte)ShroomSubType.Black, FVector.Create(700, 300), null); shroom.physics.intend = FVector.Create(-1, -1); // Confirm that Physics Alignments, IsOverlapping, GetOverlapX, GetOverlapY are working correctly: shroom.physics.AlignRight(ch); Debug.Assert(CollideDetect.IsOverlapping(ch, shroom) == false); shroom.physics.MoveToPosX(shroom.posX - 1); Debug.Assert(CollideDetect.IsOverlapping(ch, shroom) == true); Debug.Assert(CollideDetect.GetOverlapX(ch, shroom, true) == 1); shroom.physics.AlignLeft(ch); Debug.Assert(CollideDetect.IsOverlapping(ch, shroom) == false); shroom.physics.MoveToPosX(shroom.posX + 1); Debug.Assert(CollideDetect.IsOverlapping(ch, shroom) == true); Debug.Assert(CollideDetect.GetOverlapX(shroom, ch, true) == 1); shroom.physics.AlignUp(ch); Debug.Assert(CollideDetect.IsOverlapping(ch, shroom) == false); shroom.physics.MoveToPosY(shroom.posY + 1); Debug.Assert(CollideDetect.IsOverlapping(ch, shroom) == true); Debug.Assert(CollideDetect.GetOverlapY(shroom, ch, true) == 1); shroom.physics.AlignDown(ch); Debug.Assert(CollideDetect.IsOverlapping(ch, shroom) == false); shroom.physics.MoveToPosY(shroom.posY - 1); Debug.Assert(CollideDetect.IsOverlapping(ch, shroom) == true); Debug.Assert(CollideDetect.GetOverlapY(ch, shroom, true) == 1); // Move Away (no longer overlapping, off by 2) shroom.physics.MoveToPosY(shroom.posY + 3); Debug.Assert(CollideDetect.GetOverlapY(ch, shroom, true) == -2); }
private void AssignSubType(byte subType) { if (subType == (byte)ProjectileBallSubType.Fire || subType == (byte)ProjectileBallSubType.Electric) { this.Damage = DamageStrength.Standard; this.spinRate = this.physics.velocity.X > 0 ? 0.05f : -0.05f; this.physics.SetGravity(FInt.Create(0.45)); this.CollisionType = ProjectileCollisionType.BounceOnFloor; if (subType == (byte)ProjectileBallSubType.Fire) { this.SetSpriteName("Projectiles/Fire"); } else { this.SetSpriteName("Projectiles/Electric"); } } else if (subType == (byte)ProjectileBallSubType.Rock) { this.Damage = DamageStrength.Lethal; this.physics.SetGravity(FInt.Create(0.8)); this.CollisionType = ProjectileCollisionType.DestroyOnCollide; this.SetSpriteName("Projectiles/Earth1"); } else { this.Damage = DamageStrength.Standard; this.spinRate = this.physics.velocity.X > 0 ? 0.09f : -0.09f; this.physics.SetGravity(FInt.Create(0.4)); this.CollisionType = ProjectileCollisionType.DestroyOnCollide; // Sprite Image if (subType == (byte)ProjectileBallSubType.Frost) { this.SetSpriteName("Projectiles/Frost"); } else if (subType == (byte)ProjectileBallSubType.Poison) { this.SetSpriteName("Projectiles/Poison"); } else if (subType == (byte)ProjectileBallSubType.Water) { this.SetSpriteName("Projectiles/Water"); } } }
// Ancient version of the built-in script Act_DrainHealthEssence, which leeches 80% instead. // Note: Built-in script Act_DrainHealthAncient does not appear to do this. static public object Act_LifeLeech_Ancient(NetBattlefield bf, NetQueueItem q, List <NetQueueItem> stack, List <NetQueueItem> previousItems, MHRandom random) { NetSkill ns = q.GetNetSkill(bf); NetCard owner = bf.GetCardByID(ns.OwnerCardID); NetCard target = null; if (NetType.IsNullOrEmpty(q.Targets)) { return(null); } FInt damage = owner.GetSkillCastingStrength(ns); int lifeLeeched = 0; // Primary targets. foreach (var v in q.Targets.value) { target = bf.ConvertPositionIDToCard(v); if (target != null) { target.ReciveNormalDamage(damage, bf, q, v); lifeLeeched += (damage * 0.8f).ToInt(); } } // Secondary targets. if (!NetType.IsNullOrEmpty(q.SecondaryTargets)) { damage *= 0.5f; foreach (var v in q.SecondaryTargets.value) { target = bf.ConvertPositionIDToCard(v); if (target != null) { target.ReciveNormalDamage(damage, bf, q, v); lifeLeeched += (damage * 0.8f).ToInt(); } } } if (lifeLeeched > 0) { owner.ReciveHealthNormal(lifeLeeched, bf, q, t); } return(null); }
public override void AffectByInput(ref FInt velX, ref FInt velY, ref int posX, ref int posY) { PlayerInput input = this.character.input; if (input.isDown(IKey.Up)) { velX = this.character.FaceRight ? FInt.Create(7) : FInt.Create(-7); velY = this.yVelUp; } else if (input.isDown(IKey.Down)) { velX = this.character.FaceRight ? FInt.Create(5) : FInt.Create(-5); velY = this.yVelDown; } }
public Bones(RoomScene room, byte subType, FVector pos, Dictionary <string, short> paramList) : base(room, subType, pos, paramList) { this.Meta = Systems.mapper.ObjectMetaData[(byte)ObjectEnum.Bones].meta; // Movement this.speed = FInt.Create(0.8); // Physics, Collisions, etc. this.physics = new Physics(this); this.physics.SetGravity(FInt.Create(0.5)); this.physics.velocity.X = (FInt)(0 - this.speed); this.AssignSubType(subType); this.AssignBoundsByAtlas(8, 4, -4); }
public override void RunAction(Character character) { // End the action after the designated number of frames has elapsed: if (this.HasTimeElapsed(character)) { if (!character.input.isDown(IKey.BButton)) { this.EndAction(character); } return; } // Maintain Slam Motion character.physics.velocity.X = FInt.Create(0); }
static public object Rit_HigherEducation(Thea2.Server.Group target, RitualsTask sourceTask) { if (target != null && target.characters != null) { FInt extraXp = (FInt)3; FInt charactersInGroups = (FInt)target.characters.Count; FInt bonus = extraXp / charactersInGroups; foreach (var c in target.characters) { c.Get().Xp = c.Get().Xp + bonus; } } return(null); }
public Boulder(RoomScene room, byte subType, FVector pos, Dictionary <string, short> paramList) : base(room, subType, pos, paramList) { this.Meta = Systems.mapper.ObjectMetaData[(byte)ObjectEnum.Boulder].meta; this.ThrowStrength = 10; // Grip Points (When Held) this.gripLeft = -35; this.gripRight = 25; this.gripLift = -8; this.physics.SetGravity(FInt.Create(0.6)); this.AssignSubType(subType); this.AssignBoundsByAtlas(4, 2, -2, 0); }
static DPhysicsManager() { DPhysicsManager.SimulationDelta = FInt.Create(0.1); DPhysicsManager.Drag = FInt.Create(0.8); DPhysicsManager.SleepVelocity = FInt.Create(0.1); DPhysicsManager.CollisionDamp = FInt.Create(0.8); DPhysicsManager.MinimumCollisionOffset = FInt.Create(0.1); DPhysicsManager.Restitution = FInt.Create(0.8); DPhysicsManager.MaxActionsUpon = 8; DPhysicsManager.AvailableCounts = new Stack <ushort>(); DPhysicsManager.randomDirection = new Vector2d(3, 5); DPhysicsManager.randomChange = new Vector2d(-13, 7); DPhysicsManager.SimObjects = new Body[2000]; DPhysicsManager.PeakCount = 0; }
public Physics(GameObject actor) { this.actor = actor; this.physPos = FVector.Create(this.actor.posX, this.actor.posY); this.lastPosX = this.actor.posX; this.lastPosY = this.actor.posY; this.velocity = new FVector(); this.extraMovement = new FVector(); this.gravity = new FInt(); this.hasExtraMovement = false; this.touch = new Touch(); }
public Bouncer(RoomScene room, byte subType, FVector pos, Dictionary <string, short> paramList) : base(room, subType, pos, paramList) { this.Meta = Systems.mapper.ObjectMetaData[(byte)ObjectEnum.Bouncer].meta; // Physics, Collisions, etc. this.physics = new Physics(this); this.AssignSubType(subType); this.AssignBoundsByAtlas(2, 2, -2, -2); // Initialize Bounce-Like Movement this.physics.velocity.X = FInt.Create(paramList == null || !paramList.ContainsKey("x") ? 2 : paramList["x"]); this.physics.velocity.Y = FInt.Create(paramList == null || !paramList.ContainsKey("y") ? 2 : paramList["y"]); this.UpdateRotation(); }
static public object Rit_Celebration(Thea2.Server.Group target, RitualsTask sourceTask) { if (target != null && target.characters != null) { FInt newMorale = (FInt)40; foreach (Character c in target.characters) { if (c.attributes.GetFinal(TAG.MORALE) < newMorale) { c.attributes.SetBaseTo(TAG.MORALE, newMorale); } } } return(null); }
public override bool Activate() { // Make sure the power can be activated if (!this.CanActivate()) { return(false); } // References Character character = this.character; // Determine Starting Position of Projectile relative to Character int posX = character.posX + character.bounds.MidX + (character.FaceRight ? 10 : -30); int posY = character.posY + character.bounds.Top + 5; // Play Sound character.room.PlaySound(this.sound, 1f, posX, posY); // Check if the tile placement is blocked: TilemapLevel tilemap = this.character.room.tilemap; bool isBlocked = CollideTile.IsBlockingCoord(tilemap, posX + 10 + (character.FaceRight ? 6 : -6), posY + 10, character.FaceRight ? DirCardinal.Right : DirCardinal.Left); // Prevent Throw if (isBlocked) { return(false); } // Prepare Velocity FInt velX = character.FaceRight ? this.xVel : this.xVel.Inverse; FInt velY = this.yVel; // Affect the Y-Velocity of the projectile if holding UP or DOWN this.AffectByInput(ref velX, ref velY); // Apply Character's Momentum (if applicable) if (this.multMomentum > 0) { velX += character.physics.velocity.X * this.multMomentum; velY += character.physics.velocity.Y * this.multMomentum * FInt.Create(0.5); } // Launch Projectile this.Launch(posX, posY, velX, velY); return(true); }
public FVector GetGlobalPosition(FInt globalRotation) { // The sword part is the hilt (or on the ground) if there is no parent if (parent == null) { // The sword part is on the ground if there is no player if (player == null) { return _position; } return _position + player.position; } globalRotation -= rotation; FVector rotatedPosition = new FVector(_position).Rotate(globalRotation); return rotatedPosition + parent.GetGlobalPosition(globalRotation); }
public FrostBall(Character character) : base(character) { this.subType = (byte)PowerSubType.Frost; this.projSubType = (byte)ProjectileBallSubType.Frost; this.IconTexture = "Power/Frost"; this.baseStr = "magic"; this.subStr = "frost"; this.SetActivationSettings(60, 3, 12); // Power Settings this.multMomentum = FInt.Create(0.8); this.xVel = FInt.Create(11); this.yVel = FInt.Create(-6); this.yVelUp = FInt.Create(-10); this.yVelDown = FInt.Create(-2); }
public static ProjectileEnemy Create(RoomScene room, byte subType, FVector pos, FVector velocity) { // Retrieve an available projectile from the pool. ProjectileEnemy projectile = ProjectilePool.ProjectileEnemy.GetObject(); projectile.ResetProjectile(room, subType, pos, velocity); projectile.spinRate = projectile.physics.velocity.X > 0 ? 0.05f : -0.05f; projectile.AssignSubType(subType); projectile.AssignBoundsByAtlas(2, 2, -2, -2); projectile.physics.SetGravity(FInt.Create(0)); // Add the Projectile to Scene room.AddToScene(projectile, false); return(projectile); }
public WaterBall(Character character) : base(character) { this.subType = (byte)PowerSubType.Water; this.projSubType = (byte)ProjectileBallSubType.Water; this.IconTexture = "Power/Water"; this.baseStr = "magic"; this.subStr = "water"; this.SetActivationSettings(144, 2, 39); // Power Settings this.multMomentum = FInt.Create(0.2); this.xVel = FInt.Create(9); this.yVel = FInt.Create(-6); this.yVelUp = FInt.Create(-8); this.yVelDown = FInt.Create(1); }
public Grenade(Character character) : base(character) { this.subType = (byte)PowerSubType.Grenade; this.sound = Systems.sounds.axe; this.IconTexture = "Weapon/Grenade"; this.baseStr = "ranged"; this.subStr = "grenade"; this.SetActivationSettings(30, 1, 30); // Power Settings this.multMomentum = FInt.Create(0.3); this.xVel = FInt.Create(14); this.yVel = FInt.Create(-7); this.yVelUp = FInt.Create(-14); this.yVelDown = FInt.Create(5); }
public Shuriken(Character character, byte subType) : base(character) { this.projSubType = (byte)subType; this.ApplySubType(subType); this.sound = Systems.sounds.axe; this.baseStr = "ranged"; this.subStr = "shuriken"; this.SetActivationSettings(132, 3, 15); // Power Settings this.multMomentum = FInt.Create(0.45); this.xVel = FInt.Create(17); this.yVel = FInt.Create(0); this.yVelUp = FInt.Create(-18); this.yVelDown = FInt.Create(18); }
public PoisonBall(Character character) : base(character) { this.subType = (byte)PowerSubType.Poison; this.projSubType = (byte)ProjectileBallSubType.Poison; this.IconTexture = "Power/Slime"; this.baseStr = "magic"; this.subStr = "poison"; this.SetActivationSettings(96, 2, 30); // Power Settings this.multMomentum = FInt.Create(0.2); this.xVel = FInt.Create(9); this.yVel = FInt.Create(-6); this.yVelUp = FInt.Create(-16); this.yVelDown = FInt.Create(4); }
public FireBall(Character character) : base(character) { this.subType = (byte)PowerSubType.Fire; this.projSubType = (byte)ProjectileBallSubType.Fire; this.IconTexture = "Power/Fire"; this.baseStr = "magic"; this.subStr = "fire"; this.SetActivationSettings(60, 2, 15); // Power Settings this.multMomentum = FInt.Create(0.4); this.xVel = FInt.Create(8); this.yVel = FInt.Create(-3); this.yVelUp = FInt.Create(-3); this.yVelDown = FInt.Create(-3); }
static public void Tra_CrafterFlock(SPlayer player) { var sPlayerGroups = GameInstance.Get().GetPlayerGroups().FindAll(o => o.ownerID == player.ID); FInt extraCrafting = (FInt)5 / 2; foreach (var v in sPlayerGroups) { if (v.characters != null) { foreach (var c in v.characters) { c.Get().attributes.AddToBase(TAG.CRAFTING, extraCrafting); } } } }
private void AssignSubType(byte subType) { if (subType == (byte)SportBallSubType.Earth) { this.SpriteName = "Orb/Earth"; this.decelGround = FInt.Create(0.89f); this.decelAir = FInt.Create(0.99f); this.bounceX = FInt.Create(0.85f); this.bounceY = FInt.Create(0.5f); this.ThrowStrength = 3; this.KickStrength = 0; } else if (subType == (byte)SportBallSubType.Fire) { this.SpriteName = "Orb/Fire"; this.decelGround = FInt.Create(0.97f); this.decelAir = FInt.Create(0.998f); this.bounceX = FInt.Create(1); this.bounceY = FInt.Create(0.9f); this.ThrowStrength = 7; this.KickStrength = 4; } else if (subType == (byte)SportBallSubType.Forest) { this.SpriteName = "Orb/Forest"; this.decelGround = FInt.Create(0.94f); this.decelAir = FInt.Create(0.995f); this.bounceX = FInt.Create(0.95f); this.bounceY = FInt.Create(0.8f); this.ThrowStrength = 6; this.KickStrength = 3; } else if (subType == (byte)SportBallSubType.Water) { this.SpriteName = "Orb/Water"; this.decelGround = FInt.Create(0.92f); this.decelAir = FInt.Create(0.993f); this.bounceX = FInt.Create(0.9f); this.bounceY = FInt.Create(0.7f); this.ThrowStrength = 5; this.KickStrength = 2; } }
public static bool CanIntersect(DCollider polyA, DCollider polyB, ref FInt CombinedSqrRadius, out FInt sqrdistance) { sqrdistance = new FInt(); Vector2d vector2d; if (polyA.MyBounds.xMax >= polyB.MyBounds.xMin && polyA.MyBounds.xMin <= polyB.MyBounds.xMax && polyA.MyBounds.yMax >= polyB.MyBounds.yMin && polyA.MyBounds.yMin <= polyB.MyBounds.yMax) { polyA.center.Subtract(ref polyB.center, out vector2d); vector2d.SqrMagnitude(out sqrdistance); if (sqrdistance.RawValue <= CombinedSqrRadius.RawValue) { return(true); } } sqrdistance.RawValue = (long)0; return(false); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); //Serializing and caching fint creation if (dCollider.backupPoints.Length != dCollider.Vertices.Length) { dCollider.backupPoints = new Vector2d[dCollider.Vertices.Length]; } Vector2 vert; for (int i = 0; i < dCollider.Vertices.Length; i++) { vert = dCollider.Vertices[i]; dCollider.backupPoints[i] = new Vector2d(FInt.Create(vert.x), FInt.Create(vert.y)); } dCollider.radius = FInt.Create(dCollider.Radius); }
public RockBall(Character character) : base(character) { this.subType = (byte)PowerSubType.Rock; this.projSubType = (byte)ProjectileBallSubType.Rock; this.sound = Systems.sounds.rock; this.IconTexture = "Power/Rock"; this.baseStr = "magic"; this.subStr = "rock"; this.SetActivationSettings(60, 1, 30); // Power Settings this.multMomentum = FInt.Create(1); this.xVel = FInt.Create(1); this.yVel = FInt.Create(-1); this.yVelUp = FInt.Create(-4); this.yVelDown = FInt.Create(2); }
public FInt FlightDeceleration(FInt vel, FInt deceleration) { if (vel < 0) { if (vel + deceleration < 0) { return(vel + deceleration); } return(FInt.Create(0)); } if (vel - deceleration > 0) { return(vel - deceleration); } return(FInt.Create(0)); }
public Axe(Character character, WeaponAxeSubType subType) : base(character) { this.subType = (byte)PowerSubType.Axe; this.baseStr = "ranged"; this.subStr = "axe"; this.sound = Systems.sounds.axe; this.SetActivationSettings(72, 1, 36); // Power Settings this.multMomentum = FInt.Create(0.65); this.xVel = FInt.Create(5); this.yVel = FInt.Create(-12); this.yVelUp = FInt.Create(-18); this.yVelDown = FInt.Create(1); this.ApplySubType(subType); }
public void Advance() { if (swingDuration > Game.TIMESTEP) { hilt.gameObject.SetActive(true); swingDuration -= Game.TIMESTEP; FInt pct = swingDuration / maxDuration; switch (state) { case SwingState.STAB: position.x = 150 * (new FInt(1L) - pct) * FInt.Cos(angle + FInt.PI / 2); position.y = new FInt(61) + 150 * (new FInt(1L) - pct) * FInt.Sin(angle + FInt.PI / 2); rotation = angle; break; case SwingState.CWISE: position.x = 150 * FInt.Cos(angle + (new FInt(2) - pct) * FInt.PI / 2); position.y = new FInt(61) + 150 * FInt.Sin(angle + (new FInt(2) - pct) * FInt.PI / 2); rotation = angle + (-pct + 1) * FInt.PI / 2; break; case SwingState.CCWISE: position.x = 150 * FInt.Cos(angle + pct * FInt.PI / 2); position.y = new FInt(61) + 150 * FInt.Sin(angle + pct * FInt.PI / 2); rotation = angle - (-pct + 1) * FInt.PI / 2; break; } transform.localPosition = new Vector3(position.x.ToFloat(), position.y.ToFloat()); transform.localEulerAngles = new Vector3(0, 0, rotation.ToFloat() * 180 / Mathf.PI); hilt.position = position; CheckCollisions(); } else { hilt.gameObject.SetActive(false); if (swingCooldown > 0L) { swingCooldown -= Game.TIMESTEP; } else { state = SwingState.NONE; } } }
public override void Advance() { if (state == State.WAITING) { cooldown += Game.TIMESTEP; if (cooldown >= jumpCooldown) { cooldown = 0L; jumpDirection = Game.instance.GetNearestPlayerPosition(position); jumpDirection.x = (jumpDirection.x - position.x); jumpDirection.y = (jumpDirection.y - position.y); jumpDirection = jumpDirection.Normalize(); if (jumpDirection.x < 0L) { transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); } else { transform.localScale = new Vector3(-1.0f, 1.0f, 1.0f); } state = State.JUMPING; } } else if (state == State.JUMPING) { timeJumping += Game.TIMESTEP; if (timeJumping >= jumpDuration) { timeJumping = 0L; state = State.WAITING; } else { position.x += jumpDirection.x * speed * Game.TIMESTEP; position.y += jumpDirection.y * speed * Game.TIMESTEP; } } base.Advance(); }
public virtual void Advance() { if (coolingDown > waiting) { coolingDown -= Game.TIMESTEP; } else if (waiting > 0L) { waiting -= coolingDown; coolingDown = 0L; } else { coolingDown = 0L; } if (Game.instance.IsPlayerInRange(spawnPos, radius)) { waiting += Game.TIMESTEP; if (waiting >= waitTime) { waiting = waitTime; if (coolingDown <= 0L) { Spawn(); coolingDown += cooldown; } } } else if (waiting > 0L) { waiting -= Game.TIMESTEP; } else { waiting = 0L; } }
public FInt(FInt x) { value = x.Value(); floatValue = (float)(value / FSHIFT); }
public void Attach(Node attachPoint, int myPoint, GameObject sword, Player player) { this.player = player; parent = attachPoint.parent; // Attach this sword part by making the node point at myPoint // equivelant to the attach point FInt a1 = FInt.Atan(nodePoints[myPoint].dir.x, nodePoints[myPoint].dir.y); FInt a2 = FInt.Atan(attachPoint.dir.x, attachPoint.dir.y); FInt angle = a2 - a1 + new FInt(3.1415f); rotation = angle; FInt px = nodePoints[myPoint].pos.x; FInt py = nodePoints[myPoint].pos.y; FInt length = FInt.Sqrt((px * px) + (py * py)); FInt a3 = FInt.Atan(px, py); FInt transx = length * FInt.Cos(a3 + angle); FInt transy = length * FInt.Sin(a3 + angle); position = new FVector(attachPoint.pos.x - transx, attachPoint.pos.y - transy); transform.localEulerAngles = new Vector3(0, 0, rotation.ToFloat() * 180.0f / Mathf.PI); transform.localPosition = new Vector3(_position.x.ToFloat(), _position.y.ToFloat()); // TODO: Find depthInSword via recursive transformations // BREAKS: Proper sword construction }
public void AddPart(SwordPart part) { Node n = freeNodes[0]; FInt w = 0L; // First iteration counts the weight foreach (Node m in freeNodes) { if (m.parent.depthInSword < 0L) { continue; } w += new FInt(1.0f) + m.parent.depthInSword * m.parent.depthInSword; } if (w == 0L) { return; } FInt choose = FInt.RandomRange(OnlineNetwork.seed, 0L, w); // Second iteration finds the part at a random weight w = 0L; foreach (Node m in freeNodes) { if (m.parent.depthInSword < 0L) { continue; } w += new FInt(1.0f) + m.parent.depthInSword * m.parent.depthInSword; if (choose <= w) { n = m; break; } } part.transform.SetParent(n.parent.transform); int attachPoint = Random.Range(0, part.nodePoints.Length); part.Attach(n, attachPoint, this.gameObject, owner); freeNodes.Remove(n); part.consumedNode = n; for (int i = 0; i < part.nodePoints.Length; ++i) { if (i == attachPoint) { continue; } freeNodes.Add(part.nodePoints[i]); } parts.Add(part); weight += part.weight; }
public FVector(FVector z) { x = new FInt(z.x); y = new FInt(z.y); }
public static FInt Tan(FInt a) { FInt x = a % (2 * PI); x = x - x * x * x / 3 + x * x * x * x * x * 2 / 15 - x * x * x * x * x * x * x * 17 / 315 - x * x * x * x * x * x * x * x * x * 62 / 2835; return x; }
public static FInt Max(FInt a, FInt b) { long x = a.Value(); long y = b.Value(); return (x >= y) ? a : b; }
public override void Damage(int damage) { invincibility += new FInt(0.4f); }
public FVector(FInt first, FInt second) { x = first; y = second; }
// Arc Tangent (inverse tangent) // Uses GBA implementation: http://www.coranac.com/documents/arctangent/ public static FInt Atan(FInt dx, FInt dy) { if (dx.Value() == 0) { if (dy.Value() >= 0) { return new FInt(0.5) * PI; } else { return new FInt(1.5) * PI; } } if (dy.Value() == 0) { if (dx.Value() > 0) { return 0L; } else { return PI; } } if (dx.Value() < 0) { if (dy.Value() < 0) { return PI + Atan(-dx, -dy); } else { return PI - Atan(-dx, dy); } } else { if (dy.Value() < 0) { return 2 * PI - Atan(dx, -dy); } } bool swapAxes = false; if (dy > dx) { FInt tmp = dy; dy = dx; dx = tmp; swapAxes = true; } long t = (dy.Value() << FLOATING_BITS) / dx.Value(); long t2 = -(t * t) >> FLOATING_BITS; long t4 = (t2 * t2) >> FLOATING_BITS; long t6 = (t4 * t2) >> FLOATING_BITS; long t8 = (t4 * t4) >> FLOATING_BITS; long t10 = (t6 * t4) >> FLOATING_BITS; long t12 = (t6 * t6) >> FLOATING_BITS; long t14 = (t8 * t6) >> FLOATING_BITS; FInt x = new FInt( ((65536L * t) >> FLOATING_BITS) + ((((21845L * t) >> FLOATING_BITS) * t2) >> FLOATING_BITS) + ((((13107L * t) >> FLOATING_BITS) * t4) >> FLOATING_BITS) + ((((9102L * t) >> FLOATING_BITS) * t6) >> FLOATING_BITS) + ((((6317L * t) >> FLOATING_BITS) * t8) >> FLOATING_BITS) + ((((3664L * t) >> FLOATING_BITS) * t10) >> FLOATING_BITS) + ((((1432L * t) >> FLOATING_BITS) * t12) >> FLOATING_BITS) + ((((266L * t) >> FLOATING_BITS) * t14) >> FLOATING_BITS)); if (swapAxes) { return PI / 2 - x; } return x; }
public FVector GetWrappedPosition(FVector pos) { FInt px; if (pos.x < new FInt(-width) / 2) { px = pos.x + width; } else if (pos.x > new FInt(width) / 2) { px = pos.x - width; } else { px = new FInt(pos.x); } FInt py; if (pos.y < new FInt(-height) / 2) { py = pos.y + height; } else if (pos.y > new FInt(height) / 2) { py = pos.y - height; } else { py = new FInt(pos.y); } return new FVector(px, py); }
public void Swing(SwingState swingType, FInt swingAngle) { if (state != SwingState.NONE) { return; } state = swingType; swingDuration = new FInt(0.1f) + new FInt(0.025f) * weight; maxDuration = swingDuration; swingCooldown = new FInt(0.1f) + new FInt(0.01f) * weight; switch (state) { case SwingState.STAB: angle = swingAngle - FInt.PI / 2; break; case SwingState.CWISE: angle = swingAngle - FInt.PI; break; case SwingState.CCWISE: angle = swingAngle; break; } }
public static FInt Sin(FInt a) { FInt x = a % (2 * PI); bool overPi = x > PI; if (overPi) { x -= PI; } x = x - x * x * x / 6 + x * x * x * x * x / 120 - x * x * x * x * x * x * x / 5040 + x * x * x * x * x * x * x * x * x / 362880; if (overPi) { x = -x; } return x; }
public static bool CircleToCircle(FVector p1, FVector p2, FInt r1, FInt r2) { return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y) <= (r1 + r2) * (r1 + r2); }
// Return random FInt within a range. Includes both end points. public static FInt RandomRange(System.Random seed, FInt min, FInt max) { if (min > max) { Debug.LogError("Min must be less than max. Min: " + min.ToString() + ", Max: " + max.ToString()); return 0L; } FInt r = new FInt((long)seed.Next()); FInt diff = max - min; return (r * diff) / new FInt(2147483648L) + min; }
public static FInt Cos(FInt a) { FInt x = a % (2 * PI); bool overPi = x > PI; if (overPi) { x -= PI; } x = new FInt(1) - x * x / 2 + x * x * x * x / 24 - x * x * x * x * x * x / 720 + x * x * x * x * x * x * x * x / 40320 - x * x * x * x * x * x * x * x * x * x / 3628800; if (overPi) { x = -x; } return x; }
public static FInt Min(FInt a, FInt b) { long x = a.Value(); long y = b.Value(); return (x >= y) ? b : a; }
public void Attack( int sourceTeam, FVector source, FInt radius, int damage) { // Generate a list of characters to do a generic hit test Character[] characters = new Character[players.Count + enemies.Count]; int i = 0; foreach (Player player in players) { characters[i] = player; ++i; } foreach (Enemy enemy in enemies) { characters[i] = enemy; ++i; } for (i = 0; i < players.Count + enemies.Count; ++i) { Character character = characters[i]; if (character.team != sourceTeam && character.invincibility <= 0L && Collision.CircleToCircle( source, character.position, radius, character.radius)) { character.Damage(damage); } } }
public static FInt Distance(FInt x1, FInt y1, FInt x2, FInt y2) { return FInt.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
public bool IsPlayerInRange(FVector pos, FInt radius) { foreach (Player p in players) { if (Collision.CircleToCircle(p.position, pos, Player.PRADIUS, radius)) { return true; } } return false; }
public static FInt Sqrt(FInt a) { if (a.Value() == 0L) { return a; } FInt x = 1L; for (int i = 0; i < 64; i++) { x = (x + a / x) / 2; } return x; }