예제 #1
0
        private void fixedupdate()
        {
            if (fireTimer > 0f)
            {
                fireTimer -= time.deltaTime;
            }

            for (int i = _activeBullets.Count - 1; i >= 0; i--)
            {
                var index  = _activeBullets[i];
                var bullet = _bulletPool[index];

                if (bullet.energy > 0f)
                {
                    bullet.energy -= time.deltaTime;
                }
                else if (bullet.fadeOut > 0f)
                {
                    bullet.fadeOut -= time.deltaTime;
                }

                if (bullet.energy <= 0 && bullet.fadeOut <= 0)
                {
                    _bulletPool.FreeItem(index);
                    _activeBullets[i] = _activeBullets[_activeBullets.Count - 1];
                    _activeBullets.RemoveAt(_activeBullets.Count - 1);
                }
                else
                {
                    bullet.position += bullet.direction * bullet.velocity;

                    //check for collision
                    var target = _targets.get(bullet.position, 40, targetFilters).FirstOrDefault();
                    if (target != null)
                    {
                        bullet.energy  = 0;
                        bullet.fadeOut = 0;
                        _bulletPool.FreeItem(index);
                        _activeBullets[i] = _activeBullets[_activeBullets.Count - 1];
                        _activeBullets.RemoveAt(_activeBullets.Count - 1);
                        target.broadcast("takedamage", damage);
                        var scrolling = rootObject.getScript <ScrollingText>();
                        scrolling.emit(bullet.position, damage.ToString());
                    }
                }

                _bulletPool[index] = bullet;
            }
        }
예제 #2
0
        private void ongui()
        {
            var aabb = AxisAlignedBox.FromDimensions(new Vector2(0, 0), new Vector2(256, 256));

            //var p = _player.transform.DerivedPosition;
            var worldAABB = mainCamera.worldBounds;
            var p0        = worldAABB.Minimum;
            var p1        = worldAABB.Maximum;
            var scale     = 128f / _settings.SectorHalfSize;


            p0.X = Utility.Clamp(p0.X, _settings.SectorHalfSize, -_settings.SectorHalfSize) * scale;
            p0.Y = Utility.Clamp(p0.Y, _settings.SectorHalfSize, -_settings.SectorHalfSize) * scale;
            p1.X = Utility.Clamp(p1.X, _settings.SectorHalfSize, -_settings.SectorHalfSize) * scale;
            p1.Y = Utility.Clamp(p1.Y, _settings.SectorHalfSize, -_settings.SectorHalfSize) * scale;

            worldAABB.SetExtents(p0, p1);
            worldAABB.Center = worldAABB.Center;

            aabb.Center      += transform.DerivedPosition;
            worldAABB.Center += transform.DerivedPosition;

            graphics.Draw(aabb, new Color(Color.Black, 0.5f));
            graphics.DrawRect(aabb, new Color(Color.Green, 0.5f));

            var aliens = _targets.get(Vector2.Zero, _settings.SectorSize, TargetFilters.Aliens);

            foreach (var alien in aliens)
            {
                var p = alien.transform.DerivedPosition * scale;
                graphics.DrawRect(AxisAlignedBox.FromDimensions(p + transform.DerivedPosition, Vector2.One * 2), new Color(Color.Red, 0.5f));
            }

            graphics.DrawRect(worldAABB, new Color(Color.White, 0.5f));
        }
예제 #3
0
        private void dofire(bool force)
        {
            if (!isfiring)
            {
                var sp        = transform.DerivedPosition;
                var ep        = sp + transform.DerivedForward * length;
                var lp        = new LineSegment(sp, ep);
                var hastarget = targetObjects.get(lp, 20f, targetFilters).Any();

                if (!hastarget && !force)
                {
                    return;
                }

                isfiring             = true;
                damageTimerRemaining = 0f;
                fireTimerRemaining   = fireTimer;
            }
        }
예제 #4
0
        private void fixedupdate()
        {
            var targets = _targets.get(transform.DerivedPosition, 40, targetFilters);

            foreach (var target in targets)
            {
                if (target != null)
                {
                    var scrolling = rootObject.getScript <ScrollingText>();
                    scrolling.emit(transform.DerivedPosition, damage.ToString());
                    target.broadcast("takedamage", damage);

                    //target.sendMessage("takedamage", damage);
                    gameObject.destroy();
                    break;
                }
            }
        }
