public int SlowdownBeforeCall() { var curDir = GetComponent <Rigidbody>().velocity.normalized; var curPos = transform.position; var newPos = new Vector3(curPos.x + curDir.x * 3f, curPos.y + curDir.y * 3f, 0); GetComponent <Rigidbody>().velocity = Vector3.zero; RotationsPerMinute = 0.2f; State = Sphere.SphereState.CallBall; // raycast RayT.LookAt(curDir, Vector3.up); RaycastHit hitInfo; if (Physics.Raycast(RayT.position, curDir, out hitInfo, 4f)) { var x = (curDir.x > 0) ? 0.25f : -0.25f; var y = (curDir.y > 0) ? 0.25f : -0.25f; newPos = new Vector3(curPos.x + x, curPos.y + y, 0f); } _ltSlowdown = LeanTween.move(gameObject, newPos, 2f); _ltSlowdown.setEase(LeanTweenType.easeOutBack); return(_ltSlowdown.id); }
public void ChangeState(SphereState newStateType) { var newState = _stateMap[newStateType]; if (_currentState == newState) { return; } newState.EnterState(); _currentState = newState; }
void Update() { var oldState = _state; // TODO optimize this shit _curColorOnMin = Color.Lerp(colorOnMin, colorOnMax, 1f - MidiMaster.GetKnob(79, 0.3f)); _flickerSpeed = baseFlickerSpeed * (0.5f + MidiMaster.GetKnob(80, 0.5f)); if (MidiMaster.GetKeyDown(41)) { _state = SphereState.On; } else if (MidiMaster.GetKeyDown(42)) { // on _state = SphereState.Off; } else if (MidiMaster.GetKeyDown(43)) { // max _state = SphereState.Flicker; //_state = SphereState.Max; } else if (Input.GetKey(KeyCode.Alpha4)) { _state = SphereState.Flicker; } else if (Input.GetKey(KeyCode.Alpha5)) { //state = SphereState.Blue; } else if (Input.GetKey(KeyCode.Alpha6)) { } else if (Input.GetKey(KeyCode.Alpha7)) { } else if (Input.GetKey(KeyCode.Alpha8)) { } else if (Input.GetKey(KeyCode.Alpha9)) { } if (oldState != _state) { _lerpStartColor = _curColor; _lerpStartTime = Time.time; } HandleState(); }
public Sphere(Game game, Model model, float scale, SoundEffect sound, float widthRoom, float heightRoom, float depthRoom) : base(game) { this.model = model; this.scale = scale; this.sound = sound; this.state = SphereState.IDLE; this.widthRoom = widthRoom; this.heightRoom = heightRoom; this.depthRoom = depthRoom; }
private void ResetValues() { this.state = SphereState.IDLE; this.position = this.initialPosition; this.direction = Vector3.Zero; this.curving = Vector3.Zero; this.rotationX = 0; this.rotationXdelta = 0; this.rotationY = 0; this.rotationYdelta = 0; }
/// <summary> /// Handles the collision between the sphere and the room bounds. /// </summary> private void HandleCollision(float elapsedTime) { Vector3 normal = this.calculateCollisionNormal(this.bounds); if (normal != Vector3.Zero) if ((this.direction + normal).Length() <= this.direction.Length()) { //Rollback position(makes sure the sphere doesn't overhit the bounds this.position.Y -= this.direction.Y * elapsedTime; this.position.X -= this.direction.X * elapsedTime; this.direction = Vector3.Reflect(this.direction, normal); this.sound.Play(); //Rollback has been done, need to skip a direction adjustment this.state = SphereState.COLLIDING; } }
/// <summary> /// Allows the game component to update itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update(GameTime gameTime) { float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; if (this.state == SphereState.MOVING) { this.direction += this.curving * elapsedTime; this.position += this.direction * elapsedTime; } if (this.state == SphereState.COLLIDING) this.state = SphereState.MOVING; if (this.state != SphereState.IDLE) { this.onOneNonIdleTick(elapsedTime); this.rotationX += this.rotationXdelta; this.rotationX %= MathHelper.TwoPi; this.rotationY += this.rotationYdelta; this.rotationY %= MathHelper.TwoPi; this.HandleCollision(elapsedTime); this.HandleWins(); } base.Update(gameTime); }
public void AllowMovement() { this.state = SphereState.MOVING; this.levelStartTime = System.Environment.TickCount; }
public void ShootTo(Vector3 dir) { rb.AddForce(new Vector3(dir.x, dir.y, 0) * minDesiredSpeed); State = SphereState.Moving; }