コード例 #1
0
ファイル: MainGame.cs プロジェクト: DonkerNet/pong
        // Create all the components that should be used by this game
        private void CreateComponents()
        {
            _menuComponent = new MenuComponent(this);
            Components.Add(_menuComponent);

            _backgroundComponent = new BackgroundComponent(this);
            Components.Add(_backgroundComponent);

            _actorComponent = new ActorComponent(this);
            Components.Add(_actorComponent);

            _collisionComponent = new CollisionComponent(this);
            Components.Add(_collisionComponent);

            _scoreComponent = new ScoreComponent(this);
            Components.Add(_scoreComponent);

            _timeComponent = new TimeComponent(this);
            Components.Add(_timeComponent);

            _speedComponent = new SpeedComponent(this);
            Components.Add(_speedComponent);

            _statusComponent = new StatusComponent(this);
            Components.Add(_statusComponent);
        }
コード例 #2
0
        private float[] CalculatePath(Entity entity)
        {                                                            /// Will calculate how the entity will move
            float[]         entity_direction = new float[] { 0, 0 }; //Will decide which directions the entity will move
            DeltaComponent  entity_delta     = entity.Get <DeltaComponent>();
            StatusComponent entity_status    = entity.Get <StatusComponent>();

            /// Computes path for entity based on type of entity
            switch (entity_status.Type)
            {
            case (Game1.EntityType.Lightning):
                ComputeLightningDelta(entity);
                break;

            case (Game1.EntityType.Meteor):
                ComputeMeteorDelta(entity);
                break;

            case (Game1.EntityType.Fire):
                break;
            }

            entity_direction[(int)Delta_Direction.Horizontal] = entity_delta.XDelta;
            entity_direction[(int)Delta_Direction.Vertical]   = entity_delta.YDelta;

            return(entity_direction);
        }
コード例 #3
0
        public StatusComponent GetStatusComponent()
        {
            StatusComponent statusComponent = new StatusComponent();

            statusComponent.Type             = (string)comboBoxType.SelectedItem;
            statusComponent.Description      = textBoxDescription.Text;
            statusComponent.State            = radioButtonReady.Checked ? StatusType.Ready : StatusType.NotReady;
            statusComponent.StateDescription = textBoxStateText.Text;

            return(statusComponent);
        }
コード例 #4
0
            public void OnRemove(string name)
            {
                int index = _statusComponents.FindIndex(x => x.transform.name == name);

                if (index != -1)
                {
                    StatusComponent statusEffectComponent = _statusComponents[index];
                    _statusComponents.RemoveAt(index);
                    statusEffectComponent.Destroy();
                }
            }
コード例 #5
0
    public override void OnStartEvent(GameObject src, OnStartData data)
    {
        StatusComponent status = src.AddComponent <StatusComponent>() as StatusComponent;

        status.SetMaxHealth(data.m_StatusComponentData.m_Health);
        status.Heal(data.m_StatusComponentData.m_Health, GameplayStatics.DamageType.Null);
        status.m_CanUseIFrames       = data.m_StatusComponentData.m_Health > 0;
        status.m_IFrameTime          = data.m_StatusComponentData.m_IFrameTime;
        status.m_DamagePopupOverride = data.m_StatusComponentData.m_OverrideDmgType;
        status.AddOnDeath(() => Destroy(src));
    }
コード例 #6
0
            public void OnAdd(Status status)
            {
                Debug.Log("Adding: " + status.StatusEffectData.Name);
                GameObject statusEffectComponentObj = Instantiate(statusComponentPrefab, transform);

                statusEffectComponentObj.transform.SetAsLastSibling();
                statusEffectComponentObj.transform.name = status.StatusEffectData.Name;

                StatusComponent statusEffectComponent = statusEffectComponentObj.GetComponent <StatusComponent>();

                statusEffectComponent.Initialize(status, this);
                _statusComponents.Add(statusEffectComponent);
            }
コード例 #7
0
        private void UpdateDestructFrame(int entityID)
        {
            Entity          placeholder = Game1._world.GetEntity(entityID);
            StatusComponent eStatus     = placeholder.Get <StatusComponent>();

            if (eStatus.ElapsedDestructAnimFrames <= 5)
            {
                eStatus.ElapsedDestructAnimFrames++;
            }
            else
            {
                eStatus.IsReadyForCleanup = true;
            }
        }
