void UpdatePosition(FixedPointVector3 pos)
 {
     if (markerObject != null)
     {
         markerObject.transform.position = pos.ToWorkerPosition(this.Origin);
     }
 }
Exemplo n.º 2
0
    public void SpawnAsteroid()
    {
        bool horizontal = Random.value > 0.5f;
        bool left       = Random.value > 0.5f;
        bool top        = Random.value > 0.5f;

        FixedPointVector3 position = new FixedPointVector3();

        if (horizontal)
        {
            position.X = FPRandom.Range(0, sceneWidth);
            position.Y = top ? -boundarySize : sceneHeight + boundarySize;
        }
        else
        {
            position.X = left ? -boundarySize : sceneWidth + boundarySize;
            position.Y = FPRandom.Range(0, sceneHeight);
        }

        var scale    = FPRandom.Range(1.0f, 1.5f);
        var asteroid = new Asteroid(position, scale);

        asteroid.direction = (new FixedPointVector3(sceneWidth / 2, sceneHeight / 2, 0) - position).Normalized;
        asteroid.speed     = sceneWidth / FPRandom.Range(5, 10);

        entitiesToSpawn.Enqueue(asteroid);
    }
Exemplo n.º 3
0
Arquivo: Entities.cs Projeto: N-01/UFO
    public Ufo(FixedPointVector3 _pos, FixedPoint _diameter)
    {
        type = EntityType.Ufo;

        originPosition          = _pos;
        speed                   = Extensions.Range(0.5f, 1f);
        orbitRadius             = scale;
        asteroidDetectionRadius = _diameter * 5;

        health = 20;

        body = new CircleBody(originPosition, _diameter * (FixedPoint)0.5f, this);

        body.SetLayer(type);
        body.SetCollidesWith(EntityType.Asteroid, true);
        body.SetCollidesWith(EntityType.Blast, true);
        body.SetCollidesWith(EntityType.Placeholder, true);
        body.SetCollidesWith(EntityType.Ufo, true);

        //randomize rotations
        if (Random.value > 0.5f)
        {
            orbitSpeedPerSecond = -orbitSpeedPerSecond;
        }

        currentOrbitAngle = Extensions.Range(0, Mathf.PI * 2);

        behavior = new UfoBehavior(this);
    }
Exemplo n.º 4
0
 public OrientedBoxBody(FixedPointVector3 pos, FixedPoint w, FixedPoint h, FixedPoint a, Entity _owner) : base(pos)
 {
     angle  = a;
     width  = w;
     height = h;
     owner  = _owner;
 }
 void SendCommand(EntityId id, UnitSide side, Vector3 vec)
 {
     this.CommandSystem.SendCommand(new StrongholdSight.SetStrategyVector.Request(
                                        id,
                                        new StrategyVector(side, FixedPointVector3.FromUnityVector(vec)))
                                    );
 }
Exemplo n.º 6
0
    public override void UpdateLogics(FixedPoint dt, GameController gc)
    {
        if (_secondsSinceLastShot >= ufo.timeBetweenShots)
        {
            Shoot(gc);
            _secondsSinceLastShot = 0;
        }
        else
        {
            _secondsSinceLastShot += dt;
        }


        //I don't know if it's allowed to cache target until it's dead, but otherwise it'd be too wasteful
        if (cachedTarget == null || cachedTarget.dead)
        {
            cachedTarget = gc.FindClosestEntity(entity, (e, f) => e is Ufo);
        }

        if (cachedTarget != null)
        {
            var diff = (cachedTarget.position - entity.position);
            if (diff.Magnitude > entity.scale * 2)
            {
                ufo.direction = diff.Normalized;
            }
            else
            {
                ufo.direction = diff.Normalized.Turn;
            }
        }
        else
        {
            ufo.direction = new FixedPointVector3(0, 0, 0);
        }

        ufo.originPosition    += ufo.direction * dt * ufo.speed;
        ufo.currentOrbitAngle += ufo.orbitSpeedPerSecond * dt;

        //UFO can deviate it's orbit in case of collisions, but it gradually returns
        //I thought of creating a more generalized impulse var in Body
        //and updating it through CollsionController, but it led
        //to more code and hacks for a SINGLE use-case, i'd rather
        //resolve such problems with a more generalized physics engine

        FixedPointVector3 desiredOrbitPosition = new FixedPointVector3(ufo.currentOrbitAngle.Sin(), ufo.currentOrbitAngle.Cos(), 0) * ufo.orbitRadius;

        ufo.currentOrbitedPosition = FixedPointVector3.Lerp(ufo.currentOrbitedPosition + ufo.pushDirection, desiredOrbitPosition, FixedPoint.Float01);
        ufo.position       = ufo.originPosition + ufo.currentOrbitedPosition;
        ufo.pushDirection *= (FixedPoint)0.97;

        ufo.body.position = ufo.position;
    }
