Exemple #1
0
        private static int createTeammate(CharacterClass characterClass, Vector2 position, List<XElement> skillData = null)
        {
            int entityId = EntityManager.createEntity();
            CharacterComponent characterComponent;
            Vector2 feetOffset = new Vector2(0, 0.25f);
            Body body;
            Body feet;
            RevoluteJoint feetJoint;
            World world = SystemManager.physicsSystem.world;
            List<Skill> skills = skillData == null ? getStartingSkills(entityId, characterClass) : getSkillsFromData(skillData, characterClass, entityId);

            body = BodyFactory.CreateRectangle(world, 0.5f, 0.5f, 0.5f, position);
            body.BodyType = BodyType.Dynamic;
            body.UserData = entityId;
            body.FixedRotation = true;
            body.Friction = 0f;
            body.UserData = entityId;
            body.CollisionCategories = (ushort)CollisionCategory.Characters;

            feet = BodyFactory.CreateCircle(world, 0.25f, 1f, position + feetOffset);
            feet.BodyType = BodyType.Dynamic;
            feet.UserData = entityId;
            feet.Friction = 5f;
            feet.CollisionCategories = (ushort)CollisionCategory.CharacterFeet;
            feet.CollidesWith = (ushort)CollisionCategory.Terrain;

            feetJoint = new RevoluteJoint(body, feet, feetOffset, Vector2.Zero, false);
            feetJoint.MotorEnabled = true;
            feetJoint.MaxMotorTorque = 100f;
            feetJoint.MotorSpeed = 0f;
            world.AddJoint(feetJoint);

            characterComponent = new CharacterComponent(entityId, body, feet, feetJoint, characterClass);
            characterComponent.body.OnCollision += new OnCollisionEventHandler(playerCharacterBodyOnCollision);

            EntityManager.addComponent(entityId, characterComponent);
            EntityManager.addComponent(entityId, getCharacterStats(entityId, characterClass));
            EntityManager.addComponent(entityId, new PositionComponent(entityId, body));
            EntityManager.addComponent(entityId, new IgnoreRopeRaycastComponent(entityId));
            EntityManager.addComponent(entityId, new IgnoreBridgeRaycastComponent(entityId));
            EntityManager.addComponent(entityId, new SkillsComponent(entityId, skills));
            EntityManager.addComponent(entityId, new FactionComponent(entityId, Faction.Player, Faction.Enemy));
            EntityManager.addComponent(entityId, new RenderHealthComponent(entityId));
            EntityManager.addComponent(entityId, new PerformingSkillsComponent(entityId));
            EntityManager.addComponent(entityId, new ExternalMovementSpeedsComponent(entityId));
            EntityManager.addComponent(entityId, new AffectedBySpellEntitiesComponent(entityId));
            EntityManager.addComponent(entityId, new PhysicsComponent(entityId, new List<Body>( new [] { body, feet })));
            EntityManager.addComponent(entityId, new BloodColorComponent(entityId, Color.Red));
            EntityManager.addComponent(entityId, new AnimationComponent(entityId, AnimationCategory.Character, AnimationType.Idle, 3));

            return entityId;
        }
Exemple #2
0
        // Move along a grabbed rope
        private void updateGrab(int entityId, RopeGrabComponent ropeGrabComponent, CharacterComponent characterBodyComponent)
        {
            Vector2 localAnchor;
            Body body;
            int oldIndex = (int)Math.Floor(ropeGrabComponent.progress);
            int newIndex;
            float fraction;
            float segmentLength = 1.2f;
            float progress = SystemManager.physicsSystem.isSlowMotion ? 0.025f : 0.05f;

            SystemManager.physicsSystem.world.RemoveJoint(ropeGrabComponent.joint);
            ropeGrabComponent.progress += progress;
            newIndex = (int)Math.Floor(ropeGrabComponent.progress);

            if (newIndex < 0 || newIndex > ropeGrabComponent.ropeComponent.bodies.Count - 1)
            {
                releaseRope(entityId, ropeGrabComponent);
            }
            else
            {
                fraction = ropeGrabComponent.progress - newIndex;
                body = ropeGrabComponent.ropeComponent.bodies[newIndex];
                localAnchor = new Vector2((fraction - 0.5f) * segmentLength, 0f);
                ropeGrabComponent.joint = JointFactory.CreateRevoluteJoint(SystemManager.physicsSystem.world, body, characterBodyComponent.body, localAnchor, Vector2.Zero);
            }
        }
        public override void update()
        {
            _entityId = SystemManager.teamSystem.getTeammateEntityId(_teamPosition);

            if (_entityId != -1)
            {
                // Update entity/component references
                _characterComponent = EntityManager.getCharacterComponent(_entityId);
                _statsComponent = EntityManager.getStatsComponent(_entityId);

                // Update character information
                updateCharacterInformation();

                // Update health bar
                updateHealthBar();
            }
        }