public void SetUpPlayer(PlayerInfo pi, ControlKeys ck) { comp.animator = gameObject.GetComponent<Animator>(); base.speed = 2f; base.direction = base.right; playInfo = pi; SetControlKeys(ck.keyUp, ck.keyLeft, ck.keyDown, ck.keyRight, ck.keyFire, ck.keySwitchWeapon); comp.spriteRend = GetComponent<SpriteRenderer>(); comp.rb2d = gameObject.GetComponent<Rigidbody2D>(); comp.animator = GetComponent<Animator>(); setUpHB(comp, playInfo); setUpPB(comp, playInfo); setUpWeapons(pi); }
protected void UpdateControlSprites() { if (Input.anyKeyDown) { if (!CheckGamepadInput()) { if (controlKey == ControlKeys.Controller) { ConvertToKB(); controlKey = ControlKeys.Keyboard; } } } if (CheckGamepadInput() && controlKey == ControlKeys.Keyboard) { ConvertToController(); controlKey = ControlKeys.Controller; } }
public override void Update(GameSettings settings) { _dir.x = 0; _dir.y = 0; PointFloat selfPos = GetPosition(); foreach (GameObject obj in TomatoMainEngine.GameObjects) { if (obj.Type == Type && obj != this) { PointFloat objPos = obj.GetPosition(); float x = selfPos.x - objPos.x; float y = selfPos.y - objPos.y; float h = -(float)Math.Atan2(x, y); h = h + GetVelocity().GetSpeed() * 2; _dir = _dir - Helpers.PhysicsAndPositions.GetDirection(h); } } float x0 = selfPos.x; float y0 = selfPos.y; float h0 = -(float)Math.Atan2(x0, y0); h0 = h0 + GetVelocity().GetSpeed() * 2; _dir = _dir - Helpers.PhysicsAndPositions.GetDirection(h0); SetVelocityAdd(_dir / 500); _fire.SetPos(GetPosition()); _fire.Blow(0.03f, 4, false); if (_timer < 0) { SetVelocityAdd(Helpers.PhysicsAndPositions.GetDirection(GetRotation()) / 10.0f); _timer = 900; } _timer--; if (ControlKeys.IsKeyDown("e")) { SetVelocityAdd(Helpers.PhysicsAndPositions.GetDirection(GetRotation()) / 10.0f); } base.Update(settings); }
public override void Update(GameSettings settings) { PointFloat vel = GetVelocity(); float rotV = GetRotationVelocity(); rotV = rotV - (rotV / 50); if (ControlKeys.IsKeyDown("s")) { vel = MoveBackward(vel); } if (ControlKeys.IsKeyDown("w")) { vel = MoveForward(vel); //Console.WriteLine(GetPosition().x + " " + GetPosition().y); } if (ControlKeys.IsKeyDown("d")) { rotV = rotV + (0.05f - rotV); } if (ControlKeys.IsKeyDown("a")) { rotV = rotV + (-0.05f - rotV); } if (ControlKeys.IsKeyDown("e")) { gun.SetPos(Helpers.PhysicsAndPositions.OffsetPosition(GetPosition(), 2.0f, GetRotation() + (float)Math.PI * 0.5f)); gun.SetRot(GetRotation()); gun.SetSpread(Helpers.PhysicsAndPositions.PI * 2); gun.SetLifeTime(100, 200); gun.Blow(1f, 100, false); } SetVelocity(vel); SetRotationVelocity(rotV); base.Update(settings); engineFirePar.SetPos(Helpers.PhysicsAndPositions.OffsetPosition(GetPosition(), 1.0f, GetRotation() + (float)Math.PI * 1.5f)); engineFirePar.SetRot(GetRotation() + 3.14f); CamController.SetPos(GetPosition()); }
//This Class will be used by the Player to request KeyCode. public KeyCode GetKey(int PlayerID, ControlKeys controlKeys) { return(playerControls[PlayerID].GetKeyCode(controlKeys)); }
/// <summary> /// Returns table layout with pairs TextBox and Labels /// </summary> /// <param name="labels">Labels describing text boxes</param> /// <param name="keys">Keys to store the created text boxes in this.controls</param> /// <param name="height">Height of the whole table layout</param> /// <param name="location">Location of the whole table layout</param> /// <returns>Initialized table layout</returns> private TableLayoutPanel GetTextBoxesWithLabelsLayout(string[] labels, ControlKeys[] keys, int height, Point location) { TableLayoutPanel layout = new TableLayoutPanel(); layout.ColumnCount = labels.Length; layout.RowCount = 2; layout.Location = location; layout.Height = height; layout.Padding = new Padding(5); layout.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top; TableLayoutColumnStyleCollection styles = layout.ColumnStyles; for (int i = 0; i < layout.ColumnCount; i++) { // Make all columns equal size ColumnStyle columnStyle = new ColumnStyle(SizeType.Percent, 100 / layout.ColumnCount); styles.Add(columnStyle); Label label = new Label(); label.Text = labels[i]; label.AutoSize = true; label.Dock = DockStyle.Fill; label.TextAlign = ContentAlignment.MiddleCenter; layout.Controls.Add(label, i, 0); TextBox textBox = new TextBox(); textBox.AutoSize = true; textBox.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom; layout.Controls.Add(textBox, i, 1); this.controls[(int)keys[i]] = textBox; } return layout; }
/// <summary> /// Add event handlers to selected TextBox object /// </summary> /// <param name="affectedControls">Array of affected controls</param> /// <remarks>Occurance of TextChange event in any of the affected controls will cause the /// Apply and Cancel Changes buttons to become enabled. </remarks> private void AddTextChangedHandlers(ControlKeys[] affectedControls) { foreach (ControlKeys key in affectedControls) { TextBox box = (TextBox)this.controls[(int)key]; box.TextChanged += TextBoxTextChangedHandler; } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Constructs a KeyboardData from specified TCODKey object /// </summary> /// <param name="tcodKeys"></param> public KeyboardData(TCODKey tcodKeys) { if (tcodKeys == null) { throw new ArgumentNullException("tcodKeys"); } this.character = tcodKeys.Character; this.keyCode = tcodKeys.KeyCode; this.isKeyPress = tcodKeys.Pressed; int f = 0; if (tcodKeys.LeftAlt) f |= (int)ControlKeys.LeftAlt; if (tcodKeys.RightAlt) f |= (int)ControlKeys.RightAlt; if (tcodKeys.LeftControl) f |= (int)ControlKeys.LeftControl; if (tcodKeys.RightControl) f |= (int)ControlKeys.RightControl; if (tcodKeys.Shift) f |= (int)ControlKeys.Shift; this.controlKeys = (ControlKeys)f; }
// ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Constructs a KeyboardData given all of the parameters seperately /// </summary> /// <param name="character"></param> /// <param name="keyCode"></param> /// <param name="isKeyDown"></param> /// <param name="controlKeys"></param> public KeyboardData(char character, TCODKeyCode keyCode, bool isKeyDown, ControlKeys controlKeys) { this.character = character; this.isKeyPress = isKeyDown; this.keyCode = keyCode; this.controlKeys = controlKeys; }
//todo 测试操控模块 protected void FixedUpdate() { if (Controllable) { float accMultiply = 1; Vector3 tempControlVector = ControlKeys.GetVector(JOYSTICK, Vector3.positiveInfinity); if (!tempControlVector.Equals(Vector3.positiveInfinity)) { ParseDir(tempControlVector, ref accMultiply); } tempControlVector = ControlKeys.GetVector(SHOOTING_JOYSTICK, Vector3.positiveInfinity); if (!tempControlVector.Equals(Vector3.positiveInfinity)) { aimmingPos += tempControlVector * AimmingPosAcce * Time.fixedDeltaTime; } Vector3 curPos = trans.position; Quaternion curRot = trans.rotation; tempControlVector = ControlKeys.GetVector(STARING_AT, Vector3.positiveInfinity); if (tempControlVector.Equals(Vector3.positiveInfinity)) { if (ControlKeys.GetBool(TURN_RIGHT)) { curRot = TurnRight(curRot); } if (ControlKeys.GetBool(TURN_LEFT)) { curRot = Turnleft(curRot); } } else { curRot = StaringAt(curRot, tempControlVector, curPos); } trans.rotation = curRot; Vector3 curDir = (curRot * Vector3.up).normalized; Vector3 curVelocity = rb2d.velocity; curVelocity -= drag * Time.fixedDeltaTime * rb2d.velocity.magnitude * curVelocity.normalized; if (ControlKeys.GetBool(ACC_FRONT)) { curVelocity = SpeedUpFront(curVelocity, curDir, accMultiply); } if (ControlKeys.GetBool(ACC_BACK)) { curVelocity = SpeedUpBack(curVelocity, curDir, accMultiply); } if (ControlKeys.GetBool(ACC_LEFT)) { curVelocity = SpeedUpLeft(curVelocity, curDir, accMultiply); } if (ControlKeys.GetBool(ACC_RIGHT)) { curVelocity = SpeedUpRight(curVelocity, curDir, accMultiply); } if (ForceTurn) { curVelocity = ForceTurnParse(curVelocity); } rb2d.velocity = curVelocity; } }
// Use this for initialization protected virtual void Start() { Play.enabled = false; cowboyImage = Resources.Load <Sprite>("cowboy"); dancerImage = Resources.Load <Sprite>("dancer"); prospectorImage = Resources.Load <Sprite>("prospector"); freemanImage = Resources.Load <Sprite>("freeman"); backgroundImage = Resources.Load <Sprite>("selectBG"); aButton = Resources.Load <Sprite>("abutton"); bButton = Resources.Load <Sprite>("bbutton"); escButton = Resources.Load <Sprite>("escbutton"); enterButton = Resources.Load <Sprite>("enterbutton"); startButton = Resources.Load <Sprite>("startbutton"); spaceButton = Resources.Load <Sprite>("spacebutton"); if (Input.GetJoystickNames().Length > 0) { controlKey = ControlKeys.Controller; ConvertToController(); } else { controlKey = ControlKeys.Keyboard; ConvertToKB(); } _classes.Add("The Cowboy"); _classes.Add("The Dancer"); _classes.Add("The Prospector"); _classes.Add("The Freeman"); playerHorizontals.Add(new List <Button>() { p1Left, p1Right }); playerHorizontals.Add(new List <Button>() { p2Left, p2Right }); playerHorizontals.Add(new List <Button>() { p3Left, p3Right }); playerHorizontals.Add(new List <Button>() { p4Left, p4Right }); playerImages.Add(p1Image); playerImages.Add(p2Image); playerImages.Add(p3Image); playerImages.Add(p4Image); playerButtons.Add(p1Button); playerButtons.Add(p2Button); playerButtons.Add(p3Button); playerButtons.Add(p4Button); playerTexts.Add(P1Text); playerTexts.Add(P2Text); playerTexts.Add(P3Text); playerTexts.Add(P4Text); playerTextShadows.Add(P1TextShadow); playerTextShadows.Add(P2TextShadow); playerTextShadows.Add(P3TextShadow); playerTextShadows.Add(P4TextShadow); p1Button.sprite = startButton; p2Button.sprite = startButton; p3Button.sprite = startButton; p4Button.sprite = startButton; NextButton.enabled = false; BackButton.enabled = true; var speaker = GameObject.Find("Speaker"); if (speaker != null) { var audio = speaker.GetComponent <AudioSource>(); if (!audio.isPlaying) { audio.Play(); } } }
public TaskStatus TurnToTarget() { ControlKeys.SetVector(STARING_AT, targetTrans.position); return(TaskStatus.Success); }
public TaskStatus SpeedUp() { ControlKeys.SetBool(ACC_FRONT, true); return(TaskStatus.Success); }
public TaskStatus MoveBack() { ControlKeys.SetBool(ACC_BACK, true); return(TaskStatus.Success); }
public TaskStatus TurnToPathPos() { ControlKeys.SetVector(STARING_AT, pathPos[0]); return(TaskStatus.Success); }