Exemplo n.º 7
0
Arquivo: Utils.cs Projeto: N-01/UFO
        public static FixedPointVector3 RotatePoint(FixedPointVector3 p, FixedPointVector3 o, FixedPoint angle)
        {
            FixedPointVector3 r = new FixedPointVector3(p.X - o.X, p.Y - o.Y, 0);
            FixedPoint        s = angle.Sin();
            FixedPoint        c = angle.Cos();

            r.X = r.X * c - r.Y * s;
            r.Y = r.Y * c + r.X * s;

            r.X += o.X;
            r.Y += o.Y;

            return(r);
        }
Exemplo n.º 8
0
 public BulletInfo(BulletInfo info, byte act)
 {
     Power           = info.Power;
     Type            = info.Type;
     Alignment       = info.Alignment;
     LaunchPosition  = info.LaunchPosition;
     InitialVelocity = info.InitialVelocity;
     CurrentVelocity = info.CurrentVelocity;
     LaunchTime      = info.LaunchTime;
     LifeTime        = info.LifeTime;
     GunId           = info.GunId;
     ShooterEntityId = info.ShooterEntityId;
     BulletId        = info.BulletId;
     active          = act;
 }
Exemplo n.º 9
0
 public BulletInfo(BulletFireInfo fire)
 {
     Power           = fire.Power;
     Type            = fire.Type;
     Alignment       = fire.Alignment;
     LaunchPosition  = fire.LaunchPosition;
     InitialVelocity = fire.InitialVelocity;
     CurrentVelocity = InitialVelocity;
     LaunchTime      = fire.LaunchTime;
     LifeTime        = fire.LifeTime();
     GunId           = fire.GunId;
     ShooterEntityId = fire.ShooterEntityId;
     BulletId        = fire.BulletId;
     active          = 1;
 }
Exemplo n.º 10
0
Arquivo: Entities.cs Projeto: N-01/UFO
    public Asteroid(FixedPointVector3 _pos, FixedPoint _scale)
    {
        position = _pos;
        scale    = _scale;
        speed    = Extensions.Range(1, 2);
        health   = 5;
        type     = EntityType.Asteroid;

        body = new CircleBody(position, scale * (FixedPoint)0.5f, this);

        body.SetLayer(type);
        body.SetCollidesWith(EntityType.Ufo, true);
        body.SetCollidesWith(EntityType.Asteroid, true);
        body.SetCollidesWith(EntityType.Blast, true);
        body.SetCollidesWith(EntityType.Placeholder, true);

        behavior = new  AsteroidBehavior(this);
    }
