Esempio n. 1
0
 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());
 }
Esempio n. 2
0
    public override void Advance()
    {
        FVector dpos = new FVector(input.xAxis, -input.yAxis);
        dpos = dpos.Normalize();
        if (input.stab && input.stabChanged)
        {
            // Swing counter-clockwise
            sword.Swing(Sword.SwingState.CCWISE, facing);
        }
        else if (input.swingLeft && input.swingLeftChanged)
        {
            // Stab
            sword.Swing(Sword.SwingState.STAB, facing);
        }
        else if (input.swingRight && input.swingRightChanged)
        {
            // Swing clockwise
            sword.Swing(Sword.SwingState.CWISE, facing);
        }

        if (dpos.x != 0L || dpos.y != 0L)
        {
            position.x += dpos.x * CalculateSpeed() * Game.TIMESTEP;
            position.y += dpos.y * CalculateSpeed() * Game.TIMESTEP;
            lastFacing.RemoveAt(0);
            lastFacing.Add(dpos);
        }

        FInt fdx = 0L;
        FInt fdy = 0L;
        foreach (FVector vec in lastFacing)
        {
            fdx += vec.x;
            fdy += vec.y;
        }

        // TODO: Clean up this hack with animations
        if (fdx < 0L)
        {
            characterImg.transform.localPosition = new Vector3(30, 118, 0);
            characterImg.transform.localScale = new Vector3(184, 253, 1);
            characterMask.transform.localScale = new Vector3(137, 148, 1);
        }
        else
        {
            characterImg.transform.localPosition = new Vector3(-30, 118, 0);
            characterImg.transform.localScale = new Vector3(-184, 253, 1);
            characterMask.transform.localScale = new Vector3(-137, 148, 1);
        }

        sword.Advance();
        base.Advance();
    }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
    void OnDrawGizmos()
    {
        Gizmos.color = new Color(0f, 0f, 1f, 0.5f);
        Gizmos.DrawSphere(new Vector3(position.x.ToFloat(), position.y.ToFloat()), radius.ToFloat());

        Gizmos.color = new Color(0f, 1f, 0f, 0.5f);
        FInt myGlobalRotation = GetGlobalRotation();
        foreach(Node node in nodePoints)
        {
            FVector nodePos = new FVector(node.pos).Rotate(myGlobalRotation);
            nodePos += position;
            Gizmos.DrawSphere(new Vector3(nodePos.x.ToFloat(), nodePos.y.ToFloat()), 20);
        }
        if (parent != null)
        {
            Gizmos.color = new Color(1f, 0f, 1f, 0.5f);
            FVector consumedNodePos = new FVector(consumedNode.pos).Rotate(myGlobalRotation - rotation);
            consumedNodePos += parent.position;
            Gizmos.DrawSphere(new Vector3(consumedNodePos.x.ToFloat(), consumedNodePos.y.ToFloat()), 20);
        }
    }
Esempio n. 5
0
 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();
 }
Esempio n. 6
0
 /// <summary>
 /// Creates and initializes a new box from the specified extents.
 /// </summary>
 /// <param name="min">The box's minimum point.</param>
 /// <param name="max">The box's maximum point.</param>
 public FBox(FVector min, FVector max)
 {
     Min     = min;
     Max     = max;
     isValid = 1;
 }
Esempio n. 7
0
 /// <summary>
 /// Checks whether the given location is inside this box.
 /// </summary>
 /// <param name="v">The location to test for inside the bounding volume.</param>
 /// <returns>true if location is inside this volume.</returns>
 public bool IsInside(FVector v)
 {
     return((v.X > Min.X) && (v.X < Max.X) && (v.Y > Min.Y) && (v.Y < Max.Y) && (v.Z > Min.Z) && (v.Z < Max.Z));
 }
Esempio n. 8
0
 /// <summary>
 /// Checks whether the given location is inside this box in the XY plane.
 /// </summary>
 /// <param name="v">The location to test for inside the bounding box.</param>
 /// <returns>true if location is inside this box in the XY plane.</returns>
 /// <see cref="IsInside(FVector)"/>
 public bool IsInsideXY(FVector v)
 {
     return((v.X > Min.X) && (v.X < Max.X) && (v.Y > Min.Y) && (v.Y < Max.Y));
 }
