public void Down() { currentStatus = status.walking; currentFacing = facing.down; currentSprite = new LinkNoneMovingDownSprite(); /* if (currentWeapon == weapon.None) * { * currentSprite = new LinkNoneMovingDownSprite(); * } * else if (currentWeapon == weapon.WoodenSword) * { * //currentSprite = new LinkWoodenMovingDownSprite(); * } * else if (currentWeapon == weapon.WhiteSword) * { * //currentSprite = new LinkWhiteMovingDownSprite(); * } * else if (currentWeapon == weapon.MagicalSword) * { * //currentSprite = new LinkMagicalSMovingDownSprite(); * } * else if (currentWeapon == weapon.MagicalRod) * { * //currentSprite = new LinkMagicalRMovingDownSprite(); * }*/ }
public void Reset() { this.currentFacing = facing.right; this.currentWeapon = weapon.None; this.currentStatus = status.standing; this.currentSprite = new LinkNoneStandingRightSprite(); }
// Use this for initialization void Start() { me = this.gameObject; rb2 = me.GetComponent <Rigidbody2D>(); direction = facing.right; //trans = me.GetComponent<Transform>(); }
public void left() { currentStatus = status.walking; currentFacing = facing.left; currentSprite = SpriteFactory.LinkNoneMovingLeft; /* if (currentWeapon == weapon.None) * { * currentSprite = new LinkNoneMovingLeftSprite(); * } * else if (currentWeapon == weapon.WoodenSword) * { * //currentSprite = new LinkWoodenMovingLeftSprite(); * } * else if (currentWeapon == weapon.WhiteSword) * { * //currentSprite = new LinkWhiteMovingLeftSprite(); * } * else if (currentWeapon == weapon.MagicalSword) * { * //currentSprite = new LinkMagicalSMovingLeftSprite(); * } * else if (currentWeapon == weapon.MagicalRod) * { * //currentSprite = new LinkMagicalRMovingLeftSprite(); * }*/ }
/// <summary> /// Takes a block, and the physical game object associated with it, and makes it face properly. /// </summary> /// <param name="block"></param> /// <param name="model"></param> /// <returns></returns> internal static void faceBlock(Block block, GameObject model) { facing face = block.face; ///Again, an incredibly shitty way to do this, but like f**k I'm bad at linear algebra switch (face) { case facing.UP: model.transform.Rotate(90, 0, 0, 0); break; case facing.RIGHT: model.transform.Rotate(0, 90, 0, 0); break; case facing.LEFT: model.transform.Rotate(0, -90, 0, 0); break; case facing.FRONT: model.transform.Rotate(180, 0, 0, 0); break; case facing.DOWN: model.transform.Rotate(90, 0, 0, 0); break; default: break; } }
public void transitionToRightHorizontalFromUp() { clumpUpFromUpwardVertical(); hasFinishedMoving = true; for (int j = 0; j <= currentTransitionPart - 1; j++) { for (int i = 0; i < speed; i++) { //{ if (bodyPartList[j].getRec().Intersects(bodyPartList[j + 1].getRec())) { bodyPartList[j].incrementRecX(1); hasFinishedMoving = false; } } } if (hasFinishedMoving) { facingDirection = facing.right; currentTransitionPart++; if (currentTransitionPart == numParts) { currentTransitionPart = 1; } } }
public P1State()// 可能不需要parameter因为P1里面有P1State,P1State里面也不需要P1 { //initial currentFacing = facing.right; currentWeapon = weapon.None; currentStatus = status.standing; currentSprite = new LinkNoneStandingRightSprite(); }
/// <summary> /// Generates a random block. Note this is nto used in the following or previous functions /// and it should be self evident why. /// </summary> /// <returns></returns> internal static Block generateRandomBlock() { List <BlockType> blocks = blockMan.blockTypes; BlockType desired = blocks[random.Next(0, blocks.Count - 1)]; facing face = Randomizer.RandomEnumValue <facing>(); rotation rot = Randomizer.RandomEnumValue <rotation>(); Block pBlock = new Block(desired.UID, face, rot); return(pBlock); }
//Random Movement public void lurking(GameTime gameTime) { randCycle += (float)gameTime.ElapsedGameTime.TotalSeconds; if (randCycle > 2f) { int randNumber = rand.Next(0, 9); switch (randNumber) { case 1: currentFaceDirection = facing.up; break; case 2: currentFaceDirection = facing.down; break; case 3: currentFaceDirection = facing.right; break; case 4: currentFaceDirection = facing.left; break; case 5: currentFaceDirection = facing.upLeft; break; case 6: currentFaceDirection = facing.upRight; break; case 7: currentFaceDirection = facing.downLeft; break; case 8: currentFaceDirection = facing.downRight; break; } randCycle = 0f; } switch (currentFaceDirection) { case facing.up: velocity = new Vector2(velocity.X, -speed); break; case facing.down: velocity = new Vector2(velocity.X, speed); break; case facing.right: velocity = new Vector2(speed, velocity.Y); break; case facing.left: velocity = new Vector2(-speed, velocity.Y); break; case facing.upLeft: velocity = new Vector2(-speed, -speed); break; case facing.upRight: velocity = new Vector2(speed, -speed); break; case facing.downLeft: velocity = new Vector2(-speed, speed);; break; case facing.downRight: velocity = new Vector2(speed, speed);; break; } float distant = Vector2.Distance(position, target.position); if (distant <= 300f) { currentState = state.chasing; } }
private List <int> Moving(facing Facing, int X, int Y, string command) { switch (Facing) { case facing.N: if (command == InstructionModel.A) { Y -= 1; } else if (command == InstructionModel.B) { Y += 1; } break; case facing.E: if (command == InstructionModel.A) { X += 1; } else if (command == InstructionModel.B) { X -= 1; } break; case facing.S: if (command == InstructionModel.A) { Y += 1; } else if (command == InstructionModel.B) { Y -= 1; } break; case facing.W: if (command == InstructionModel.A) { X -= 1; } else if (command == InstructionModel.B) { X += 1; } break; } var value = new List <int> { X, Y }; return(value); }
void FixedUpdate() { running = false; //New velocity to apply to player, Left & Right key handling Vector2 physicsVelocity = Vector2.zero; if (Input.GetKey(KeyCode.A)) { currentFacing = facing.Left; physicsVelocity.x -= 2; running = true; } if (Input.GetKey(KeyCode.D)) { currentFacing = facing.Right; physicsVelocity.x += 2; running = true; } //Allow player to jump if bool is true if (Input.GetKey(KeyCode.W)) { if (canJump) { GetComponent <Rigidbody>().velocity = new Vector2(physicsVelocity.x, 6); canJump = false; grounded = false; AudioSource.PlayClipAtPoint(jumpnoise, transform.position); } } //Test to see if actually standing on ground, therefore if jump if again available if (Physics.Raycast (new Vector2(transform.position.x - 0.1f, transform.position.y), -Vector2.up, 0.35f, groundMask)) { canJump = true; grounded = true; isFall = false; } else { if (tempy > transform.position.y) { isFall = true; } GetComponent <Rigidbody>().AddForce(-Vector2.up * 1f); } //Apply appropriate velocity to the body GetComponent <Rigidbody>().velocity = new Vector2(physicsVelocity.x, GetComponent <Rigidbody>().velocity.y); tempy = transform.position.y; }
private facing ChangeDirection(facing Facing, string command) { facing NewFacing = Facing; switch (Facing) { case facing.N: if (command == InstructionModel.TL) { NewFacing = facing.W; } else if (command == InstructionModel.TR) { NewFacing = facing.E; } break; case facing.E: if (command == InstructionModel.TL) { NewFacing = facing.N; } else if (command == InstructionModel.TR) { NewFacing = facing.S; } break; case facing.S: if (command == InstructionModel.TL) { NewFacing = facing.E; } else if (command == InstructionModel.TR) { NewFacing = facing.W; } break; case facing.W: if (command == InstructionModel.TL) { NewFacing = facing.S; } else if (command == InstructionModel.TR) { NewFacing = facing.N; } break; } return(NewFacing); }
private void UpdateWeapons() { if (isDead) { return; } if (lastFacingDirection != facingDirection) { currentWeapon = spawnersList[(int)facingDirection]; lastFacingDirection = facingDirection; } }
// Start is called before the first frame update void Start() { lastFacingDirection = facingDirection; animator.SetInteger("DirectionState", (int)facingDirection); spawnersList.Add(leftSpawner); spawnersList.Add(rightSpawner); spawnersList.Add(upSpawner); spawnersList.Add(downSpawner); /*spawnersList.Add(left_upSpawner); * spawnersList.Add(left_downSpawner); * spawnersList.Add(right_upSpawner); * spawnersList.Add(right_downSpawner);*/ currentWeapon = leftSpawner; }
void updateFacing() { if (transform.eulerAngles.z >= 45 && transform.eulerAngles.z <= 135)//we are facing left { face = facing.left; } else if (transform.eulerAngles.z >= 135 && transform.eulerAngles.z <= 225)//we are facing down { face = facing.down; } else if (transform.eulerAngles.z >= 225 && transform.eulerAngles.z <= 315)//we are facing down { face = facing.right; } else if (transform.eulerAngles.z >= 315 && transform.eulerAngles.z <= 45)//we are facing down { face = facing.up; } }
// Update is called once per frame void Update() { var plSign = player.transform.position.x - transform.position.x; if (Mathf.Sign(plSign) > 0) { transform.localScale = new Vector3(1, 1, 1); dir = facing.LEFT; } else if (Mathf.Sign(plSign) < 0) { transform.localScale = new Vector3(-1, 1, 1); dir = facing.RIGHT; } if (Vector3.Distance(gameObject.transform.position, player.transform.position) > 0.05) { gameObject.transform.position = Vector3.MoveTowards(gameObject.transform.position, player.transform.position, speed * Time.deltaTime); } }
void FixedUpdate() { //Move the character left, right, up or down float hoz = Input.GetAxis("Horizontal"); float vert = Input.GetAxis("Vertical"); if (hoz != 0f) { // move the char rb2.AddForce(new Vector2(hoz * hozSpeed, 0)); // Debug.Log("Hoz = " + hoz + ", applying force."); //update which way facing direction = lookingWhichWay(hoz); } if(vert > 0f) { if (jumping == false) { jumping = true; Debug.Log("Set jumping = true"); rb2.AddForce(new Vector2(0, jumpForce)); // Debug.Log("Vert = " + vert + ", applying force."); } } // therefore jumping == true if (Mathf.Abs(oldY - transform.localPosition.y) < jumpLimit && jumping == true) { jumping = false; Debug.Log("Set jumping to false"); } // Update storage variables oldY = transform.localPosition.y; }
void FixedUpdate() { //Move the character left, right, up or down float hoz = Input.GetAxis("Horizontal"); float vert = Input.GetAxis("Vertical"); if (hoz != 0f) { // move the char rb2.AddForce(new Vector2(hoz * hozSpeed, 0)); // Debug.Log("Hoz = " + hoz + ", applying force."); //update which way facing direction = lookingWhichWay(hoz); } if (vert > 0f) { if (jumping == false) { jumping = true; Debug.Log("Set jumping = true"); rb2.AddForce(new Vector2(0, jumpForce)); // Debug.Log("Vert = " + vert + ", applying force."); } } // therefore jumping == true if (Mathf.Abs(oldY - transform.localPosition.y) < jumpLimit && jumping == true) { jumping = false; Debug.Log("Set jumping to false"); } // Update storage variables oldY = transform.localPosition.y; }
public override void SetRotation(facing newFacing) { currFace = newFacing; switch (currFace) { case facing.left: gameObject.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 180)); break; case facing.right: gameObject.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0)); break; case facing.up: gameObject.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 90)); break; case facing.down: gameObject.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 270)); break; } }
/// <summary> /// Pass in the structure which holds your blocks, as well as the type of block you would like added, and /// this will add that block at a random spot to your structure /// </summary> /// <param name="structure"></param> /// <param name="type"></param> /// <returns>The altered datastructure, null if failed</returns> internal static bool insertBlockTypeAtRandom(IndividualDatastructure structure, BlockType type) { double openSpace = BlockFunctions.randomOpenSpace(structure.openSpaces); ///This is our block facing face = Randomizer.RandomEnumValue <facing>(); rotation rot = Randomizer.RandomEnumValue <rotation>(); Block pBlock = new Block(type.UID, face, rot); ///If we've gotten to this point, then we can successfully place ourself into the individual /* * IVE BEEN GETTING AN ERROR WHERE WE TRY TO PLACE BLOCKS THAT ALREADY EXIST. * NO IDEA WHY THIS HAPPENS AND IT SHOULDN'T SO I'M SIMPLY PUTTING THIS CONDITIONAL HERE AS A JANK FIX */ if (structure.contents.ContainsKey(openSpace)) { return(false); } structure.contents.Add(openSpace, pBlock); ///Remove the open space from structure.openSpaces structure.openSpaces.Remove(openSpace); ///Add the possible neighbours of the placed block to our open neighbours list List <double> openConsiderations = BlockFunctions.addNeighboursToOpen(openSpace, structure.contents); ///Iterating over the open spots we are considering, and check to see if they are already filled or not. ///Then adding them to our open spaces list if they are not. foreach (double possible in openConsiderations) { if (structure.contents.ContainsKey(possible)) { continue; } structure.openSpaces.Add(possible); } return(true); }
//Konstruktor public Enemy(Player target, Projectiles projectiles) { //Static erhöhen seed++; //Kollision größe einstellen noClip = false; collRect = new Rectangle(350, 350, 64, 64); position = new Vector2(350, 350); bulletCollision = false; isDeath = false; //Animation einstellen currentAnimation = new Animation(0.30f, 2, collRect.Width, collRect.Height); //Target und Geschwindigkeit festlegen this.target = target; this.projectiles = projectiles; speed = 25 * 50f; shootSpeed = 1f; currentState = state.lurking; currentFaceDirection = facing.right; //ZufallsGenerator rand = new Random(seed); randCycle = 0f; //Leben festlegen currentHealth = 300; maxHealth = 300; healthBar = new Bar(new Vector2((float)collRect.X, (float)collRect.Y), 70, 5, Color.Red, Color.DarkRed); }
private void Animate(facing dir) //changes sprite and shotspawn location { float x = shotSpawnDist, y = 0, rot = 0; switch (dir) { case facing.right: //Reset to default flipSprite = false; //shotSpawn.localPosition = new Vector3(shotSpawnDist, 0, 0); //shotSpawn.localRotation = Quaternion.Euler(0, 0, 0); animator.SetInteger("direction", 0); //resets animation to default break; case facing.upright: flipSprite = false; //shotSpawn.localPosition = new Vector3(shotSpawnDiag, shotSpawnDiag, 0); x = shotSpawnDiag; y = shotSpawnDiag; //shotSpawn.localRotation = Quaternion.Euler(0, 0, 45); rot = 45; animator.SetInteger("direction", 2); break; case facing.up: //shotSpawn.localPosition = new Vector3(0, shotSpawnDist, 0); x = 0; y = shotSpawnDist; //shotSpawn.localRotation = Quaternion.Euler(0, 0, 90); rot = 90; animator.SetInteger("direction", 1); break; case facing.upleft: flipSprite = true; //shotSpawn.localPosition = new Vector3(-shotSpawnDiag, shotSpawnDiag, 0); x = -shotSpawnDiag; y = shotSpawnDiag; //shotSpawn.localRotation = Quaternion.Euler(0, 0, 135); rot = 135; animator.SetInteger("direction", 2); break; case facing.left: flipSprite = true; //shotSpawn.localPosition = new Vector3(-shotSpawnDist, 0, 0); x = -shotSpawnDist; //y = 0; //shotSpawn.localRotation = Quaternion.Euler(0, 0, 180); rot = 180; animator.SetInteger("direction", 0); //resets animation to default (but flipped sprite) break; case facing.downleft: flipSprite = true; //shotSpawn.localPosition = new Vector3(-shotSpawnDiag, -shotSpawnDiag, 0); x = -shotSpawnDiag; y = -shotSpawnDiag; //shotSpawn.localRotation = Quaternion.Euler(0, 0, -135); rot = -135; animator.SetInteger("direction", 3); break; case facing.down: //shotSpawn.localPosition = new Vector3(0, -shotSpawnDist, 0); x = 0; y = -shotSpawnDist; //shotSpawn.localRotation = Quaternion.Euler(0, 0, -90); rot = -90; animator.SetInteger("direction", 4); break; case facing.downright: flipSprite = false; //shotSpawn.localPosition = new Vector3(shotSpawnDiag, -shotSpawnDiag, 0); x = shotSpawnDiag; y = -shotSpawnDiag; //shotSpawn.localRotation = Quaternion.Euler(0, 0, -45); rot = -45; animator.SetInteger("direction", 3); break; default: Debug.Log("DEFAULT"); break; } spriteRenderer.flipX = flipSprite; //Flip sprite if facing left if (crouching) { y -= crouchShot; } shotSpawn.localPosition = new Vector2(x, y); //Move crosshair for weapon shotSpawn.localRotation = Quaternion.Euler(0, 0, rot); }
private void Aim(float vert) { if (vert > 0) //If up button is held { if (move.x > 0.01) { direction = facing.upright; } else if (move.x < -0.01) { direction = facing.upleft; } else { direction = facing.up; } } else if (vert < 0) //If down button is held { if (grounded) { crouching = true; } //if (move.x > 0.01) direction = facing.downright; //else if (move.x < -0.01) direction = facing.downleft; else { direction = facing.down; crouching = false; } } else if (Input.GetAxisRaw("Aim") > 0) //Not moving, pressing AIM UP { switch (direction) { case facing.right: direction = facing.upright; break; case facing.left: direction = facing.upleft; break; default: break; } } else if (Input.GetAxisRaw("Aim") < 0) //Not moving, pressing AIM DOWN { switch (direction) { case facing.right: direction = facing.downright; break; case facing.left: direction = facing.downleft; break; default: break; } } else if (move.x > 0) //If moving right { if (canWallJump) { direction = facing.left; //flips direction if wall sliding } else { direction = facing.right; } } else if (move.x < 0) //If moving left { if (canWallJump) { direction = facing.right; //flips direction } else { direction = facing.left; } } else //if standing still, default to left or right direction { switch (direction) { case facing.upright: case facing.downright: direction = facing.right; break; case facing.upleft: case facing.downleft: direction = facing.left; break; case facing.up: case facing.down: if (flipSprite) { direction = facing.left; } else { direction = facing.right; } break; default: break; } } Animate(direction); //animate sprite and move crosshair }
// Update is called once per frame void Update() { input = Input.GetAxisRaw("Horizontal"); if (input > 0) { trans.localScale = new Vector3(0.5f, 0.5f, 1); if (speech != null) { speech.transform.localScale = new Vector3(2f, 2f, 0f); } if (tail != null) { tail.transform.localScale = new Vector3(1f, 1f, 0f); } if (dir == facing.LEFT) { dirChange = true; } else { dirChange = false; } dir = facing.RIGHT; } else if (input < 0) { trans.localScale = new Vector3(-0.5f, 0.5f, 1); if (speech != null) { speech.transform.localScale = new Vector3(-2f, 2f, 0f); } if (tail != null) { tail.transform.localScale = new Vector3(-1f, 1f, 0f); } if (dir == facing.RIGHT) { dirChange = true; } else { dirChange = false; } dir = facing.LEFT; } if (input != 0 && !lockInputs) { anim.SetBool("Walking", true); velocity.x = Mathf.MoveTowards(velocity.x, speed * input, maxAcell * Time.deltaTime); if (dirChange) { velocity.x /= 2.5f; } } else { anim.SetBool("Walking", false); velocity.x = Mathf.MoveTowards(velocity.x, 0, Deceleration * Time.deltaTime); } if (Mathf.Abs(velocity.x) > maxSpeed)//limits speed { velocity.x = maxSpeed * Mathf.Sign(velocity.x); } velocity.y += Physics2D.gravity.y * Time.deltaTime; //gM.anim.SetFloat("Walking",input); //deals with checking for floors and slopes LayerMask lM = 1 << 8; RaycastHit2D hit2D = Physics2D.Raycast(rayTrans.position, -Vector2.up, rayLength, lM); RaycastHit2D hit2DL = Physics2D.Raycast(rayTrans.position, RotatePoint(-Vector2.up, 1, 35f), rayLength - curveMod, lM); RaycastHit2D hit2DR = Physics2D.Raycast(rayTrans.position, RotatePoint(-Vector2.up, 1, -35f), rayLength - curveMod, lM); Debug.DrawRay(rayTrans.position, RotatePoint(-Vector2.up, 1, 35f) * (rayLength - curveMod), Color.green); Debug.DrawRay(rayTrans.position, RotatePoint(-Vector2.up, 1, -35f) * (rayLength - curveMod), Color.blue); Debug.DrawRay(rayTrans.position, -Vector2.up * rayLength, Color.red); //Debug.Log((Vector3)(-Vector2.up * rayLength) + rayTrans.position); if (hit2D.collider != null) { //landing Anim if (hit2D.collider.tag == "Ground") { if (!grounded) { anim.SetBool("Jump", false); } //anim.SetTrigger("Ground"); velocity.y = 0; grounded = true; jump2 = false; } } else if (hit2DL.collider != null) { //landing Anim if (hit2DL.collider.tag == "Ground") { if (!grounded) { anim.SetBool("Jump", false); } velocity.y -= Physics2D.gravity.y * Time.deltaTime; grounded = true; jump2 = false; } } else if (hit2DR.collider != null) { //landing Anim if (hit2DR.collider.tag == "Ground") { if (!grounded) { anim.SetBool("Jump", false); } velocity.y -= Physics2D.gravity.y * Time.deltaTime; grounded = true; jump2 = false; } } else { grounded = false; } //jumping if (grounded || !jump2) { //jump anim if (Input.GetButtonDown("Jump") && !lockInputs) { sound.PlayOneShot(Jump); anim.SetBool("Jump", true); //anim.SetTrigger("Jump"); velocity.y = Mathf.Sqrt(2 * jumpForce * Mathf.Abs(Physics2D.gravity.y)); if (!grounded) { jump2 = true; } } } //anti-wall clipping if (wall) { velocity.x = 0; } if (Input.GetButtonDown("Fire1") && !lockInputs)//sword { if (gM != null) { gM.SwingSword(); } } if (Input.GetButtonDown("Fire2") && !lockInputs)//bullet { if (gM != null) { gM.ThrowWeapon(); } } trans.Translate(velocity * Time.deltaTime); wall = false; //collision check Collider2D[] hits = Physics2D.OverlapBoxAll(transform.position, capCol.size, 0); foreach (Collider2D hit in hits) { if (hit == capCol || hit == sword || hit.isTrigger) { continue; } ColliderDistance2D colliderDistance = hit.Distance(capCol); if (colliderDistance.isOverlapped) { transform.Translate(colliderDistance.pointA - colliderDistance.pointB); if (Vector2.Angle(colliderDistance.normal, Vector2.down) < 90 && velocity.y > 0) { velocity.y *= -0.5f; } if (hit.tag == "Baddie") { TakeDamage(1); } if (Vector2.Angle(colliderDistance.normal, Vector2.right) == 180 && velocity.x > 0) { Debug.Log("Triggered"); wall = true; } if (Vector2.Angle(colliderDistance.normal, Vector2.left) == 180 && velocity.x < 0) { Debug.Log("Triggered"); wall = true; } } if (invulCtnDwn > 0) { invulCtnDwn -= Time.deltaTime; } } }
// Use this for initialization void Start() { me = this.gameObject; rb2 = me.GetComponent<Rigidbody2D>(); direction = facing.right; //trans = me.GetComponent<Transform>(); }
// Update is called once per frame public void Update() { if (networkView.isMine) { if (NetworkManager._playerPos == NetworkManager.PlayerPosition.Player1) { CamMovement._target = GameObject.FindGameObjectWithTag("Player1"); } // these are false unless one of keys is pressed currentInputState = inputState.None; // keyboard input if (Input.GetKey (KeyCode.LeftArrow)) { currentInputState = inputState.WalkLeft; facingDir = facing.Left; } if (Input.GetKey (KeyCode.RightArrow) && currentInputState != inputState.WalkLeft) { currentInputState = inputState.WalkRight; facingDir = facing.Right; } if (Input.GetKeyDown (KeyCode.UpArrow)) { currentInputState = inputState.Jump; } UpdatePhysics (); checkIfFallen(); manageCheckPoints(); } }
/// <summary> /// Takes a face and an orientation, and returns what the face should be after orientation /// </summary> /// <param name="before"></param> /// <param name="orientation"></param> /// <returns></returns> internal static facing orientFace(facing before, facing orientation) { facing retFace = before; #region downward facing if (orientation == facing.DOWN) { switch (before) { case facing.DOWN: retFace = facing.FRONT; break; case facing.FRONT: retFace = facing.UP; break; case facing.UP: retFace = facing.BACK; break; case facing.BACK: retFace = facing.DOWN; break; default: break; } } #endregion #region frontward facing if (orientation == facing.FRONT) { switch (before) { case facing.DOWN: retFace = facing.UP; break; case facing.FRONT: retFace = facing.BACK; break; case facing.UP: retFace = facing.DOWN; break; case facing.BACK: retFace = facing.FRONT; break; default: break; } } #endregion #region upward facing if (orientation == facing.UP) { switch (before) { case facing.DOWN: retFace = facing.BACK; break; case facing.FRONT: retFace = facing.DOWN; break; case facing.UP: retFace = facing.FRONT; break; case facing.BACK: retFace = facing.UP; break; default: break; } } #endregion #region leftward facing if (orientation == facing.LEFT) { switch (before) { case facing.LEFT: retFace = facing.FRONT; break; case facing.FRONT: retFace = facing.RIGHT; break; case facing.RIGHT: retFace = facing.BACK; break; case facing.BACK: retFace = facing.LEFT; break; default: break; } } #endregion #region rightward facing if (orientation == facing.RIGHT) { switch (before) { case facing.LEFT: retFace = facing.BACK; break; case facing.FRONT: retFace = facing.LEFT; break; case facing.RIGHT: retFace = facing.FRONT; break; case facing.BACK: retFace = facing.RIGHT; break; default: break; } } #endregion return(retFace); }
// Update is called once per frame void Update() { var sign = 0f; var plSign = player.transform.position.x - trans.position.x; if (reachedEnd) { sign = start.transform.position.x - trans.position.x; } else { sign = endt.transform.position.x - trans.position.x; } //checks if direction has changed if (Mathf.Sign(sign) < 0) { trans.localScale = new Vector3(setScale.x, setScale.y, 1); if (dir == facing.LEFT) { dirChange = true; } else { dirChange = false; } dir = facing.RIGHT; } else if (Mathf.Sign(sign) > 0) { trans.localScale = new Vector3(-setScale.x, setScale.y, 1); if (dir == facing.RIGHT) { dirChange = true; } else { dirChange = false; } dir = facing.LEFT; } switch (stance) { case Stance.IDLE: //face player lookTmr.timerUpdate(); if (lookTmr.checkTimer()) { lookTmr.resetTimer(); lookTmr.startTimer(); look = (int)(Random.Range(0f, 10f)); } if (look < 6) { trans.localScale = new Vector3(1, 1, 1); dir = facing.RIGHT; } else { trans.localScale = new Vector3(-1, 1, 1); dir = facing.LEFT; } break; case Stance.GAURD: //walk between 2 points if (Mathf.Abs(sign) > 0.05f && !dying) { velocity.x = Mathf.MoveTowards(velocity.x, SpeedWagon * Mathf.Sign(sign), maxAcell * Time.deltaTime); if (dirChange) { velocity.x /= 2.5f; } anim.SetBool("Walking", true); } else { anim.SetBool("Walking", false); reachedEnd = !reachedEnd; if (dirChange) { velocity.x /= 2.5f; } } break; case Stance.CHARGE: RaycastHit2D loS = Physics2D.Raycast(rayTrans.position, player.transform.position - trans.position); Debug.DrawRay(rayTrans.position, player.transform.position - trans.position, Color.magenta); if (Mathf.Sign(plSign) < 0) { trans.localScale = new Vector3(1, 1, 1); if (dir == facing.RIGHT) { dirChange = true; } else { dirChange = false; } dir = facing.LEFT; } else if (Mathf.Sign(plSign) > 0) { trans.localScale = new Vector3(-1, 1, 1); if (dir == facing.LEFT) { dirChange = true; } else { dirChange = false; } dir = facing.RIGHT; } if (loS.collider != null) { //print(loS.collider.ToString()+ " : " + loS.distance.ToString()); if (loS.distance < Sight) { if (loS.collider.tag == "Player") { if (Mathf.Abs(plSign) > 0.2f && !dying) { velocity.x = Mathf.MoveTowards(velocity.x, SpeedWagon * Mathf.Sign(plSign), maxAcell * Time.deltaTime); if (dirChange) { velocity.x /= 2.5f; } anim.SetBool("Walking", true); } else { anim.SetBool("Walking", false); reachedEnd = !reachedEnd; if (dirChange) { velocity.x /= 2.5f; } } } } } break; } if (dying) { velocity.x = 0; trans.localScale = new Vector3(-1, 1, 1); dir = facing.LEFT; } velocity.y += Physics2D.gravity.y * Time.deltaTime; //ground detection LayerMask lM = 1 << 8; RaycastHit2D hit2D = Physics2D.Raycast(rayTrans.position, -Vector2.up, rayLength, lM); RaycastHit2D hit2DL = Physics2D.Raycast(rayTrans.position, RotatePoint(-Vector2.up, 1, 35f), rayLength - curveMod, lM); RaycastHit2D hit2DR = Physics2D.Raycast(rayTrans.position, RotatePoint(-Vector2.up, 1, -35f), rayLength - curveMod, lM); Debug.DrawRay(rayTrans.position, RotatePoint(-Vector2.up, 1, 35f) * (rayLength - curveMod), Color.green); Debug.DrawRay(rayTrans.position, RotatePoint(-Vector2.up, 1, -35f) * (rayLength - curveMod), Color.blue); Debug.DrawRay(rayTrans.position, -Vector2.up * rayLength, Color.red); //Debug.Log((Vector3)(-Vector2.up * rayLength) + rayTrans.position); if (hit2D.collider != null) { //landing Anim if (hit2D.collider.tag == "Ground") { //Debug.Log("Triggered feet"); velocity.y = 0; } } else if (hit2DL.collider != null) { //landing Anim if (hit2DL.collider.tag == "Ground") { //Debug.Log("Triggered slope"); velocity.y -= Physics2D.gravity.y * Time.deltaTime; } } else if (hit2DR.collider != null) { //landing Anim if (hit2DR.collider.tag == "Ground") { //Debug.Log("Triggered slope"); velocity.y -= Physics2D.gravity.y * Time.deltaTime; } } if (wall) { velocity.x = 0; } trans.Translate(velocity * Time.deltaTime); wall = false; Collider2D[] hits = Physics2D.OverlapBoxAll(transform.position + (Vector3)eneCapCol.offset, eneCapCol.size, 0); foreach (Collider2D hit in hits) { if (hit == eneCapCol || hit.tag == "Attack") { continue; } ColliderDistance2D colliderDistance = hit.Distance(eneCapCol); if (colliderDistance.isOverlapped) { transform.Translate(colliderDistance.pointA - colliderDistance.pointB); if (Vector2.Angle(colliderDistance.normal, Vector2.right) == 180 && velocity.x > 0) { //Debug.Log("Triggered"); wall = true; } if (Vector2.Angle(colliderDistance.normal, Vector2.left) == 180 && velocity.x < 0) { //Debug.Log("Triggered"); wall = true; } } } atkTimer.timerUpdate(); }
public void setFacing(facing toSet) { this.dir = toSet; }
//flips token to face destination on x axis void Flip() { float pos = gameObject.transform.localPosition.x; if(destination.x < pos){ if(face == facing.Right){ face = facing.Left; StartCoroutine("FlipAround"); } } if(destination.x > pos){ if(face == facing.Left){ face = facing.Right; StartCoroutine("FlipAround"); } } }
private ResultModel Scenario5(int X, int Y, int Battery, facing Facing, ICollection <ICollection <RoomInfo> > Maps) { var value = new List <string>(); var Steps = new List <string> { "TL", "TL", "A" }; var results = new ResultModel(); results.Visited = new List <XY>(); results.Cleaned = new List <XY>(); results.final = new final(); int battery = Convert.ToInt32(Battery); int currentX = X; int currentY = Y; foreach (var step in Steps) { var directions = new[] { "TL", "TR" }; var ValidMap = ValidateMaps(Maps, X, Y); battery -= UsingBattery(step); results.Battery = battery.ToString(); if (battery > 0 && ValidMap) { if (directions.Any(x => x.Contains(step))) { Facing = ChangeDirection(Facing, step); } else if (step != InstructionModel.C) { int oldX = currentX; int oldY = currentY; List <int> moving = Moving(Facing, currentX, currentY, step); currentX = moving.ElementAt(0); currentY = moving.ElementAt(1); ValidMap = ValidateMaps(Maps, currentX, currentY); if (ValidMap) { var newloc = Maps.ElementAt(currentY).ElementAt(currentX); if (newloc == RoomInfo.S) { results.Visited.Add(new XY { X = currentX, Y = currentY }); } else { return(results); } } else { return(results); } } else if (step == InstructionModel.C) { results.Cleaned.Add(new XY { X = currentX, Y = currentY }); } } else if (battery > 0) { return(results); } else { results.Battery = battery.ToString(); } } results.final.X = currentX; results.final.Y = currentY; results.final.facing = Facing.ToString(); return(results); }
public ResultModel Cleaning(InformationModel values) { var commands = values.commands; var Battery = values.Battery; var Maps = values.Map; var start = values.start; int X = start.X; int Y = start.Y; facing Facing = (facing)Enum.Parse(typeof(facing), start.facing, true); //Cleaning(X, Y, Battery, Facing, Command, Maps); var results = new ResultModel(); results.Visited = new List <XY>(); results.Cleaned = new List <XY>(); results.final = new final(); int battery = Convert.ToInt32(Battery); int currentX = X; int currentY = Y; try { results.Visited.Add(new XY { X = currentX, Y = currentY }); foreach (var step in commands) { var directions = new[] { "TL", "TR" }; var ValidMap = ValidateMaps(Maps, X, Y); battery -= UsingBattery(step); results.Battery = battery.ToString(); if (battery > 0 && ValidMap) { if (directions.Any(x => x.Contains(step))) { Facing = ChangeDirection(Facing, step); } else if (step != InstructionModel.C) { int oldX = currentX; int oldY = currentY; List <int> moving = Moving(Facing, currentX, currentY, step); currentX = moving.ElementAt(0); currentY = moving.ElementAt(1); ValidMap = ValidateMaps(Maps, currentX, currentY); if (ValidMap) { var newloc = Maps.ElementAt(currentY).ElementAt(currentX); if (newloc == RoomInfo.S) { results.Visited.Add(new XY { X = currentX, Y = currentY }); } else { var result = Scenario1(oldX, oldY, battery, Facing, Maps); results.Visited.AddRange(result.Visited); results.Cleaned.AddRange(result.Cleaned); currentX = result.final.X; currentY = result.final.Y; Facing = (facing)Enum.Parse(typeof(facing), result.final.facing, true); battery = Convert.ToInt32(result.Battery); } } else { var result = Scenario1(oldX, oldY, battery, Facing, Maps); results.Visited.AddRange(result.Visited); results.Cleaned.AddRange(result.Cleaned); currentX = result.final.X; currentY = result.final.Y; Facing = (facing)Enum.Parse(typeof(facing), result.final.facing, true); battery = Convert.ToInt32(result.Battery); } } else if (step == InstructionModel.C) { results.Cleaned.Add(new XY { X = currentX, Y = currentY }); } } else if (battery > 0) { var result = Scenario1(currentX, currentY, battery, Facing, Maps); results.Visited.AddRange(result.Visited); results.Cleaned.AddRange(result.Cleaned); currentX = result.final.X; currentY = result.final.Y; Facing = (facing)Enum.Parse(typeof(facing), result.final.facing, true); battery = Convert.ToInt32(result.Battery); } else { results.Battery = battery.ToString(); } } results.final.X = currentX; results.final.Y = currentY; results.final.facing = Facing.ToString(); results.Visited = results.Visited.GroupBy(x => new { x.X, x.Y }).Select(y => new XY() { X = y.Key.X, Y = y.Key.Y }).OrderBy(z => z.X).ToList(); results.Cleaned = results.Cleaned.GroupBy(x => new { x.X, x.Y }).Select(y => new XY() { X = y.Key.X, Y = y.Key.Y }).OrderBy(z => z.X).ToList(); } catch (Exception ex) { var message = ex.Message; var ada = ex; } return(results); }
private void KeyInput(KeyboardState currentKeyboardState, KeyboardState previousKeyboardState) { if (currentState != state.jumping && currentState != state.falling) //Als de speler niet in de lucht is { if (!currentKeyboardState.IsKeyDown(Keys.LeftShift)) //Als shift niet is ingedrukt { if (currentKeyboardState.IsKeyDown(Keys.D)) //Laat character naar rechts lopen als D is ingedrukt { currentState = state.walkingRight; currentFacing = facing.right; } if (currentKeyboardState.IsKeyDown(Keys.A)) //Laat character naar links lopen als A is ingedrukt { currentState = state.walkingLeft; currentFacing = facing.left; } if (!currentKeyboardState.IsKeyDown(Keys.D) && (currentState == state.walkingRight | currentState == state.runningRight)) //Zorg dat character stopt met lopen of rennen als D wordt losgelaten { currentState = state.standing; currentFacing = facing.right; } if (!currentKeyboardState.IsKeyDown(Keys.A) && (currentState == state.walkingLeft | currentState == state.runningLeft)) //Zorg dat character stopt met lopen of rennen als A wordt losgelaten { currentState = state.standing; currentFacing = facing.left; } if (currentKeyboardState.IsKeyDown(Keys.W)) //Laat character springen als W wordt ingedrukt { currentState = state.jumping; //Game1.jumpSound.Play(); } if (currentKeyboardState.IsKeyDown(Keys.S)) //Laat character iets oppakken als Spatie wordt ingedrukt { currentState = state.picking; } if (currentState == state.picking && !currentKeyboardState.IsKeyDown(Keys.S)) { currentState = state.standing; } //Later misschien ook toevoegen dat je ook in de lucht kan schieten, maar daar ik vond de oplossing op de bug niet if (carryingGun == true) { if (shootingTimer > 50) { if (currentKeyboardState.IsKeyDown(Keys.Space) && !previousKeyboardState.IsKeyDown(Keys.Space)) { if (currentFacing == facing.left) Game1.AddProjectile(new Vector2(bounds.X - Game1.projectileTexture.Width, bounds.Y + sourceHeight / 2 - 5)); else Game1.AddProjectile(new Vector2(bounds.X + source.Width, bounds.Y + sourceHeight / 2 - 5)); shootingTimer = 0; //zorg dat hij weer een tijdje niet meer kan schieten isShooting = true; //Met boolian, zodat spatie niet ingedrukt hoeft te worden gehouden } } } } else if (currentKeyboardState.IsKeyDown(Keys.LeftShift)) { if (!currentKeyboardState.IsKeyDown(Keys.D)) //Zorg dat character stopt met rennen als shift nog steeds is ingedrukt, maar D niet meer { currentState = state.standing; } if (!currentKeyboardState.IsKeyDown(Keys.A)) //Zorg dat character stopt met rennen als shift nog steeds is ingedrukt, maar A niet meer { currentState = state.standing; } if (currentKeyboardState.IsKeyDown(Keys.D)) //Run right when shift and D are pressed { currentState = state.runningRight; currentFacing = facing.right; } if (currentKeyboardState.IsKeyDown(Keys.A)) //Run left when shift and A are pressed { currentState = state.runningLeft; currentFacing = facing.left; } if (currentKeyboardState.IsKeyDown(Keys.W)) //Jump when W is pressed once { currentState = state.jumping; //Game1.jumpSound.Play(); } if (currentKeyboardState.IsKeyDown(Keys.S)) //Laat character iets oppakken als Spatie wordt ingedrukt { currentState = state.picking; } } } else if (currentState == state.jumping | currentState == state.falling) { if (!currentKeyboardState.IsKeyDown(Keys.LeftShift)) //When he's not running when jumping { if (currentKeyboardState.IsKeyDown(Keys.D)) { if (speed <= maxWalkingSpeed) speed += .2f; currentFacing = facing.right; } if (currentKeyboardState.IsKeyDown(Keys.A)) { if (speed >= -maxWalkingSpeed) speed -= .2f; currentFacing = facing.left; } } else if (currentKeyboardState.IsKeyDown(Keys.LeftShift)) //When he's running { if (currentKeyboardState.IsKeyDown(Keys.D)) { if (speed <= maxRunningSpeed) speed += .2f; currentFacing = facing.right; } if (currentKeyboardState.IsKeyDown(Keys.A)) { if (speed >= -maxRunningSpeed) speed -= .2f; currentFacing = facing.left; } } } }
public void Update(GameTime gameTime) { if (alive) { //if (richting == -1) //naar links //{ // richting = 1; // currentFacing = facing.right; // distance--; //} //else if (richting == 1) //{ // richting = -1; // currentFacing = facing.left; // distance++; //} //if (distance >= 200) // richting = -1; //else if (distance <= 200) // richting = 1; //bounds.X += richting; Platform platform = GetIntersectingPlatform(feetBounds); //Kijk in game1.cs of de character in contact is met een platform is de lijst if (platform == null)//Als enemy geen platform raakt. { bounds.X += richting; if (turningTimer == 0) { if (richting == -1) //naar links { richting = 1; bounds.X += 2; currentFacing = facing.right; bounds.Y--; } else if (richting == 1) { richting = -1; bounds.X -= 2; currentFacing = facing.left; bounds.Y--; } } bounds.Y++; } else { bounds.Y = platform.boundingBoxTop.Y - bounds.Height + 1; bounds.X += richting; if (turningTimer >= 1) turningTimer++; if (turningTimer >= 30) turningTimer = 0; } feetBounds = new Rectangle(bounds.X + (bounds.Width / 4), (bounds.Y + bounds.Height) - 5, (bounds.Width / 4), 5); if (frameCount % delay == 0) //Eens in de <delay-waarde> frames { if (texture == enemyTexture1) //Slime { if (frameCount / delay >= 3) frameCount = 0; source = new Rectangle(frameCount / delay * 0, 0, 75, 55); } else if (texture == enemyTexture2) //Draak { if (frameCount / delay >= 3) frameCount = 0; source = new Rectangle(frameCount / delay * 96, 2 * 96, 96, 96); } else if (texture == enemyTexture3) //Spider { if (frameCount / delay >= 4) frameCount = 0; source = new Rectangle(frameCount / delay * 93, 3, 89, 65); } } frameCount++; } if (health <= 0) { alive = false; bounds = new Rectangle(-1000, -1000, 0, 0); giveScore(); } }
/// <summary> /// Takes a face and a rotation, and returns what that face should be after rotation /// </summary> /// <param name="before">the face</param> /// <param name="rotate">the rotation value</param> /// <returns></returns> internal static facing rotateFace(facing before, rotation rotate) { facing retFace = before; #region 90degrees if (rotate == rotation.R90) { switch (before) { case facing.DOWN: retFace = facing.LEFT; break; case facing.LEFT: retFace = facing.UP; break; case facing.UP: retFace = facing.RIGHT; break; case facing.RIGHT: retFace = facing.DOWN; break; default: break; } } #endregion #region 180degrees if (rotate == rotation.R180) { switch (before) { case facing.DOWN: retFace = facing.UP; break; case facing.LEFT: retFace = facing.RIGHT; break; case facing.UP: retFace = facing.DOWN; break; case facing.RIGHT: retFace = facing.LEFT; break; default: break; } } #endregion #region 270degrees if (rotate == rotation.R270) { switch (before) { case facing.DOWN: retFace = facing.RIGHT; break; case facing.LEFT: retFace = facing.DOWN; break; case facing.UP: retFace = facing.LEFT; break; case facing.RIGHT: retFace = facing.UP; break; default: break; } } #endregion return(retFace); }
private void UpdateFacing(float moveHorizontal, float moveVertical) { if (isDead) { return; } if (moveHorizontal > 0 && moveVertical >= 0) { if (moveHorizontal > moveVertical) { facingDirection = facing.right; } else { facingDirection = facing.up; } } else if (moveHorizontal > 0 && moveHorizontal < 0) { if (moveHorizontal > moveVertical * -1) { facingDirection = facing.right; } else { facingDirection = facing.down; } } else if (moveHorizontal < 0 && moveVertical >= 0) { if (moveHorizontal * -1 > moveVertical) { facingDirection = facing.left; } else { facingDirection = facing.up; } } else if (moveHorizontal < 0 && moveHorizontal < 0) { if (moveHorizontal < moveVertical) { facingDirection = facing.left; } else { facingDirection = facing.down; } } else if (moveHorizontal >= 0 && moveVertical > 0) { if (moveHorizontal < moveVertical) { facingDirection = facing.up; } else { facingDirection = facing.right; } } else if (moveHorizontal < 0 && moveHorizontal > 0) { if (moveHorizontal * -1 > moveVertical) { facingDirection = facing.left; } else { facingDirection = facing.up; } } else if (moveHorizontal >= 0 && moveVertical < 0) { if (moveHorizontal > moveVertical * -1) { facingDirection = facing.right; } else { facingDirection = facing.down; } } /* if (moveHorizontal > 0 && moveVertical == 0) * facingDirection = facing.right; * else if (moveHorizontal < 0 && moveVertical == 0) * facingDirection = facing.left; * else if (moveHorizontal == 0 && moveVertical > 0) * facingDirection = facing.up; * else if (moveHorizontal == 0 && moveVertical < 0) * facingDirection = facing.down; */ /*else if (moveHorizontal < 0 && moveVertical < 0) * facingDirection = facing.left_down; * else if (moveHorizontal > 0 && moveVertical < 0) * facingDirection = facing.right_down; * else if (moveHorizontal < 0 && moveVertical > 0) * facingDirection = facing.left_up; * else if (moveHorizontal > 0 && moveVertical > 0) * facingDirection = facing.right_up;*/ animator.SetInteger("DirectionState", (int)facingDirection); }
private void CollisionEnemies() { if (hurtTimer > 50) { if (game.currentLevel == game.level1) { for (int i = 0; i < Level1.enemies.Count; i++) { if (boundingBox.X < Level1.enemies[i].bounds.X + Level1.enemies[i].bounds.Width && boundingBox.Y + boundingBox.Height > Level1.enemies[i].bounds.Y + 10 && boundingBox.X + boundingBox.Width > Level1.enemies[i].bounds.X && boundingBox.Y < Level1.enemies[i].bounds.Y + Level1.enemies[i].bounds.Height) { Game1.hurtSound.Play(); health.lifes -= 1; if ((boundingBox.X + boundingBox.Width) - (Level1.enemies[i].bounds.X + Level1.enemies[i].bounds.Width) > 0) { currentFacing = facing.left; bounds.X += instantBounceBack; speed = bounceBackSpeed; isHurt = true; hurtTimer = 0; } else { currentFacing = facing.right; bounds.X -= instantBounceBack; speed = -bounceBackSpeed; isHurt = true; hurtTimer = 0; } } } } else if (game.currentLevel == game.level2) { for (int i = 0; i < Level2.enemies.Count; i++) { if (boundingBox.X < Level2.enemies[i].bounds.X + Level2.enemies[i].bounds.Width && boundingBox.Y + boundingBox.Height > Level2.enemies[i].bounds.Y + 10 && boundingBox.X + boundingBox.Width > Level2.enemies[i].bounds.X && boundingBox.Y < Level2.enemies[i].bounds.Y + Level2.enemies[i].bounds.Height) { health.lifes -= 1; if ((boundingBox.X + boundingBox.Width) - (Level2.enemies[i].bounds.X + Level2.enemies[i].bounds.Width) > 0) { currentFacing = facing.left; bounds.X += instantBounceBack; speed = bounceBackSpeed; isHurt = true; hurtTimer = 0; } else { currentFacing = facing.right; bounds.X -= instantBounceBack; speed = -bounceBackSpeed; isHurt = true; hurtTimer = 0; } } } } else if (game.currentLevel == game.level3) { for (int i = 0; i < Level3.enemies.Count; i++) { if (boundingBox.X < Level3.enemies[i].bounds.X + Level3.enemies[i].bounds.Width && boundingBox.Y + boundingBox.Height > Level3.enemies[i].bounds.Y + 10 && boundingBox.X + boundingBox.Width > Level3.enemies[i].bounds.X && boundingBox.Y < Level3.enemies[i].bounds.Y + Level3.enemies[i].bounds.Height) { health.lifes -= 1; if ((boundingBox.X + boundingBox.Width) - (Level3.enemies[i].bounds.X + Level3.enemies[i].bounds.Width) > 0) { currentFacing = facing.left; bounds.X += instantBounceBack; speed = bounceBackSpeed; isHurt = true; hurtTimer = 0; } else { currentFacing = facing.right; bounds.X -= instantBounceBack; speed = -bounceBackSpeed; isHurt = true; hurtTimer = 0; } } } } } }
public facing switchFacing() { dir = dir == facing.Left ? facing.Right : facing.Left; return dir; }
void Start() { main = FindObjectOfType<CameraController>(); turn = TurnTimer.currentTurn; face = facing.Left; speed = critter.GetSpeed(); SetScale(age); ScaleToCamera(); }
public static void respawn(Game1 game) { if (game.currentLevel == game.level1) { for (int i = 0; i < Level1.platforms.Count; i++) // Platformen op begin positie plaatsen { Level1.platforms[i].boundingBox = new Rectangle((int)Level1.startDimPlat[i].X, (int)Level1.startDimPlat[i].Y, Level1.platforms[i].boundingBox.Width, Level1.platforms[i].boundingBox.Height); Level1.platforms[i].boundingBoxTop = new Rectangle(Level1.platforms[i].boundingBox.X, Level1.platforms[i].boundingBox.Y, Level1.platforms[i].boundingBox.Width, 5); } game.level1.Initialize(); health.lifes = health.startLifes; score.currentScore = 0; for (int i = 0; i < Level1.coins.Count; i++) { coins.taken[i] = false; } game.level1.gun.picked = false; carryingGun = false; currentState = state.standing; currentFacing = facing.right; jumpingSpeed = -20; jumpCount = 0; } }
//checks current facing of the token void CheckFacing() { if(gameObject.transform.localRotation.y == 180){ face = facing.Right; } if(gameObject.transform.localRotation.y == 0){ face = facing.Left; } }
private void TakeInput() { direction = Vector2.zero; if (Input.GetKey(KeyCode.UpArrow)) { direction += Vector2.up; lookDirection = facing.up; } if (Input.GetKey(KeyCode.LeftArrow)) { direction += Vector2.left; lookDirection = facing.left; } if (Input.GetKey(KeyCode.DownArrow)) { direction += Vector2.down; lookDirection = facing.down; } if (Input.GetKey(KeyCode.RightArrow)) { direction += Vector2.right; lookDirection = facing.right; } if (Input.GetKey(KeyCode.UpArrow) && Input.GetKey(KeyCode.LeftArrow)) { direction = new Vector2(-1.0f, 1.0f); lookDirection = facing.upleft; } if (Input.GetKey(KeyCode.UpArrow) && Input.GetKey(KeyCode.RightArrow)) { direction = new Vector2(1.0f, 1.0f); lookDirection = facing.upright; } if (Input.GetKey(KeyCode.DownArrow) && Input.GetKey(KeyCode.LeftArrow)) { direction = new Vector2(-1.0f, -1.0f); lookDirection = facing.downleft; } if (Input.GetKey(KeyCode.DownArrow) && Input.GetKey(KeyCode.RightArrow)) { direction = new Vector2(1.0f, -1.0f); lookDirection = facing.downright; } if (Input.GetKeyDown(KeyCode.Space)) { Vector2 currPos = transform.position; targetPos = Vector2.zero; if (lookDirection == facing.up) { targetPos.y += 1; } if (lookDirection == facing.down) { targetPos.y -= 1; } if (lookDirection == facing.right) { targetPos.x += 1; } if (lookDirection == facing.left) { targetPos.x -= 1; } transform.Translate(targetPos * dashRange); } }