protected override void OnUpdate() { Random random = Rand.GetRandom(); float3 playerPos = new float3(); foreach (var entity in GetEntities <Player>()) { playerPos = entity.transform.position; } foreach (var entity in GetEntities <Artifact>()) { bool isActivate = entity.chanceByHpLoseComponent.isActivate; GameObject bullet = entity.aroundShotPassiveArtifact.bullet; if (isActivate) { //TODO: fix anysizing for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (i == 0 && j == 0) { continue; } GameObject bulletInstance = GameObject.Instantiate(bullet, playerPos, quaternion.identity); MovingComponent movingComponent = bulletInstance.GetComponent <MovingComponent>(); movingComponent.vertical = i; movingComponent.horizontal = j; } } } } }
/////////////////////////////////////////////////////////// private IShip CreateShip() { var gameObject = new GameObject("Ship"); var model = new GameObject("Model"); model.AddComponent <SpriteRenderer>(); model.transform.parent = gameObject.transform; var shipModel = new ShipModel(5, 0, ""); var shipView = new ShipView(model); var speedConfigs = new MockSpeedConfigs(); speedConfigs.acceleration = 0; speedConfigs.startSpeed = 5; speedConfigs.maxSpeed = 15; var ship = gameObject.AddComponent <Ship>(); var movingComponent = new MovingComponent(ship, gameObject.transform, speedConfigs); ship.Construct(shipModel, shipView, movingComponent); return(ship); }
public virtual void Send(Vector2 target) { foreach (Entity entity in ProcessedEntities()) { MovingComponent moving = entity.GetComponent <MovingComponent>(); moving.IsMoving = true; moving.Target = target; } }
public void InitializeAsteroid() { GameObject asteroid = pool.Get(); asteroid.transform.position = new Vector3(spawnPointX, RandomYPosition()); asteroid.transform.parent = transform; MovingComponent moving = asteroid.GetComponent <MovingComponent>(); moving.Initialize(RandomSpeed(), new LeftInputAdapter()); moving.StartCoroutine(WaitForDestruction(asteroid)); IAsteroidCollider asteroidCollider = asteroid.GetComponent <IAsteroidCollider>(); asteroidCollider.SetCollisionCallBack(ReturnToPool); }
public override void Update(Entity entity) { MovingComponent moving = entity.GetComponent <MovingComponent>(); if (!moving.IsMoving) { return; } PositionComponent position = entity.GetComponent <PositionComponent>(); position.Position = Vector2.MoveTowards(position.Position, moving.Target, moving.Speed * Timer.DeltaTime); const float eps = 0.001f; if (Vector2.Distance(position.Position, moving.Target) < eps) { moving.IsMoving = false; } }
protected override void OnUpdate() { float3 position = new float3(); foreach (var entity in GetEntities <Player>()) { position = entity.transform.position; } foreach (PreAttack entity in GetEntities <PreAttack>()) { bool isAttacked = entity.preAttackComponent.isAttacked; if (!isAttacked) { continue; } RangedWeapon weapon = entity.preAttackComponent.weapon; if (weapon.preAttack != Structures.PreAttack.AroundShot) { continue; } for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (i == 0 && j == 0) { continue; } GameObject bulletInstance = GameObject.Instantiate(weapon.bulletPrefab, position, quaternion.identity); MovingComponent movingComponent = bulletInstance.GetComponent <MovingComponent>(); movingComponent.vertical = i; movingComponent.horizontal = j; } } entity.preAttackComponent.isAttacked = false; } }
private void Awake() { IPrefabPool asteroidPool = new PrefabPool(asteroidPoolsize, asteroidPrefab); asteroidCreator.Initialize(asteroidsSpeedMin, asteroidsSpeedMax, asteroidSpawnPointX, asteroidSpawnPointY, asteroidSpawnDeley, asteroidPool); for (int i = 0; i < ship.Count; i++) { IGameEnding gameEnding = new GameEnding(ship[i], this, gameEndingObject, gameEndingDelay); LifeManager lifeManager = gameObject.AddComponent <LifeManager>(); lifeManager.Initialize(lifeBar, shipMaxLife, ship[i], gameEnding); MovingComponent movingComponent = ship[i].GetComponent <MovingComponent>(); movingComponent.Initialize(shipSpeed, new InputAdapter()); movingComponent.GetComponent <ShipCollisionDetector>().Initialize(lifeManager.DealDamage); } }
// Possible Rat States /* * 1. Patrolling * 2. Chasing */ // Start is called before the first frame update void Start() { sensingComp = GetComponent <SensingComponent>(); movingComp = GetComponent <MovingComponent>(); moveToTargetComp = GetComponent <MoveToTargetComponent>(); }
// Start is called before the first frame update void Start() { move = GetComponent <MovingComponent>(); startTime = Time.time; deltaTime = Time.time - startTime; }