Esempio n. 9
0
 public static FVector operator -(FVector x, FVector y)
 {
     FVector z = new FVector(x.x - y.x, x.y - y.y);
     return z;
 }
Esempio n. 10
0
 /// <summary>
 /// Gets the center and extents of this box.
 /// </summary>
 /// <param name="center">Will contain the box center point.</param>
 /// <param name="extents">Will contain the extent around the center.</param>
 /// <see cref="GetCenter"/>
 /// <see cref="GetExtent"/>
 /// <see cref="GetSize"/>
 /// <see cref="GetVolume"/>
 public void GetCenterAndExtents(out FVector center, out FVector extents)
 {
     extents = GetExtent();
     center  = Min + extents;
 }
Esempio n. 11
0
 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);
         }
     }
 }
Esempio n. 12
0
 public SwordPart DropPart(GameObject swordPartObject, FVector pos)
 {
     GameObject obj = Instantiate(swordPartPrefabs[0]) as GameObject;
     obj.transform.SetParent(this.transform);
     obj.transform.position = new Vector3(pos.x.ToFloat(), pos.y.ToFloat());
     SwordPart part = obj.GetComponent<SwordPart>();
     return part;
 }
Esempio n. 13
0
        private static object ReadDataType(RepLayoutCmdType replayout, NetBitReader netBitReader, Type objectType = null)
        {
            object data = null;

            switch (replayout)
            {
            case RepLayoutCmdType.Property:
                data = Activator.CreateInstance(objectType);
                (data as IProperty).Serialize(netBitReader);
                break;

            case RepLayoutCmdType.PropertyBool:
                data = netBitReader.SerializePropertyBool();
                break;

            case RepLayoutCmdType.PropertyName:
                netBitReader.Seek(netBitReader.Position + netBitReader.GetBitsLeft());
                break;

            case RepLayoutCmdType.PropertyFloat:
                data = netBitReader.SerializePropertyFloat();
                break;

            case RepLayoutCmdType.PropertyNativeBool:
                data = netBitReader.SerializePropertyNativeBool();
                break;

            case RepLayoutCmdType.PropertyNetId:
                data = netBitReader.SerializePropertyNetId();
                break;

            case RepLayoutCmdType.PropertyObject:
                data = netBitReader.SerializePropertyObject();
                break;

            case RepLayoutCmdType.PropertyPlane:
                throw new NotImplementedException("Plane RepLayoutCmdType not implemented");

            case RepLayoutCmdType.PropertyRotator:
                data = netBitReader.SerializePropertyRotator();
                break;

            case RepLayoutCmdType.PropertyString:
                data = netBitReader.SerializePropertyString();
                break;

            case RepLayoutCmdType.PropertyVector10:
                data = netBitReader.SerializePropertyVector10();
                break;

            case RepLayoutCmdType.PropertyVector100:
                data = netBitReader.SerializePropertyVector100();
                break;

            case RepLayoutCmdType.PropertyVectorNormal:
                data = netBitReader.SerializePropertyVectorNormal();
                break;

            case RepLayoutCmdType.PropertyVectorQ:
                data = netBitReader.SerializePropertyQuantizeVector();
                break;

            case RepLayoutCmdType.RepMovement:
                data = netBitReader.SerializeRepMovement();
                break;

            case RepLayoutCmdType.Enum:
                data = netBitReader.SerializeEnum();
                break;

            //Auto generation fix to handle 1-8 bits
            case RepLayoutCmdType.PropertyByte:
                data = (byte)netBitReader.ReadBitsToInt(netBitReader.GetBitsLeft());
                break;

            //Auto generation fix to handle 1-32 bits.
            case RepLayoutCmdType.PropertyInt:
                data = netBitReader.ReadBitsToInt(netBitReader.GetBitsLeft());
                break;

            case RepLayoutCmdType.PropertyUInt64:
                data = netBitReader.ReadUInt64();
                break;

            case RepLayoutCmdType.PropertyUInt16:
                data = (ushort)netBitReader.ReadBitsToInt(netBitReader.GetBitsLeft());
                break;

            case RepLayoutCmdType.PropertyUInt32:
                data = netBitReader.ReadUInt32();
                break;

            case RepLayoutCmdType.Pointer:
                switch (netBitReader.GetBitsLeft())
                {
                case 8:
                    data = (uint)netBitReader.ReadByte();
                    break;

                case 16:
                    data = (uint)netBitReader.ReadUInt16();
                    break;

                case 32:
                    data = netBitReader.ReadUInt32();
                    break;
                }
                break;

            case RepLayoutCmdType.PropertyVector:
                data = new FVector(netBitReader.ReadSingle(), netBitReader.ReadSingle(), netBitReader.ReadSingle());
                break;

            case RepLayoutCmdType.Ignore:
                netBitReader.Seek(netBitReader.Position + netBitReader.GetBitsLeft());
                break;
            }

            return(data);
        }
