void IMovable.Move() { this.Left += dx; this.Top += dy; if (this.Left <= 0 || this.Right >= this.Parent.ClientRectangle.Width) { dx = -dx; } if (this.Top <= 0 || this.Bottom >= this.Parent.ClientRectangle.Height) { dy = -dy; } IHittable obj = this.HitOthers(); if (obj != null) { Control c = (Control)obj; if (dy > 0) { this.Top = c.Top - this.Height; } else { this.Top = c.Bottom; } dy = -dy; //if (obj is Brick) // Brick b = (Brick)obj; } }
void IMovable.Move() { this.Left += dx; this.Top += dy; if (this.Left <= 0 || this.Right >= this.Parent.ClientRectangle.Right) { dx = -dx; } if (this.Top <= 0 || this.Bottom >= this.Parent.ClientRectangle.Bottom) { dy = -dy; } IHittable obj = HitOthers(); if (obj != null) { Control c = (Control)obj; if (dy < 0) // moving up { this.Top = c.Bottom + 1; } else // moving down { this.Top = c.Top - this.Height; } dy = -dy; } }
private static void PlaceShip(ShipType ship, Arena computerArena) { Random random = new Random(); IHittable shipCreated = null; bool shipPlaced = false; while (!shipPlaced) { var orientValues = Enum.GetValues(typeof(Orientation)); Orientation orient = (Orientation)orientValues.GetValue(random.Next(orientValues.Length)); int[] inputCoordinates = { random.Next(1, 10), random.Next(1, 10) }; try { shipCreated = ShipFactory.CreateShip(ship, inputCoordinates, orient); shipPlaced = true; bool availableCoordinates = computerArena.SpaceAvailable(shipCreated); if (!availableCoordinates) { shipPlaced = false; } } catch (System.Exception) { shipPlaced = false; } } computerArena.AddHittable(shipCreated); }
public void ClientShoot(StateManager states, Vector3 dir, Vector3 origin) { Ray ray = new Ray(origin, dir); Debug.DrawLine(origin, dir); RaycastHit[] hits; hits = Physics.RaycastAll(origin, dir, 100); if (hits == null) { return; } if (hits.Length == 0) { return; } RaycastHit closestHit; closestHit = GetClosestHit(origin, hits, states.photonId); IHittable isHittable = closestHit.transform.GetComponentInParent <IHittable>(); if (isHittable == null) { GameObject hitParticle = GameManagers.GetObjectPool().RequestObject("Bullet_Impact_FX"); Quaternion rot = Quaternion.LookRotation(-dir); hitParticle.transform.position = closestHit.point; hitParticle.transform.rotation = rot; } else { isHittable.OnHit(states, states.inventory.currentWeapon, dir, closestHit.point); } }
protected void MakeExplosion(Vector3 pos) { //lazy initialization if (!explosionPrefab) { explosionPrefab = GameObject.CreatePrimitive(PrimitiveType.Sphere); GameObject.Destroy(explosionPrefab.GetComponent <Collider>()); explosionPrefab.GetComponent <Renderer>().material.color = Color.yellow; explosionPrefab.transform.localScale = Vector3.one * BOMB_RAIDUS * 2; explosionPrefab.SetActive(false); //Since it is not actually a prefab, we deactivate it } GameObject explosion = GameObject.Instantiate(explosionPrefab); explosion.SetActive(true); explosion.transform.position = pos; GameObject.Destroy(explosion, .2f); foreach (Collider c in Physics.OverlapSphere(pos, BOMB_RAIDUS, LayerMask.GetMask("Enemy", "Building", "Floor", "Wall"))) { IHittable hittable = c.GetComponent <IHittable>(); if (hittable != null) { hittable.HitByProjectile(BOMB_DMG); } } }
public HitTestResult(IHittable target, bool hit, Coordinates snapPoint, object data) { this.target = target; this.hit = hit; this.snapPoint = snapPoint; this.data = data; }
public void Register(GameObject gameObject, IHittable hittable) { if (gameObject != null) { _collidablesByID.Add(gameObject.GetInstanceID(), hittable); } }
void CheckForTarget() { if (Input.GetButtonDown("Fire1")) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction); if (hit.collider != null) { IHittable hittable = hit.collider.gameObject.GetComponent <IHittable>(); if (hittable != null) { hittable.OnHit(); } } } if (Input.GetButton("Fire1")) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction); if (hit.collider != null) { IHittable hittable = hit.collider.gameObject.GetComponent <IHittable>(); Debug.Log(hit.collider.name); if (hittable != null) { hittable.OnHit(); } } } }
public void StopAttacking() { this.target = null; this.state = State.Free; animationHandler.SetAttacking(false); animationHandler.OnHitFrame -= ExecuteAttack; }
protected virtual void OnHit(IHittable target) { if ((target as Character) != wielder) { target.OnGetHit(currentAttack); } }
public void StartAttacking(IHittable target) { this.target = target; this.state = State.Attacking; animationHandler.SetAttacking(true); animationHandler.OnHitFrame += ExecuteAttack; }
private HitTestResult HitTest(IHittable obj, Coordinates point, double tolerance, HitTestFilter filter) { // check if we're in the bounding box RectangleF boundingBox = obj.GetBoundingBox(); // inflate by the tolerance if (!boundingBox.IsEmpty) { boundingBox.Inflate((float)tolerance, (float)tolerance); } // check if the bounding box is empty or we're inside it if (boundingBox.IsEmpty || boundingBox.Contains(Utility.ToPointF(point))) { // run the hit test HitTestResult result = obj.HitTest(point, (float)tolerance); // apply the filter if (filter(result)) { return(result); } } // return a no-hit return(HitTestResult.NoHit); }
void IMovable.Move() { switch (this.Status) { case BrickStatus.Normal: break; case BrickStatus.Falling: this.Top += 2; if (this.Top >= this.Parent.ClientRectangle.Height) { this.Status = BrickStatus.Dead; } break; case BrickStatus.Floating: this.Top -= 2; IHittable obj = this.HitOthers(); if (obj != null && (this.Top <= 4 || obj is Brick)) { this.Status = BrickStatus.Normal; this.Top += 3; } break; case BrickStatus.Dead: break; default: break; } }
void SpawnEnemies() { foreach (EnemyType enemyType in enemies) { if (enemyType.enemy == null) { Debug.LogWarning("Enemy Type cannot be null when spawning"); continue; } Room room = dungeon.GetRandomRoomNotAdjacent(playerTransform.value.position); Vector3 spawnPos = new Vector3(room.rect.center.x, enemyType.elevation, room.rect.center.y); for (int i = 0; i < enemyType.number; ++i) { GameObject enemy = Instantiate(enemyType.enemy, spawnPos, Quaternion.identity, enemiesParent); IHittable enemyHittable = enemy.GetComponent <IHittable>(); if (enemyHittable != null) { aliveEnemies.Add(enemyHittable); } if (!enemyType.sameRoom) { room = dungeon.GetRandomRoom(); spawnPos = new Vector3(room.rect.center.x, enemyType.elevation, room.rect.center.y); } } } }
public override void OnHit(IHittable hittable) { if (hittable.Faction != this.Hitbox.HitStat.Faction) { this.Detonate(); } }
void IMovable.Move() { switch (this.Status) { case BulletStatus.Flying: this.Top -= 4; IHittable obj = HitOthers(); if (obj != null && obj is Brick) { Brick b = (Brick)obj; b.Status = BrickStatus.Dead; this.Status = BulletStatus.Dead; } if (obj != null && obj is Ball) { this.Status = BulletStatus.Dead; // Ball b = new Ball(); // Ball ob = (Ball)obj; // b.Left = ob.Left; // b.Top = ob.Top; // b.dx = -b.dx; // this.Parent.Controls.Add(b); } break; case BulletStatus.Dead: this.Visible = false; break; } }
private int BoxCompare(IHittable a, IHittable b, int axis) { var boxA = a.BoundingBox(); var boxB = b.BoundingBox(); return(boxA.Min[axis].CompareTo(boxB.Min[axis])); }
public void Fire(Vector3 direction, IHittable owner = null) { AudioManager.Instance.PlayFx("TowerShoot"); var bullet = GameObject.Instantiate(prefab, origin.position, Quaternion.LookRotation(direction), folder); bullet.Shoot(direction, owner); }
private void Start() { //Destroy this after about a second Destroy(gameObject, 1); //Camera shake CameraController.instance.AddCameraShake(.75f); //Check for all objects in radius int size = WaveSpawner.instance?.GetEnemyCount() * 2 ?? 10; Collider2D[] hits = new Collider2D[size]; if (Physics2D.OverlapCircleNonAlloc(transform.position, explosionRadius, hits) > 0) { //Look for hittable thing foreach (Collider2D coll in hits) { //Ignore null colliders and the player if (coll == null) { continue; } //Find hittable objects IHittable hit = coll.GetComponent <IHittable>(); if (hit != null) { //Do 4 damage hit.OnHit(4, (coll.transform.position - transform.position) * 15); } } } }
public override void Destroy() { gameObject.layer = LayerMask.NameToLayer("Scenario"); explosionRadius.UpdateColliders(); for (int i = 0; i < explosionRadius.Colliders.Length; i++) { if (explosionRadius.Colliders [i] != null) { ExplosionCrate explosionCrate = explosionRadius.Colliders [i].gameObject.GetComponent <ExplosionCrate> (); if (explosionCrate != null) { explosionCrate.OnExplode(0.2f); } else { IHittable hittable = explosionRadius.Colliders [i].gameObject.GetComponent <IHittable> (); if (hittable != null) { hittable.OnThrowAway(); hittable.OnHit(transform.position); } } } } Destroy(gameObject); }
public override void ProjectileHit(Projectile projectile, RaycastHit hitInfo) { //only the master client can process the shot upon hit if (!photonView.IsMine) { return; } GameObject hitObject = hitInfo.collider.gameObject; string hitPoint = hitInfo.point.ToString(); PhotonView hitObjectView = hitInfo.collider.gameObject.GetComponent <PhotonView>(); IDamageable damageable = hitObject.gameObject.transform.root.GetComponent <IDamageable>(); if (damageable != null) { damageable.GetHit(hitInfo, projectile.Damage, projectile.Knockback); } IHittable hittable = hitObject.gameObject.GetComponent <IHittable>(); if (hittable != null) { hittable.GetHit(); } photonView.RPC("NetProjectileHit", RpcTarget.All, projectile.Index, hitPoint); }
private HashSet <IHittable> FindSquadEnemies(Squad squad) { HashSet <IHittable> finalEnemiesList = new HashSet <IHittable>(); foreach (var unit in squad.Units) { if (unit.Equals(null)) { continue; } Collider[] hitColliders = Physics.OverlapSphere(unit.position, viewRadius); int i = 0; while (i < hitColliders.Length) { ChildOfInteractiveGameObject[] seenEnemies = hitColliders[i].gameObject.GetComponents <ChildOfInteractiveGameObject>(); if (seenEnemies != null && seenEnemies.Length != 0) { int j = 0; while (j < seenEnemies.Length) { IHittable finalEnemy = seenEnemies[j].Owner.GetComponent <IHittable>(); if (finalEnemy != null && this.isEnemy(unit, finalEnemy)) { finalEnemiesList.Add(finalEnemy); } j++; } } i++; } } return(finalEnemiesList); }
private void Start() { playerPicture = GameObject.FindWithTag(TagsHelper.PlayerTag); player = playerPicture.GetComponent <IHittable>(); player.Hp.ObserveEveryValueChanged(x => x.Value) .Subscribe(healthUi.UpdateHealth) .AddTo(healthUi.gameObject); GameController.StaticObject.ScoreKilled.ObserveEveryValueChanged(x => x.Value) .Subscribe(scoreUi.UpdateScore) .AddTo(scoreUi.gameObject); player.IsDead.ObserveEveryValueChanged(x => x.Value).Where(x => x == true) .Subscribe(x => GameController.StaticObject.IsGameOver.Value = true) .AddTo(GameController.StaticObject); GameController.StaticObject.IsGameOver.ObserveEveryValueChanged(x => x.Value) .Subscribe(xs => { if (xs) { gameOverUi.GameOverShow(GameController.StaticObject.LevelComplete.Value); playerPicture.SetActive(false); } }) .AddTo(gameOverUi.gameObject); GameController.StaticObject.SpecifiedTime.ObserveEveryValueChanged(x => x.Value) .Subscribe(x => timerUi.UpdateTimer(x)) .AddTo(timerUi.gameObject); }
//TODO Add the projectile interface to this class for ALL Ruyo and the test projectiles. private void OnTriggerEnter2D(Collider2D other) { var hit = other.gameObject; if (hit != null) { if ((ignoredLayersMask.value & (1 << hit.layer)) != 0) //Is the detected collider assigned to any of the ignored layers? { return; //If yes - return, ignoring the collision. } } IHittable hitEntity = hit.GetComponentInParent <Player>(); if (hitEntity != null) { if (hitEntity.ChkHit(projectile) && !(projectile.CanPenetrate)) { Destroy(gameObject);//The projectile hit the player and cannot penetrate them - destroy the projectile. return; } return;//The projectile has done no harm to player or can penetrate through them. Let it phase through } //if we got here - the projectile did not hit player at all. probably hit a wall. if (!projectile.CanPenetrate) { Destroy(gameObject); } }
public color ComputeRayColor(Ray ray, IHittable world, int recursiveDepth) { if (recursiveDepth <= 0) { return(color.Zero); } var hitRec = new HitRecord(); // use t_min=0.001 to fix the shadow acne if (world.Hit(ray, 0.001, float.PositiveInfinity, out hitRec)) { Ray scattered = new Ray(); color attenuation = color.Zero; if (hitRec.material.Scatter(ray, ref hitRec, out attenuation, out scattered)) { return(attenuation * ComputeRayColor(scattered, world, recursiveDepth - 1)); } return(color.Zero); } var unit_dir = ray.Direction.unit_vector(); var t = 0.5 * (unit_dir.Y() + 1.0); color end = new color(1.0, 1.0, 1.0); color start = new color(0.5, 0.7, 1.0); return((1.0 - t) * end + t * start); }
public virtual void UpdateProjectile() { if (Time.time >= timeOfExpire) { LifespanExpired(); //will contiously trigger if we dont kill projectile } RaycastHit rayHit; if (Physics.Raycast(transform.position, currentMovementVector, out rayHit, projectileSpeed * Time.fixedDeltaTime, LayerMask.GetMask("Enemy", "Building", "Floor", "Wall"))) { IHittable ihittable = rayHit.transform.GetComponent <IHittable>(); //If the thing we hit has implemented "IHittable" if (ihittable != null) { HitTarget(ihittable, LayerMask.LayerToName(rayHit.transform.gameObject.layer)); } else { HitNonTarget(rayHit.point, LayerMask.LayerToName(rayHit.transform.gameObject.layer)); } DestroyProjectile(); } else { transform.position += currentMovementVector * projectileSpeed * Time.fixedDeltaTime; //else move forward } }
/// <summary> /// Launch the projectile and capture the source (firedFrom). /// </summary> /// <param name="forward"></param> /// <param name="firedFrom"></param> public void Fire(Vector3 forward, IHittable firedFrom) { projectile.velocity = forward * speed; lastBackPosition = projectileBack.position; this.firedFrom = firedFrom; Destroy(projectile.gameObject, 5f); }
public void OverKill() { IHittable testSubject = getHittable(); testSubject.Hit(int.MaxValue); Assert.IsTrue(testSubject.CurrentHP <= 0, "HP: " + testSubject.CurrentHP); Assert.IsFalse(testSubject.Alive, "Survived"); }
public void DeathAtZero() { IHittable testSubject = getHittable(); testSubject.Hit(testSubject.CurrentHP); Assert.AreEqual(testSubject.CurrentHP, 0, "HP: " + testSubject.CurrentHP); Assert.IsFalse(testSubject.Alive, "Survived"); }
private void OnTriggerStay2D(Collider2D collision) { if (collision.gameObject.CompareTag("Enemy") && animator.GetBool("isAttacking")) { IHittable script = collision.gameObject.GetComponent <IHittable>(); script.receiveDamage(1); } }
/// <summary> /// Обработка события удаления врага из списока возможных целей /// </summary> /// <param name="enemy"></param> public virtual void RemoveCript(IHittable enemy) { allEnemy.Remove(enemy); }
public void StartGame() { _allEnemies = new List<IHittable>(); _builder = FindObjectOfType<TowerBuilder>(); _keep = GameObject.FindGameObjectWithTag("Keep").GetComponent<HaveHitPoint>(); gameIsEnd = false; _status = GameResult.InBuildProcess; _builder.ShowUI = true; }
/// <summary> /// Keep неподвижен и уйти не может /// </summary> /// <param name="enemy"></param> public override void RemoveCript(IHittable enemy) { }
/// <summary> /// Переопределение логики добавления цели для атаки - проверка, что это Keep /// </summary> /// <param name="enemy"></param> public override void AddCript(IHittable enemy) { var go = enemy as HaveHitPoint; if (go.gameObject.tag != "Keep") return; allEnemy.Add(enemy); }
public void Awake() { _iam = GetComponent<HaveHitPoint>(); _maxHP = _iam.HP; }
/// <summary> /// Обработка события добавления врага в список возможных целей /// </summary> /// <param name="enemy"></param> public virtual void AddCript(IHittable enemy) { var go = enemy as HaveHitPoint; if (go.gameObject.tag != "Enemy") return; allEnemy.Add(enemy); }
public void BeginDPS(IHittable target) { if (_target != null) EndDPS(); _target = target; StartCoroutine(inflictDamage()); }
/// <summary> /// Прератить наносить текущей цели урон /// </summary> public void EndDPS() { _target = null; }
public HitTestResult(IHittable target, bool hit, object data) : this(target, hit, Coordinates.NaN, data) { }
/// <summary> /// Обработка события когда нужна новая цель для атаки /// </summary> public void CurrentTargetLose(IHittable _target) { SendMessage("RemoveCript", _target); TrySelectTarget(); }
public HitTestResult(IHittable target, bool hit) : this(target, hit, Coordinates.NaN, null) { }
private HitTestResult HitTest(IHittable obj, Coordinates point, double tolerance, HitTestFilter filter) { // check if we're in the bounding box RectangleF boundingBox = obj.GetBoundingBox(); // inflate by the tolerance if (!boundingBox.IsEmpty) { boundingBox.Inflate((float)tolerance, (float)tolerance); } // check if the bounding box is empty or we're inside it if (boundingBox.IsEmpty || boundingBox.Contains(Utility.ToPointF(point))) { // run the hit test HitTestResult result = obj.HitTest(point, (float)tolerance); // apply the filter if (filter(result)) { return result; } } // return a no-hit return HitTestResult.NoHit; }