Beispiel #1
0
 protected override void OnInitialize()
 {
     isEquiped     = false;
     weaponTrans   = Actor.GetComponent <Transform2>();
     body          = Actor.GetComponent <Rigidbody>();
     drawComponent = Actor.GetComponent <DrawTextureRegionComponent>();
 }
Beispiel #2
0
        /// <summary>
        /// Creates all components for a bullet without the Bullet component.
        /// </summary>
        /// <param name="netId">The id of the NetSyncComponent to which the Bullet should be added to.</param>
        /// <returns>A reference to the Actor.</returns>
        public static Actor CreatePreparedBullet(byte netId)
        {
            Actor bullet = NetManager.Instance.GetNetSyncComponent(netId).Actor;

            bullet.AddComponent <Transform2>();

            Rigidbody body = bullet.AddComponent <Rigidbody>();

            TextureRegion tex = Instance.bulletTex;
            DrawTextureRegionComponent drawTexture = bullet.AddComponent <DrawTextureRegionComponent>();

            drawTexture.region = tex;

            body.Set(width: tex.sourceRectangle.Width, height: tex.sourceRectangle.Height, collisionLayer: GameManager.physicsBulletLayer, isStatic: false, isSquare: true, isTrigger: false, ignoreGravity: true);

            return(bullet);
        }
Beispiel #3
0
        /// <summary>
        /// Creates all components for a weapon.
        /// </summary>
        /// <param name="netId">The id of the NetSyncComponent to which the weapon should be added to.</param>
        /// <param name="weaponId">The id of the weapon that should be created.</param>
        /// <returns>A reference to the weapon.</returns>
        public static Weapon CreateWeapon(byte netId, byte weaponId)
        {
            Actor weaponActor = NetManager.Instance.GetNetSyncComponent(netId).Actor;

            Transform2 weaponTrans = weaponActor.AddComponent <Transform2>();
            Rigidbody  body        = weaponActor.AddComponent <Rigidbody>();
            DrawTextureRegionComponent drawComponent = weaponActor.AddComponent <DrawTextureRegionComponent>();
            Weapon weapon = (Weapon)weaponActor.AddComponent(GameManager.GunIDForType[weaponId]);

            TextureRegion tex = Instance.gunRegions.Get(weapon.XIndexInTilesheet, weapon.YIndexInTilesheet);

            drawComponent.region = tex;

            body.Set(width: tex.sourceRectangle.Width, height: tex.sourceRectangle.Height, collisionLayer: 2, isStatic: false, isSquare: true, isTrigger: false);

            return(weapon);
        }
Beispiel #4
0
        public void OnObjectLoaded(List <TiledMapComponent> allMapComponents, TmxObject loadedObject)
        {
            if (loadedObject.Type.Equals("boxSpawn", StringComparison.CurrentCultureIgnoreCase) == false)
            {
                return;
            }

            Actor      actor = stage.CreateActor(2);
            Transform2 trans = actor.AddComponent <ScaledTransform2>();

            trans.LocalPosition = new Vector2((float)loadedObject.X, (float)loadedObject.Y);
            Rigidbody body = actor.AddComponent <Rigidbody>();

            body.Set(width: textureRegion.sourceRectangle.Width, height: textureRegion.sourceRectangle.Height, isStatic: false, isSquare: true, isTrigger: false);
            DrawTextureRegionComponent drawTexture = actor.AddComponent <DrawTextureRegionComponent>();

            drawTexture.region = textureRegion;
        }
Beispiel #5
0
        public void OnObjectLoaded(List <TiledMapComponent> allMapComponents, TmxObject loadedObject)
        {
            if (loadedObject.Type.Equals("gunSpawn", StringComparison.CurrentCultureIgnoreCase) == false)
            {
                return;
            }

            Actor      actor = stage.CreateActor(2);
            Transform2 trans = actor.AddComponent <ScaledTransform2>();

            trans.LocalPosition = new Vector2((float)loadedObject.X, (float)loadedObject.Y);
            Rigidbody body = actor.AddComponent <Rigidbody>();

            TextureRegion textureRegion = regions[random.Next(regions.Length - 1)]; // last one is empty

            body.Set(width: textureRegion.sourceRectangle.Width, height: textureRegion.sourceRectangle.Height, collisionLayer: 2, isStatic: false, isSquare: true, isTrigger: false);

            DrawTextureRegionComponent drawTexture = actor.AddComponent <DrawTextureRegionComponent>();

            drawTexture.region = textureRegion;

            DefaultRifle pistol = actor.AddComponent <DefaultRifle>();
        }