コード例 #8
0
    public static bool ApplyDamage(GameObject src, float amount, DamageType type = DamageType.Normal)
    {
        StatusComponent status = src.GetComponent <StatusComponent>();

        if (status)
        {
            status.TakeDamage(amount, type);
            return(true);
        }
        else
        {
            // Debug.LogWarning("Source GameObj has no Status Component. Can't apply damage to him");
            return(false);
        }
    }
コード例 #9
0
    public override void PickupItem(Collider2D target, GameObject src)
    {
        GameObject obj = target.gameObject;

        if (obj.CompareTag("Player")) // Check if it was the player that tried to pic the item
        {
            //get player status component
            StatusComponent comp = obj.GetComponent <StatusComponent>();
            comp.Heal(m_HealAmount); // heal the player
            Debug.Log("Current Health = " + comp.GetCurrentHealth());
            if (m_OnPickup != null)
            {
                m_OnPickup.Invoke(target, obj); // call auxiliary m_OnPickup function if there's one
            }
            DestroyItem();                      // destroy the potion, since it was used
        }
    }
コード例 #10
0
        public override void Update(GameTime gameTime)
        {
            foreach (int eID in ActiveEntities)
            {
                Entity placeholder = Game1._world.GetEntity(eID);
                if (placeholder == null)
                {
                    return;
                }
                StatusComponent eStatus = placeholder.Get <StatusComponent>();

                if (eStatus.IsDestroyed && eStatus.Type != Game1.EntityType.Fire)
                {
                    // call the destruction animation
                    SpriteComponent newSprite = new SpriteComponent(Game1.SpriteDict["explosion"], 1);
                    placeholder.Detach <SpriteComponent>();
                    placeholder.Attach <SpriteComponent>(newSprite);
                    UpdateDestructFrame(eID);
                }
                else if (eStatus.IsDestroyed && eStatus.Type == Game1.EntityType.Fire)
                {
                    // call the destruction animation
                    SpriteComponent newSprite = new SpriteComponent(Game1.SpriteDict["ashes"], 1);
                    placeholder.Detach <SpriteComponent>();
                    placeholder.Attach <SpriteComponent>(newSprite);
                    UpdateDestructFrame(eID);
                }
                else if (eStatus.IsGazed && eStatus.ElapsedAnimFrames == 5)    // different animations when gazed
                {
                    eStatus.ElapsedAnimFrames = 0;
                    DwellUpdateSprite(eID);
                }
                else if (eStatus.ElapsedAnimFrames < 5)    // do not change anim frame
                {
                    eStatus.ElapsedAnimFrames++;
                }
                else if (!eStatus.IsGazed && eStatus.ElapsedAnimFrames == 5)
                {
                    eStatus.ElapsedAnimFrames = 0;
                    UpdateSprite(eID);
                    // set new sprite
                }
            }
        }
コード例 #11
0
 public override void Update(GameTime gameTime)
 {
     foreach (int entityID in ActiveEntities)
     {
         Entity          placeholder    = Game1._world.GetEntity(entityID);
         StatusComponent capturedStatus = placeholder.Get <StatusComponent>(); // get the status component of the entity
         if (capturedStatus.Type == Game1.EntityType.Fire)                     // if the entity is a Lightining Disaster
         {
             if (capturedStatus.ElapsedBurnFrames >= capturedStatus.FireBurnInterval)
             {
                 capturedStatus.IsDestroyed = true;
             }
             else
             {
                 capturedStatus.ElapsedBurnFrames++;
             }
         }
     }
 }
コード例 #12
0
    // Update is called once per frame
    private void Start()
    {
        if (!m_StatusComponent)
        {
            m_StatusComponent = GetComponent <StatusComponent>();
            if (!m_StatusComponent)
            {
                Debug.LogWarning("Actor StatusComponent wasn't successfully set or found. Actor won't be able to benefit from this component");
            }

            UpdateHealthBar(0); // Update Canvas HealthBar
        }
        if (!m_SpellComponent)
        {
            m_SpellComponent = GetComponent <SpellCastingComponent>();
            if (!m_SpellComponent)
            {
                Debug.LogWarning("Actor SpellCastingComponent wasn't successfully set or found. Actor won't be able to benefit from this component");
            }
        }
        UpdateSpellIconAndBorders();
    }