Esempio n. 14
0
        public override void RunTick()
        {
            base.RunTick();

            // Check if an attack needs to be made:
            if (this.attack.AttackThisFrame())
            {
                ProjectileEnemy projectile = ProjectileEnemy.Create(room, (byte)ProjectileEnemySubType.Fire, FVector.Create(this.posX + this.bounds.MidX - 10, this.posY + this.bounds.MidY - 10), FVector.Create(this.attSpeed, 0));
                projectile.physics.SetGravity(this.gravity);
                this.room.PlaySound(Systems.sounds.flame, 0.6f, this.posX + 16, this.posY + 16);
            }
        }
Esempio n. 15
0
        public static GrenadeProjectile Create(RoomScene room, byte subType, FVector pos, FVector velocity)
        {
            // Retrieve an available projectile from the pool.
            GrenadeProjectile projectile = ProjectilePool.GrenadeProjectile.GetObject();

            projectile.ResetProjectile(room, subType, pos, velocity);
            projectile.SetState((byte)CommonState.Move);
            projectile.AssignBoundsByAtlas(2, 2, -2, -2);
            projectile.spinRate = projectile.physics.velocity.X > 0 ? 0.07f : -0.07f;

            // Add the Projectile to Scene
            room.AddToScene(projectile, false);

            return(projectile);
        }
Esempio n. 16
0
 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);
 }
Esempio n. 17
0
 public FVector(FVector z)
 {
     x = new FInt(z.x);
     y = new FInt(z.y);
 }
Esempio n. 18
0
 public static FVector operator /(FVector x, FInt y)
 {
     FVector z = new FVector(x.x / y, x.y / y);
     return z;
 }
Esempio n. 19
0
 public static FVector operator *(FVector x, FInt y)
 {
     FVector z = new FVector(x.x * y, x.y * y);
     return z;
 }
Esempio n. 20
0
 public T SpawnActor <T>(FVector location, FRotator rotation, FActorSpawnParametersInterop parameters) where T : AActor
 {
     return(SpawnActor(UClass.GetClass <T>(), ref location, ref rotation, ref parameters) as T);
 }
Esempio n. 21
0
        public override void Launch(GameObject actor, int posX, int posY, FInt velX, FInt velY)
        {
            var projectile = ProjectileBolt.Create(actor.room, (byte)ProjectileBoltSubType.Gold, FVector.Create(posX, posY), FVector.Create(velX, velY));

            projectile.SetActorID(actor);
        }
Esempio n. 22
0
 public void SummonEnemy(GameObject enemyObject, FVector pos)
 {
     Enemy enemy = world.SummonEnemy(enemyObject, pos);
     enemy.Setup(pos);
     enemies.Add(enemy);
 }
Esempio n. 23
0
 public Enemy(RoomScene room, byte subType, FVector pos, Dictionary <string, short> paramList) : base(room, subType, pos, paramList)
 {
 }
