public void update() //this is the update method { if (cooldown > 0) // the the cooldown is greater than 0 { cooldown--; //it reduces the cooldown } switch (swinging) // the switch to see if their swinging { case Swinging.Not: //if their not { rotation = 0; // it removes the rotation from the sword break; } case Swinging.Is: //if they are swinging { swing(); //it swings timer++; // and adds to the time if (timer > interval - 100 / .98) // if the timer has been running for longer than the interval - aspeed { timer = 0; //it sets the timer to 0 swinging = Swinging.Not; //and it sets swinging to not swinged = false; //and swinged to false to reset all the stuff } break; } } }
private void directionToSwing() { if (direction == Swinging.None) { direction = Swinging.Right; } else if (direction == Swinging.Right) { transform.Rotate(new Vector3(0, 0, rotationSpeed)); if (currentAngle == 30) { direction = Swinging.Left; } } else if (direction == Swinging.Left) { transform.Rotate(new Vector3(0, 0, -rotationSpeed)); if (currentAngle == 330) { direction = Swinging.Right; } } }
void Start() { desiredDirection = Quaternion.identity; walking = gameObject.GetComponent<Walking> (); rotating = gameObject.GetComponent<Rotating> (); shooting = gameObject.GetComponent<Shooting> (); swinging = gameObject.GetComponent<Swinging> (); energy = gameObject.GetComponent<Energy> (); }
public void update(MouseState mouse, Viewport view, EntitySprite player, BinaryWriter writer, MemoryStream writeStream, TcpClient client) //this is the update method { if (mouse.X < view.Width / 2 && swinged == false) //if the mouse if on the left side of the screen it sets swung to left { SWUNG = swung.left; } else if (mouse.X >= view.Width / 2 && swinged == false)//if its on the right and they havent swung it sets it to right { SWUNG = swung.right; } if (mouse.RightButton == ButtonState.Pressed && ((PlayerStats)player).mana >= 20 && cooldown <= 0) //if they rightclick and it isnt on cooldown and they have enough mana { ((PlayerStats)player).mana = -20; //it takes the mana ((PlayerStats)player).health = ((PlayerStats)player).intelligence; //and heals them cooldown = 100; //and puts the spell on CD heal = true; //and makes the heal bool true writeStream.Position = 0; writer.Write((byte)Protocol.weaponCreated); writer.Write((byte)2); SendData(GetDataFromMemoryStream(writeStream), client); } else if (cooldown > 0) // the the cooldown is greater than 0 { cooldown--; //it reduces the cooldown } switch (swinging) // the switch to see if their swinging { case Swinging.Not: //if their not { rotation = 0; // it removes the rotation from the sword if (mouse.LeftButton == ButtonState.Pressed) // when they left click { swinging = Swinging.Is; // it changes state to swinging } break; } case Swinging.Is: //if they are swinging { if (timer == 0) { writeStream.Position = 0; writer.Write((byte)Protocol.weaponCreated); if (mouse.X < view.Width / 2) { writer.Write((byte)0); } else { writer.Write((byte)1); } SendData(GetDataFromMemoryStream(writeStream), client); } swing(); //it swings timer++; // and adds to the time if (timer > interval - ((PlayerStats)player).aSpeed / .98) // if the timer has been running for longer than the interval - aspeed { timer = 0; //it sets the timer to 0 swinging = Swinging.Not; //and it sets swinging to not swinged = false; //and swinged to false to reset all the stuff } break; } } }
// Use this for initialization void Start() { direction = Swinging.None; }