コード例 #13
0
    public override void OnTick(GameObject obj)
    {
        if (m_OnHitEffect)
        {
            GameObject fx = MonoBehaviour.Instantiate(m_OnHitEffect);
            fx.transform.position = obj.transform.position + new Vector3(0, 0, -15);

            Vector3      pos      = fx.transform.position;
            Collider2D[] overlaps = Physics2D.OverlapCircleAll(pos, 2.0f);

            foreach (Collider2D overlap in overlaps)
            {
                if (overlap.gameObject.CompareTag("Enemy"))
                {
                    StatusComponent st = overlap.GetComponent <StatusComponent>();
                    if (st)
                    {
                        st.TakeDamage(m_Damage);
                    }
                }
            }
        }
    }
コード例 #14
0
 private void Awake()
 {
     _movementComponent = GetComponent <MovementComponent>();
     _statusComponent   = GetComponent <StatusComponent>();
 }
コード例 #15
0
 public StatusComponent(StatusComponent other) : this(other.stacks)
 {
 }
コード例 #16
0
ファイル: Rovio.cs プロジェクト: pet1330/RovioAssignment
 /// <summary>
 /// The constructor.
 /// </summary>
 public Other(Robot _robot)
     : base(_robot)
 {
     Status = new StatusComponent(_robot);
 }
コード例 #17
0
    void Start()
    {
        if (!m_MovementComponent)
        {
            m_MovementComponent = GetComponent <MovementComponent>();
            if (!m_MovementComponent)
            {
                Debug.LogWarning("Actor MovementComponent wasn't successfully set or found. Actor won't be able to benefit from this component");
            }
            else
            {
                m_MovementComponent.m_OnFlip = new UnityEngine.Events.UnityEvent();
                m_MovementComponent.m_OnFlip.AddListener(FlipHand);
            }
        }

        if (!m_StatusComponent)
        {
            m_StatusComponent = GetComponent <StatusComponent>();
            if (!m_StatusComponent)
            {
                Debug.LogWarning("Actor StatusComponent wasn't successfully set or found. Actor won't be able to benefit from this component");
            }
            else
            {
                m_StatusComponent.AddOnDeath(PlayerDeath);
                m_StatusComponent.AddOnTakeDamage(MakePlayerInvulnerable);
            }
        }

        if (!m_SpellComponent)
        {
            m_SpellComponent = GetComponent <SpellCastingComponent>();
            if (!m_SpellComponent)
            {
                Debug.LogWarning("Actor SpellCastingComponent wasn't successfully set or found. Actor won't be able to benefit from this component");
            }
        }

        if (!m_WeaponComponent)
        {
            m_WeaponComponent = GetComponent <WeaponComponent>();
            if (!m_WeaponComponent)
            {
                Debug.LogWarning("Actor WeaponComponent wasn't successfully set or found. Actor won't be able to benefit from this component");
            }
        }

        m_WeaponComponent.SetTargetingFunction(() =>
        {
            if (!target)
            {
                var vec3 = m_FirePoint.position - m_PlayerHand.transform.position;
                return(new Vector2(vec3.x, vec3.y));
            }
            else
            {
                return(target.transform.position - m_FirePoint.position);
            }
        });

        if (!m_EffectManager)
        {
            m_EffectManager = GetComponent <EffectManagerComponent>();
            if (!m_EffectManager)
            {
                Debug.LogWarning("Actor EffectManagerComponent wasn't successfully set or found. Actor won't be able to benefit from this component");
            }
        }
    }
