コード例 #1
0
    protected void MuzzleFlash(EntityUid gun, AmmoComponent component, EntityUid?user = null)
    {
        var sprite = component.MuzzleFlash?.ToString();

        // TODO: AAAAA THIS MUZZLE FLASH CODE IS BAD
        // NEEDS EFFECTS TO NOT BE BAD!
        if (sprite == null)
        {
            return;
        }

        var time      = Timing.CurTime;
        var deathTime = time + TimeSpan.FromSeconds(MuzzleFlashLifetime);
        // Offset the sprite so it actually looks like it's coming from the gun
        var offset = new Vector2(0.0f, -0.5f);

        var message = new EffectSystemMessage
        {
            EffectSprite      = sprite,
            Born              = time,
            DeathTime         = deathTime,
            AttachedEntityUid = gun,
            AttachedOffset    = offset,
            //Rotated from east facing
            Rotation   = -MathF.PI / 2f,
            Color      = Vector4.Multiply(new Vector4(255, 255, 255, 255), 1.0f),
            ColorDelta = new Vector4(0, 0, 0, -1500f),
            Shaded     = false
        };

        CreateEffect(message, user);
    }
コード例 #2
0
    private void OnTriggerEnter2D(Collider2D collider)
    {
        if (collider.CompareTag("Worm"))
        {
            if (!ownerAmmo)
            {
                if (GetComponentInParent <AmmoComponent>())
                {
                    ownerAmmo = GetComponentInParent <AmmoComponent>();
                }
            }

            if (collider.GetComponent <WormCharacter>().IsDead)
            {
                return;
            }


            // For now always of type Explosion for Ammo
            if (!damageApplied)
            {
                //    damageApplied = true; // Commenter sinon sa empeche les autres cas standard ( grenade)
                ownerAmmo.AmmoBehaviourDamage((transform.position - collider.transform.position).normalized, collider.GetComponent <WormInfo>());
            }
        }
    }
コード例 #3
0
        private void CreateObjects()
        {
            var obj1 = EntityManager.GetEntityManager().NewEntity();

            var light = new LightComponent()
            {
                Light = new PointLight()
                {
                    Position   = new Vector2(50, 50),
                    Scale      = new Vector2(500f),
                    ShadowType = ShadowType.Solid // Will not lit hulls themselves
                }
            };

            var player = new PlayerComponent()
            {
                Name = "Kalle"
            };

            var ammo = new AmmoComponent()
            {
                Amount = 65
            };

            var health = new HealthComponent()
            {
                CurrentHealth = 34,
                MaxHealth     = 77
            };

            ComponentManager.Instance.AddComponentToEntity(light, obj1);
            ComponentManager.Instance.AddComponentToEntity(player, obj1);
            ComponentManager.Instance.AddComponentToEntity(ammo, obj1);
            ComponentManager.Instance.AddComponentToEntity(health, obj1);
        }
コード例 #4
0
    protected void MuzzleFlash(EntityUid gun, AmmoComponent component, EntityUid?user = null)
    {
        var sprite = component.MuzzleFlash;

        if (sprite == null)
        {
            return;
        }

        var ev = new MuzzleFlashEvent(sprite);

        CreateEffect(gun, ev, user);
    }
コード例 #5
0
    public void Fire(WormCharacter shooter, WeaponType typeWeapon, Vector2 startPos, Vector2 dir, float forceFactor = 1)
    {
        GameObject    ammo          = Instantiate(db.ListWeapons[(int)typeWeapon - 1].prefab);
        AmmoComponent ammoComponent = ammo.GetComponent <AmmoComponent>();

        Physics2D.IgnoreCollision(shooter.GetComponent <Collider2D>(), ammoComponent.AmmoCollider);
        ammoComponent.Direction    = dir;
        ammoComponent.DamageRadius = db.ListWeapons[(int)typeWeapon - 1].damageRadius;
        ammoComponent.Damage       = db.ListWeapons[(int)typeWeapon - 1].damage;
        ammoComponent.Force        = db.ListWeapons[(int)typeWeapon - 1].force * forceFactor;

        ammo.transform.position = startPos;
    }
