public void HandleInput() { _interfaceBoundsRect = new Rectangle((Int32)_interfacePosition.X, (Int32)_interfacePosition.Y, _interfaceTexture.Width, _interfaceTexture.Height); foreach (var towerIcon in _towerIcons) { if (towerIcon.IsSelected()) { _towerInformationBox.Display(); _towerInformationBox.Text = towerIcon.Text; TowerSelectedType = towerIcon.Type; break; } } _lifeBar.ChangeLife(GlobalsVar.PlayerLife); if (ToolsInterface.isMouseLeftPressed()) { if (ToolsInterface.isMouseIntersects(_lifeButtonPosition, _lifeButtonBoundsRect)) { _lifeBar.ChangeLife(-1); //_waveBar.ChangeLife(1); } } }
/** * Calculates the new velocity with respect to x * @param velocity: the velocity to be changed */ private void HorizontalCollisions(ref Vector3 velocity) { if (velocity.x == 0) { return; } float direction = Mathf.Sign(velocity.x); float speed = Mathf.Abs(velocity.x); // Doesn't use rays on the corner to allow for corner fudging for (int i = 1; i < bounds.vRayCount - 1; i++) { Vector2 origin = bounds.bottomLeft; if (direction == 1) { origin = bounds.bottomRight; } Vector2 shift = new Vector2(0, i * bounds.vRaySpace); RaycastHit2D hit = Physics2D.Raycast(origin + shift, direction * Vector2.right, speed, collisionMask); if (DebugFlag) { Debug.DrawRay(origin + shift, direction * Vector2.right, Color.green); } if (hit.collider != null) { if (ps != null) { switch (hit.transform.tag) { case "FinalBoss": case "hazard": ps.KillPlayer(); break; case "tools": ToolsInterface t = hit.collider.gameObject.GetComponent <ToolsInterface>(); t.Interact(gameObject); goto default; default: speed = HorizontalCollide(ref velocity, hit, direction); break; } } else if (bs != null) { if (hit.transform.tag == "tools") { Debug.Log("bottle tool collide"); ToolsInterface t = hit.collider.gameObject.GetComponent <ToolsInterface>(); t.Interact(gameObject); } if (hit.transform.tag == "FinalBoss") { hit.transform.gameObject.GetComponent <FinalBossScript>().Hurt(bs); } speed = HorizontalCollide(ref velocity, hit, direction); } else if (ec != null) { if (hit.transform.tag != "Player") { speed = HorizontalCollide(ref velocity, hit, direction); } } else { speed = HorizontalCollide(ref velocity, hit, direction); } } } }