コード例 #18
0
        private void UpdateSprite(int entityID)
        {
            Entity          placeholder = Game1._world.GetEntity(entityID);
            StatusComponent eStatus     = placeholder.Get <StatusComponent>();

            switch (eStatus.Type)
            {
            case Game1.EntityType.Meteor:
                PositionComponent pos = placeholder.Get <PositionComponent>();
                if (eStatus.CurrentAnimSprite == 1)
                {
                    eStatus.CurrentAnimSprite++;
                    SpriteComponent newSprite;
                    if (pos.XCoor <= (Game1.screenWidth * 0.5) && pos.YCoor <= (Game1.screenHeight * 0.5))      // SE meteor
                    {
                        newSprite = new SpriteComponent(Game1.SpriteDict["meteorSE_2"], 1);
                        placeholder.Detach <SpriteComponent>();
                        placeholder.Attach <SpriteComponent>(newSprite);
                    }
                    else if (pos.XCoor >= (Game1.screenWidth * 0.5) && pos.YCoor <= (Game1.screenHeight * 0.5))      // SW meteor
                    {
                        newSprite = new SpriteComponent(Game1.SpriteDict["meteorSW_2"], 1);
                        placeholder.Detach <SpriteComponent>();
                        placeholder.Attach <SpriteComponent>(newSprite);
                    }
                    else if (pos.XCoor <= (Game1.screenWidth * 0.5) && pos.YCoor >= (Game1.screenHeight * 0.5))      // NE meteor
                    {
                        newSprite = new SpriteComponent(Game1.SpriteDict["meteorNE_2"], 1);
                        placeholder.Detach <SpriteComponent>();
                        placeholder.Attach <SpriteComponent>(newSprite);
                    }
                    else if (pos.XCoor >= (Game1.screenWidth * 0.5) && pos.YCoor >= (Game1.screenHeight * 0.5))      // NW meteor
                    {
                        newSprite = new SpriteComponent(Game1.SpriteDict["meteorNW_2"], 1);
                        placeholder.Detach <SpriteComponent>();
                        placeholder.Attach <SpriteComponent>(newSprite);
                    }
                }
                else if (eStatus.CurrentAnimSprite == 2)
                {
                    eStatus.CurrentAnimSprite++;
                    SpriteComponent newSprite;
                    if (pos.XCoor <= (Game1.screenWidth * 0.5) && pos.YCoor <= (Game1.screenHeight * 0.5))      // SE meteor
                    {
                        newSprite = new SpriteComponent(Game1.SpriteDict["meteorSE_3"], 1);
                        placeholder.Detach <SpriteComponent>();
                        placeholder.Attach <SpriteComponent>(newSprite);
                    }
                    else if (pos.XCoor >= (Game1.screenWidth * 0.5) && pos.YCoor <= (Game1.screenHeight * 0.5))      // SW meteor
                    {
                        newSprite = new SpriteComponent(Game1.SpriteDict["meteorSW_3"], 1);
                        placeholder.Detach <SpriteComponent>();
                        placeholder.Attach <SpriteComponent>(newSprite);
                    }
                    else if (pos.XCoor <= (Game1.screenWidth * 0.5) && pos.YCoor >= (Game1.screenHeight * 0.5))      // NE meteor
                    {
                        newSprite = new SpriteComponent(Game1.SpriteDict["meteorNE_3"], 1);
                        placeholder.Detach <SpriteComponent>();
                        placeholder.Attach <SpriteComponent>(newSprite);
                    }
                    else if (pos.XCoor >= (Game1.screenWidth * 0.5) && pos.YCoor >= (Game1.screenHeight * 0.5))      // NW meteor
                    {
                        newSprite = new SpriteComponent(Game1.SpriteDict["meteorNW_3"], 1);
                        placeholder.Detach <SpriteComponent>();
                        placeholder.Attach <SpriteComponent>(newSprite);
                    }
                }
                else
                {
                    eStatus.CurrentAnimSprite = 1;
                    SpriteComponent newSprite;
                    if (pos.XCoor <= (Game1.screenWidth * 0.5) && pos.YCoor <= (Game1.screenHeight * 0.5))      // SE meteor
                    {
                        newSprite = new SpriteComponent(Game1.SpriteDict["meteorSE_1"], 1);
                        placeholder.Detach <SpriteComponent>();
                        placeholder.Attach <SpriteComponent>(newSprite);
                    }
                    else if (pos.XCoor >= (Game1.screenWidth * 0.5) && pos.YCoor <= (Game1.screenHeight * 0.5))      // SW meteor
                    {
                        newSprite = new SpriteComponent(Game1.SpriteDict["meteorSW_1"], 1);
                        placeholder.Detach <SpriteComponent>();
                        placeholder.Attach <SpriteComponent>(newSprite);
                    }
                    else if (pos.XCoor <= (Game1.screenWidth * 0.5) && pos.YCoor >= (Game1.screenHeight * 0.5))      // NE meteor
                    {
                        newSprite = new SpriteComponent(Game1.SpriteDict["meteorNE_1"], 1);
                        placeholder.Detach <SpriteComponent>();
                        placeholder.Attach <SpriteComponent>(newSprite);
                    }
                    else if (pos.XCoor >= (Game1.screenWidth * 0.5) && pos.YCoor >= (Game1.screenHeight * 0.5))      // NW meteor
                    {
                        newSprite = new SpriteComponent(Game1.SpriteDict["meteorNW_1"], 1);
                        placeholder.Detach <SpriteComponent>();
                        placeholder.Attach <SpriteComponent>(newSprite);
                    }
                }
                break;

            case Game1.EntityType.Lightning:
                if (eStatus.CurrentAnimSprite == 1)
                {
                    eStatus.CurrentAnimSprite++;
                    SpriteComponent newSprite;
                    newSprite = new SpriteComponent(Game1.SpriteDict["lightning_2"], 1);
                    placeholder.Detach <SpriteComponent>();
                    placeholder.Attach <SpriteComponent>(newSprite);
                }
                else if (eStatus.CurrentAnimSprite == 2)
                {
                    eStatus.CurrentAnimSprite++;
                    SpriteComponent newSprite;
                    newSprite = new SpriteComponent(Game1.SpriteDict["lightning_3"], 1);
                    placeholder.Detach <SpriteComponent>();
                    placeholder.Attach <SpriteComponent>(newSprite);
                }
                else
                {
                    eStatus.CurrentAnimSprite = 1;
                    SpriteComponent newSprite;
                    newSprite = new SpriteComponent(Game1.SpriteDict["lightning_1"], 1);
                    placeholder.Detach <SpriteComponent>();
                    placeholder.Attach <SpriteComponent>(newSprite);
                }
                break;

            case Game1.EntityType.Fire:
                if (eStatus.CurrentAnimSprite == 1)
                {
                    eStatus.CurrentAnimSprite++;
                    SpriteComponent newSprite;
                    newSprite = new SpriteComponent(Game1.SpriteDict["fire_2"], 1);
                    placeholder.Detach <SpriteComponent>();
                    placeholder.Attach <SpriteComponent>(newSprite);
                }
                else if (eStatus.CurrentAnimSprite == 2)
                {
                    eStatus.CurrentAnimSprite++;
                    SpriteComponent newSprite;
                    newSprite = new SpriteComponent(Game1.SpriteDict["fire_3"], 1);
                    placeholder.Detach <SpriteComponent>();
                    placeholder.Attach <SpriteComponent>(newSprite);
                }
                else
                {
                    eStatus.CurrentAnimSprite = 1;
                    SpriteComponent newSprite;
                    newSprite = new SpriteComponent(Game1.SpriteDict["fire_1"], 1);
                    placeholder.Detach <SpriteComponent>();
                    placeholder.Attach <SpriteComponent>(newSprite);
                }
                break;

            default:
                break;
            }
            return;
        }
