Esempio n. 1
0
    public static void SetPriceTag(Vector3 pos, Building building, EnergyComponent e)
    {
        if (!CityManager.gamePlaying)
        {
            return;
        }
        Vector3 UIpos = pos;

        if (Input.mousePosition.x > 790)
        {
            UIpos.x -= 100;
        }
        if (Input.mousePosition.y < 100)
        {
            UIpos.y += 50;
        }
        self.transform.position = self.baseLoc = UIpos;
        self.num              = building.price;
        self.title.text       = building.buildingName;
        self.titleShadow.text = building.buildingName;
        self.gameObject.SetActive(true);
        self.current = building;
        self.owned   = building.owned;
        SetProperty(CityManager.Property.HEALTH, e.Health);
        SetProperty(CityManager.Property.HAPPINESS, e.Happiness);
        SetProperty(CityManager.Property.ECONOMY, e.Economy);
    }
Esempio n. 2
0
        public void Update(GameTime gameTime)
        {
            ComponentManager cm = ComponentManager.GetInstance();

            foreach (var entity in cm.GetComponentsOfType <SkillComponent>())
            {
                CooldownComponent cd             = cm.GetComponentForEntity <CooldownComponent>(entity.Key);
                SkillComponent    skillComponent = (SkillComponent)entity.Value;
                foreach (int entityUser in skillComponent.UsingEntities)
                {
                    if (cm.HasEntityComponent <EnergyComponent>(entityUser))
                    {
                        EnergyComponent energyComponent = cm.GetComponentForEntity <EnergyComponent>(entityUser);

                        if (skillComponent.EnergyCost < energyComponent.Current && cd.CooldownTimer <= 0)
                        {
                            skillComponent.Use(entityUser, 0);
                            energyComponent.Current -= skillComponent.EnergyCost;
                            cd.CooldownTimer         = cd.Cooldown;
                        }
                    }
                }
                skillComponent.UsingEntities.Clear();
            }
        }
Esempio n. 3
0
 private void PreloadUI()
 {
     windmillButton = windmillComponent.GetComponent <Button>();
     solarButton    = solarComponent.GetComponent <Button>();
     nuclearButton  = nuclearComponent.GetComponent <Button>();
     windmill       = windmillButton.GetComponent <EnergyComponent>();
     solar          = solarButton.GetComponent <EnergyComponent>();
     nuclear        = nuclearButton.GetComponent <EnergyComponent>();
 }
