/// <summary> /// /// </summary> /// <param name="script"></param> /// <param name="dungeon"></param> public WallSwitchScriptForm(WallSwitchScript script, Dungeon dungeon) { InitializeComponent(); if (script == null) Script = new WallSwitchScript(); else Script = script; ActionBox.Dungeon = dungeon; ActionBox.Script = Script; }
/// <summary> /// /// </summary> /// <param name="node"></param> /// <returns></returns> public override bool Load(XmlNode xml) { if (xml == null || xml.Name != Tag) { return(false); } ConsumeItem = xml.Attributes["consumeitem"] != null?bool.Parse(xml.Attributes["consumeitem"].Value) : false; Reusable = xml.Attributes["reusable"] != null?bool.Parse(xml.Attributes["reusable"].Value) : false; Side = xml.Attributes["side"] != null ? (CardinalPoint)Enum.Parse(typeof(CardinalPoint), xml.Attributes["side"].Value) : CardinalPoint.North; NeededItem = xml.Attributes["activateitem"] != null ? xml.Attributes["activateitem"].Value : string.Empty; LockLevel = xml.Attributes["picklock"] != null?int.Parse(xml.Attributes["picklock"].Value) : 0; foreach (XmlNode node in xml) { switch (node.Name.ToLower()) { case "decoration": { ActivatedDecoration = int.Parse(node.Attributes["activated"].Value); DeactivatedDecoration = int.Parse(node.Attributes["deactivated"].Value); } break; case "scripts": { foreach (XmlNode sub in node) { WallSwitchScript script = new WallSwitchScript(); script.Load(sub); Scripts.Add(script); } } break; default: { base.Load(node); } break; } } return(true); }
/// <summary> /// /// </summary> /// <param name="script"></param> /// <param name="dungeon"></param> public WallSwitchScriptForm(WallSwitchScript script, Dungeon dungeon) { InitializeComponent(); if (script == null) { Script = new WallSwitchScript(); } else { Script = script; } ActionBox.Dungeon = dungeon; ActionBox.Script = Script; }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MoveUpBox_Click(object sender, EventArgs e) { if (Scripts == null) { return; } int id = ScriptListBox.SelectedIndex; if (id <= 0) { return; } WallSwitchScript script = Scripts[id]; Scripts.RemoveAt(id); Scripts.Insert(id - 1, script); UpdateUI(); ScriptListBox.SelectedIndex = id - 1; }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MoveDownBox_Click(object sender, EventArgs e) { if (Scripts == null) { return; } int id = ScriptListBox.SelectedIndex; if (id >= Scripts.Count - 1) { return; } WallSwitchScript action = Scripts[id]; Scripts.RemoveAt(id); Scripts.Insert(id + 1, action); UpdateUI(); ScriptListBox.SelectedIndex = id + 1; }
// Update is called once per frame void Update() { // Check if crosshair is behind player if (transform.position.x < Camera.main.ScreenToWorldPoint(Input.mousePosition).x) { if (!isFacingRight) { flip(); isFacingRight = true; } } else { if (isFacingRight) { flip(); isFacingRight = false; } } // Check if animation is currently playing so player is invincible if (takingDamage == true) { invincibleTimer -= Time.deltaTime; } // If animation is not playing anymore if (invincibleTimer <= 0) { takingDamage = false; } // Delay on rolling so you can't keep rolling if (rollDelay > 0) { rollDelay -= Time.deltaTime; } // count down on roll timer and invisibility timer if (rollTimer >= 0) { rollTimer -= Time.deltaTime; // change sprite to something else //gameObject.GetComponent<SpriteRenderer>().sprite = rollSprite; } else { isRoll = false; rollTimer = rollTime; //change sprite back to original //gameObject.GetComponent<SpriteRenderer>().sprite = mainSprite; } checkCrouch(); // Check if interaction key is being pressed if (Input.GetKeyDown("f")) { // Check if touching a sign if (touchSign) { // Do something here GameObject sign = GameObject.FindGameObjectWithTag("IsTouching"); sign.transform.GetChild(0).gameObject.GetComponent <TextMeshPro>().SetText("This Is A Sign."); } // Check if door is open else if (touchDoor) { // Determine which door is which GameObject originDoor = GameObject.FindGameObjectWithTag("IsTouching"); DoorScript doorScript = originDoor.GetComponent <DoorScript>(); if (doorScript.isOpen) { GameObject destDoor = GameObject.FindGameObjectWithTag("TeleportDoor"); transform.position = destDoor.transform.position; pet.transform.position = destDoor.transform.position; AstarPath.active.Scan(); } } // Check if touching a switch else if (touchSwitch) { SwitchScript switchScript = GameObject.FindGameObjectWithTag("IsTouching").GetComponent <SwitchScript>(); // Change status of switch if (switchScript.isOn) { switchScript.isOn = false; } else { switchScript.isOn = true; } } // Check if touching wall switch else if (touchWallSwitch) { WallSwitchScript wsScript = GameObject.FindGameObjectWithTag("IsTouching").GetComponent <WallSwitchScript>(); if (wsScript.state) { wsScript.state = false; wsScript.OpenDoor(); animator.SetBool("isInteracting", true); } } else if (touchPuzzleSwitch) { PuzzleSwitchScript psScript = GameObject.FindGameObjectWithTag("IsTouching").GetComponent <PuzzleSwitchScript>(); if (psScript.state) { psScript.state = false; } else { psScript.state = true; } } } // Checks if the "d" key is being pressed if (Input.GetKey("d") && !isRoll) { // Changes the x-axis velocity of the player while retaining the y-axis velocity if (isCrouching) { rbody.velocity = new Vector3(moveSpeed / 2, rbody.velocity.y); } else { rbody.velocity = new Vector2(moveSpeed, rbody.velocity.y); } } // Checks if the "a" key is being pressed else if (Input.GetKey("a") && !isRoll) { // Changes the x-axis velocity of the player while retaining the y-axis velocity if (isCrouching) { rbody.velocity = new Vector3(-(moveSpeed / 2), rbody.velocity.y); } else { rbody.velocity = new Vector2(-(moveSpeed), rbody.velocity.y); } } // This else statement is to set the player's x-axis velocity to 0 if neither "a" nor "d" are being pressed. // Without this statement, the player would glide. else { if (!onMovingPlatform && !isRoll) { // Set player x-axis velocity to 0 while retaining y-axis velocity rbody.velocity = new Vector2(0, rbody.velocity.y); } else if (onMovingPlatform) { // Set player velocity to moving platform velocity rbody.velocity = new Vector2(mPVel, rbody.velocity.y); } } // Check if the space key is pressed AND that the player is on the ground if (Input.GetKey("space") && onGround) { // Retain current x-axis velocity, while adding a bit of y-axis velocity rbody.velocity = new Vector2(rbody.velocity.x, 6f); } isPassThroughBlock(); // Double tap down key to go down a pass through block if (Input.GetKeyDown(KeyCode.S)) { if (doubleTapDownTimer > 0 && doubleTapDownCount == 1 && currentPassThroughBlock != null /*Number of Taps you want Minus One*/) { currentPassThroughBlock.GetComponent <BoxCollider2D>().isTrigger = true; onGround = false; } else { doubleTapDownTimer = 0.5f; doubleTapDownCount += 1; } } if (doubleTapDownTimer > 0) { doubleTapDownTimer -= 1 * Time.deltaTime; } else { doubleTapDownCount = 0; } // Check if the "shift" key is pressed // Can only roll if grounded if (Input.GetKey(KeyCode.LeftShift) && isRoll == false && rollDelay <= 0) { // play the roll animation // Player is invisible for the duration of the roll isRoll = true; rollTimer = rollTime; invincibleTimer = 0.3f; takingDamage = true; rollDelay = 2f; //direction of roll // rolls right if (transform.localScale.x > 0) { //rbody.AddForce(new Vector2(3, 0)); rbody.velocity = new Vector2(3, rbody.velocity.y); } // rolls left else if (transform.localScale.x < 0) { //rbody.AddForce(new Vector2(-3, 0)); rbody.velocity = new Vector2(-3, rbody.velocity.y); } } // If on a ladder and press W, go up if (Input.GetKey("w") && onLadder) { rbody.velocity = new Vector2(rbody.velocity.x, 3); } // If on a ladder and press S, go down else if (Input.GetKey("s") && onLadder) { rbody.velocity = new Vector2(rbody.velocity.x, -3); } // Check if mouse key is pressed if (Input.GetMouseButton(0) && weapon != null) { // Fire bullet if (weapon.Shoot()) { // Knockback shootDirection = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position; shootDirection.Normalize(); rbody.AddForce((-shootDirection * weapon.recoil), ForceMode2D.Force); } } // Check if weapon realod is pressed if (Input.GetKeyDown(KeyCode.R)) { weapon.Reload(); } // If player is not on the ground, countdown from timer if (!onGround) { fallTimer -= Time.deltaTime; } // This checks if the player has been falling for over 5 seconds // I have a timer variable set to 5, that counts down every time it is not touching the ground // If it touches the ground, the timer resets back to 5 seconds // This just moves the player back to the starting position // It doesn't reset the level, so the player can keep trying the level over and over again if (fallTimer <= 0) { ResetPlayer(); } // Check if player health is 0 if (health <= 0) { ResetPlayer(); } animationStates(); }
/// <summary> /// /// </summary> /// <param name="node"></param> /// <returns></returns> public override bool Load(XmlNode xml) { if (xml == null || xml.Name != Tag) return false; ConsumeItem = xml.Attributes["consumeitem"] != null ? bool.Parse(xml.Attributes["consumeitem"].Value) : false; Reusable = xml.Attributes["reusable"] != null ? bool.Parse(xml.Attributes["reusable"].Value) : false; Side = xml.Attributes["side"] != null ? (CardinalPoint)Enum.Parse(typeof(CardinalPoint),xml.Attributes["side"].Value) : CardinalPoint.North; NeededItem = xml.Attributes["activateitem"] != null ? xml.Attributes["activateitem"].Value : string.Empty; LockLevel = xml.Attributes["picklock"] != null ? int.Parse(xml.Attributes["picklock"].Value) : 0; foreach (XmlNode node in xml) { switch (node.Name.ToLower()) { case "decoration": { ActivatedDecoration = int.Parse(node.Attributes["activated"].Value); DeactivatedDecoration = int.Parse(node.Attributes["deactivated"].Value); } break; case "scripts": { foreach (XmlNode sub in node) { WallSwitchScript script = new WallSwitchScript(); script.Load(sub); Scripts.Add(script); } } break; default: { base.Load(node); } break; } } return true; }