Exemplo n.º 11
0
        private bool OOBvsCircle(OrientedBoxBody box, CircleBody circle)
        {
            FixedPointVector3 rotated  = MathExt.RotatePoint(circle.position, box.position, 0);
            FixedPointVector3 relative = rotated - box.position;

            FixedPoint        halfW   = box.width * FixedPoint.Float05;
            FixedPoint        halfH   = box.height * FixedPoint.Float05;
            FixedPointVector3 clamped = new FixedPointVector3(
                relative.X.Clamp(-halfW, halfW),
                relative.Y.Clamp(-halfH, halfH),
                0);

            //rotate back
            FixedPointVector3 transformedBack = MathExt.RotatePoint(clamped, box.position, 0);

            transformedBack += box.position;

            return((circle.position - transformedBack).Magnitude <= circle.radius);
        }
Exemplo n.º 12
0
Arquivo: Entities.cs Projeto: N-01/UFO
    public Blast(FixedPointVector3 pos, FixedPointVector3 dir, Entity _source)
    {
        position  = pos;
        direction = dir;
        speed     = Extensions.Range(2, 3);
        angle     = (FixedPoint)(Mathf.Atan2(-dir.X.Float, dir.Y.Float));

        type  = EntityType.Blast;
        body  = new OrientedBoxBody(pos, (FixedPoint)0.13f, (FixedPoint)0.39f, -angle, this);
        scale = (FixedPoint)0.25f;

        body.SetLayer(type);
        body.SetCollidesWith(EntityType.Ufo, true);
        body.SetCollidesWith(EntityType.Asteroid, true);

        behavior = new BlastBehavior(this);

        source = _source;
    }
Exemplo n.º 13
0
    //do the pew pews
    //i didn't bother with grid here
    //because it doesn't happen every frame and has low locality
    private void Shoot(GameController gc)
    {
        Entity closestEntity = gc.FindClosestEntity(entity, (e, dist) =>
        {
            if (e is Ufo)
            {
                return(true);
            }

            if (e is Asteroid)
            {
                return(dist <= ufo.asteroidDetectionRadius);
            }

            return(false);
        });

        if (closestEntity != null)
        {
            FixedPointVector3 direction = (closestEntity.position - ufo.position).Normalized;
            gc.SpawnBlast(ufo.position + direction, direction, ufo);
        }
    }
Exemplo n.º 14
0
 public static float SqrMagnitude(this FixedPointVector3 vec)
 {
     return((vec.X * vec.X) + (vec.Y * vec.Y) + (vec.Z * vec.Z));
 }
Exemplo n.º 15
0
 public static Vector3 ToWorkerPosition(this FixedPointVector3 pos, Vector3 origin)
 {
     return(pos.ToUnityVector() + origin);
 }
Exemplo n.º 16
0
 public void SpawnUfo(FixedPointVector3 pos)
 {
     entitiesToSpawn.Enqueue(new Ufo(pos, 1));
 }
Exemplo n.º 17
0
 public void SpawnBlast(FixedPointVector3 pos, FixedPointVector3 dir, Entity source)
 {
     entitiesToSpawn.Enqueue(new Blast(pos, dir, source));
 }
Exemplo n.º 18
0
        public static CompressedLocalTransform ConvertTransform(Coordinates position, CompressedQuaternion rotation, FixedPointVector3 scale)
        {
            var trans = new CompressedLocalTransform();

            trans.Position = position.ToFixedPointVector3();
            trans.Rotation = rotation;
            trans.Scale    = scale;

            return(trans);
        }
Exemplo n.º 19
0
 public Body(FixedPointVector3 pos)
 {
     position = pos;
 }
Exemplo n.º 20
0
 public CircleBody(FixedPointVector3 pos, FixedPoint r, Entity _owner) : base(pos)
 {
     radius = r;
     owner  = _owner;
 }
 public PlayerInitInfo(UnitSide side, Vector3 pos)
 {
     this.side = side;
     this.pos  = pos.ToFixedPointVector3();
 }
Exemplo n.º 22
0
 public static Coordinates ToCoordinates(this FixedPointVector3 pos)
 {
     return(pos.ToUnityVector().ToCoordinates());
 }