//攻击函数,进行攻击 protected void ImAttacking(RaycastHit enemy) { strength -= COMSUMEPERATTACK; //扣除移动体力 if (enemy.transform.GetComponent <InfantryUnit>()) //对敌方目标造成伤害 { DamageToEnemyInfantry(enemy); Debug.Log("hit inf"); } else if (enemy.transform.GetComponent <TankUnit>()) { Debug.Log("hit tank"); DamageToEnemyTank(enemy); } //if(enemy.transform.GetComponent<TankUnit>().infantryState == myState.Alert) {//如果敌方处于警戒状态,(((((并且此单位处于敌方单位的攻击范围内(←←←←←等待做!!!))) // DamageToSelf(enemy); //} DrawInfantryUI();//重新绘制UI IfShowInfantryUI(true); for (int index = 0; index < tagetHexList.Count; index++) { tagetHexList[index].GetComponent <SpriteRenderer>().color = defaultHexColor[index]; } infantryState = myState.Idle; tagetHexList.Clear();//清除目标地块列表 defaultHexColor.Clear(); }
// Update is called once per frame void Update() { if (myTurn == false) { playerState = myState.NotMyTurn;//myTurn为False时,玩家处于NotMyTurn的状态 SetColorOfFirstLine(defaultHexColor); } switch (playerState) { case myState.Idle: //待命状态 break; case myState.Command: //命令状态 break; case myState.Set: //等待放置状态 if (hasPut == true) { SetColorOfFirstLine(defaultHexColor); playerState = Player.myState.Idle; //如果已经放置,则恢复为Idle状态 } else { PutUnit(waitingForPut); //否则继续放置 } break; } }
void executeRule2() { cur = nState; nState = tbl[(int)cur, (int)type]; cb = clbTbl[(int)cur, (int)type]; cb(res, null); }
//点击之后单位状态变为移动 public void MoveNow( ) { if ((infantryState == myState.Idle || infantryState == myState.Atk) && IfCanMove( )) //只有在待命状态或者Atk时,并且体力值满足时才能移动 { infantryState = myState.Mov; }//状态变为Mov }
//点击之后单位状态变为攻击 public void AtkNow( ) { if ((infantryState == myState.Idle || infantryState == myState.Mov) && IfCanAttack( )) //Idle时,或者Mov时,且有体力值才能攻击 { infantryState = myState.Atk; //状态变为Mov } }
//选中目标地块 protected void ReadyToMove( ) { if (Input.GetMouseButtonDown(0)) //如果鼠标左键点击 { Ray ray = mainCamera.GetComponent <Camera> ( ).ScreenPointToRay(Input.mousePosition); //检测鼠标点击位置 RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.transform.GetComponent <SpriteRenderer> ( ) && hit.transform.GetComponent <SpriteRenderer> ( ).color == movHexColor)//如果有SpriteRenderer,并且点击的是可移动位置(即点击的是地块而不是其他东西) { targetHex = hit; CountHexMoved(targetHex.transform); //计算移动的格数,方便后面扣除体力值。 infantryState = myState.IsMoving; //状态成为正在移动 } else { for (int index = 0; index < tagetHexList.Count; index++) { tagetHexList[index].GetComponent <SpriteRenderer> ( ).color = defaultHexColor[index]; } tagetHexList.Clear( ); //清除目标地块 defaultHexColor.Clear( ); infantryState = myState.Idle; //状态变回Idle } } } }
public override void OnHitWall(HitWallEvent evnt) { if (state == myState.Start) { if ((this.Y > BattleFieldHeight * 0.5 && this.X > BattleFieldWidth * 0.5) || (this.Y < BattleFieldHeight * 0.5 && this.X < BattleFieldWidth * 0.5)) { TurnLeft(90); TurnGunLeft(90); } else { TurnRight(90); TurnGunRight(90); } state = myState.FollowinWall; } else { invertDir = !invertDir; /* if ((this.Y > BattleFieldHeight * 0.5 && this.X > BattleFieldWidth * 0.5) || (this.Y < BattleFieldHeight * 0.5 && this.X < BattleFieldWidth * 0.5)) TurnLeft(180); else TurnRight(180); */ } }
static myPaserResult myparser2(string line) { //state table //state |token // |, |" |other //------+-------+-------+------ //s |s |a |e //a |a |b |a //b |s |a |invalid //e |s |invalid|e myPaserResult res = new myPaserResult(); myState cur = myState.s; myState nState = myState.s; foreach (char c in line) { myToken tk = new myToken(c); cur = nState; nState = tbl[(int)cur, (int)tk.type]; if (nState == myState.invalid) { break; } myRule cb = clbTbl[(int)cur, (int)tk.type]; cb(res, tk); } //case eol return(res); }
public override void OnHitWall(HitWallEvent evnt) { if (state == myState.Start) { if ((this.Y > BattleFieldHeight * 0.5 && this.X > BattleFieldWidth * 0.5) || (this.Y < BattleFieldHeight * 0.5 && this.X < BattleFieldWidth * 0.5)) { TurnLeft(90); TurnGunLeft(90); } else { TurnRight(90); TurnGunRight(90); } state = myState.FollowinWall; } else { invertDir = !invertDir; /* * if ((this.Y > BattleFieldHeight * 0.5 && this.X > BattleFieldWidth * 0.5) || (this.Y < BattleFieldHeight * 0.5 && this.X < BattleFieldWidth * 0.5)) * TurnLeft(180); * else * TurnRight(180); */ } }
public void OnTouch() { if (_isActive) { _myState = myState.STAY; _square.GetComponent<Square>().setState(Square.myState.MOVETO); } }
//放置步兵单位 public void PutUnit(string unitName) { waitingForPut = unitName; //等待放置的单位 playerState = Player.myState.Set; //变为Set状态,等待放置 hasPut = false; //等待放置 if (Input.GetMouseButtonDown(0)) //如果鼠标左键点击 { Ray ray = mainCamera.GetComponent <Camera>().ScreenPointToRay(Input.mousePosition); //检测鼠标点击位置 RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.transform.GetComponent <SpriteRenderer>().color == setHexColor && !hit.transform.GetComponent <HexControl>().hasUnit) //点击位置颜色为setHexColor,且此单元格没有单位才允许放置 { Vector3 putPosition = hit.transform.GetComponent <Renderer>().bounds.center; //获取放置位置的中心坐标 readyForPut = Instantiate(unitsList.transform.Find(unitName), putPosition, unitsList.transform.Find(unitName).GetComponent <Transform>().rotation, this.transform); //生成单位并且赋值给readyForPut(获取这个新生成的单位) readyForPut.name = readyForPut.name + index; //设置单位名称 if (unitName == "GermanTiger" || unitName == "USSherman") { readyForPut.GetComponent <TankUnit>().unitName = unitName; //设置单位内单位名称,注意,此名称和上一行的名称不一样 readyForPut.GetComponent <TankUnit>().SetData(); //设置单位数据 } else { readyForPut.GetComponent <InfantryUnit>().unitName = unitName; //设置单位内单位名称,注意,此名称和上一行的名称不一样 readyForPut.GetComponent <InfantryUnit>().SetData(); //设置单位数据 } readyForPut.tag = transform.name; //当前放置单位的tag为当前玩家的名字 index++; //增加索引 if (unitName == "GermanTiger" || unitName == "USSherman") { readyForPut.GetComponent <TankUnit>().nowOnHex = hit.transform; //此单位所在地块信息写入此单位 soucesPoints -= readyForPut.GetComponent <TankUnit>().resourcesNeeded; //扣除相应的人力值 } else { readyForPut.GetComponent <InfantryUnit>().nowOnHex = hit.transform; //此单位所在地块信息写入此单位 soucesPoints -= readyForPut.GetComponent <InfantryUnit>().resourcesNeeded; //扣除相应的人力值 } hit.transform.GetComponent <HexControl>().unitOnThisHex = readyForPut; //此单位信息写入此单位所在地块 resourcesUI.transform.Find("Holder/iPep").GetComponent <Text>().text = "Manpower Point:" + soucesPoints; //刷新左下角人力值 Debug.Log("LOOOOK!"); hasPut = true; //已经放置 } else { hasPut = true;//还未放置,点击其他地方取消放置 } } } }
public void SetInteractable(GameObject interactable, bool onOrOff) { if (onOrOff) { m_Interactable = interactable; } else { m_Interactable = null; m_MyState = myState.explore; m_InputX = 0; m_InputY = -1; } }
static myPaserResult myparser2(string line) { //state table //state |token // |, |" |other //------+-------+-------+------ //s |s |a |e //a |a |b |a //b |s |a |invalid //e |s |invalid|e myPaserResult res = new myPaserResult(line); myState cur = myState.s; myState nState = myState.s; foreach (char c in line) { myTkType type; #if false myToken tk = new myToken(c); type = tk.type; #else switch (c) { case '"': type = myTkType.t_dblq; break; case ',': type = myTkType.t_comma; break; default: type = myTkType.t_other; break; } #endif cur = nState; nState = tbl[(int)cur, (int)type]; if (nState == myState.invalid) { break; } myRule cb = clbTbl[(int)cur, (int)type]; cb(res, null); } //case eol return(res); }
//移动函数,进行移动 protected void ImMoving( ) { for (int index = 0; index < tagetHexList.Count; index++) { tagetHexList[index].GetComponent <SpriteRenderer> ( ).color = defaultHexColor[index]; } transform.position = Vector3.Lerp(transform.position, targetHex.transform.GetComponent <Transform> ( ).position, 20 * Time.deltaTime); if ((Vector3.Distance(transform.position, targetHex.transform.GetComponent <Transform> ( ).position)) <= MINMUMDISTANCE) { infantryState = myState.Idle; //单位与目标地块的间距小于最小距离之后,单位状态变为Idle nowOnHex.GetComponent <HexControl> ( ).unitOnThisHex = null; //出发地块中此单位信息被移除 nowOnHex = targetHex.transform; //目前所在的地块变更为目标地块 nowOnHex.GetComponent <HexControl> ( ).unitOnThisHex = transform; //目标地块中此单位信息被添加 strength -= distInPerDist * COMSUMEPERMOVEMENT; //扣除移动体力 tagetHexList.Clear( ); //清除目标地块 defaultHexColor.Clear( ); DrawInfantryUI( ); //重新绘制UI } IfShowInfantryUI(true); }
// Perform robot logic here calling robot commands etc. private void Update() { if (state == myState.Start) { if (wantedX == 0) { if (this.Heading > 90 && this.Heading <= 270) { TurnRight(270 - this.Heading); } else { TurnLeft(270 - this.Heading); } Ahead(this.X); } else { if (this.Heading >= 90 && this.Heading < 270) { TurnRight(90 - this.Heading); } else { TurnRight(90 - this.Heading); } Ahead(BattleFieldWidth - this.X); } } else if (state == myState.FollowinWall) { TurnRadarRight((Math.Sin(this.Time * 0.1) + 1) * 180); //TurnRadarRight(double.PositiveInfinity); //TurnGunRight(double.PositiveInfinity); Ahead(invertDir?-5000:5000); } else if (state == myState.Panic) { state = myState.FollowinWall; } }
// Update the state of the button ----------------------- public void UpdateState(MouseState input_mouse_state) { if (rectangle.Contains(input_mouse_state.Position.X, input_mouse_state.Position.Y)) // If cursor is over button { if (input_mouse_state.LeftButton == ButtonState.Pressed) // If button is left clicked { myButtonState = myState.Pressed; color = Color.Red; } else // Cursor is over button, but not clicked { myButtonState = myState.Hover; color = Color.DarkCyan; } } else { myButtonState = myState.Nothing; color = Color.Cyan; } }
//选中步兵单位进行攻击 protected void ReadyToAtk( ) { if (Input.GetMouseButtonDown(0)) //如果鼠标左键点击 { Ray ray = mainCamera.GetComponent <Camera> ( ).ScreenPointToRay(Input.mousePosition); //检测鼠标点击位置 RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.transform.GetComponent <TankUnit>() && hit.transform.GetComponent <TankUnit>().nowOnHex.GetComponent <SpriteRenderer>().color == atkHexColor) //选中的是敌军目标,并且敌军目标目标处于红色地块上时 { targetEnemy = hit; //确定攻击目标,赋值给targetEnemy infantryState = myState.IsAttacking; //状态成为正在攻击 } else if (hit.transform.GetComponent <InfantryUnit>() && hit.transform.GetComponent <InfantryUnit>().nowOnHex.GetComponent <SpriteRenderer>().color == atkHexColor) //选中的是敌军目标,并且敌军目标目标处于红色地块上时 { targetEnemy = hit; //确定攻击目标,赋值给targetEnemy infantryState = myState.IsAttacking; //状态成为正在攻击 } else { for (int index = 0; index < tagetHexList.Count; index++) { tagetHexList[index].GetComponent <SpriteRenderer> ( ).color = defaultHexColor[index]; } //foreach (Transform hex in tagetHexList) { // foreach (Color hexColor in defaultHexColor) { // hex.GetComponent<SpriteRenderer>().color = hexColor;//范围地块恢复成默认颜色 // } //} tagetHexList.Clear( ); //清除目标地块 defaultHexColor.Clear( ); infantryState = myState.Idle; //状态变回Idle } } } }
void OnTurnArround() { if (_square.GetComponent<Square>().getActive()) { float x = _square.transform.position.x + (1.5f * Mathf.Cos(_angle * Mathf.Deg2Rad)); float y = _square.transform.position.y + (1.5f * Mathf.Sin(_angle * Mathf.Deg2Rad)); transform.position = new Vector3(x, y, 0); _angle -= _circleSpeed; if (_angle <= 0) _angle = 360; } else _myState = myState.MOVEFAR; }
static void myparser(string line) { Stack <myState> sStack = new Stack <myState>(); Stack <myToken> tStack = new Stack <myToken>(); //rule //----------------------------- //s->space s //trim - not use //s->,s //empty //s->"a //a->other a //a->space a //a->,a //a->"b //b->,s //b->"a //s->other e //e->other e //e->,s //------------------------------ myState cur; myState nState = myState.s; //sStack.Push(myState.s); foreach (char c in line) { myToken tk = new myToken(c); cur = nState; nState = myState.invalid; switch (cur) { case myState.s: if (tk.type == myTkType.t_comma) { nState = myState.s; } //else if (tk.type == myTkType.t_spec) nState = myState.s; else if (tk.type == myTkType.t_dblq) { nState = myState.a; } else if (tk.type == myTkType.t_other) { nState = myState.e; } break; case myState.a: if (tk.type == myTkType.t_dblq) { nState = myState.b; } else { nState = myState.a; } break; case myState.b: if (tk.type == myTkType.t_comma) { nState = myState.s; } else if (tk.type == myTkType.t_dblq) { nState = myState.a; } break; case myState.e: if (tk.type == myTkType.t_other) { nState = myState.e; } else if (tk.type == myTkType.t_comma) { nState = myState.s; } break; } if (nState == myState.invalid) { break; } } }
void OnTriggerEnter2D(Collider2D col) { if (col.tag == "Mur") { _mySFX.clip = _deathClip; _mySFX.Play(); GameObject.Find("GameManager").GetComponent<GameManager>()._gameState = GameManager.GameState.GameOver; _myState = myState.DEAD; _isActive = false; } }
public override void OnHitByBullet(HitByBulletEvent evnt) { state = myState.Panic; }
void Start() { _sphere = GameObject.FindGameObjectWithTag("Sphere"); myCollider = GetComponent<Collider2D>(); _myState = myState.STAY; _attraction = 0.1f; _circleSpeed = 2f; _shootSpeed = 0.075f; _isActive = false; _anim = GetComponent<Animator>(); _mySFX = GetComponent<AudioSource>(); }
public override void OnEnd(myState nextState) { }
// Use this for initialization void Start() { _square = GameObject.FindGameObjectWithTag("Square"); myCollider = GetComponent<Collider2D>(); _anim = GetComponent<Animator>(); _myState = myState.STAY; _attraction = 0.1f; _circleSpeed = 2f; _shootSpeed = 0.075f; _isActive = true; _anim.SetBool("ActiveOrNot", true); _mySFX = GetComponent<AudioSource>(); }
void executeRule() { cur = nState; nState = tbl[(int)cur, (int)type]; cbid id = cbidTbl[(int)cur, (int)type]; switch (id) { case cbid.o1: //do nonthing break; case cbid.ss: res.count++; res.arr.Add(""); res.curObj.iStart = ++res.curObj.iCur; break; case cbid.sa: res.curObj.iStart = ++res.curObj.iCur; break; case cbid.aa: res.curObj.iCur++; break; case cbid.bs: res.count++; res.arr.Add(res.gerCurObj()); res.curObj.iCur += 2; break; case cbid.es: res.count++; res.arr.Add(res.gerCurObj()); res.curObj.iCur++; break; case cbid.ba: res.curObj.iCur += 2; res.curObj.dblQt = true; break; case cbid.sz: res.curObj.iStart = res.curObj.iCur; goto case cbid.en; case cbid.en: res.arr.Add(res.gerCurObj()); //save rec & reset #if use_res_queue m_resQueue.push(res.arr); #else m_res.Add(res.arr); #endif m_recCount++; res.reset(); break; case cbid.se: res.curObj.iStart = res.curObj.iCur++; break; case cbid.zz: res.curObj.iCur++; break; default: throw new Exception(); } }
public void BeginInteraction() { m_MyState = myState.interact; }
public void setState(myState arg) { _myState = arg; }
public override void OnBegin(myState previousState) { Debug.Log("녹"); }
void OnMoveTo() { float distance = Vector3.Distance(this.transform.position, _square.transform.position); if (distance > 1.75f) transform.position = Vector3.MoveTowards(transform.position, _square.transform.position, distance * _attraction); else if (distance <= 1.75f) { _angle = Mathf.Atan2(transform.position.y - _square.transform.position.y, transform.position.x - _square.transform.position.x) * 180 / Mathf.PI; if (_angle < 0) _angle = 360 - Mathf.Abs(_angle); _myState = myState.TURNAROUND; } }
public override void OnBegin(myState previousState) { }