void Update() { float speed = Body.velocity.magnitude; if (speed > MaxSpeed) { Body.velocity = Body.velocity.normalized * MaxSpeed; } if (speed < MinSpeed) { Body.velocity = Body.velocity.normalized * MinSpeed; } //var axisSpeedVec = SpeedAxel.InverseTransformVector(Body.velocity); //float axisSpeed = axisSpeedVec.z; //if (axisSpeed < MinSpeedAxelRelative) { vec1 = SpeedAxel.forward * MinSpeedAxelRelative; vec2 = Body.velocity; var speedPoint = MathHelp.ProjectPointOnLine(Vector3.zero, Body.velocity, SpeedAxel.forward * MinSpeedAxelRelative); //Body.velocity = speedPoint; vec3 = speedPoint; } //Trans.rotation = Quaternion.RotateTowards(Trans.rotation, Quaternion.Euler(0, 1, 0), StabalizingSpeed * Time.deltaTime); }
public bool HaveCommonElementWith(MarginPosition position) { if (!((IsVertical && position.IsVertical) || (IsHorizontal && position.IsHorizontal))) { return(false); } if (IsVertical) { if (StartPoint.X != position.StartPoint.X) { return(false); } else { return(MathHelp.SegmentsHaveCommonElement(StartPoint.Y, EndPoint.Y, position.StartPoint.Y, position.EndPoint.Y)); } } else { if (StartPoint.Y != position.StartPoint.Y) { return(false); } else { return(MathHelp.SegmentsHaveCommonElement(StartPoint.X, EndPoint.X, position.StartPoint.X, position.EndPoint.X)); } } }
public override void AI() { Projectile.scale = 3f; if (MathHelp.Magnitude(Projectile.velocity) > 0) { Projectile.velocity.Y += 0.1f; Projectile.frame = (Projectile.velocity.Y == 0)?0:((Projectile.velocity.Y > 0)?4:5); } else { Projectile.frame = 0; } for (int i = 0; i < Main.maxNPCs; i++) { if (Main.npc[i].active && !Main.npc[i].friendly && !Main.npc[i].townNPC) { if (Vector2.Distance(Main.npc[i].Center, Projectile.Center) < (Main.npc[i].width + Main.npc[i].height) / 2 + (Projectile.width + Projectile.height) / 2) { Main.npc[i].life = 0; Main.npc[i].checkDead(); } } } }
public override void AI() { Projectile.scale = 0.5f; if (Projectile.ai[0] < 30) { Projectile.velocity.Y -= 0.1f; Projectile.velocity *= (MathHelp.Magnitude(Projectile.velocity) > 1) ? 0.9f : 1f; Projectile.ai[0]++; } else { if (CheckTarget()) { Projectile.velocity = MathHelp.Normalize(targetLastPos - Projectile.Center) * 7; if (Vector2.Distance(targetLastPos, Projectile.Center) < Projectile.width) { Projectile.timeLeft = 1; } } else { Projectile.velocity *= (MathHelp.Magnitude(Projectile.velocity) > 1)?0.9f:1f; } } }
bool CheckTarget() { if (MathHelp.Magnitude(targetLastPos) == 0) { if (target == -1 || !Main.npc[target].active || Main.npc[target].friendly) { target = -1; NPC postarget; for (int i = 0; i < Main.maxNPCs; i++) { postarget = Main.npc[i]; if (postarget.active && !postarget.townNPC && !postarget.friendly && postarget.CanBeChasedBy(this)) { if (target == -1) { target = i; targetLastPos = postarget.Center; } else if (Vector2.Distance(Projectile.Center, postarget.Center) < Vector2.Distance(Projectile.Center, Main.npc[target].Center)) { target = i; targetLastPos = postarget.Center; } } } } } return(MathHelp.Magnitude(targetLastPos) != 0); }
public override void AI() { if (MathHelp.Magnitude(Projectile.velocity) > 0) { Projectile.velocity.Y += 0.1f; } }
protected new void Update() { base.Update(); _moveLerpTime = MathHelp.Clamp(_moveLerpTime + Time.deltaTime * movementSpeed, _moveMinClamp, _moveMaxClamp); _rotationLerpTime = MathHelp.Clamp(_rotationLerpTime + Time.deltaTime * rotationSpeed, _rotationMaxClamp, _rotationMinClamp); _isUp = _moveLerpTime == _moveMaxClamp; _isDown = _moveLerpTime == _moveMinClamp; float totalMass = 0; for (int i = 0; i < _colliders.Length; i++) { if (_colliders[i].GetComponent <Item>()) { totalMass += _colliders[i].GetComponent <Rigidbody>().mass; } } if (totalMass >= _massThreshold) { _hasWeight = true; GoDown(); } else { _hasWeight = false; } transform.position = Vector3.Lerp(_pressedPos, _unpressedPos, _moveLerpTime); }
private void Update() { #region color if (_isUnderCursor) { _isUnderCursor = false; } else { _material.color = _defaultColor; } #endregion _oldIsSendingSignal = _isSendingSignal; _isSendingSignal = _currentStep == ActiveStep - 1; _isUsedInPuzzle = _puzzleMaster != null; _lerpTime = MathHelp.Clamp(_lerpTime + Time.deltaTime * Speed, _minLerp, _maxLerp); transform.position = Vector3.Lerp(Off.position, On.position, _lerpTime); transform.rotation = Quaternion.Lerp(Off.rotation, On.rotation, _lerpTime); if (_isUsedInPuzzle) { CheckSingalChanged(); } }
private void Update() { #region color if (_isUnderCursor) { _isUnderCursor = false; } else { _material.color = _defaultColor; } #endregion _lerpTime = MathHelp.Clamp(_lerpTime + Time.deltaTime * speed, _minLerp, _maxLerp); transform.position = Vector3.Lerp(off.position, on.position, _lerpTime); transform.rotation = Quaternion.Lerp(off.rotation, on.rotation, _lerpTime); if (_lerpTime == _minLerp || _lerpTime == _maxLerp) { enabled = false; } }
public override void update(GameTime time) { base.update(time); if (this.FadeTime < 256) { this.FadeTime += MathHelp.ceil((256 - this.FadeTime) / 10D); if (this.FadeTime >= 256) { if (this.ShouldClose) { EvolvinaryMain.get().openGui(null); } else { this.ButtonList.Add(new ButtonTextOnly(1, this, 60, 30, 150, 20, "Save Game", 2F)); this.ButtonList.Add(new ButtonTextOnly(2, this, 60, 80, 150, 20, "Load Game", 2F)); this.ButtonList.Add(new ButtonTextOnly(3, this, 60, 130, 150, 20, "Start New Game", 2F)); this.ButtonList.Add(new ButtonTextOnly(4, this, 60, 180, 150, 20, "Options", 2F)); this.ButtonList.Add(new ButtonTextOnly(5, this, 60, 230, 150, 20, "To Title Screen", 2F)); this.ButtonList.Add(new ButtonTextOnly(6, this, 60, 280, 150, 20, "Quit Game", 2F)); this.hasButtons = true; } } } }
public override void Ephemerides() { Diameter = d0 / this.Distance; double test = (this.SunDistance * this.SunDistance + this.Distance * this.Distance - helDist * helDist) / (2 * this.SunDistance * this.Distance + 0.000000001); if (test < -1) { test = -1; } if (test > 1) { test = 1; } Elongation = Math.Acos(test) * 180 / Math.PI; test = (helDist * helDist + this.Distance * this.Distance - this.SunDistance * this.SunDistance) / (2 * helDist * this.Distance + 0.000000001); if (test < -1) { test = -1; } if (test > 1) { test = 1; } this.FV = Math.Acos(test) * 180 / Math.PI; this.Phase = (1 + Math.Cos(MathHelp.DegreeToRadian(this.FV))) / 2; this.Magnitude = -7.15 + 5 * Math.Log10(helDist * this.Distance) + 0.001 * this.FV; }
public void UpdateVolumeSlider(float speed) { if (isMusicNoice) { _lerpTime = musicNoice; } if (isSoundNoice) { _lerpTime = soundNoice; } _lerpTime = MathHelp.Clamp(_lerpTime + Time.unscaledDeltaTime * speed, 0f, 1f); transform.position = Vector3.Lerp(mute.position, noice.position, _lerpTime); transform.rotation = Quaternion.Lerp(mute.rotation, noice.rotation, _lerpTime); if (isMusicNoice) { musicNoice = _lerpTime; SaveLoad.Floats[SaveLoad.MUSIC_NOICE] = musicNoice; } if (isSoundNoice) { soundNoice = _lerpTime; SaveLoad.Floats[SaveLoad.SOUND_NOICE] = soundNoice; } SaveLoad.Save(); }
public EntityAIAvoid(Entity e, int min, int max) : base(e, 6) { MaxDist = (int)MathHelp.constrain(max, 1, e.Map.Width - 32); MinDist = (int)MathHelp.constrain(min, 0, MaxDist); targetX = -1; }
public override void AI() { if (Main.rand.Next(2) == 0 && MathHelp.Magnitude(Projectile.velocity) > 0) { Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, DustID.Torch); } }
private void Update() { if (_stopFade && _sinValue > 0.9f) { #region show and hide _showHideLerp = MathHelp.Clamp(_showHideLerp + Time.deltaTime * showHideSpeed, 0f, 1f); _infoMaterial.mainTextureOffset = Vector2.Lerp(hideOffset, showOffset, _showHideLerp); _infoMaterial.mainTextureScale = Vector2.Lerp(hideScale, showScale, _showHideLerp); _stopFade = _showHideLerp != 1f; #endregion } else { #region alpha fade // timer _fadeTimer += Time.deltaTime * alphaSpeed; _sinValue = Mathf.Sin(_fadeTimer) * 0.5f + 0.5f; // set colors alpha value (between min and max) _defaultColor.a = minAlpha + _sinValue * (maxAlpha - minAlpha); // set color to material _infoMaterial.color = _defaultColor; #endregion } }
private void addToOpenList(SubWaypoint parent, Entity entity) { var adjacent = World.getAdjacentCoords(MathHelp.floor(parent.Pos.X), MathHelp.floor(parent.Pos.Y), false); foreach (var coord in adjacent) { if (entity.World.isWalkableExcept(MathHelp.floor(coord.X), MathHelp.floor(coord.Y), entity)) { var subWaypoint = new SubWaypoint(coord, parent, this.Goal); if (getContainedSubWaypoint(this.closedList, subWaypoint) == null) { var contained = getContainedSubWaypoint(this.openList, subWaypoint); if (contained == null) { this.openList.Add(subWaypoint); } else { if (parent.CostFromStart + 10 < contained.CostFromStart) { contained.Parent = parent; contained.calculateCosts(this.Goal); } } } } } }
private new void Update() { #region color if (_isUnderCursor) { _isUnderCursor = false; } else { _material.color = _defaultColor; } #endregion base.Update(); if (_colliders.Length > 0 && speed < 0) { return; } _lerpTime = MathHelp.Clamp(_lerpTime + Time.deltaTime * speed, 0f, 1f); transform.position = Vector3.Lerp(close.position, open.position, _lerpTime); offset = close.position - transform.position; }
public virtual bool canPlace(PlayerData placerPlayer, World world, Vector2 pos) { var box = this.BoundingBox.offset(pos); var entities = world.getEntitiesInBound(box, null, false); foreach (var entity in entities) { if (!entity.isWalkable()) { return(false); } } for (var x = 0; x < box.Width; x++) { for (var y = 0; y < box.Height; y++) { var cell = world.getTile(MathHelp.floor(box.X + x), MathHelp.floor(box.Y + y)); if (cell == null || !cell.isWalkable()) { return(false); } } } return(true); }
protected void setJointMotor(RevoluteJoint joint, float targetAngle) { float radDiff = MathHelp.getRadDiff(joint.JointAngle, targetAngle); joint.MotorSpeed = radDiff * 10; joint.MaxMotorTorque = 2500; }
protected virtual void track() { reloadClock--; if (!inRange()) { state = State.Scanning; } Vector2 targetVector = target.Position - body.Position; float targetAngle = (float)Math.Atan2(targetVector.Y, targetVector.X); float radDiff = MathHelp.getRadDiff(body.Rotation, targetAngle); if (Math.Abs(radDiff) > rotationSpeed) { body.Rotation += MathHelp.clamp(radDiff, rotationSpeed, -rotationSpeed); } else { if (hasLineOfSight()) { body.Rotation += radDiff; if (reloadClock <= 0) { prepFireState(); state = State.Firing; } } } body.Rotation = body.Rotation; }
private void StartNormal() { m_mode = Mode.Normal; MathHelp.InitRandom(); timerManager = CreateTimerManager(); notifications = CreateNotifications(timerManager); sharedStorage = CreateSharedStorage("storage", timerManager); inputManager = CreateInputManager(); if (inputManager is IUpdatable) { AddUpdatable(inputManager as IUpdatable); } CreateDemoRecorder(); assetManager = CreateAssetManager(); rootController = CreateRootController(); AddGameObject(rootController); started = true; OnStart(); inputManager.AddInputListener(rootController); rootController.Start(); }
private void chaseOrAttack() { if (Vector3.Distance(position, focus.data.pos) <= (0.001f + data.stats.attRange)) { chaseDelta = 0f; if (toWaitbeforeAttack == 0) { float damage = 1f + (data.stats.pAttack - focus.stats.pDefense) + (data.stats.mAttack - focus.stats.mDefense); toWaitbeforeAttack = (int)data.stats.attSpeed * MOB_ATTACK_SPEED_MODIFIER; focus.receiveDamage(damage); } else { toWaitbeforeAttack--; } return; } else { chaseDelta += MOB_WALK_SPEED_MODIFIER * (data.stats.movSpeed * Math.Abs(Vector3.Distance(position, focus.data.pos))); chaseDelta = Math.Clamp(chaseDelta, 0f, 1f); position = MathHelp.Lerp(position, focus.data.pos, chaseDelta); toWaitbeforeAttack = (int)data.stats.attSpeed * MOB_ATTACK_SPEED_MODIFIER; } }
public PathWaypoint(Vector2 goal, Action <PathWaypoint, bool> callback) { this.Goal = goal; this.goalRounded = new Vector2(MathHelp.floor(this.Goal.X), MathHelp.floor(this.Goal.Y)); this.callback = callback; }
public bool CanMoveCheck(Vector3 movement) { RaycastHit[] hits; Vector3 direction = movement.normalized; float maxDistance = movement.magnitude; foreach (Collider col in _colliders) { hits = null; if (col is BoxCollider) { // box info _boxCol = col as BoxCollider; Vector3 center = col.transform.position + _boxCol.center; Vector3 fromCenterToCorner = MathHelp.MultiplyVector3(col.transform.localScale, _boxCol.size) * 0.5f * _castSizeFactor; Quaternion orientation = col.transform.rotation; hits = Physics.BoxCastAll(center, fromCenterToCorner, direction, orientation, maxDistance, LayerMask.NameToLayer("Item")); } else if (col is SphereCollider) { // sphere info _sphereCol = col as SphereCollider; Vector3 origin = col.transform.position + _sphereCol.center; float radius = MathHelp.AbsBiggest(col.transform.localScale, false) * _sphereCol.radius * _castSizeFactor; hits = Physics.SphereCastAll(origin, radius, direction, maxDistance); } else if (col is CapsuleCollider) { // capsule info float radius; Vector3[] centers = MathHelp.CapsuleEndPoints(col as CapsuleCollider, out radius); radius *= _castSizeFactor; if (centers.Length == 1) { hits = Physics.SphereCastAll(centers[0], radius, direction, maxDistance); } else { hits = Physics.CapsuleCastAll(centers[0], centers[1], radius, direction, maxDistance); } } if (hits != null) { foreach (RaycastHit hit in hits) { if (hit.collider.GetComponent <StaticObject>() != null) { Debug.DrawLine(hit.point, hit.point + hit.normal, Color.white, 1f); return(false); } } } } return(true); }
public DemoRecorder() { m_buffer = new BitWriteBuffer(); m_tickCmd = new DemoTickCmd(); m_inputCmd = new DemoInputCmd(); Write(new DemoInitCmd(MathHelp.GetRandomSeed())); }
public override void AI() { Projectile.ai[0]++; Projectile.scale = Math.Clamp(3f - (Projectile.ai[0] / 10), 1, 2f); Player player = Main.player[Projectile.owner]; SoraPlayer sora = player.GetModPlayer <SoraPlayer>(); blockedAttack = sora.blockedAttack || blockedAttack; if (blockedAttack) { Projectile.frame = 4; Projectile.damage = projDamage; Projectile.timeLeft = (Projectile.timeLeft > 3) ? 3 : Projectile.timeLeft; if (canChainGuards) { sora.guardTime = 5; sora.guardType = blockingType.normal; sora.guardProj = Projectile.whoAmI; } else { sora.guardTime = -1; sora.guardType = blockingType.none; sora.guardProj = -1; } sora.AddInvulnerability(5); } else { Projectile.frameCounter++; Projectile.frame = (Projectile.frameCounter / 3) % 4; Projectile.damage = 0; sora.guardTime = 5; sora.guardType = blockingType.normal; sora.guardProj = Projectile.whoAmI; } Vector2 mPos = Main.MouseWorld - player.Center; Projectile.spriteDirection = (int)MathHelp.Sign(mPos.X); Projectile.rotation = -(float)Math.Atan2(mPos.X, mPos.Y) + (float)Math.PI / 2 + (int)(Projectile.spriteDirection == -1 ? (float)Math.PI : 0); Projectile.Center = player.Center + MathHelp.Normalize(mPos) * 10; player.direction = Projectile.spriteDirection; if (player.dead || !player.controlUseTile) { Projectile.Kill(); return; } }
public override void AI() { TargetEnemie(); Projectile.ai[0]++; Projectile.frame = (int)(Projectile.ai[0] / 50f) % 2; if (target != -1 && Vector2.Distance(Main.npc[target].Center, Projectile.Center) < 750) { if (Vector2.Distance(Main.npc[target].Center, Projectile.Center) > 400) { Projectile.velocity = MathHelp.Normalize(Main.npc[target].Center - Projectile.Center); Projectile.spriteDirection = (Projectile.velocity.X == 0) ? Projectile.spriteDirection : ((Projectile.velocity.X > 0) ? 1 : -1); Projectile.rotation = (Projectile.spriteDirection > 0) ? (float)Math.Atan2(Projectile.velocity.Y, Projectile.velocity.X) : (float)(Math.PI + Math.Atan2(Projectile.velocity.Y, Projectile.velocity.X)); } else { Projectile.spriteDirection = (Main.npc[target].Center - Projectile.Center).X > 0 ? 1 : -1; if (Projectile.ai[0] % 2 == 0) { ProjectileSource_ProjectileParent s = new ProjectileSource_ProjectileParent(Projectile); int proj = Projectile.NewProjectile(s, Projectile.Center, MathHelp.Normalize(Main.npc[target].Center + new Vector2(0, 25) - Projectile.Center) * 5, ProjectileID.WaterStream, Projectile.damage / 4, 3, Projectile.owner); Main.projectile[proj].timeLeft = 50; if (Projectile.ai[0] % 120 == 0) { int itm = Item.NewItem(Projectile.getRect(), ItemID.Star); Main.item[itm].velocity = new Vector2(Main.rand.Next(-3, 3), Main.rand.Next(-3, 3)); } } Projectile.velocity = Vector2.Zero; Projectile.rotation = 0; } } else { if (Vector2.Distance(Main.player[Projectile.owner].Center, Projectile.Center) > 200) { Projectile.velocity = MathHelp.Normalize(Main.player[Projectile.owner].Center - Projectile.Center); if (Vector2.Distance(Main.player[Projectile.owner].Center, Projectile.Center) > 700) { Projectile.timeLeft = 2; } Projectile.spriteDirection = (Projectile.velocity.X == 0) ? Projectile.spriteDirection : ((Projectile.velocity.X > 0) ? 1 : -1); Projectile.rotation = (Projectile.spriteDirection > 0) ? (float)Math.Atan2(Projectile.velocity.Y, Projectile.velocity.X) : (float)(Math.PI + Math.Atan2(Projectile.velocity.Y, Projectile.velocity.X)); } else { Projectile.velocity = Vector2.Zero; Projectile.rotation = 0; } } }
public override void AI() { Projectile.velocity.X = Projectile.velocity.X + Projectile.velocity.Y * MathHelp.Sign(Projectile.velocity.X); Projectile.velocity.Y = 0; timeLeft = (timeLeft == 0) ? Projectile.timeLeft : timeLeft; Projectile.alpha = (Projectile.timeLeft > 50) ? 100 : 100 + 155 * (Projectile.timeLeft); }
public void calculateCosts(Vector2 endPos) { this.CostFromStart = this.Parent == null ? 0 : this.Parent.CostFromStart + 10; var costToEndX = Math.Abs(endPos.X - this.Pos.X); var costToEndY = Math.Abs(endPos.Y - this.Pos.Y); this.CostToEnd = MathHelp.floor((costToEndX + costToEndY) * 10); }
private void doWanderCycle() { if (hittenBy.Count != 0) { hittenBy.Clear(); } if (data.stats.wanderRadius == 0f) { return; } if (startingWalkPoint == Vector3.Zero) { startingWalkPoint = position; } if (wanderKey == 0) { if (wanderDelta == 0f) { Random rnd = new Random(); float wanderX = Math.Clamp(startingWalkPoint.X + (rnd.Next(1, 500) / 100f), 0, owner.width); float wanderZ = Math.Clamp(startingWalkPoint.Z + (rnd.Next(1, 500) / 100f), 0, owner.height); float wanderY = owner.heightMap[(int)wanderX, (int)wanderZ]; wanderPos = new Vector3(wanderX, wanderY, wanderZ); } wanderDelta += MOB_WALK_SPEED_MODIFIER * (data.stats.movSpeed * Math.Abs(Vector3.Distance(position, wanderPos))); wanderDelta = Math.Clamp(wanderDelta, 0f, 1f); if (wanderDelta == 1f) { position = wanderPos; wanderKey = 1; wanderDelta = 0f; } else { position = MathHelp.Lerp(position, wanderPos, wanderDelta); } } else { wanderDelta += data.stats.movSpeed / Math.Abs(Vector3.Distance(position, startingWalkPoint)); wanderDelta = Math.Clamp(wanderDelta, 0f, 1f); if (wanderDelta == 1f) { position = startingWalkPoint; wanderKey = 0; wanderDelta = 0f; } else { position = MathHelp.Lerp(position, startingWalkPoint, wanderDelta); } } }