public void Death() { if (state == ePlayerState.Dead) { return; } state = ePlayerState.Dead; CVoice.PlayLongCrySound(); if (GameManager.instance.timeout) { if (!grounded) { rigid.AddForce(new Vector2(0, -0.1f)); } anim.SetTrigger("timeout"); } else { anim.SetTrigger("dying"); } StartCoroutine(GameManager.instance.TextStuff()); }
private void m_timer_Elapsed(object sender, ElapsedEventArgs e) { if (this.m_state == ePlayerState.Stopped) { this.Stop(); this.m_queue = new Queue <PlayerExecutable>(); } else { m_lifeTime += 100; PlayerExecutable executable = null; lock (this.m_queue) { if (this.m_queue.Count > 0) { executable = this.m_queue.Dequeue(); } } if (executable != null) { try { executable(); } catch (Exception exception) { this.m_state = ePlayerState.Stopped; this.LastError = exception.Message; Console.WriteLine("player[{0}] execute error:{1}", this.m_account, exception.Message); Console.WriteLine(exception.StackTrace); } } } }
//Knocks the player down public void Knockdown(float strength, float upOrdown) { state = ePlayerState.Knockeddown; print(gameObject.name + " is knocked down"); anim.SetBool("knockdown", true); StartCoroutine(GetOutOfHurt(0.27f)); StartCoroutine(opponent.GetComponent <Player>().GetOutOfHurt(0.05f)); if (facingRight) { if (cornered) { rigid.AddForce(new Vector2(-strength / 30, upOrdown)); opponent.GetComponent <Rigidbody2D>().AddForce(new Vector2(+strength / 1.5f, 0f)); } else { rigid.AddForce(new Vector2(-strength / 10, upOrdown)); } } else if (!facingRight) { if (cornered) { rigid.AddForce(new Vector2(+strength / 30, upOrdown)); opponent.GetComponent <Rigidbody2D>().AddForce(new Vector2(-strength / 1.5f, 0f)); } else { rigid.AddForce(new Vector2(+strength / 10, upOrdown)); } } }
// プレイヤーと当たった時 void OnTriggerEnter2D(Collider2D coll) { // レイヤー情報取得 string layerName = LayerMask.LayerToName(coll.gameObject.layer); // 敵、プレイヤーが生きてる時 if (layerName == "Enemy" && PlayerState == ePlayerState.NONE) { float player_pos_x; Vector3 text_pos; hitcount++; // プレイヤー情報設定 PlayerSprite.enabled = false; player_pos_x = transform.position.x; PlayerState = ePlayerState.DOWN; recovery_cnt = Define.PLAYER_WEIGHT * hitcount; down_cnt = Define.PLAYER_DOWNCOUNT; // ダウンカウント再設定 TextScript[0].textmesh.color = Color.red; TextScript[0].texttype = eTextType.RecoveryCount; text_pos = TextScript[0].transform.position; text_pos.x = player_pos_x; TextScript[0].transform.position = text_pos; // 復帰カウント再設定 TextScript[1].texttype = eTextType.DownCount; text_pos = TextScript[1].transform.position; text_pos.x = player_pos_x; TextScript[1].transform.position = text_pos; } }
public void EnterWaitingRoom() { this.m_state = ePlayerState.WaitingRoom; GSPacketIn pkg = new GSPacketIn((byte)ePackageType.SCENE_LOGIN); this.SendTCP(pkg); }
public void Jump() { state = ePlayerState.InAir; grounded = false; rigid.AddForce(new Vector2(0f, JumpForce / 10)); //SVFXManager.instance.InstantiateDustJump(dustJumpY, this.gameObject); }
public void CallbackPostion(Vector3 _vPos) { m_Debug.text = string.Format("X:{0} Y:{1} Z:{2}", _vPos.x, _vPos.y, _vPos.z); m_vTargetpos = _vPos; m_vDir = m_vTargetpos - transform.position; m_vDir.Normalize(); m_PlayerState = ePlayerState.eRun; }
public void EnterWaitingRoom(int typeScene) { this.m_state = ePlayerState.WaitingRoom; GSPacketIn pkg = new GSPacketIn((byte)ePackageType.SCENE_LOGIN); pkg.WriteInt(typeScene); this.SendTCP(pkg); }
private void _OnStateChanged(PlayerAnimation source, ePlayerState prevState, ePlayerState newState) { if (m_animator != null) { //m_animator.ResetTrigger(prevState.ToString()); //NOTE: be sure the last trigger is the one used in the animator m_animator.Play(newState.ToString()); } }
public void LoginWeb() { this.InnerPwd = this.GrenateInnerPassword(); string s = this.m_account + "," + Md5(this.Password) + "," + this.InnerPwd + "," + this.NickName; MemoryStream output = new MemoryStream(); string requestUriString = ""; using (BinaryWriter writer = new BinaryWriter(output)) { writer.Write((short)DateTime.UtcNow.Year); writer.Write((byte)DateTime.UtcNow.Month); writer.Write((byte)DateTime.UtcNow.Date.Day); writer.Write((byte)DateTime.UtcNow.Hour); writer.Write((byte)DateTime.UtcNow.Minute); writer.Write((byte)DateTime.UtcNow.Second); writer.Write(Encoding.UTF8.GetBytes(s)); // Debug.Log(Encoding.UTF8.GetString(output.ToArray(), 7, output.ToArray().Length - 7)); byte[] inArray = Rsa(output.ToArray()); requestUriString = string.Format("{0}?p={1}&v=0", ConfigMgr.LoginUrl, HttpUtility.UrlEncode(Convert.ToBase64String(inArray))); Debug.Log(requestUriString); } string str3 = ""; using (WebResponse response = WebRequest.Create(requestUriString).GetResponse()) { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { str3 = reader.ReadLine(); } } if (str3.IndexOf("true") > 0) { Console.WriteLine("{0} web login success....", this.m_account); this.m_state = ePlayerState.WebLogined; if (!base.Connect()) { this.lastErr = eErrorCode.SERVER_FAILED; Console.WriteLine("{0} connect to server failed...", this.m_account); this.m_state = ePlayerState.Stopped; this.LastError = "Kh\x00f4ng thể kết nối tới server."; } else { Console.WriteLine("{0} socket connected....", this.m_account); if (this.m_state == ePlayerState.WebLogined) { // this.LoginSocket(); this.Act(new PlayerExecutable(this.LoginSocket)); } } } else { this.lastErr = eErrorCode.USER_FAILED; this.m_state = ePlayerState.Stopped; this.LastError = "Lỗi dữ liệu User"; } }
protected override void OnDisconnect() { base.OnDisconnect(); if (this.m_state != ePlayerState.Stopped) { this.m_state = ePlayerState.Stopped; this.LastError = "Bị kick khỏi game!"; } }
public void CreateLogin() { this.lastErr = eErrorCode.LOADING; UnityEngine.Debug.Log("Create Login"); //string str = DateTime.Now.ToFileTime().ToString(); string str = "132178654824148372"; string requestUriString = string.Format("{0}?content={1}", ConfigMgr.CreateLoginUrl, HttpUtility.UrlEncode(this.m_account + "|" + this.Password + "|" + str + "|" + Md5(this.m_account + this.Password + str + ConfigMgr.Md5Key))); string str3 = ""; using (WebResponse response = WebRequest.Create(requestUriString).GetResponse()) { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { str3 = reader.ReadLine(); } } if (str3 == "0") { this.m_state = ePlayerState.CreateLogined; string xml = ""; using (WebResponse response2 = WebRequest.Create(string.Format("{0}?username={1}", ConfigMgr.LoginSelectList, this.m_account)).GetResponse()) { using (StreamReader reader2 = new StreamReader(response2.GetResponseStream())) { xml = reader2.ReadToEnd(); } } UnityEngine.Debug.Log("XXX" + xml); GameController.LogToScreen("XXX" + xml); if (xml.IndexOf("NickName") > 0) { XmlDocument document = new XmlDocument(); document.LoadXml(xml); XmlNodeList elementsByTagName = document.GetElementsByTagName("Item"); for (int i = 0; i < elementsByTagName.Count; i++) { this.NickName = elementsByTagName[i].Attributes["NickName"].Value; } } this.LoginWeb(); if (lastErr == eErrorCode.LOADING) { lastErr = eErrorCode.DONE; } //this.Act(new PlayerExecutable(this.LoginWeb)); } else { this.m_state = ePlayerState.Stopped; lastErr = eErrorCode.LOGIN_FAILED; this.LastError = "CreateLogin Failed!"; GameController.LogToScreen("CreateLogin Failed"); } }
/// <summary> /// Makes the player crouch. pLookLeft is an optional parameter, when supplied, changes the look direction /// </summary> private void Crouch(bool?pLookLeft = null) { this.State = ePlayerState.Crouch; // Allow the player to change direction when crouched if (pLookLeft.HasValue) { mLookDir.LookLeft = pLookLeft.Value; } }
public void Stop() { this.m_state = ePlayerState.Stopped; this.Disconnect(); this.m_timer.Stop(); /*if (this.m_log != null) * { * this.m_log.Dispose(); * }*/ }
// ゲームオーバー判定 void GameOverJudge() { var TextTagNum = GameObject.FindGameObjectsWithTag("Text"); // 消え残しがなくなった時 if (TextTagNum.Length == 0) { // BGMを止めてゲームオーバーへ SoundManager.Instance.StopBgm(); PlayerState = ePlayerState.GAMEOVER; } }
public virtual void OnDead() //躺尸 { if (!IsDie) { return; } if (mStateLastTime >= GameSet.Instance.DeadBodyTime) { mState = ePlayerState.None; } }
public IEnumerator GetOutOfHurt(float stunned) { if (countingHurt) { yield break; } countingHurt = true; yield return(new WaitForSeconds(stunned)); state = ePlayerState.Ready; countingHurt = false; }
// 復帰 void Recovery() { // カウント表示 TextScript[0].textmesh.text = ((int)down_cnt).ToString(); TextScript[1].textmesh.text = recovery_cnt.ToString(); // 押された時 if (GodTouch.GetPhase() == GodPhase.Began) { recovery_cnt--; // 復帰 if (recovery_cnt <= 0) { PlayerSprite.enabled = true; PlayerState = ePlayerState.NONE; TextScript[0].textmesh.text = ""; TextScript[1].textmesh.text = ""; // 無敵状態コルーチン StartCoroutine("Invincible"); } } down_cnt -= Time.deltaTime; // 復帰不可 if (down_cnt <= 0) { // エフェクト再生 this.GetComponent <ParticleSystem>().Play(); // 今取得したスコア生成表示 var DeathTextObj = Instantiate(TextPrefab, transform.position, Quaternion.identity); var PlayerDeathTextScript = DeathTextObj.gameObject.GetComponent <TextGenerator>(); PlayerDeathTextScript.textmesh.text = 10.ToString(); // 得点文字に当たり判定追加 var TextCircleCollider2D = DeathTextObj.gameObject.AddComponent <CircleCollider2D>(); TextCircleCollider2D.radius = Define.TEXT_RADIUS; TextCircleCollider2D.isTrigger = true; // 状態更新 PlayerState = ePlayerState.DEATH; // 復帰・ダウンカウント文字削除 Destroy(PlayerTextObj[0]); Destroy(PlayerTextObj[1]); } }
private void OnPlayerStateChangedHandler(ePlayerState obj) { switch (obj) { case ePlayerState.Normal: _input.Player.Enable(); break; case ePlayerState.Distracted: case ePlayerState.InFlow: DeactivateRemoval(0); DeactivateRemoval(1); _input.Player.Disable(); break; } }
public void HurtTimer() { if (hurtT > 0) { hurtT -= Time.deltaTime; } if (hurtT == 0) { state = ePlayerState.Ready; hurtT = hurtCooldown; } if (hurtT < 0) { hurtT = hurtCooldown; } }
/// <summary> /// /// </summary> public void DieArthurDie() { if (this.Lives > 1) { this.Lives--; // Play audio just once mAudioSource.PlayOneShot(this.AudioDeath, 0.75f); this.State = ePlayerState.Die; return; } else { GameOver(); } }
public BotPlayer(string account, int interval, string ip, int port) : base(ip, port, false, new byte[0x2000], new byte[0x2000]) { this.Account = account; this.Password = "******"; this.m_isHost = false; this.m_timer = new System.Timers.Timer((double)interval); this.m_timer.Elapsed += new ElapsedEventHandler(this.m_timer_Elapsed); this.m_queue = new Queue <PlayerExecutable>(); this.m_state = ePlayerState.Init; this.m_lastSentTick = TickHelper.GetTickCount(); this.m_actionInterval = 0L; this.m_recvCount = 0; this.m_sentCount = 0; base.Strict = true; base.Encryted = true; //this.m_log = new StreamWriter(System.IO.File.Create(string.Format("./logs/{0}.log", account))); }
// 初期化 void Start() { // プレイヤー画像情報 PlayerSprite = GetComponent <SpriteRenderer>(); // プレハブ設定 TextPrefab = Resources.Load("Prefab/TextPrefab") as GameObject; ShotPrefab = Resources.Load("Prefab/ShotPrefab") as GameObject; // カウント文字生成 // 0:ダウンカウント用 1:復帰カウント用 Vector3 pos = transform.position; pos.y += 1; PlayerTextObj = new GameObject[] { Instantiate(TextPrefab, pos, Quaternion.identity), Instantiate(TextPrefab, transform.position, Quaternion.identity) }; TextScript = new TextGenerator[] { PlayerTextObj[0].gameObject.GetComponent <TextGenerator>(), PlayerTextObj[1].gameObject.GetComponent <TextGenerator>() }; // ダウンカウント文字設定 TextScript[0].textmesh.text = " "; TextScript[0].textmesh.color = Color.red; TextScript[0].texttype = eTextType.RecoveryCount; // 復帰カウント文字設定 TextScript[1].textmesh.text = " "; TextScript[1].texttype = eTextType.DownCount; // プレイヤー状態 PlayerState = ePlayerState.NONE; hitcount = 0; // エフェクト色設定 ParticleSystem.MainModule main = this.GetComponent <ParticleSystem>().main; main.startColor = Function.GetSelectRandomColor(); // タッチ位置初期化 TouchManager.Instance.transform.position = Vector3.zero; // BGM開始 SoundManager.Instance.PlayBgmByName(Define.MAIN); }
// Use this for initialization void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(this); } playCont = GetComponent <PlayerContollerEC>(); playerState = ePlayerState.idle; DialogueManager.instance.initiateDialogueEvent += SetPlayerInDialogue; DialogueManager.instance.endDialogueEvent += SetPlayerOutOfDialogue; EndCubeScript.instance.endLevelFeedback += DisableMovement; }
//Called by opponent on hit public void ApplyDamage(float dmgreceived) { print(gameObject.name + " got hit"); if (stun == eStun.blocking) { //CVoice.PlayVoiceSound(); CVoice.PlayImpactSound(); StartCoroutine(camShake.Shake(0.15f, 0.4f)); hitPoints -= dmgreceived; GameManager.instance.UpdateHP(); } else if (stun == eStun.blockbroken) { state = ePlayerState.Hurt; //anim.SetBool("knockdown", true); //TODO implement knockdown anim CVoice.PlayLongCrySound(); StartCoroutine(camShake.Shake(0.15f, 0.4f)); hitPoints -= dmgreceived; GameManager.instance.UpdateHP(); } else if (stun == eStun.jumped) { state = ePlayerState.Hurt; anim.SetTrigger("longhurt"); CVoice.PlayVoiceSound(); StartCoroutine(camShake.Shake(0.15f, 0.4f)); hitPoints -= dmgreceived; GameManager.instance.UpdateHP(); } else if (stun == eStun.normal) { state = ePlayerState.Hurt; anim.SetTrigger("hurt"); CVoice.PlayVoiceSound(); StartCoroutine(camShake.Shake(0.15f, 0.4f)); hitPoints -= dmgreceived; GameManager.instance.UpdateHP(); } print(gameObject.name + "s HP: " + hitPoints); stun = eStun.normal; }
public void ChangeState(ePlayerState state) { if (IsDie && mState != ePlayerState.None && state != ePlayerState.Dead) { return; } if (mState == state) { return; } mState = state; mStateLastTime = 0; //不是巡逻,追击,回出生点,移动停下来 if (mState != ePlayerState.Quest && mState != ePlayerState.FollowTarget && mState != ePlayerState.Pause) { CleanMoveNodes(); } }
void Run() { // 이동 transform.position += m_vDir * 5f * Time.deltaTime; anim.SetFloat("Speed", Mathf.Abs(m_vDir.x)); // Animator側で設定している"Speed"パラメタにvを渡す anim.SetFloat("Direction", Mathf.Abs(m_vDir.z)); // Animator側で設定している"Direction"パラメタにhを渡す anim.speed = 1.5f; // 회전 처리 Quaternion from = transform.rotation; Quaternion to = Quaternion.LookRotation(m_vDir); transform.rotation = Quaternion.Lerp(from, to, 5f * Time.deltaTime); float fDist = Vector3.Distance(transform.position, m_vTargetpos); if (fDist < 0.1f) { m_PlayerState = ePlayerState.eWait; } }
/// <summary> /// /// </summary> private void Shoot(bool pCrouch) { if (mShots.Count < 3) { mStateBeforeShooting = this.State; SpawnShot(); if (pCrouch) { this.State = ePlayerState.ShootCrouch; } else { this.State = ePlayerState.Shoot; } mAudioSource.clip = this.AudioThrow; mAudioSource.Play(); } }
public ClientConnector(string account, string password, int interval, string ip, int port, ConnectorManager cManager) : base(ip, port, false, new byte[0x2000], new byte[0x2000]) { this.m_account = account; this.Password = password; this.m_isHost = false; this.m_timer = new System.Timers.Timer((double)interval); this.m_timer.Elapsed += new ElapsedEventHandler(this.m_timer_Elapsed); this.m_queue = new Queue <PlayerExecutable>(); this.m_state = ePlayerState.Init; this.m_lastSentTick = TickHelper.GetTickCount(); this.m_actionInterval = 0L; this.m_recvCount = 0; this.m_sentCount = 0; base.Strict = true; base.Encryted = true; this.connectorManager = cManager; this.SetHostIp(ip); this.lastErr = eErrorCode.DONE; //this.m_log = new StreamWriter(System.IO.File.Create(string.Format("./logs/{0}.log", account))); }
public float mCastSpellDistance; //攻击距离 public bool InitState() { BaseGameLogic <IPlayerLogic> bgLogic = (BaseGameLogic <IPlayerLogic>)GameLogicManager.Instance.GetGameLogic(eGameLogicType.PlayerLogic, (short)ePlayerLogicType.Robot); if (null == bgLogic) { return(false); } mLogic = bgLogic.Logic; if (IsDie) { mState = ePlayerState.None; } else { mState = ePlayerState.Idle; } return(true); }
//public eCharacter character; public void Start() { if (PlayerIndex == 0) { this.gameObject.name = "Subject 1"; facingRight = true; } else if (PlayerIndex == 1) { this.gameObject.name = "Subject 2"; facingRight = false; } origScale = transform.localScale.x; hitPoints = maxHitPoints; GetComponents(); FindOpponent(); Flip(); GameManager.instance.UpdateHP(); state = ePlayerState.Ready; //GetAnimClipTimes(); }
private void SetPlayerState(ePlayerState _state) { m_ePlayerState = _state; }
void Wait() { if(Input.GetMouseButtonDown(0)) { Vector3 vPos = ScreenToWorld(Input.mousePosition);//Camera.main.ScreenToWorldPoint(Input.mousePosition); m_vTargetpos = vPos; m_vDir = m_vTargetpos - transform.position; m_vDir.Normalize(); m_PlayerState = ePlayerState.eRun; // CNetClient.Instance.SendPosition(m_vTargetpos); } anim.Play("Rest"); anim.SetFloat("Speed", 0f); // Animator側で設定している"Speed"パラメタにvを渡す anim.SetFloat("Direction", 0f); // Animator側で設定している"Direction"パラメタにhを渡す }
public override void Update(GameTime gameTime) { float mls = (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f; if (!bInitialized) { ResetPosition(); bInitialized = true; return; } Vector2 mergedMoveDirection = new Vector2(); if (this.IsMerged) { if (!Player.IsThisPlayerCaptain(this)) { base.Update(gameTime); return; } else { if (m_PlayerMerges.ContainsKey(this.id)) { // Check if someone is trying to break the merge which // anyone in the merge group is allowed to do if (m_PlayerMerges[this.id].IsAnyoneTryingToBreakTheMerge() || IsMergeBreakButtonPressed()) { // If yes then this captain and its merge need to be removed from our // merge list Player.RemoveMergeList(this.id); this.IsMerged = false; this.Reset(mDefaultSize); } else { // Set state to always running. Update the animation here! // this.PlayerState = ePlayerState.RUN; this.m_runAnim.Update(gameTime); Player.m_mergeMonsterAnim.Update(gameTime); mergedMoveDirection = new Vector2(); mergedMoveDirection = GetAvgDirectionForAllPlayers(this); // There is always a speed movement applied when the players // are merged // if (mergedMoveDirection.Length() == 0) mergedMoveDirection = new Vector2(1, 1); this.mVelocity.X = mls * (mergedMoveDirection.X * 800.0f); this.mVelocity.Y = mls * (mergedMoveDirection.Y * 800.0f); //mergedMoveDirection *= new Vector2(5, 5); this.mPositionX += this.mVelocity.X;// mergedMoveDirection.X; this.mPositionY += this.mVelocity.Y;//mergedMoveDirection.Y; base.Update(gameTime); return; } } } } // Check for collisions with other players foreach (Player p in Program.Instance.GamePlayers) { // Don't bother checking if this player has collided with itself // if (p.id == this.id) continue; if (CheckForCollision(p)) { // Case 1 - I am not merged with any other players if ( !IsMerged || !p.IsMerged ) { // TODO - Remove for final game! if (IsMergeButtonPressed() && p.IsMergeButtonPressed()) { m_bIsMerged = true; // Has a captain been selected? // If yes then add me to the list of merged players for this list if (m_PlayerMerges.ContainsKey(this.id)) { m_PlayerMerges[this.id].Add(p); p.IsMerged = true; } // If no then make me the captain else { m_PlayerMerges[this.id] = new PlayerMergeList(); p.IsMerged = true; m_PlayerMerges[this.id].Add(p); } } } // Case 2 - I am merged with one or more players else { // Another player is trying to join the collective. Since all parties involved in the // collision will send a collision event only the captain should check if members // of its list have merge keys pressed. To avoid doing too much processing. // if (Player.IsThisPlayerCaptain(this)) { // Checked if this player is already merged in with this captain. If so // then don't bother checking if we should merge it. // if (!p.IsMerged) { //bool bAllPlayersReadyToMerge = false; //foreach (Player pMerged in Player.m_PlayerMerges[this.id].players) //{ // All players in the collective will need to have their merge // buttons pressed as well as the new player wanting to join to add // the new player // If all players have their merge buttons pressed // If yes then add the new player to the merged player list //if (!pMerged.IsMergeButtonPressed()) //{ // bAllPlayersReadyToMerge = false; //break; //} //} // Check if all the players who are already merged and the new merged player have their keys // pressed to merge. If they do then merge them! // if (Player.m_PlayerMerges[this.id].AreAllPlayersReadyToMerge() && p.IsMergeButtonPressed()) Player.m_PlayerMerges[this.id].Add(p); } } } } } SetState(); switch(this.PlayerState) { case ePlayerState.IDLE: this.m_idleFrontAnim.Update(gameTime); break; case ePlayerState.RUN: this.m_runAnim.Update(gameTime); break; } List<Enemy> destroy = new List<Enemy>(); foreach (Enemy e in Program.Instance.mEnemies) { if (CheckForCollision(e)) { if (e.PixelWidth < this.PixelWidth) { AudioManager.Instance.PlaySound("MonsterDie"); AnimatedSpriteEx killAnim = new AnimatedSpriteEx(this.Game); killAnim.Position = new Vector2(e.mPosition.X - (e.PixelWidth * 2), e.mPosition.Y - (e.PixelHeight * 2)); killAnim.Load(this.Game.Content, new Vector2(0, 0), "\\kill anim\\Kill", 8, 20); AnimatedSpriteManager.Instance.Add(killAnim); e.Destroy(); destroy.Add(e); Vector2 pos = mPosition; PixelWidth += 5; PixelHeight += 5; //mScale.X *= 1.1f; //mScale.Y = mScale.X; mPosition = pos; //mBounds.Radius = Radius; //mBounds.Center.X = mPositionX; //mBounds.Center.Y = mPositionY; this.SetBboxPos(mPosition); this.m_idleFrontAnim.Scale = mScale.X; this.m_runAnim.Scale = mScale.X; Program.Instance.mEnemiesKilled++; if (Program.Instance.mEnemiesKilled % 3 == 0) { if (Program.Instance.mMaxEnemies < 100) Program.Instance.mMaxEnemies++; } } else { e.Destroy(); destroy.Add(e); Reset((int)(PixelWidth*0.5f)); } } } foreach (Enemy e in destroy) { Program.Instance.mEnemies.Remove(e); } GamePadState state = GamePad.GetState(id); if (mIsUsingKeyboard) { if (Keyboard.GetState().GetPressedKeys().Length > 0) { if (id == PlayerIndex.One) { this.moveY = Keyboard.GetState().IsKeyDown(Keys.W) ? -1 : 0; this.moveX = Keyboard.GetState().IsKeyDown(Keys.D) ? 1 : 0; if (moveX == 0) moveX = Keyboard.GetState().IsKeyDown(Keys.A) ? -1 : 0; if (moveY == 0) moveY = Keyboard.GetState().IsKeyDown(Keys.S) ? 1 : 0; } else if (id == PlayerIndex.Two) { this.moveY = Keyboard.GetState().IsKeyDown(Keys.I) ? -1 : 0; this.moveX = Keyboard.GetState().IsKeyDown(Keys.L) ? 1 : 0; if (moveX == 0) moveX = Keyboard.GetState().IsKeyDown(Keys.J) ? -1 : 0; if (moveY == 0) moveY = Keyboard.GetState().IsKeyDown(Keys.K) ? 1 : 0; } mVelocity.X += mls * (moveX * 1000); mVelocity.Y += mls * (moveY * 1000); Vector2 drag = new Vector2(-mVelocity.X, -mVelocity.Y); if (drag.Length() != 0) { drag.Normalize(); mVelocity = mVelocity + mls * (drag * (mVelocity.Length()*2)); } if (mVelocity.Length() > mMaxSpeed) { mVelocity.Normalize(); mVelocity = mVelocity * mMaxSpeed; } // set position mPositionX = mPosition.X + mls * mVelocity.X; mPositionY = mPosition.Y + mls * mVelocity.Y; if (mPositionX + Radius > Config.Instance.GetAsInt("ScreenWidth")) mPositionX = Config.Instance.GetAsInt("ScreenWidth") - Radius; if (mPositionX - Radius < 0) mPositionX = Radius; if (mPositionY + Radius > Config.Instance.GetAsInt("ScreenHeight")) mPositionY = Config.Instance.GetAsInt("ScreenHeight") - Radius; if (mPositionY - Radius < 0) mPositionY = Radius; base.Update(gameTime); return; } } this.moveX = state.ThumbSticks.Left.X; this.moveY = state.ThumbSticks.Left.Y; state.ThumbSticks.Left.Normalize(); this.mVelocity.X += mls * (state.ThumbSticks.Left.X*1000); this.mVelocity.Y += mls * (-state.ThumbSticks.Left.Y*1000); Vector2 drag2 = new Vector2(-mVelocity.X, -mVelocity.Y); if (drag2.Length() != 0) { drag2.Normalize(); mVelocity = mVelocity + mls * (drag2 * (mVelocity.Length() * 2)); } if (mVelocity.Length() > mMaxSpeed) { mVelocity.Normalize(); mVelocity = mVelocity * mMaxSpeed; } // set position mPositionX = mPosition.X + mls * mVelocity.X; mPositionY = mPosition.Y + mls * mVelocity.Y; if (mPositionX + Radius > Config.Instance.GetAsInt("ScreenWidth")) mPositionX = Config.Instance.GetAsInt("ScreenWidth") - Radius; if (mPositionX - Radius < 0) mPositionX = Radius; if (mPositionY + Radius > Config.Instance.GetAsInt("ScreenHeight")) mPositionY = Config.Instance.GetAsInt("ScreenHeight") - Radius; if (mPositionY - Radius < 0) mPositionY = Radius; base.Update(gameTime); }
public void SetState() { if (IsStopped()) this.PlayerState = ePlayerState.IDLE; else this.PlayerState = ePlayerState.RUN; }