void FixedUpdate() { if (initialization) { if (!UIPowerBar.IsVisible()) { HidePowerBar(); } HideKey(); initialization = false; } if (Player.HasOrbem()) { if (Player.CanSwitchWorld() && orbState.Equals(OrbState.NOTACTIVABLE)) { orbState = OrbState.ACTIVABLE; UIPowerBar.EnablePowerBar(); } else if (!Player.CanSwitchWorld() && orbState.Equals(OrbState.ACTIVABLE)) { orbState = OrbState.NOTACTIVABLE; UIPowerBar.DisablePowerBar(); } } }
private void GetInputs() { oldAutoHold = autoHold; if (Input.GetButtonDown("StickButton")) { stickToggle = !stickToggle; } stick = (Input.GetAxis("Stick") > 0 || Input.GetButton("StickShift")) ? !stickToggle : stickToggle; inputDir = (new Vector2(Input.GetAxis("Horizontal2"), Input.GetAxis("Vertical2"))).normalized; Vector2 playerInput = Vector2.right * Input.GetAxis("Horizontal") + Vector2.up * Input.GetAxis("Vertical"); autoHold = !(!player.GetComponent <PlayerController>().grounded&& (playerInput.y <= -0.1f && (inputDir != Vector2.zero || !autoHold))); if (autoHold && !oldAutoHold) { state = OrbState.Push; } if (Input.GetMouseButton(0)) { Vector2 pos = focusMode ? rb.position : playerRB.position; Vector2 mouseInWorld = cam.GetComponent <Camera>().ScreenToWorldPoint(Input.mousePosition); inputDir = (mouseInWorld - pos).normalized; } }
void Respawn() { ClearOrbBehavior(); this.state = OrbState.Spawning; this.transform.position = Game.Levels.CurrentLevel.OrbSpawn; respawnTimer.Restart(); }
public void Serve() { var direction = new Vector2(0, -1); //if (scoredSide == HeroSide.Top) // direction = new Vector2(0, 1); this.state = OrbState.Moving; ForceHit(direction, 1); }
// Use this for initialization void Awake() { if (instance == null) { instance = this; orbState = OrbState.ACTIVABLE; } else { Destroy(gameObject); } }
protected override void OnConstruct() { defaultSprite = this.AddChild(Game.Objects.CreatePrefab <SpriteWrapper>(defaultOrbSprite)); ClearOrbBehavior(); direction = startDirection; speed = startSpeed; collider = this.GetComponentStrict <CircleCollider2D>(); respawnTimer = new Timer(1); state = OrbState.Spawning; scoredSide = HeroSide.Bottom; sprites = new Dictionary <HeroSide, ISpriteWrapper>(); }
public void setState(OrbState os) { currState = os; updateMarkerSprite(); }
public override bool Update() { radius = 0.2f * Screen.Scale; nBuild.PolyColor = Color.Lerp(Color.Red, Color.Yellow, health / 40.0f); float speed = 0.75f + (0.75f * ((40.0f - health) / 40.0f)); if (health == 3) { Invulnerable = true; health = 2; spin = 0; } else if (health <= 2) { Invulnerable = true; spin += Time.Delta * speed / 2; fireTimer += Time.Delta; if (fireTimer > 0.1) { fireTimer = 0; for (double dir = 0; dir < 6.283; dir += 6.283 / 8.0) if (r.Next(2) == 1) Tesseract.Engine.GameWorld.GameState.InstantiateCurrent(new EnemyBullet(this.Position, new Vector2((float)Math.Cos(dir + spin), (float)Math.Sin(dir + spin)))); } if (spin > 10) { return false; } } else if (state == OrbState.Bounce) { if (left && this.Position.X < -Screen.X + 0.1f) { FireArray(); left = false; } else if (!left && this.Position.X > Screen.X - 0.1f) { FireArray(); left = true; } if (up && this.Position.Y > Screen.Y - 0.1f) { FireArray(); up = false; } else if (!up && this.Position.Y < -Screen.Y + 0.1f) { FireArray(); up = true; } this.Position += new Vector2(!left ? speed : -speed, up ? speed : -speed) * Time.Delta; } else { Vector2 target = -this.Position; if (target.Length() > speed * Time.Delta) { target.Normalize(); this.Position += target * speed * Time.Delta; spin = 0; } else { this.Invulnerable = true; spin += Time.Delta * speed / 2; if (spin > 5) { state = OrbState.Bounce; this.Invulnerable = false; } fireTimer += Time.Delta; if (fireTimer > 0.2) { fireTimer = 0; for (double dir = 0; dir < 6.283; dir += 6.283 / 8.0) Tesseract.Engine.GameWorld.GameState.InstantiateCurrent(new EnemyBullet(this.Position, new Vector2((float)Math.Cos(dir + spin), (float)Math.Sin(dir + spin)))); } } } return base.Update(); }
private void FireArray() { health -= 1; if (health < lastMult * 10) { lastMult = health / 10; state = OrbState.Spin; } DynamicBackground.ApplyColor(nBuild.PolyColor, this.Position, 5f); for (double dir = 0; dir < 6.283; dir += 6.283 / 16.0) Tesseract.Engine.GameWorld.GameState.InstantiateCurrent(new EnemyBullet(this.Position, new Vector2((float)Math.Cos(dir), (float)Math.Sin(dir)))); //throw new NotImplementedException(); for (int i = 0; i < r.Next(3) + 3; ++i) GameManager.State.Instantiate(new ScoreDrop(Position, i)); }
//Changes the orbs state based on given parameter and Updates the state. void ChangeState(OrbState _orbState) { orbState = _orbState; UpdateState(); }
private void HandleOrbState() { if (inputDir != Vector2.zero || focusMode || !autoHold) { state = OrbState.Push; targetPosition = rb.position + (inputDir * 5); } else if ((rb.position - playerRB.position).magnitude > HOLD_RANGE && state != OrbState.Hold && state != OrbState.Pull) { state = OrbState.Pull; targetPosition = playerRB.position; } else if (state == OrbState.Pull) { targetPosition = playerRB.position; float dist = (targetPosition - rb.position).magnitude; if (dist <= (HOLD_RANGE * 3)) { if (dist <= HOLD_RANGE || CheckLineSegmentAgainstCircle(prevPosition, rb.position, playerRB.position, HOLD_RANGE / 2)) { state = OrbState.Hold; } else { rb.velocity = (targetPosition - rb.position).normalized * (rb.velocity.magnitude * 0.5f); } } } else if (state == OrbState.Hold) { targetPosition = playerRB.position; } targetPositionDir = (targetPosition - rb.position).normalized; if (targetPositionDir != Vector2.zero) { force = BlackMagic(); } else { force = Vector2.zero; } if (state != OrbState.Hold) { // detect platforms, ignore them if the orb is moving upwards float gcf = Mathf.Clamp(Mathf.Abs(rb.velocity.y) * Time.deltaTime, 1f, 50f); Vector2 gcSize = Vector2.right * 0.15f + Vector2.up * gcf; Vector2 gcOrigin = rb.position + Vector2.down * 0.05f + Vector2.down * gcf * 0.5f; int gcLayerMask = LayerMask.GetMask("Platform"); RaycastHit2D groundCheck = Physics2D.BoxCast(gcOrigin, gcSize, 0, Vector2.zero, 0, gcLayerMask, 0); ignorePlatforms = rb.velocity.y > 0f && !groundCheck; } trail.material.color = stick ? Color.magenta : Color.cyan; switch (state) { case OrbState.Hold: Timer.Increment(ref trailScale); trail.time = trail.time * trailScale / 2; break; default: trailScale = 2; trail.time = maxTrailTime; break; } }
// Start is called before the first frame update void Start() { curState = OrbState.Resting; }