예제 #5
0
        private void processlogic()
        {
            if (_ship != null)
            {
                //return;
                var from = transform.DerivedPosition;
                switch (_aistate)
                {
                case AIState.LookingForTarget:
                {
                    _targetAcquistionTimer -= time.deltaTime;
                    if (_targetAcquistionTimer <= 0f)
                    {
                        _targetAcquistionTimer = _targetAcquistion;

                        var targets = _targetObjects.get(from, aggressionRange, attackFilters);
                        var target  = targets.OrderByDescending(x => x.transform.DerivedPosition.LengthSquared()).FirstOrDefault();

                        if (target != null)
                        {
                            _aistate        = AIState.ChasingTarget;
                            _target         = target;
                            _returnLocation = from;
                            break;
                        }
                    }

                    if (aroundRadius > 0f)
                    {
                        var arSQ  = aroundRadius * aroundRadius;
                        var dstSQ = (around - from).LengthSquared();

                        _ship.steering.seek(from, around, dstSQ / arSQ);
                        _ship.steering.wander(from, distance, radius, change);
                    }
                    else
                    {
                        _ship.steering.wander(from, distance, radius, change);
                    }

                    _lookAt = transform.DerivedPosition + _ship.steering.velocity * 300f;
                    engineEmitter.emitParticles(30, 50, 0.1f);
                    break;
                }

                case AIState.ChasingTarget:
                {
                    if (_target.destroyed)
                    {
                        _target  = null;
                        _aistate = AIState.Returning;
                        break;
                    }

                    var targetPosition   = _target.transform.DerivedPosition;
                    var followDistanceSq = followDistance * followDistance;
                    var direction        = (from - targetPosition);
                    var distanceSq       = direction.LengthSquared();

                    if (followDistanceSq < distanceSq)
                    {
                        _aistate = AIState.Returning;
                        _target  = null;
                        break;
                    }

                    if (distanceSq < 50 * 50)
                    {
                        //moveState = 3;
                        //_ship.steering.flee(from, targetPosition);
                    }

                    if (distanceSq > 550 * 550)
                    {
                        shit      = false;
                        moveState = 2;
                        //direction.Normalize();
                        //targetPosition += direction * 300f;
                        _ship.steering.seek(from, targetPosition);
                        engineEmitter.emitParticles(30, 50, 0.1f);
                    }
                    else
                    {
                        moveTimer -= time.deltaTime;
                        if (moveTimer <= 0f)
                        {
                            moveState = random.Next(5);
                            moveTimer = random.Next(1f, 2f);
                            _ship.steering.seek(from, transform.DerivedRight * 300f);
                        }
                        else if (random.Next(6) == 0)
                        {
                            _ship.steering.seek(from, transform.DerivedRight * -300f);
                        }

                        switch (moveState)
                        {
                        case 0: _ship.steering.seek(from, transform.DerivedRight * 300f); break;

                        case 1: _ship.steering.seek(from, -transform.DerivedRight * 300f); break;

                        case 2: _ship.steering.seek(from, transform.DerivedForward * 300f); break;

                        case 3: _ship.steering.seek(from, -transform.DerivedForward * 300f); break;

                        case 4: _ship.steering.wander(from, 6f, 10f, change); break;

                        default:
                            break;
                        }

                        //else if (random.Next(10) == 0)
                        //{
                        //    _ship.steering.seek(from, transform.DerivedForward * 300f);
                        //}
                        //else if (random.Next(5) == 0)
                        //{
                        //    _ship.steering.seek(from, transform.DerivedForward * -300f);
                        //}
                        //else if (random.Next(5) == 0)
                        //else if (random.Next(15) == 0)
                        //{
                        //    var arSQ = aroundRadius * aroundRadius;
                        //    var dstSQ = (around - from).LengthSquared();

                        //    //_ship.steering.seek(from, targetPosition, dstSQ / arSQ);
                        //    _ship.steering.wander(from, 6f, 10f, change);
                        //}


                        this.gameObject.broadcast("tryfire");
                    }
                    _lookAt = targetPosition;



                    break;
                }

                case AIState.Returning:
                {
                    var distanceSq        = (from - _returnLocation).LengthSquared();
                    var returnThresholdSq = 150 * 150;

                    if (distanceSq < returnThresholdSq)
                    {
                        _aistate = AIState.LookingForTarget;
                        break;
                    }

                    _ship.steering.seek(from, _returnLocation);
                    _lookAt = _returnLocation;
                    engineEmitter.emitParticles(30, 50, 0.1f);
                    break;
                }
                }


                _ship.steering.steering  += -seperation(20f) * 0.1f;
                transform.DerivedPosition = _ship.steering.integrate(transform.DerivedPosition, _ship.mass);
                lookAt(from, _lookAt);


                //var sep = seperation(10f);
                //_ship.steering.seek(transform.DerivedPosition, transform.DerivedPosition + _ship.steering.truncate(sep, _ship.steering.maxVelocity));
                //transform.DerivedPosition = _ship.steering.integrate(transform.DerivedPosition, _ship.mass);
            }
        }