Esempio n. 24
0
 public FVector GetNearestPlayerPosition(FVector position)
 {
     FVector pos = new FVector(players[0].position);
     FInt dist = Collision.Distance(pos.x, pos.y, position.x, position.y);
     foreach (Player player in players)
     {
         FInt newDist = Collision.Distance(player.position.x, player.position.y, position.x, position.y);
         if (dist > newDist)
         {
             dist = newDist;
             pos = new FVector(player.position);
         }
     }
     return pos;
 }
Esempio n. 25
0
        public static DaggerProjectile Create(RoomScene room, byte subType, FVector pos, FVector velocity)
        {
            // Retrieve an available projectile from the pool.
            DaggerProjectile projectile = ProjectilePool.DaggerProjectile.GetObject();

            projectile.ResetProjectile(room, subType, pos, velocity);
            projectile.AssignBoundsByAtlas(5, 5, -5, -5);             // Reduce Bounds (otherwise it appears to hit too much, too quickly)
            projectile.rotation = projectile.physics.velocity.X > 0 ? 0 : Radians.Rotate180;

            // Add the Projectile to Scene
            room.AddToScene(projectile, false);

            return(projectile);
        }
Esempio n. 26
0
 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);
 }
Esempio n. 27
0
 public FTransform(EForceInit init = EForceInit.ForceInit)
 {
     Rotation    = new FQuat(0f, 0f, 0f, 1f);
     Translation = new FVector(0f);
     Scale3D     = FVector.OneVector;
 }
Esempio n. 28
0
        /// <summary>
        /// Moves the center of bounding box to new destination.
        /// </summary>
        /// <param name="destination">The destination point to move center of box to.</param>
        /// <returns>A new bounding box.</returns>
        public FBox MoveTo(FVector destination)
        {
            FVector offset = destination - GetCenter();

            return(new FBox(Min + offset, Max + offset));
        }
Esempio n. 29
0
 public FTransform(FQuat rotation, FVector translation, FVector scale3D)
 {
     Rotation    = rotation;
     Translation = translation;
     Scale3D     = scale3D;
 }
Esempio n. 30
0
 /// <summary>
 /// Set the initial values of the bounding box to Zero.
 /// </summary>
 public void Init()
 {
     Min     = Max = FVector.ZeroVector;
     isValid = 0;
 }
Esempio n. 31
0
 public FTransform(FRotator rotation, FVector translation, FVector scale3D)
 {
     Rotation    = new FQuat(rotation);
     Translation = translation;
     Scale3D     = scale3D;
 }
Esempio n. 32
0
 /// <summary>
 /// Checks whether the given location is inside or on this box.
 /// </summary>
 /// <param name="v">The location to test for inside the bounding volume.</param>
 /// <returns>true if location is inside this volume.</returns>
 /// <see cref="IsInsideXY(FVector)"/>
 public bool IsInsideOrOn(FVector v)
 {
     return((v.X >= Min.X) && (v.X <= Max.X) && (v.Y >= Min.Y) && (v.Y <= Max.Y) && (v.Z >= Min.Z) && (v.Z <= Max.Z));
 }
Esempio n. 33
0
 public static bool AnyHasNegativeScale(FVector scale3D, FVector otherScale3D) => scale3D.X < 0 || scale3D.Y < 0 || scale3D.Z < 0 ||
 otherScale3D.X < 0 || otherScale3D.Y < 0 || otherScale3D.Z < 0;
Esempio n. 34
0
 /// <summary>
 /// Utility function to build an AABB from Origin and Extent
 /// </summary>
 /// <param name="origin">The location of the bounding box.</param>
 /// <param name="extent">Half size of the bounding box.</param>
 /// <returns>A new axis-aligned bounding box.</returns>
 public static FBox BuildAABB(FVector origin, FVector extent)
 {
     return(new FBox(origin - extent, origin + extent));
 }
Esempio n. 35
0
 public Projectile(RoomScene room, byte subType, FVector pos, FVector velocity) : base(room, subType, pos)
 {
     this.Meta    = Systems.mapper.MetaList[MetaGroup.Projectile];
     this.physics = new Physics(this);
     this.ResetProjectile(room, subType, pos, velocity);
 }
