Exemplo n.º 1
0
        private void initCollision()
        {
            rigidBody = addComponent <FSRigidBody>()
                        .setBodyType(BodyType.Dynamic)
                        .setFixedRotation(true)
                        .setIsSleepingAllowed(false)
                        .setLinearDamping(0.8f)
                        .setMass(2f);

            collider = addComponent <FSCollisionCircle>();
            collider.setRadius(20)
            .setIsSensor(true);
            collider.setCollisionCategories(CollisionSetting.enemyCategory);
            collider.setCollidesWith(
                CollisionSetting.playerAttackCategory
                );

            addComponent <RigidBodyVelocityLimited>();


            colliderEntity = scene.createEntity("collision").setPosition(this.position);
            colliderEntity.addComponent <FSRigidBody>()
            .setBodyType(BodyType.Static);

            var shape = colliderEntity.addComponent <FSCollisionBox>()
                        .setSize(28, 28);

            shape.setCollisionCategories(CollisionSetting.wallCategory);
        }
Exemplo n.º 2
0
        public void Update()
        {
            //checks if client is still connected
            //CheckIfConnected();
            timeSpan += Time.DeltaTime;
            //Updates every 1/20 second
            if (timeSpan > 0.05)
            {
                if (CurrentLayer != null)
                {
                    HashSet <LoginManagerServer> characterlist = CurrentLayer.LayerLogins;

                    if (characterlist != null && characterlist.Count > 0 && loginManager != null)
                    {
                        CharacterPlayer tempc = loginManager.GetCharacter();

                        //sets the position of the entity's physical body as the physical position
                        FSRigidBody v = Core.Scene.FindEntity(tempc._name).GetComponent <FSRigidBody>();

                        tempc.physicalPosition = v.Transform.Position;

                        DataTemplate dataTemplate = new DataTemplate
                        {
                            RecieverCharacter = tempc,
                            OthersCharacters  = FillRecieverList(characterlist, tempc)
                        };
                        //makes the position relative to client's side of the map position
                        dataTemplate.RecieverCharacter.physicalPosition = dataTemplate.RecieverCharacter.physicalPosition - MapContainer.GetMapByName(CurrentLayer.MapName).Entity.Position;
                        string posString = Newtonsoft.Json.JsonConvert.SerializeObject(dataTemplate);

                        MessageManager.SendStringToUniqueID(Entity.Scene, posString, loginManager.GetUniqueID(), MessageType.GameUpdate);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void InitializeCollision()
        {
            rigidBody = addComponent <FSRigidBody>()
                        .setBodyType(BodyType.Dynamic)
                        .setLinearDamping(0.9f)
                        .setMass(2f)
                        .setFixedRotation(true)
                        .setIsSleepingAllowed(false)
                        .setIsBullet(true);


            Vector2[] points = new Vector2[4] {
                new Vector2(5 - 12, 17 - 18),
                new Vector2(17 - 12, 17 - 18),
                new Vector2(17 - 12, 26 - 16),
                new Vector2(5 - 12, 26 - 16)
            };

            shape = addComponent(new FSCollisionPolygon(points));

            shape.setCollisionCategories(CollisionSetting.playerCategory);
            shape.setCollidesWith(CollisionSetting.playerShouldTriggerCategory);


            addComponent <RigidBodyVelocityLimited>();
        }
Exemplo n.º 4
0
        private void initCollision()
        {
            rigidBody = addComponent <FSRigidBody>()
                        .setBodyType(FarseerPhysics.Dynamics.BodyType.Dynamic)
                        .setLinearDamping(0.8f)
                        .setMass(2f);

            collider = addComponent <FSCollisionCircle>()
                       .setRadius(8);
            collider.setCollisionCategories(CollisionSetting.enemyCategory);
            collider.setCollidesWith(CollisionSetting.wallCategory
                                     | CollisionSetting.allAttackTypeCategory
                                     | CollisionSetting.playerAttackCategory
                                     );


            damageTriger = addComponent <DamageTrigerComponent>();
            damageTriger.setRadius(16).setIsSensor(true);
            damageTriger.setCollisionCategories(
                CollisionSetting.enemyAttackCategory);
            damageTriger.setCollidesWith(CollisionSetting.playerCategory);
            damageTriger.onAdded += damageOnAdded;

            viewFieldTrigger = addComponent <EnemyViewComponent>();
            viewFieldTrigger.setRadius(fieldOfView);
            viewFieldTrigger.setIsSensor(true);
            viewFieldTrigger.setCollisionCategories(CollisionSetting.enemyCategory);
            viewFieldTrigger.setCollidesWith(CollisionSetting.playerCategory);

            viewFieldTrigger.onAdded += onAdded;

            addComponent <RigidBodyVelocityLimited>();
        }
Exemplo n.º 5
0
        public void AssignToLayer(Scene scene, LoginManagerServer login, PlayerComponent pc = null)
        {
            MapLayer assignedLayer = null;

            if (MapType == MapType.Multi)
            {
                //find first that isn't full
                assignedLayer = MapLayers.Find(l =>
                {
                    if (l != null)
                    {
                        return(l.LayerLogins.Count < ConstantValues.MaxConnectionsToLayer);
                    }
                    return(false);
                });
                //if none found then make new layer
                if (assignedLayer == null)
                {
                    assignedLayer = CreateNewLayer(-1);
                }
                login.GetCharacter().LastMultiLocation = MapName;
            }
            else if (MapType == MapType.Single)
            {
                assignedLayer = CreateNewLayer(login.GetUniqueID());
            }

            assignedLayer.AddLoginToLayer(login);

            Entity e = Core.Scene.FindEntity(login.GetCharacter()._name);

            if (e == null)
            {
                FSRigidBody fbody = new FSRigidBody().SetBodyType(BodyType.Dynamic).SetIgnoreGravity(true).SetLinearDamping(15f);

                e = scene.CreateEntity(login.GetCharacter()._name).SetPosition(login.GetCharacter().physicalPosition);
                e.AddComponent(fbody)
                .AddComponent(new FSCollisionCircle(25))
                .AddComponent(new PlayerComponent(login)
                {
                    CurrentLayer = assignedLayer
                })
                .AddComponent(new Mover())
                .AddComponent(new CircleCollider(25))
                .AddComponent(new StatsComponent())
                .AddComponent(new DamageComponent());
                fbody.Body.FixedRotation = true;
                login.SetEntity(e);
            }
            if (pc != null)
            {
                pc.CurrentLayer = assignedLayer;
            }
        }
Exemplo n.º 6
0
        private void initCollision()
        {
            rigidBody = addComponent <FSRigidBody>()
                        .setBodyType(BodyType.Dynamic)
                        .setFixedRotation(true)
                        .setLinearDamping(0.8f)
                        .setMass(2f);

            collider = addComponent <FSCollisionCircle>()
                       .setRadius(8);
            collider.setCollisionCategories(CollisionSetting.enemyCategory);
            collider.setCollidesWith(CollisionSetting.wallCategory
                                     | CollisionSetting.allAttackTypeCategory
                                     | CollisionSetting.playerAttackCategory
                                     | CollisionSetting.tiledHoleCategory
                                     );

            var damageTriger = addComponent <DamageTrigerComponent>();

            damageTriger.setRadius(8).setIsSensor(true);
            damageTriger.setCollisionCategories(
                CollisionSetting.enemyAttackCategory);
            damageTriger.setCollidesWith(CollisionSetting.playerCategory);
            damageTriger.onAdded += () =>
            {
                damageTriger.GetFixture().onCollision += (fixtureA, fixtureB, contact) =>
                {
                    var component     = fixtureB.userData as Component;
                    var actorProperty = component.entity.getComponent <ActorPropertyComponent>();
                    actorProperty.executeDamage?.Invoke(AttackTypes.Physics, 5);
                    var rigidbody = component.entity.getComponent <FSRigidBody>();
                    var dir       = component.entity.position - this.position;
                    dir.Normalize();
                    rigidbody.body.applyLinearImpulse(dir * rigidbody.body.mass);
                    return(true);
                };
            };

            addComponent <RigidBodyVelocityLimited>();
        }
Exemplo n.º 7
0
 public override void onAddedToEntity()
 {
     base.onAddedToEntity();
     rigidBody = entity.getComponent <FSRigidBody>();
 }
Exemplo n.º 8
0
        public override void onAddedToScene()
        {
            base.onAddedToScene();

            this.actorProperty               = addComponent <ActorPropertyComponent>();
            this.actorProperty.HP            = this.actorProperty.MaxHP = 30;
            this.actorProperty.moveSpeed     = 70;
            this.actorProperty.executeDamage = executeDamageMethod;

            var texture1 = scene.content.Load <Texture2D>("Images/Enemys/BlackOctor1");
            var texture2 = scene.content.Load <Texture2D>("Images/Enemys/BlackOctor2");
            var texture3 = GameResources.GameTextureResource.xObjectPacker.Packer.getSubtexture(750);

            animations = addComponent(new Sprite <OctorAnimations>(new Subtexture(texture1)));
            animations.setLayerDepth(LayerDepthExt.caluelateLayerDepth(this.position.Y));
            animations.addAnimation(OctorAnimations.Attack, new SpriteAnimation(new Subtexture(texture2)));
            animations.addAnimation(OctorAnimations.Appera, new SpriteAnimation(new Subtexture(texture1)));
            animations.addAnimation(OctorAnimations.Hide, new SpriteAnimation(texture3));

            animations.currentAnimation = OctorAnimations.Hide;

            rigidBody = addComponent <FSRigidBody>()
                        .setBodyType(BodyType.Dynamic)
                        .setLinearDamping(int.MaxValue)
                        .setMass(2f);

            var collider = addComponent <FSCollisionCircle>()
                           .setRadius(5);

            collider.setCollisionCategories(CollisionSetting.enemyCategory);
            collider.setCollidesWith(CollisionSetting.allAttackTypeCategory
                                     | CollisionSetting.playerAttackCategory);


            ViewTrigger = scene.createEntity("OctorViewTrigger").setPosition(this.position);
            ViewTrigger.addComponent <FSRigidBody>()
            .setBodyType(BodyType.Dynamic);
            var view = ViewTrigger.addComponent <EnemyViewComponent>();

            view.setRadius(fieldOfView)
            .setIsSensor(true);

            view.setCollisionCategories(CollisionSetting.enemyCategory);
            view.setCollidesWith(CollisionSetting.playerCategory);

            view.onAdded += () =>
            {
                view.GetFixture().onCollision += (fixtureA, fixtureB, contact) =>
                {
                    var compoent = fixtureB.userData as Component;
                    target       = compoent.entity;
                    isFindTarget = true;
                    return(true);
                };

                view.GetFixture().onSeparation += (fixtureA, fixtureB) => {
                    target       = null;
                    isFindTarget = false;
                };
            };

            colliderEntity = scene.createEntity("collision").setPosition(this.position);
            colliderEntity.addComponent <FSRigidBody>()
            .setBodyType(BodyType.Static);

            colliderShape = colliderEntity.addComponent <FSCollisionCircle>()
                            .setRadius(7);
            colliderShape.setCollisionCategories(CollisionSetting.wallCategory);


            stateMachine = addComponent(new OctorSimpleStateMachine(this));
        }
Exemplo n.º 9
0
        public static bool CalculateMovement(CharacterPlayer character, Keys[] keys, long ID)
        {
            if (character == null)
            {
                return(false);
            }
            float speed = 350;

            try
            {
                IsShiftDown = false;
                var dir = Vector2.Zero;
                foreach (var key in keys)
                {
                    //add proper movement with deltaTime later
                    switch (key)
                    {
                    case Keys.W:
                        //character._pos.Y -= 3f;
                        dir.Y = -1f;
                        break;

                    case Keys.A:
                        //character._pos.X -= 3f;
                        dir.X = -1f;
                        break;

                    case Keys.S:
                        //character._pos.Y += 3f;
                        dir.Y = 1f;
                        break;

                    case Keys.D:
                        //character._pos.X += 3f;
                        dir.X = 1f;
                        break;

                    case Keys.T:
                        character.AddItemToInventory(ItemManager.GenerateItem());
                        LoginManagerServer login = MapContainer.GetLoginByID(ID);
                        MapContainer.MoveLoginToMap(login, MapContainer.GetMapByName("MapTwo"));
                        break;

                    case Keys.LeftShift:
                        IsShiftDown = true;
                        break;

                    default:
                        break;
                    }
                }
                if (dir != Vector2.Zero)
                {
                    Entity e = Core.Scene.FindEntity(character._name);
                    e.RemoveComponent <ChannelingComponent>();

                    var movement = dir * speed * Time.DeltaTime;

                    FSRigidBody body  = e.GetComponent <FSRigidBody>();
                    Mover       mover = e.GetComponent <Mover>();

                    if (mover.Move(movement, out CollisionResult collisionResult))
                    {
                        //Debug.DrawLine(e.Position, e.Position + collisionResult.Normal * 100, Color.Black, 1f);
                    }
                    return(true);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return(false);
        }