/// <summary> /// ボール射出用 /// </summary> private void BallShot() { if (m_touchZone.flicking) { m_startPostion = Camera.main.ScreenToWorldPoint(m_touchZone.pressStartPosition); //角度指定 float zRotation = Mathf.Atan2(m_touchZone.flickEndPosition.y - m_startPostion.y, m_touchZone.flickEndPosition.x - m_startPostion.x) * Mathf.Rad2Deg; //値格納 AngleRotation = zRotation; //取得した角度反映 transform.rotation = Quaternion.Euler(0f, 0f, AngleRotation); //移動量 angleVec = transform.rotation * new Vector3(m_ballSpeed, 0f, 0); //向いている方向に向かって移動 transform.position += angleVec * Time.deltaTime; if (!m_audioSource.isPlaying) { m_audioSource.Play(); } } //指が離されたら通常に戻る else if (m_player.m_playerState == Player.PlayerState.Deffault) { shotState = ShotState.def; } }
private void DoShot(ShotState state) { GameObject go = (GameObject) Instantiate(Shot, transform.position, Quaternion.identity); EnemyShootFlying shotFlying = go.GetComponent<EnemyShootFlying> (); switch (state) { case ShotState.DOWN: // Set flying direction and revert CoRoutineRunningValue shotFlying.FlyDown = true; CoRoutineIsRunningDown = false; break; case ShotState.LEFT: shotFlying.FlyLeft = true; CoRoutineIsRunningLeft = false; break; case ShotState.RIGHT: shotFlying.FlyRight = true; CoRoutineIsRunningRight = false; break; case ShotState.UP: shotFlying.FlyUp = true; CoRoutineIsRunningUp = false; break; } }
/// <summary> /// Finishing killing some ship after the first lucky shot /// </summary> /// <param name="userBoard">board in which ship located</param> private void ShotFinishing(Board userBoard) { if (_shotOnDirection.Count == 0) { AddPossibleDirection(userBoard); } _curShotRow = _luckyShotRow; _curShotCol = _luckyShotCol; bool shotSuccess = true; while (shotSuccess && userBoard[_luckyShotRow, _luckyShotCol].Type != TypeCell.KilledShip) { shotSuccess = _shotOnDirection[_indxDirection](userBoard); if (!shotSuccess) { _indxDirection++; } } if (userBoard[_luckyShotRow, _luckyShotCol].Type == TypeCell.KilledShip) { Shot = ShotFinding; _indxDirection = 0; _shotOnDirection.Clear(); } }
public void ParseInfo(Hashtable info) { sourceID = info.GetValueString((int)SPC.Source); sourceType = (ItemType)info.GetValueByte((int)SPC.SourceType, (byte)ItemType.Avatar); targetID = info.GetValueString((int)SPC.Target); targetType = (ItemType)info.GetValueByte((int)SPC.TargetType, (byte)ItemType.Avatar); sourceWorkshop = (Workshop)info.GetValueByte((int)SPC.Workshop, (byte)Workshop.Arlen); skillID = info.GetValueInt((int)SPC.Skill, -1); //isHitAllowed = info.GetValueBool((int)SPC.FireAllowed, false); //isHitted = info.GetValueBool((int)SPC.IsHitted, false); damage = info.GetValueFloat((int)SPC.ActualDamage, 0f); //isCritical = info.GetValueBool((int)SPC.IsCritical, false); //errorMessage = info.GetValueString((int)SPC.ErrorMessageId, string.Empty); rocketDamage = info.GetValueFloat((int)SPC.RocketDamage); acidDamage = info.GetValueFloat((int)SPC.AcidDamage); laserDamage = info.GetValueFloat((int)SPC.LaserDamage); weaponBaseType = (WeaponBaseType)info.GetValueInt((int)SPC.WeaponBaseType, (int)WeaponBaseType.Rocket); if (info.ContainsKey((int)SPC.ShotState)) { state = (ShotState)info.GetValueByte((int)SPC.ShotState); } else { state = ShotState.normal; } }
/// <summary> /// ボールのオブジェクト格納と状態遷移 /// </summary> /// <param name="arg_collision"></param> private void OnTriggerEnter2D(Collider2D arg_collision) { m_hitPositon = transform.position; switch (arg_collision.tag) { case "Wall": m_colGameObject = arg_collision.gameObject; shotState = ShotState.back; break; case "Ground": m_colGameObject = arg_collision.gameObject; shotState = ShotState.back; break; case "Monster": m_colGameObject = arg_collision.gameObject; shotState = ShotState.back; break; case "PassWall": m_colGameObject = arg_collision.gameObject; shotState = ShotState.back; break; default: break; } }
private void DoShot(ShotState state) { GameObject go = (GameObject)Instantiate(Shot, transform.position, Quaternion.identity); EnemyShootFlying shotFlying = go.GetComponent <EnemyShootFlying> (); switch (state) { case ShotState.DOWN: // Set flying direction and revert CoRoutineRunningValue shotFlying.FlyDown = true; CoRoutineIsRunningDown = false; break; case ShotState.LEFT: shotFlying.FlyLeft = true; CoRoutineIsRunningLeft = false; break; case ShotState.RIGHT: shotFlying.FlyRight = true; CoRoutineIsRunningRight = false; break; case ShotState.UP: shotFlying.FlyUp = true; CoRoutineIsRunningUp = false; break; } }
public override void Update() { if (state == ShotState.flying) { life -= Time.deltaTime; if (life <= 0) { life = 0; state = ShotState.splat; box.enabled = true; } Vector3 travel = Vector3.Lerp(_spawn, _target, 1 - (life / MAX_LIFE)); travel.y += Mathf.Sin((life / MAX_LIFE) * Mathf.PI) * ARC_HEIGHT; float dx = travel.x - transform.position.x; float dy = travel.y - transform.position.y; Debug.Log("Angle: " + Mathf.Atan2(dy, dx) * 180 / Mathf.PI); transform.eulerAngles = new Vector3(0, 0, Mathf.Atan2(dy, dx) * 180 / Mathf.PI); transform.position = travel; } else { // Vanish right away. Reason we add this state is so the box collider can be enabled for a frame to hit the player. Destroy(gameObject); } }
void CheckTrigger() { if (touchPos.x < 0) { if (Input.GetMouseButtonDown(0)) { Ray ray = cameraForShooter.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { ShotBall sb = hit.collider.transform.GetComponent <ShotBall>(); if (sb != null && !sb.isActive) { sb.ChangeActive(); touchPos = Input.mousePosition; shotPower = 0.0f; } } } } else { if (touchPos.x != Input.mousePosition.x || touchPos.y != Input.mousePosition.y) { touchPos.x = -1.0f; startTime = Time.time; state = ShotState.DirectionAndPower; } } }
public void MakeCritical() { if (normal) { m_State = ShotState.normalCritical; } }
void ChargeBall() { if (objBall == null) { objBall = (GameObject)Instantiate(ballPrefab); objBall.AddComponent <ShotBall>(); ballRigidbody = objBall.GetComponent <Rigidbody>(); Vector3 shotPos = shotPoint.transform.localPosition; shotPos.z -= offsetZShotPoint; objBall.transform.position = shotPoint.transform.TransformPoint(shotPos); objBall.transform.eulerAngles = new Vector3(100f, 180f, 0f); //设置初始角度 ballRigidbody.velocity = Vector3.zero; ballRigidbody.AddForce(shotPoint.transform.TransformDirection(new Vector3(0.0f, 0.0f, powerToRoll)), ForceMode.Impulse); //让小球先向前方滚动一段距离 } float dis = Vector3.Distance(shotPoint.transform.position, objBall.transform.position); if (dis <= 0.2f) { state = ShotState.Ready; objBall.transform.position = shotPoint.transform.position; } }
private void Start() { m_lineRenderer = GetComponent <LineRenderer>(); m_audioSource = GetComponent <AudioSource>(); //開始時はデフォルト状態 shotState = ShotState.def; }
//public void ChangeState(ShotState state) { // m_State = state; //} public void Interrupt(ShotState state) { //interrup only if before was normal state if (normal) { m_State = state; } }
public WeaponHitInfo() { //hitAllowed = false; ////hitProb = 0f; //isHitted = false; //isCritical = false; //errorMessageId = string.Empty; m_State = ShotState.normal; }
public WeaponHitInfo(ShotState state) { // this.hitAllowed = hitAllowed; // this.hitProb = hitProb; // this.isHitted = isHitted; // this.isCritical = isCritical; // this.errorMessageId = errorMsgId; m_State = state; }
public override void onExitCollider(Collider other) { if (other.gameObject == null || !other.gameObject.name.Equals(Const.PLAY)) { return; } this.rival = null; currState = ShotState.IDLE; }
public override void onEnterCollider(Collider other) { if (other.gameObject == null || !other.gameObject.name.Equals(Const.PLAY)) { return; } currState = ShotState.ATTACTING; this.rival = other.gameObject; }
private static ShotState[,] PrevShots(params GridSquare[] targets) { var prevShots = new ShotState[10, 10]; foreach (var target in targets) { prevShots[target.Point.X, target.Point.Y] = ShotState.Miss; } return(prevShots); }
private void Deffault() { //ボールは常にプレイヤー座標に追従 transform.position = m_player.transform.position; //プレイヤーが射出待機状態の時射出可能 if (m_player.m_playerState == Player.PlayerState.Shot) { shotState = ShotState.shot; } }
public override void Update(GameTime gameTime) { if (ShotState == ShotState.TargetHit || ShotState == ShotState.Out) { DeleteShot(); } else if (Target == null || Target.CreepState != CreepState.Running) { ShotState = ShotState.TargetLost; } else if ((ShotState == ShotState.Flying) && (Target.CreepState == CreepState.Running)) { Vector2 dPos = Position - Target.Position; LastDir = dPos; double hyp = dPos.Length(); if (hyp < 10) { ShotState = ShotState.TargetHit; HitTarget(); } else { double dHyp = hyp - (hyp - (Speed * gameTime.ElapsedGameTime.TotalSeconds * 10)); var newdPos = new Vector2((float)(dHyp / hyp) * dPos.X, (float)(dHyp / hyp) * dPos.Y); Position = new Vector2(Position.X - newdPos.X, Position.Y - newdPos.Y); } } if (ShotState == ShotState.TargetLost) { double hyp = LastDir.Length(); double dHyp = hyp - (hyp - (Speed * gameTime.ElapsedGameTime.TotalSeconds * 10)); var newdPos = new Vector2((float)(dHyp / hyp) * LastDir.X, (float)(dHyp / hyp) * LastDir.Y); Position = new Vector2(Position.X - newdPos.X, Position.Y - newdPos.Y); foreach (var creep in Creeps) { Vector2 dPos = Position - creep.Position; double dist = dPos.Length(); if (dist < 10) { ShotState = ShotState.TargetHit; creep.Hit((int)Damage); } } } if ((Position.X < -50) || (Position.Y < -50) || (Position.X > CurrGame.CreepFieldWidth + 50) || (Position.Y > CurrGame.CreepFieldHeight + 50)) { ShotState = ShotState.Out; } base.Update(gameTime); }
// Update is called once per frame void Update() { if (currState == ShotState.ATTACTING && rival != null) { if (checkShouldShoot()) { attack(); } } else if (rival == null) { currState = ShotState.IDLE; } }
public override void Start() { base.Start(); damage = 0; velocity = 3.5f; life = MAX_LIFE; knockback = 1; box = GetComponent <BoxCollider2D>(); box.enabled = false; offset = Random.Range(-OFFSET_MAX, OFFSET_MAX); state = ShotState.flying; }
public Shot(Game game, Tower parent, Creep target, List <Creep> creeps, Vector2 position, string shotTextName, float speed, float damage) : base(game) { Parent = parent; Creeps = creeps; Position = position; TextureName = shotTextName; TextureDirectory = "Tower/Textures/Shot/"; Speed = speed; StandardSpeed = speed; Damage = damage; Target = target; ShotState = ShotState.Flying; }
/// <summary> /// Random shooting on ships /// </summary> /// <param name="userBoard">board in which ships located</param> private void ShotFinding(Board userBoard) { do { _luckyShotRow = _rand.Next(1, Settings.boardSize + 1); _luckyShotCol = _rand.Next(1, Settings.boardSize + 1); } while (userBoard[_luckyShotRow, _luckyShotCol].Type == TypeCell.AreaAroundShip || userBoard[_luckyShotRow, _luckyShotCol].Type == TypeCell.KilledShip || userBoard[_luckyShotRow, _luckyShotCol].Type == TypeCell.MuffShot); if (userBoard.Shot(_luckyShotRow, _luckyShotCol)) { Shot = ShotFinishing; Shot(userBoard); } }
private void CheckOnExistDamagetShip(Board board) { for (int row = 1; row < Settings.boardSize + 1; row++) { for (int col = 1; col < Settings.boardSize + 1; col++) { if (board[row, col].Type == TypeCell.DamagetShip) { _luckyShotRow = row; _luckyShotCol = col; Shot = ShotFinishing; return; } } } }
// Update is called once per frame void Update() { if (this.State == ShotState.Shooting) { //move the shot this.moveTranslation = new Vector3(this.Direction.x, this.Direction.y) * Time.deltaTime * this.Speed; this.transform.position = new Vector3(this.transform.position.x + this.moveTranslation.x, this.transform.position.y + this.moveTranslation.y); } //check off screen if (Util.IsOnScreen(this.gameObject) == false) { this.State = ShotState.Done; } }
public virtual void OnTriggerEnter(Collider coll) { if (coll.gameObject.tag == "Player" && OwnerOfShot == PlayerOrEnemyShot.Enemy) { coll.GetComponent <Attacker>().TakeDamage(this.damage); this.State = ShotState.Done; } if (coll.gameObject.tag == "Enemy" && OwnerOfShot == PlayerOrEnemyShot.Player) { coll.GetComponent <Attacker>().TakeDamage(this.damage); this.State = ShotState.Done; } if (coll.gameObject.tag == "Obstacle") { this.State = ShotState.Done; } }
/** * <summary>Initialize array after start</summary> **/ private void InitializeArrays() { shipBoard = new ShipPresence[STAGE_WIDTH, STAGE_HEIGHT]; shotBoard = new ShotState[STAGE_WIDTH, STAGE_HEIGHT]; visibleCharacters = new char[STAGE_WIDTH * STAGE_HEIGHT]; for (int i = 0; i < STAGE_WIDTH; i++) { for (int j = 0; j < STAGE_HEIGHT; j++) { shipBoard[i, j] = ShipPresence.Empty; shotBoard[i, j] = ShotState.Intact; visibleCharacters[i * STAGE_WIDTH + j] = INTACT_CHAR; } } recievedAttack = false; allShipsSank = false; }
/// <summary> /// 衝突した際の動作 /// </summary> private void BackBall() { //コライダーオブジェクト格納時 if (m_colGameObject) { switch (m_colGameObject.tag) { //地形に当たったら戻ってくる case "Ground": transform.position = Vector3.MoveTowards(transform.position, m_player.transform.position, 0.5f); break; //壁に当たったらその座標に移動する case "Wall": m_player.transform.position = Vector3.MoveTowards(m_player.transform.position, m_hitPositon, 0.5f); break; //モンスターに当たったらくっつけて戻ってくる case "Monster": m_colGameObject.transform.position = transform.position; transform.position = Vector3.MoveTowards(transform.position, m_player.transform.position, 0.5f); break; case "PassWall": transform.position = Vector3.MoveTowards(transform.position, m_player.transform.position, 0.5f); break; default: break; } } //コライダーオブジェクト消失時はそのままプレイヤーの位置へ戻る else { transform.position = Vector3.MoveTowards(transform.position, m_player.transform.position, 0.5f); } //プレイヤーの位置まで戻ったら通常時に移行 if (transform.position == m_player.transform.position) { shotState = ShotState.def; } }
void ChargeBall() { if (objBall == null) { objBall = (GameObject)Instantiate(ballPrefab); objBall.AddComponent <ShotBall>(); ballRigidbody = objBall.GetComponent <Rigidbody>(); if (cloth != null) { ClothSphereColliderPair[] cscp = new ClothSphereColliderPair[ballCount + 1]; int index = 0; for (int i = 0; i < cloth.sphereColliders.Length; i++) { if (cloth.sphereColliders[i].first != null) { cscp[index] = cloth.sphereColliders[i]; index++; } } cscp[cscp.Length - 1] = new ClothSphereColliderPair(objBall.GetComponent <SphereCollider>()); cloth.sphereColliders = cscp; ballCount = index + 1; } Vector3 shotPos = shotPoint.transform.localPosition; shotPos.z -= offsetZShotPoint; objBall.transform.position = shotPoint.transform.TransformPoint(shotPos); objBall.transform.eulerAngles = shotPoint.transform.eulerAngles; ballRigidbody.velocity = Vector3.zero; ballRigidbody.AddForce(shotPoint.transform.TransformDirection(new Vector3(0.0f, 0.0f, powerToRoll)), ForceMode.Impulse); } float dis = Vector3.Distance(shotPoint.transform.position, objBall.transform.position); if (dis <= 0.2f) { state = ShotState.Ready; objBall.transform.position = shotPoint.transform.position; } }
void CheckShot() { float elapseTime = Time.time - startTime; if (Input.GetMouseButtonUp(0)) { if (objBall != null) { ShootBall(elapseTime); } state = ShotState.Charging; objBall = null; } if (timeoutForShot < elapseTime) { Destroy(objBall); state = ShotState.Charging; objBall = null; } }
private void Update() { switch (_shotState) { case ShotState.PREPAREPOS: //角度指定 var rotation = CalcStickRotation(); SetStick(rotation); if (Input.GetMouseButtonDown(0)) { _shotState = ShotState.SHOT; } break; case ShotState.SHOT: if (Input.GetMouseButtonDown(0)) { _shotState = ShotState.NONE; Shot(); } break; } }
IEnumerator FireCoRoutine(ShotState state) { yield return (new WaitForSeconds (Random.Range (ShotAfterTimeMin, ShotAfterTimeMax))); DoShot (state); }
void CheckTrigger() { if (touchPos.x < 0) { if (Input.GetMouseButtonDown (0)) { Ray ray = cameraForShooter.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { ShotBall sb = hit.collider.transform.GetComponent<ShotBall>(); if (sb != null && !sb.isActive) { sb.ChangeActive(); touchPos = Input.mousePosition; shotPower = 0.0f; } } } } else { if (touchPos.x != Input.mousePosition.x || touchPos.y != Input.mousePosition.y) { touchPos.x = -1.0f; startTime = Time.time; state = ShotState.DirectionAndPower; } } }
void CheckShot() { float elapseTime = Time.time - startTime; if (Input.GetMouseButtonUp (0)) { if (objBall != null) { ShootBall(elapseTime); } state = ShotState.Charging; objBall = null; } if (timeoutForShot < elapseTime) { Destroy (objBall); state = ShotState.Charging; objBall = null; } }
public override void Update(GameTime gameTime) { // see if we need to setup initial time if (InitialTime == TimeSpan.Zero) initialTime = gameTime.TotalRealTime; // if we're starting, move straight to active if (State == ShotState.Starting) state = ShotState.Active; // if we're ending, we'll update the explosion if (State == ShotState.Ending) { explosion.Update(gameTime); if (explosion.Done) state = ShotState.Ended; } // can the shot explode based on time yet? if (InitialTime + MaxTTL <= gameTime.TotalRealTime) { if (State == ShotState.Ended) state = ShotState.None; else if (State != ShotState.Ending) End(true); } // see if we can bail out now if (State == ShotState.Ending || State == ShotState.Ended || State == ShotState.None) return; // the following is expensive, so we only do it if it's a local shot // we trust everyone else will end their shots for us if (Local) { // see if we collide with any world objects Single overlap; Vector2 collisionProjection; if (FindNearestCollision(World.MapGrid.PotentialIntersects(this), out overlap, out collisionProjection)) { // move our position back Position += overlap * collisionProjection; // end shot End(true); } } Position += Velocity * (Single)gameTime.ElapsedGameTime.TotalSeconds; // the shot has travelled its maximum distance if (Math.Abs(Vector2.Distance(initialPosition, Position)) >= maxShotRange) { // end shot End(true); } base.Update(gameTime); }
public void End(bool explode) { // we are no longer moving now Velocity = Vector2.Zero; // and we are ending, if we choose to explode, or go straight to ended if (explode) state = ShotState.Ending; else state = ShotState.Ended; explosion = new AnimatedSprite(World, World.Content.Load<Texture2D>("textures/bz/explode1"), Position, new Vector2(8, 8), Rotation, new Point(8, 8), new Point(64, 64), SpriteSheetDirection.RightToLeft, false); // we only broadcast the end shot if it's a local one we're keeping track of if (Local) { NetOutgoingMessage endShotMessage = World.ServerLink.CreateMessage(); MsgEndShotPacket endShotPacket = new MsgEndShotPacket(this.Slot, explode); endShotMessage.Write((Byte)endShotPacket.MsgType); endShotPacket.Write(endShotMessage); World.ServerLink.SendMessage(endShotMessage, NetDeliveryMethod.ReliableUnordered, 0); } }
public Shot(World world, Player player, Byte slot, bool local, Vector2 initialPosition, Single rotation, Vector2 initialVelocity) : base(world, GetTexture(world, player), initialPosition, new Vector2(2, 2), rotation) { Single shotSpeed = (Single)World.VarDB["shotSpeed"].Value; // get the unit vector in the forward direction Velocity = new Vector2((Single)Math.Cos(Rotation - Math.PI / 2), (Single)Math.Sin(Rotation - Math.PI / 2)); // get our shot velocity by multiplying by the magnitude Velocity *= shotSpeed; // add the velocity from the tank to the shot //Velocity += initialVelocity; // store info... this.slot = slot; this.local = local; this.player = player; this.initialPosition = initialPosition; this.maxShotRange = (Single)World.VarDB["shotRange"].Value; this.maxTTL = new TimeSpan(0, 0, 0, 0, (int)((Single)World.VarDB["reloadTime"].Value * 1000)); // start the shot state = ShotState.Starting; }
void ChargeBall() { if (objBall == null) { objBall = (GameObject)Instantiate(ballPrefab); objBall.AddComponent<ShotBall>(); ballRigidbody = objBall.GetComponent<Rigidbody>(); Vector3 shotPos = shotPoint.transform.localPosition; shotPos.z -= offsetZShotPoint; objBall.transform.position = shotPoint.transform.TransformPoint(shotPos); objBall.transform.eulerAngles = shotPoint.transform.eulerAngles; ballRigidbody.velocity = Vector3.zero; ballRigidbody.AddForce(shotPoint.transform.TransformDirection(new Vector3 (0.0f, 0.0f, powerToRoll)), ForceMode.Impulse); } float dis = Vector3.Distance(shotPoint.transform.position, objBall.transform.position); if (dis <= 0.1f) { state = ShotState.Ready; } }