コード例 #6
0
    public void MuzzleFlash(EntityUid entity, AmmoComponent component, Angle angle)
    {
        if (component.MuzzleFlashSprite == null)
        {
            return;
        }

        var time      = _gameTiming.CurTime;
        var deathTime = time + TimeSpan.FromMilliseconds(200);
        // Offset the sprite so it actually looks like it's coming from the gun
        var offset = new Vector2(0.0f, -0.5f);

        var message = new EffectSystemMessage
        {
            EffectSprite      = component.MuzzleFlashSprite.ToString(),
            Born              = time,
            DeathTime         = deathTime,
            AttachedEntityUid = entity,
            AttachedOffset    = offset,
            //Rotated from east facing
            Rotation   = -MathF.PI / 2f,
            Color      = Vector4.Multiply(new Vector4(255, 255, 255, 255), 1.0f),
            ColorDelta = new Vector4(0, 0, 0, -1500f),
            Shaded     = false
        };

        /* TODO: Fix rotation when shooting sideways. This was the closest I got but still had issues.
         * var time = _gameTiming.CurTime;
         * var deathTime = time + TimeSpan.FromMilliseconds(200);
         * var entityRotation = EntityManager.GetComponent<TransformComponent>(entity).WorldRotation;
         * var localAngle = entityRotation - (angle + MathF.PI / 2f);
         * // Offset the sprite so it actually looks like it's coming from the gun
         * var offset = localAngle.RotateVec(new Vector2(0.0f, -0.5f));
         *
         * var message = new EffectSystemMessage
         * {
         *  EffectSprite = component.MuzzleFlashSprite.ToString(),
         *  Born = time,
         *  DeathTime = deathTime,
         *  AttachedEntityUid = entity,
         *  AttachedOffset = offset,
         *  //Rotated from east facing
         *  Rotation = (float) (localAngle - MathF.PI / 2),
         *  Color = Vector4.Multiply(new Vector4(255, 255, 255, 255), 1.0f),
         *  ColorDelta = new Vector4(0, 0, 0, -1500f),
         *  Shaded = false
         * };
         */

        _effects.CreateParticle(message);
    }
コード例 #7
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.collider.CompareTag("Map"))
        {
            // error when throw in water or worm ? ?
            if (!ownerAmmo)
            {
                if (GetComponentInParent <AmmoComponent>())
                {
                    ownerAmmo = GetComponentInParent <AmmoComponent>();
                }
            }

            // One case for rocket stuck on worm ?
            ///TODO : Here !!

            ownerAmmo.AmmoBehaviourImpact(collision.collider.GetComponent <TerrainDestructible>());
        }
        else if (collision.collider.CompareTag("Worm"))
        {
            if (collision.collider.GetComponent <WormInfo>() && collision.collider.GetComponent <WormInfo>().underMe != null)
            {
                // error when throw in water or worm ? ?
                if (!ownerAmmo)
                {
                    if (GetComponentInParent <AmmoComponent>())
                    {
                        ownerAmmo = GetComponentInParent <AmmoComponent>();
                    }
                }

                if (collision.collider.GetComponent <WormCharacter>().IsDead)
                {
                    return;
                }

                ownerAmmo.AmmoBehaviourImpact(collision.collider.GetComponent <WormInfo>().underMe);
            }
        }
    }
コード例 #8
0
        public override void OnAddedToScene()
        {
            base.OnAddedToScene();

            var mainScene = (Scene as MainScene);

            truck        = mainScene.truck;
            playerWeapon = truck.GetComponent <PlayerWeaponComponent>();
            playerWeapon.OnWeaponCycle += UpdateWeaponIcons;

            playerMove = truck.GetComponent <PlayerMovementComponent>();

            playerHealth = truck.GetComponent <HealthComponent>();
            playerHealth.OnHealthChanged += (h) => UpdateHealth(h);

            playerAmmo = truck.GetComponent <AmmoComponent>();
            playerAmmo.OnAmmoChanged += a => UpdateAmmo(a);

            playerState = truck.GetComponent <PlayerStateMachine>();

            SetUpUI();
        }
