Exemplo n.º 1
0
        protected Entity(WorldProxy proxy, Sprite sprite, Vector2 position, float rotation, float size, bool isRectangle = false)
        {
            Size = size;
            WorldProxy = proxy;
            CurrentSprite = sprite;

            //Creating body with specified shape (round or square)
            Body = isRectangle
                ? BodyFactory.CreateRectangle(WorldProxy.World, ConvertUnits.ToSimUnits(CurrentSprite.ObjectSize * size),
                    ConvertUnits.ToSimUnits(CurrentSprite.ObjectSize * size), 5f, position)
                : BodyFactory.CreateCircle(WorldProxy.World,
                    ConvertUnits.ToSimUnits(Math.Min(CurrentSprite.ObjectSize, CurrentSprite.ObjectSize) * size),
                    1.5f, position);

            Body.BodyType = BodyType.Dynamic;
            Body.Rotation = rotation;
            Body.Friction = 0.0f;
            Body.Restitution = 0.2f;
            Body.LinearDamping = 0.2f;
            Body.AngularDamping = 0.2f;
            Body.CollisionCategories = Category.All;
            Body.CollidesWith = Category.All;
            Body.LocalCenter = new Vector2(CurrentSprite.ObjectSize/2);
        }
Exemplo n.º 2
0
        public Creature(WorldProxy proxy, Sprite sprite, Sprite attackSprite, Vector2 position, float rotation, float size, int generation = 0)
            : base(proxy, sprite, position, rotation, size)
        {
            Body.UserData = "creature";
            _generation = generation;
            _normalSprite = sprite;
            _attackSprite = attackSprite;

            //Most of parameters are based on creature size
            Health = MaxHealth = size*100f;
            _maxSpeed = GameSettings.CreatureMovingSpeed/size;
            _maxRotatingSpeed = GameSettings.CreatureRotatingSpeed/size;
            _breedingEnergy = GameSettings.CreatureBreedingEnergy*size;
            _maxSmellDistance = ConvertUnits.ToSimUnits(CurrentSprite.ObjectSize*
                                                         size*GameSettings.CreatureSniffRange);

            //Initizating the network layer
            _neuralNetwork = new RecurrentNetwork(GameSettings.NetworkInputs, GameSettings.NetworkOutputs,
                GameSettings.NetworkHiddenLayers, GameSettings.NetworkHiddenNeurons);
            _neuralNetwork.Layers[1 + GameSettings.NetworkHiddenLayers].RecurrentLayer = null;
            _neuralNetwork.Layers[2 + GameSettings.NetworkHiddenLayers].OutputLayer = _neuralNetwork.Layers[GameSettings.NetworkHiddenLayers];
            _neuralNetwork.Layers[GameSettings.NetworkHiddenLayers].RecurrentLayer = _neuralNetwork.Layers[2 + GameSettings.NetworkHiddenLayers];
            _neuralNetwork.Initialize(GameSettings.NetworkInitMinValue, GameSettings.NetworkInitMaxValue);
            _neuralNetwork.LearningRate = NetworkUtils.RandomSpread(GameSettings.NetworkLearningRate, GameSettings.NetworkRandomSpread);
            _networkThreshold = Utils.RandomSpread(GameSettings.NetworkThreshold, GameSettings.NetworkRandomSpread);

            Body.Rotation = 0;

            //Creating a claws
            _claws = FixtureFactory.AttachCircle(
                ConvertUnits.ToSimUnits(CurrentSprite.ObjectSize*
                                        size*GameSettings.ClawsSize), 1f, Body,
                ConvertUnits.ToSimUnits(new Vector2(CurrentSprite.ObjectSize * size * (1 - GameSettings.ClawsSize/4), 0)), "creature");
            _claws.CollidesWith = Category.All;
            _claws.OnCollision = BodyOnOnCollision;
            Body.Rotation = rotation;

            for(var i=0; i < GameSettings.NetworkOutputs; i++)
                _actions.Add((CreatureActions)i, false);
        }
Exemplo n.º 3
0
 public Food(WorldProxy proxy, Sprite sprite, Vector2 position, float rotation, float size = 1f)
     : base(proxy, sprite, position, rotation, size)
 {
     Body.UserData = "food";
 }
Exemplo n.º 4
0
 //The simpliest object in game.
 //They do nothing, but they are visible and pushable.
 public Crate(WorldProxy proxy, Sprite sprite, Vector2 position, float rotation, float size)
     : base(proxy, sprite, position, rotation, size, true)
 {
     Body.UserData = "crate";
 }
Exemplo n.º 5
0
 public EntityFactory(SpriteFactory spriteFactory, WorldManager worldManager)
 {
     //Sprite factory is using for creating entities' own sprites
     _spriteFactory = spriteFactory;
     _worldProxy = new WorldProxy(worldManager);
 }