コード例 #19
0
        private async void BuildLightningEntity(int newLightningID)
        {
            /// using newLightningID we can grab the correct entity in _world and call Attach<T>(T component) to attach our own custom components to the existing entity
            Entity placeHolder = Game1._world.GetEntity(newLightningID);

            /// Attach all the correct components to the entity
            // First give it a starting position - this is randomly selected from 4 pre-defined spawn points
            // Second, give it a delta which should be calculated based off of the initial position
            GodsOfCalamityBeta.ECSComponents.PositionComponent InitialPosition;

            int   spawnPoint = randomNumGen.Next(1, 5);
            float initX;
            float initY;
            float initAngle;

            switch (spawnPoint)
            {
            case 1:     // calculate starting position
                initX           = (float)0.25 * Game1.screenWidth;
                initY           = (float)0.5 * Game1.screenHeight;
                initAngle       = 0;
                InitialPosition = new PositionComponent(initX, initY, initAngle);
                placeHolder.Attach(InitialPosition);

                break;

            case 2:     // calculate starting position
                initX           = (float)0.5 * Game1.screenWidth;
                initY           = (float)0.25 * Game1.screenHeight;
                initAngle       = 0;
                InitialPosition = new PositionComponent(initX, initY, initAngle);
                placeHolder.Attach(InitialPosition);

                break;

            case 3:     // calculate starting position
                initX           = (float)0.75 * Game1.screenWidth;
                initY           = (float)0.5 * Game1.screenHeight;
                initAngle       = 0;
                InitialPosition = new PositionComponent(initX, initY, initAngle);
                placeHolder.Attach(InitialPosition);

                break;

            case 4:     // calculate starting position
                initX           = (float)0.5 * Game1.screenWidth;
                initY           = (float)0.75 * Game1.screenHeight;
                initAngle       = 0;
                InitialPosition = new PositionComponent(initX, initY, initAngle);
                placeHolder.Attach(InitialPosition);

                break;

            default:
                break;
            }

            /// Initializes Components
            SpriteComponent      new_sprite    = new SpriteComponent(Game1.SpriteDict["lightning"], 1);
            DeltaComponent       new_delta     = new DeltaComponent(0, 0, 0);
            StatusComponent      new_status    = new StatusComponent(false, Game1.EntityType.Lightning);
            CollisionBoxComponet new_collision = new CollisionBoxComponet(new_sprite.Sprite, placeHolder.Get <PositionComponent>());

            /// Attaches Components
            placeHolder.Attach(new_sprite);
            placeHolder.Attach(new_delta);
            placeHolder.Attach(new_status);
            placeHolder.Attach(new_collision);

            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                          () =>
            {
                Game1.myGamePage.CreateNewLightning(newLightningID);
            }
                                                                          );

            return;
        }