コード例 #9
0
    public EntityUid?TakeBullet(AmmoComponent component, EntityCoordinates spawnAt)
    {
        if (component.AmmoIsProjectile)
        {
            return(component.Owner);
        }

        if (component.Spent)
        {
            return(null);
        }

        component.Spent = true;

        if (TryComp(component.Owner, out AppearanceComponent? appearanceComponent))
        {
            appearanceComponent.SetData(AmmoVisuals.Spent, true);
        }

        var entity = EntityManager.SpawnEntity(component.ProjectileId, spawnAt);

        return(entity);
    }
コード例 #10
0
    private void OnAmmoExamine(EntityUid uid, AmmoComponent component, ExaminedEvent args)
    {
        var text = Loc.GetString("ammo-component-on-examine", ("caliber", component.Caliber));

        args.PushMarkup(text);
    }
コード例 #11
0
 void Start()
 {
     ownerAmmo = GetComponentInParent <AmmoComponent>();
     GetComponent <CircleCollider2D>().radius = ownerAmmo.DamageRadius;
 }
コード例 #12
0
        // DrwaTitleSafe gets all the components and draws them in a
        // correct format, so the data will sortet so that each entity will
        // have it's own row, and each component will be sorted by column.
        private void DrawTitleSafe()
        {
            GraphicsDevice graphics      = _gameDependencies.GraphicsDeviceManager.GraphicsDevice;
            Rectangle      titlesafearea = graphics.Viewport.TitleSafeArea;

            Dictionary <int, IComponent> playerComponents = ComponentManager.Instance.GetEntitiesWithComponent(typeof(PlayerComponent));

            // We save the previous text height so we can stack
            // them (the text for every player) on top of eachother.
            float previousHeight = 5f;

            ContentManager contentManager = _gameDependencies.GameContent as ContentManager;
            // Maybe let the user decide?
            SpriteFont spriteFont = contentManager.Load <SpriteFont>("ZEone");

            Vector2 position = Vector2.Zero;

            gameHUD.Clear();

            foreach (var playerInstance in playerComponents)
            {
                var playerComponent = playerInstance.Value as PlayerComponent;
                gameHUD.AppendLine();
                gameHUD.Append(playerComponent.Name);

                // Adding the health component to text.
                if (ComponentManager.Instance.EntityHasComponent <HealthComponent>(playerInstance.Key))
                {
                    HealthComponent health = ComponentManager.Instance.GetEntityComponentOrDefault <HealthComponent>(playerInstance.Key);

                    if (health.Alive)
                    {
                        var currentHealth = health.MaxHealth - health.Damage.Sum();
                        gameHUD.Append(":");
                        gameHUD.Append(currentHealth);
                        gameHUD.Append("HP");

                        //text = text + ": " + currentHealth + "HP";
                    }
                    else
                    {
                        //text = text + ": Rest in peace";
                        gameHUD.Append(": Rest in peace");
                    }

                    // adding ammo here the same way.
                    if (ComponentManager.Instance.EntityHasComponent <AmmoComponent>(playerInstance.Key) && health.Alive)
                    {
                        AmmoComponent ammo = ComponentManager.Instance.GetEntityComponentOrDefault <AmmoComponent>(playerInstance.Key);
                        //text = text + " Ammo: " + ammo.Amount;
                        gameHUD.Append(" Ammo: ");
                        gameHUD.Append(ammo.Amount);
                    }
                }

                // this call gives us the height of the text,
                // so now we are able to stack them on top of each other.
                float textHeight = spriteFont.MeasureString(gameHUD).Y;

                float xPosition = titlesafearea.Width - spriteFont.MeasureString(gameHUD).X - 10;
                float yPosition = titlesafearea.Height - (textHeight + previousHeight);
                previousHeight += textHeight;

                position = new Vector2(xPosition, yPosition);
            }

            _gameDependencies.SpriteBatch.Begin(SpriteSortMode.FrontToBack);
            _gameDependencies.SpriteBatch.DrawString(spriteFont, gameHUD, position, Color.BlueViolet);
            _gameDependencies.SpriteBatch.End();
        }
コード例 #13
0
 void Start()
 {
     ownerAmmo = GetComponentInParent <AmmoComponent>();
 }