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 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(); }
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); }
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); } }
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(); }
/// <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; }
/// <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)); }
/// <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)); }
public static FVector operator -(FVector x, FVector y) { FVector z = new FVector(x.x - y.x, x.y - y.y); return z; }
/// <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; }
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 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; }
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); }
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); } }
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); }
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); }
public FVector(FVector z) { x = new FInt(z.x); y = new FInt(z.y); }
public static FVector operator /(FVector x, FInt y) { FVector z = new FVector(x.x / y, x.y / y); return z; }
public static FVector operator *(FVector x, FInt y) { FVector z = new FVector(x.x * y, x.y * y); return z; }
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); }
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); }
public void SummonEnemy(GameObject enemyObject, FVector pos) { Enemy enemy = world.SummonEnemy(enemyObject, pos); enemy.Setup(pos); enemies.Add(enemy); }
public Enemy(RoomScene room, byte subType, FVector pos, Dictionary <string, short> paramList) : base(room, subType, pos, paramList) { }
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; }
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); }
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 FTransform(EForceInit init = EForceInit.ForceInit) { Rotation = new FQuat(0f, 0f, 0f, 1f); Translation = new FVector(0f); Scale3D = FVector.OneVector; }
/// <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)); }
public FTransform(FQuat rotation, FVector translation, FVector scale3D) { Rotation = rotation; Translation = translation; Scale3D = scale3D; }
/// <summary> /// Set the initial values of the bounding box to Zero. /// </summary> public void Init() { Min = Max = FVector.ZeroVector; isValid = 0; }
public FTransform(FRotator rotation, FVector translation, FVector scale3D) { Rotation = new FQuat(rotation); Translation = translation; Scale3D = scale3D; }
/// <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)); }
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;
/// <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)); }
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); }
// 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); }
public void SetVelocity(FVector velocity) { this.physics.velocity = velocity; }
public FVector GetWrappedPosition(FVector pos) { return world.GetWrappedPosition(pos); }
/// <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); }
private void DropPart(GameObject swordPartObject, FVector pos) { SwordPart part = world.DropPart(swordPartObject, pos); part.Setup(pos); swordParts.Add(part); }
private void TouchStopped(ETouchIndex fingerIndex, FVector location) { // Cease jumping once touch stopped StopJumping(); }
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; }
private void TouchStart(ETouchIndex fingerIndex, FVector location) { // Jump on any touch Jump(); }
public static FVector Lerp(FVector A, FVector B, float V) { return(A + (B - A) * V); }
public void Setup(FVector pos) { position = new FVector(pos); transform.position = new Vector3(pos.x.ToFloat(), pos.y.ToFloat()); }
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; }
/// <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)); }
/// <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)); }
public static FVector operator +(FVector x, FVector y) { FVector z = new FVector(x.x + y.x, x.y + y.y); return z; }
public void Setup(FVector pos) { position = pos; }
/// <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)); }
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 }
/// <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)); }