Esempio n. 36
0
        // Functions.

        /**
         * Calculates distance between plane and a point.
         *
         * @param P The other point.
         * @return >0: point is in front of the plane, <0: behind, =0: on the plane.
         */
        public float PlaneDot(FVector P)
        {
            return(X * P.X + Y * P.Y + Z * P.Z - W);
        }
Esempio n. 37
0
 public void SetVelocity(FVector velocity)
 {
     this.physics.velocity = velocity;
 }
Esempio n. 38
0
 public FVector GetWrappedPosition(FVector pos)
 {
     return world.GetWrappedPosition(pos);
 }
Esempio n. 39
0
 /// <summary>
 /// Adds to the bounding box to include a given point.
 /// </summary>
 /// <param name="box">The rectangle.</param>
 /// <param name="other">The point to increase the bounding volume to.</param>
 /// <returns>The bounding box after resizing to include the other point.</returns>
 public static FBox Add(FBox box, FVector other)
 {
     Add(ref box, ref other, out box);
     return(box);
 }
Esempio n. 40
0
 private void DropPart(GameObject swordPartObject, FVector pos)
 {
     SwordPart part = world.DropPart(swordPartObject, pos);
     part.Setup(pos);
     swordParts.Add(part);
 }
Esempio n. 41
0
 private void TouchStopped(ETouchIndex fingerIndex, FVector location)
 {
     // Cease jumping once touch stopped
     StopJumping();
 }
Esempio n. 42
0
 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;
 }
Esempio n. 43
0
 private void TouchStart(ETouchIndex fingerIndex, FVector location)
 {
     // Jump on any touch
     Jump();
 }
Esempio n. 44
0
 public static FVector Lerp(FVector A, FVector B, float V)
 {
     return(A + (B - A) * V);
 }
Esempio n. 45
0
 public void Setup(FVector pos)
 {
     position = new FVector(pos);
     transform.position = new Vector3(pos.x.ToFloat(), pos.y.ToFloat());
 }
Esempio n. 46
0
 public Enemy SummonEnemy(GameObject enemyObject, FVector pos)
 {
     GameObject obj = Instantiate(enemyObject);
     obj.transform.SetParent(transform);
     obj.transform.position = new Vector3(pos.x.ToFloat(), pos.y.ToFloat());
     Enemy enemy = obj.GetComponent<Enemy>();
     return enemy;
 }
Esempio n. 47
0
 /// <summary>
 /// Shifts the bounding box position.
 /// </summary>
 /// <param name="offset">The vector to shift the box by.</param>
 /// <returns>A new bounding box.</returns>
 public FBox ShiftBy(FVector offset)
 {
     return(new FBox(Min + offset, Max + offset));
 }
Esempio n. 48
0
 /// <summary>
 /// Calculates the distance of a point to this box.
 /// </summary>
 /// <param name="point">The point.</param>
 /// <returns>The distance.</returns>
 public float ComputeSquaredDistanceToPoint(FVector point)
 {
     return(FVector.ComputeSquaredDistanceFromBoxToPoint(Min, Max, point));
 }
Esempio n. 49
0
 public static FVector operator +(FVector x, FVector y)
 {
     FVector z = new FVector(x.x + y.x, x.y + y.y);
     return z;
 }
Esempio n. 50
0
 public void Setup(FVector pos)
 {
     position = pos;
 }
Esempio n. 51
0
 /// <summary>
 /// Increases the box size.
 /// </summary>
 /// <param name="v">The size to increase the volume by.</param>
 /// <returns>A new bounding box.</returns>
 public FBox ExpandBy(FVector v)
 {
     return(new FBox(Min - v, Max + v));
 }
Esempio n. 52
0
    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
    }
Esempio n. 53
0
 /// <summary>
 /// Increases the box size.
 /// </summary>
 /// <param name="neg">The size to increase the volume by in the negative direction (positive values move the bounds outwards)</param>
 /// <param name="pos">The size to increase the volume by in the positive direction (positive values move the bounds outwards)</param>
 /// <returns>A new bounding box.</returns>
 public FBox ExpandBy(FVector neg, FVector pos)
 {
     return(new FBox(Min - neg, Max + pos));
 }