Beispiel #1
0
    public void TryLaserShot()
    {
        float LaserLen = 10f;

        if (LasersCharges.x > 0)
        {
            LasersCharges.x--;
            AsteroidsGame.current.UpdateLaserCounter();
            var up = logicobj.up;
            foreach (var item in Engine.FindObjectsOfType <FastPhysics>())
            {
                if (!FastPhysics.CrossArray(item.logicobj.tags, tagsblacklist))
                {
                    //Расстояние до лазера от объекта это длина его перпендикуляра если корабль смотрит в сторону объекта
                    var ip = item.position;
                    if (Vector2.Distance(up + position, ip) < Vector2.Distance(position, ip))//Если корабль смотрит в сторону объекта
                    {
                        Vector2 cross = PerpPoint(ip - position, up);
                        if (cross.magnitude < item.Radius && Vector2.Distance(ip - cross, position) < LaserLen)//Длина перепендикуляра
                        {
                            AsteroidsGenerator.Crush(item.logicobj, true);
                        }
                    }
                }
            }
            var laser = LogicalObject.Create()
                        .AddPart(new PolyRenderer(new Vector2[] {
                new Vector2(0, 0.5f),
                new Vector2(0, LaserLen)
            }, Color.red));
            laser.position = position;
            laser.angle    = angle;
            Destroy(laser, 0.1f);
        }
    }
Beispiel #2
0
 public override void Update()
 {
     ShotCooldown.Update(Time.deltaTime * FastPhysics.TimeScale);
     LaserCooldown.Update(Time.deltaTime * FastPhysics.TimeScale);
     FastPhysics.CheckCollisions(FastPhysics, tagsblacklist, (item) =>
     {
         //TODO audio
         AsteroidsGenerator.Crush(item.logicobj);
         OnDamage();
     });
 }
Beispiel #3
0
    private void Update()
    {
        if (seed == lastSeed)
        {
            return;
        }
        tilemap.ResetTiles();
        var asteroid = new AsteroidsGenerator(xMax, yMax, noiseScale, seed);

        asteroid.SetTilemap(ref tilemap, tileBase);
        lastSeed = seed;
    }
Beispiel #4
0
        public DataObject ToObject()
        {
            AsteroidsGenerator generator = FindObjectOfType <AsteroidsGenerator>();
            Asteroid           asteroid  = generator.SpawAsteroid(PrebafIndex, new Vector2(PositionX, PositionY), new Vector2(DirectionX, DirectionY));

            asteroid.transform.eulerAngles = new Vector3(0, 0, Angle);
            asteroid.rotationSpeed         = RotationSpeed;
            asteroid.rotationDirection     = RotationDirection;

            asteroid.WasLoaded = true;

            return(asteroid);
        }
Beispiel #5
0
 public override void Update()
 {
     FastPhysics.CheckCollisions(FastPhysics, tagsblacklist, (item) => {
         //TODO audio
         AsteroidsGenerator.Crush(item.logicobj);
         Destroy();
     });
     lifetime -= Time.deltaTime * FastPhysics.TimeScale;
     if (lifetime <= 0)
     {
         Destroy();
     }
 }
Beispiel #6
0
 public void OnCrush(bool islaser = false)
 {
     if (!islaser)
     {
         float offset = Random.Range(0, 360);
         for (int k = 0; k < PartsCount; k++)
         {
             float angle = (((float)k / (float)PartsCount) * 360f + offset) % 360;
             var   obj   = AsteroidsGenerator.CreateMeteor(position);
             obj.FastPhysics.Velocity =
                 new Vector2(Mathf.Sin(angle * Mathf.Deg2Rad), Mathf.Cos(angle * Mathf.Deg2Rad)) * MeteorsSpeed;
             obj.FastPhysics.Angularvelocity = UnityEngine.Random.Range(-360f, 360f);
         }
     }
     Destroy();
     AsteroidsGenerator.Objects.Remove(logicobj);
     AsteroidsGame.current.Score += ScoreReward;
 }
Beispiel #7
0
 /// <summary>
 ///     Generates a map
 /// </summary>
 /// <param name="pos">The portion of the map to generate as the coordinates of 100x100 squares centred on the origin</param>
 /// <param name="tilemap">The tilemap template to use for the asteroids</param>
 /// <param name="grid">The grid objects to attach the tilemaps to</param>
 /// <param name="pool">The object pool to use</param>
 public void Generate(IEnumerable <Vector2Int> pos, GameObject tilemap, Transform grid, ObjectPool pool)
 {
     foreach (Vector2Int vector2Int in pos)
     {
         if (!CheckPoint(vector2Int) || vector2Int == Vector2Int.zero)
         {
             continue;
         }
         var asteroid = new AsteroidsGenerator(Random.Range(25, 35), Random.Range(25, 35), Random.Range(10, 20),
                                               (vector2Int.y + yOffset) * (vector2Int.x + xOffset));
         var        posWorld      = new Vector2(vector2Int.x * scale, vector2Int.y * scale);
         GameObject mapGameObject = Object.Instantiate(tilemap, grid);
         mapGameObject.transform.position = posWorld + Random.insideUnitCircle * (scale - 50);
         int rot = Random.Range(0, 365);
         mapGameObject.transform.rotation = Quaternion.Euler(0, 0, rot);
         mapGameObject.GetComponent <Rigidbody2D>().angularVelocity = Random.Range(0, 5f);
         var map = mapGameObject.GetComponent <TileManager>();
         map.pool = pool;
         asteroid.SetTilemap(ref map, tileBase);
     }
 }
Beispiel #8
0
    private void Start()
    {
        var asteroid = new AsteroidsGenerator(30, 30, 15);

        asteroid.SetTilemap(ref tilemap, tileBase);
    }
    [SerializeField] private Transform[] pfAsteroids = null; //Attached in the Editor

    void Awake()
    {
        current = this;
    }