public bool SprayWater(bool frogIsBot = false, Vector2?target = null) { if (BubbleEnabled && !PlayerInfo.isPaused && (frogIsBot || Input.GetMouseButtonDown(0)) && playerInfo.waterLevel > PlayerInfo.BUBBLE_COST) { if (!frogIsBot) { target = (Vector2?)(Camera.main.ScreenToWorldPoint(Input.mousePosition)); } Vector2 shotDirection = (Vector2)target - (Vector2)(transform.position); float angle = Mathf.Atan2(shotDirection.y, shotDirection.x) * Mathf.Rad2Deg; if (transform.parent.GetComponent <Animator>().GetBool("Sitting")) { transform.parent.GetComponent <Animator>().SetBool("Sitting", false); } if (movement != null) { movement.OverrideRotation(angle); } MouseTargeter mouseTargeter = transform.parent.GetComponent <MouseTargeter>(); if (mouseTargeter != null) { mouseTargeter.StopTargeting(); } AStarTargeter aStarTargeter = transform.parent.GetComponent <AStarTargeter>(); if (aStarTargeter != null) { aStarTargeter.StopTargeting(); } shotDirection.Normalize(); Instantiate(waterProjectilePrefab, new Vector3(transform.position.x + shotDirection.x * BubbleLaunchDistance, transform.position.y + shotDirection.y * BubbleLaunchDistance, transform.position.z), Quaternion.Euler(0.0f, 0.0f, angle - rotationOffset)); playerInfo.ReduceWaterAfterBubble(); return(true); } else { return(false); } }
// Update is called once per frame void Update() { horizontal = (int)Input.GetAxisRaw("Horizontal"); vertical = (int)Input.GetAxisRaw("Vertical"); if (Input.GetKeyUp(KeyCode.I)) { _inventoryPanel.SetActive(!_inventoryPanel.activeSelf); } if (Input.GetMouseButtonUp(1)) { SpellBook.Instance.UseFireballSpell(gameObject.transform.position); } if (Input.GetMouseButton(0)) { if (Time.time > nextAttack) { var collisions = MouseTargeter.AquireTargets(); var target = collisions.FirstOrDefault(); if (target != null) { if (transform.IsInRange(target.transform, attackRange)) { nextAttack = Time.time + attackRate; _animator.SetTrigger("PlayerChop"); collisions.FirstOrDefault().DealDamageToTarget(_damage); } } } } if (Input.GetKeyUp(KeyCode.PageUp)) { gameObject.GetComponentInChildren <Camera>().orthographicSize++; } if (Input.GetKeyUp(KeyCode.PageDown)) { gameObject.GetComponentInChildren <Camera>().orthographicSize--; } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { BlackBoard.CurrentSpriteBatch = new SpriteBatch(this.GraphicsDevice); BlackBoard.LogPrinter = new BasicLogPrinter(this); BlackBoard.CurrentCamera = new Camera(new Vector2(15, 11), new Vector2(0, 50)); BlackBoard.Scheduler = new Scheduler(); BlackBoard.LogPrinter.PositionPixel = new Vector2(517, 420); this.Components.Add(BlackBoard.LogPrinter); this.donjon = new Dongeon(this); this.map = this.donjon.CurrentMap; MapFiller.InitializePlayer(this.map); MapFiller.InitializeItems(this.map); MapFiller.InitializeEnnemis(this.map); base.Initialize(); this.keyBoardInputHandler = new KeyBoardInputHandler(); BlackBoard.InputHandler = this.keyBoardInputHandler; this.map.SetAsActive(true); BlackBoard.CurrentMap = this.map; this.mt = new MouseTargeter(this); this.Components.Add(this.mt); }