コード例 #20
0
        private void DwellUpdateSprite(int entityID)
        {
            Entity          placeholder = Game1._world.GetEntity(entityID);
            StatusComponent eStatus     = placeholder.Get <StatusComponent>();

            switch (eStatus.Type)
            {
            case Game1.EntityType.Meteor:
                break;

            case Game1.EntityType.Lightning:
                if (eStatus.CurrentAnimSprite == 1)
                {
                    eStatus.CurrentAnimSprite++;
                    SpriteComponent newSprite;
                    newSprite = new SpriteComponent(Game1.SpriteDict["lightning_dwell_2"], 1);
                    placeholder.Detach <SpriteComponent>();
                    placeholder.Attach <SpriteComponent>(newSprite);
                }
                else if (eStatus.CurrentAnimSprite == 2)
                {
                    eStatus.CurrentAnimSprite++;
                    SpriteComponent newSprite;
                    newSprite = new SpriteComponent(Game1.SpriteDict["lightning_dwell_3"], 1);
                    placeholder.Detach <SpriteComponent>();
                    placeholder.Attach <SpriteComponent>(newSprite);
                }
                else
                {
                    eStatus.CurrentAnimSprite = 1;
                    SpriteComponent newSprite;
                    newSprite = new SpriteComponent(Game1.SpriteDict["lightning_dwell_1"], 1);
                    placeholder.Detach <SpriteComponent>();
                    placeholder.Attach <SpriteComponent>(newSprite);
                }
                break;

            case Game1.EntityType.Fire:
                if (eStatus.CurrentAnimSprite == 1)
                {
                    eStatus.CurrentAnimSprite++;
                    SpriteComponent newSprite;
                    newSprite = new SpriteComponent(Game1.SpriteDict["fire_dwell_2"], 1);
                    placeholder.Detach <SpriteComponent>();
                    placeholder.Attach <SpriteComponent>(newSprite);
                }
                else if (eStatus.CurrentAnimSprite == 2)
                {
                    eStatus.CurrentAnimSprite++;
                    SpriteComponent newSprite;
                    newSprite = new SpriteComponent(Game1.SpriteDict["fire_dwell_3"], 1);
                    placeholder.Detach <SpriteComponent>();
                    placeholder.Attach <SpriteComponent>(newSprite);
                }
                else
                {
                    eStatus.CurrentAnimSprite = 1;
                    SpriteComponent newSprite;
                    newSprite = new SpriteComponent(Game1.SpriteDict["fire_dwell_1"], 1);
                    placeholder.Detach <SpriteComponent>();
                    placeholder.Attach <SpriteComponent>(newSprite);
                }
                break;

            default:
                break;
            }
            return;
        }