Esempio n. 4
0
        public void Update(GameTime gameTime)
        {
            ComponentManager cm = ComponentManager.GetInstance();

            foreach (var entity in cm.GetComponentsOfType <EnergyComponent>())
            {
                EnergyComponent es = (EnergyComponent)entity.Value;

                if (es.Current < es.Max)
                {
                    es.Current += (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
            }
        }
Esempio n. 5
0
        protected override void OnUpdate()
        {
            for (int i = 0; i < EnergyEntities.Length; i++)
            {
                EnergyComponent energy = EnergyEntities.EnergyComponents[i];

                energy.energy = Mathf.Clamp(energy.energy, 0, energy.maxEnergy);

                if (energy.regenEnabled)
                {
                    energy.energy += energy.regenRate * Time.deltaTime;
                }
            }
        }
Esempio n. 6
0
 public bool ActivateWallJump()
 {
     if (energyComponent == null)
     {
         energyComponent = GetComponentInParent <EnergyComponent>();
     }
     if (energyComponent.SpendEnergy(ActivationCost))
     {
         this.enabled = true;
         movementComponent.CanWallStick = true;
         return(true);
     }
     return(false);
 }
Esempio n. 7
0
        public static Entity GetFoodPellet(Color color)
        {
            float radius = 10f;

            var foodEntity = new Entity("food");

            var transform = new TransformComponent(foodEntity)
            {
                LocalPosition = Vector2.Zero,
                LocalRotation = new Rotation(0),
                LocalDepth    = 0.09f,
                Scale         = new Vector2(1, 1)
            };

            var graphics = new GraphicsComponent(foodEntity)
            {
                TexturePath = TextureAtlas.SoupPath,
                Dimensions  = new Point((int)(radius * 2), (int)(radius * 2)),
                Color       = color
            };

            var colourComp = new VisibleColourComponent(foodEntity)
            {
                RealR = 0.9f,
                RealB = 0.05f,
                RealG = 0.05f,
            };

            var energy = new EnergyComponent(foodEntity)
            {
                Energy = 3
            };

            var edible = new EdibleComponent(foodEntity)
            {
            };


            var collider = new CircleColliderComponent(foodEntity)
            {
                Radius = radius,
            };

            foodEntity.AddComponents(transform, graphics, energy, edible, collider, colourComp);

            return(foodEntity);
        }
Esempio n. 8
0
        //Add Intellect
        private void UpdateEntityIntellect(int entity)
        {
            ComponentManager cm = ComponentManager.GetInstance();

            if (cm.HasEntityComponent <EnergyComponent>(entity))
            {
                StatsComponent  statComp   = cm.GetComponentForEntity <StatsComponent>(entity);
                EnergyComponent energyComp = cm.GetComponentForEntity <EnergyComponent>(entity);
                energyComp.Max = energyComp.Max + (2 * statComp.AddInt);

                for (int i = 0; i <= statComp.AddInt - 1; i++)
                {
                    statComp.StatHistory += "int";
                }

                statComp.Intellect += statComp.AddInt;
                statComp.AddInt     = 0;
            }
        }
Esempio n. 9
0
        public void Render(RenderHelper rh)
        {
            GraphicsDevice   gd = rh.graphicsDevice;
            ComponentManager cm = ComponentManager.GetInstance();

            foreach (var entity in cm.GetComponentsOfType <PlayerComponent>())
            {
                HealthComponent healthComponent = cm.GetComponentForEntity <HealthComponent>(entity.Key);
                EnergyComponent energyComponent = cm.GetComponentForEntity <EnergyComponent>(entity.Key);

                if (energyComponent != null && healthComponent != null && healthComponent.IsAlive == true)
                {
                    float     currEnergy      = energyComponent.Current;
                    Rectangle energyRectangle = new Rectangle();
                    int       playNum         = cm.GetComponentForEntity <PlayerComponent>(entity.Key).Number;
                    float     scaledEnergy    = (float)currEnergy / energyComponent.Max * 100f;
                    //check if its player 1 entity
                    if (playNum == 1)
                    {
                        energyRectangle = new Rectangle(
                            gd.Viewport.TitleSafeArea.Left + 5,
                            gd.Viewport.TitleSafeArea.Top + 28,
                            (int)scaledEnergy,
                            12
                            );
                    }
                    //check if its player 2 entity - FIXXXXAAA
                    else if (playNum == 2)
                    {
                        energyRectangle = new Rectangle(
                            gd.Viewport.TitleSafeArea.Right - 105 + 100 - (int)scaledEnergy,
                            gd.Viewport.TitleSafeArea.Top + 28,
                            (int)scaledEnergy,
                            12
                            );
                    }
                    rh.Draw(energyTexture, energyRectangle, Color.White, RenderLayer.GUI1);
                }
            }
        }
Esempio n. 10
0
 public void Build(GameObject obj, EnergyComponent e)
 {
     building = obj;
     energy   = e;
 }
Esempio n. 11
0
 // Start is called before the first frame update
 void Start()
 {
     energyComponent = FindObjectOfType <EnergyComponent>();
 }
Esempio n. 12
0
        private void LoadEntities()
        {
            throw new NotImplementedException();
            int entitesCount     = _savedComponents.Positions.Length;
            int?firstEntityIndex = null;

            _context.ReplacePlayerEntity(_savedComponents.PlayerEntityId);
            for (int i = 0; i < entitesCount; i++)
            {
                GameEntity entity = _context.CreateEntity();
                if (!firstEntityIndex.HasValue)
                {
                    firstEntityIndex = entity.creationIndex;
                }
                int currentEntityIndex = entity.creationIndex;
                int componentIndex     = currentEntityIndex - firstEntityIndex.Value;

                IdComponent savedId = _savedComponents.Ids[componentIndex];
                entity.ReplaceId(savedId.Id);

                bool[] componentPresence = _savedComponents.EntityToHasComponent[savedId.Id];

                PositionComponent savedPosition = _savedComponents.Positions[componentIndex];
                if (componentPresence[GameComponentsLookup.Position])
                {
                    entity.AddPosition(savedPosition.Position);
                    entity.AddPositionAfterLastTurn(default(Position));
                }

                VisionComponent savedVision = _savedComponents.Visions[componentIndex];
                if (componentPresence[GameComponentsLookup.Vision])
                {
                    entity.AddVision(savedVision.VisionRange, savedVision.PerceptionRange,
                                     savedVision.EntitiesNoticed ?? new HashSet <Guid>());
                }

                RecipeeComponent savedRecipee = _savedComponents.Recipees[componentIndex];
                if (componentPresence[GameComponentsLookup.Recipee])
                {
                    entity.AddRecipee(savedRecipee.RecipeeName);
                }

                EnergyComponent savedEnergy = _savedComponents.Energies[componentIndex];
                if (componentPresence[GameComponentsLookup.Energy])
                {
                    entity.AddEnergy(savedEnergy.EnergyGainPerSegment, savedEnergy.Energy);
                }

                IntegrityComponent savedIntegrity = _savedComponents.Integrities[componentIndex];
                if (componentPresence[GameComponentsLookup.Integrity])
                {
                    entity.AddIntegrity(savedIntegrity.Integrity, savedIntegrity.MaxIntegrity);
                }

                SkillsComponent savedSkill = _savedComponents.Skills[componentIndex];
                if (componentPresence[GameComponentsLookup.Skills])
                {
                    entity.AddSkills(savedSkill.Skills);
                }

                StomachComponent savedStomach = _savedComponents.Stomachs[componentIndex];
                if (componentPresence[GameComponentsLookup.Stomach])
                {
                    entity.AddStomach(savedStomach.Satiation, savedStomach.MaxSatiation);
                }

                TeamComponent savedTeam = _savedComponents.Teams[componentIndex];
                if (componentPresence[GameComponentsLookup.Team])
                {
                    entity.AddTeam(savedTeam.Team);
                }

                LooksComponent savedLooks = _savedComponents.Looks[componentIndex];
                if (componentPresence[GameComponentsLookup.Looks])
                {
                    entity.AddLooks(savedLooks.BodySprite);
                }

                EdibleComponent savedEdible = _savedComponents.Edibles[componentIndex];
                if (componentPresence[GameComponentsLookup.Edible])
                {
                    entity.AddEdible(savedEdible.Satiety);
                }

                if (componentPresence[GameComponentsLookup.BlockingPosition])
                {
                    entity.isBlockingPosition = true;
                }

                entity.isFinishedTurn = true;
                if (_context.playerEntity.Id == entity.id.Id)
                {
                    entity.isPlayerControlled = true;
                }
            }
        }
Esempio n. 13
0
 // Start is called before the first frame update
 void Start()
 {
     wallLayerMask   = LayerMask.GetMask(new string[] { "Wall" });
     energyComponent = GetComponent <EnergyComponent>();
 }
Esempio n. 14
0
        //Update stats according to the history (if player died)
        private void UpdateEntityStatsFromHistory(int entity)
        {
            ComponentManager cm      = ComponentManager.GetInstance();
            StatsComponent   comp    = cm.GetComponentForEntity <StatsComponent>(entity);
            LevelComponent   lvlComp = cm.GetComponentForEntity <LevelComponent>(entity);

            while (comp.RemoveStats > 0)
            {
                if (lvlComp.CurrentLevel <= 0)
                {
                    break;
                }

                if (comp.SpendableStats > 0)
                {
                    comp.SpendableStats -= 1;
                    comp.RemoveStats    -= 1;
                }
                else
                {
                    if (comp.StatHistory.Length >= 3)
                    {
                        int    start = comp.StatHistory.Length - 3;
                        string stat  = comp.StatHistory.Substring(start);
                        switch (stat)
                        {
                        case "str":
                            if (cm.HasEntityComponent <AttackComponent>(entity) && cm.HasEntityComponent <HealthComponent>(entity))
                            {
                                AttackComponent attackComp = cm.GetComponentForEntity <AttackComponent>(entity);
                                HealthComponent healthComp = cm.GetComponentForEntity <HealthComponent>(entity);
                                attackComp.Damage  = attackComp.Damage - 2;
                                healthComp.Max     = healthComp.Max - 1;
                                healthComp.Current = healthComp.Current - 1;
                                comp.Strength     -= 1;
                            }
                            break;

                        case "agi":
                            if (cm.HasEntityComponent <MoveComponent>(entity) && cm.HasEntityComponent <AttackComponent>(entity))
                            {
                                MoveComponent   moveComp   = cm.GetComponentForEntity <MoveComponent>(entity);
                                AttackComponent attackComp = cm.GetComponentForEntity <AttackComponent>(entity);
                                attackComp.RateOfFire = attackComp.RateOfFire - 0.05f;
                                moveComp.Speed        = moveComp.Speed - 0.03f;
                                comp.Agility         -= 1;
                            }
                            break;

                        case "sta":
                            if (cm.HasEntityComponent <HealthComponent>(entity))
                            {
                                HealthComponent healthComp = cm.GetComponentForEntity <HealthComponent>(entity);
                                healthComp.Max     = healthComp.Max - 2;
                                healthComp.Current = healthComp.Current - 2;
                                comp.Stamina      -= 1;
                            }
                            break;

                        case "int":
                            if (cm.HasEntityComponent <EnergyComponent>(entity))
                            {
                                EnergyComponent energyComp = cm.GetComponentForEntity <EnergyComponent>(entity);
                                energyComp.Max  = energyComp.Max - 2;
                                comp.Intellect -= 1;
                            }
                            break;
                        }
                        comp.StatHistory  = comp.StatHistory.Substring(0, comp.StatHistory.Length - 3);
                        comp.RemoveStats -= 1;
                    }
                }
            }
        }
Esempio n. 15
0
 // Start is called before the first frame update
 void Start()
 {
     energyComponent = GetComponentInParent <EnergyComponent>();
 }
Esempio n. 16
0
        public static Entity GetCritter(Color color)
        {
            float radius = 10f;

            var critter = new Entity();

            var pos = new Vector2(0, 0);

            var transform = new TransformComponent(critter)
            {
                LocalPosition = pos,
                LocalRotation = new Rotation(MathHelper.PiOver4),
                LocalDepth    = 0.1f,
                Scale         = new Vector2(1, 1)
            };

            var graphics = new GraphicsComponent(critter)
            {
                TexturePath = TextureAtlas.CirclePath,
                Dimensions  = new Point((int)(radius * 2), (int)(radius * 2)),
                Color       = color
            };


            var velocity = new VelocityComponent(critter)
            {
                RotationalVelocity = 0,
                Velocity           = Vector2.Zero
            };

            var circleCollider = new CircleColliderComponent(critter)
            {
                Radius = radius
            };


            var rigidbody = new RigidBodyComponent(critter)
            {
                Mass        = 0.05f,
                Restitution = 0.1f
            };

            var drag = new DragComponent(critter)
            {
                MovementDragCoefficient = 0.1f,
                RotationDragCoefficient = 10f
            };

            var movementControl = new MovementControlComponent(critter)
            {
                MaxMovementForceNewtons = 10.0f,
                MaxRotationForceNewtons = 10.0f,
                MovementMode            = MovementMode.TwoWheels,
            };

            var colour = new VisibleColourComponent(critter)
            {
            };

            var energy = new EnergyComponent(critter)
            {
                Energy = 4f
            };

            var reproduction = new ReproductionComponent(critter)
            {
                Efficency = 0.7f,
                ReproductionEnergyCost = 8f,
                Reproduce               = 0,
                ReproductionThreshold   = 0.5f,
                RequiredRemainingEnergy = 1f,
                ChildDefinitionId       = "Soupling"
            };

            var health = new HealthComponent(critter)
            {
                Health    = 100,
                MaxHealth = 100,
            };

            var age = new OldAgeComponent(critter)
            {
                MaxAge = 5 * 60
            };

            var brain = new BrainComponent(critter)
            {
                InputMap = new Dictionary <string, string>
                {
                    { "eye1R", "eye1.EyeComponent.ActivationR" },
                    { "eye1G", "eye1.EyeComponent.ActivationG" },
                    { "eye1B", "eye1.EyeComponent.ActivationB" },

                    { "eye2R", "eye2.EyeComponent.ActivationR" },
                    { "eye2G", "eye2.EyeComponent.ActivationG" },
                    { "eye2B", "eye2.EyeComponent.ActivationB" },

                    { "eye3R", "eye3.EyeComponent.ActivationR" },
                    { "eye3G", "eye3.EyeComponent.ActivationG" },
                    { "eye3B", "eye3.EyeComponent.ActivationB" },

                    { "eye4R", "eye4.EyeComponent.ActivationR" },
                    { "eye4G", "eye4.EyeComponent.ActivationG" },
                    { "eye4B", "eye4.EyeComponent.ActivationB" },

                    { "mouth", "mouth.MouthComponent.Eating" },
                    { "nosecos", "nose.NoseComponent.CosActivation" },
                    { "nosesin", "nose.NoseComponent.SinActivation" },
                    { "health", "HealthComponent.HealthPercent" },
                    { "myRed", "VisibleColourComponent.RealR" },
                    { "myGreen", "VisibleColourComponent.RealG" },
                    { "myBlue", "VisibleColourComponent.RealB" },
                    { "Random", "Random" },
                    { "Bias", "Bias" },
                },
                //OutputMap = new Dictionary<string, string>
                //    {
                //        {"forwardback", "MovementControlComponent.WishForceForward" },
                //        {"rotation", "MovementControlComponent.WishRotForce" },
                //        {"reproduce", "ReproductionComponent.Reproduce" },
                //        {"red", "VisibleColourComponent.R" },
                //        {"green", "VisibleColourComponent.G" },
                //        {"blue", "VisibleColourComponent.B" },
                //        {"attack", "weapon.WeaponComponent.Activation" }
                //    }
                OutputMap = new Dictionary <string, string>
                {
                    { "wheelLeft", "MovementControlComponent.WishWheelLeftForce" },
                    { "wheelRight", "MovementControlComponent.WishWheelRightForce" },
                    { "reproduce", "ReproductionComponent.Reproduce" },
                    { "red", "VisibleColourComponent.R" },
                    { "green", "VisibleColourComponent.G" },
                    { "blue", "VisibleColourComponent.B" },
                    { "attack", "weapon.WeaponComponent.Activation" }
                }
            };

            critter.AddComponents(transform, graphics, velocity, circleCollider, rigidbody, drag, movementControl, reproduction, colour, energy, health, age, brain);

            var eye1 = Eye.GetEye(Color.White, MathHelper.ToRadians(30));

            eye1.Tag = "eye1";
            critter.AddChild(eye1);

            var eye2 = Eye.GetEye(Color.White, MathHelper.ToRadians(-30));

            eye2.Tag = "eye2";
            critter.AddChild(eye2);

            var eye3 = Eye.GetEye(Color.White, MathHelper.ToRadians(90));

            eye3.Tag = "eye3";
            critter.AddChild(eye3);

            var eye4 = Eye.GetEye(Color.White, MathHelper.ToRadians(-90));

            eye4.Tag = "eye4";
            critter.AddChild(eye4);


            var mouth = Mouth.GetMouth(Color.White);

            critter.AddChild(mouth);
            mouth.GetComponent <TransformComponent>().LocalPosition = new Vector2(15, 0);

            var nose = Nose.GetNose(Color.White, 0, 10);

            nose.Tag = "nose";
            critter.AddChild(nose);

            var weapon = Weapon.GetWeapon(Color.White);

            weapon.Tag = "weapon";
            critter.AddChild(weapon);
            weapon.GetComponent <TransformComponent>().LocalPosition = new Vector2(30, 0);

            return(critter);
        }