Exemple #1
0
        private void HandleGravityInitialize(EntityUid uid, GravityComponent component, ComponentInit args)
        {
            // Incase there's already a generator on the grid we'll just set it now.
            var gridId = Transform(component.Owner).GridUid;

            if (gridId == null)
            {
                return;
            }

            GravityChangedMessage message;

            foreach (var generator in EntityManager.EntityQuery <GravityGeneratorComponent>())
            {
                if (Transform(generator.Owner).GridUid == gridId && generator.GravityActive)
                {
                    component.Enabled = true;
                    message           = new GravityChangedMessage(gridId.Value, true);
                    RaiseLocalEvent(message);
                    return;
                }
            }

            component.Enabled = false;
            message           = new GravityChangedMessage(gridId.Value, false);
            RaiseLocalEvent(message);
        }
 public bool CanSwimAtCurrentLocation(bool check_head)
 {
     if (base.def.canSwim)
     {
         Vector3 position = base.transform.GetPosition();
         float   num      = 1f;
         if (!check_head)
         {
             num = 0.5f;
         }
         float   y    = position.y;
         Vector2 size = base.transform.GetComponent <KBoxCollider2D>().size;
         position.y = y + size.y * num;
         int cell = Grid.PosToCell(position);
         if (Grid.IsSubstantialLiquid(cell, 0.35f))
         {
             if (!GameComps.Gravities.Has(base.gameObject))
             {
                 return(true);
             }
             GravityComponent data = GameComps.Gravities.GetData(GameComps.Gravities.GetHandle(base.gameObject));
             if (data.velocity.magnitude < 2f)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
        /// <summary>
        /// Check if networkinputcomponent's parameters are true and do actions on remote player
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="playerEntity"></param>
        private void ParseNetworkInput(GameTime gameTime, Entity playerEntity)
        {
            NetworkInputComponent networkInputComponent = ComponentManager.Instance.ConcurrentGetComponentOfEntity <NetworkInputComponent>(playerEntity);
            VelocityComponent     velocityComponent     = ComponentManager.Instance.ConcurrentGetComponentOfEntity <VelocityComponent>(playerEntity);
            TransformComponent    transformComponent    = ComponentManager.Instance.ConcurrentGetComponentOfEntity <TransformComponent>(playerEntity);
            GravityComponent      gravityComponent      = ComponentManager.Instance.ConcurrentGetComponentOfEntity <GravityComponent>(playerEntity);

            if (networkInputComponent.MoveForward)
            {
                PlayerActions.AcceleratePlayerForwards(gameTime, velocityComponent);
            }
            if (networkInputComponent.MoveLeft)
            {
                PlayerActions.AcceleratePlayerLeftwards(gameTime, velocityComponent);
            }
            if (networkInputComponent.MoveRight)
            {
                PlayerActions.AcceleratePlayerRightwards(gameTime, velocityComponent);
            }
            if (networkInputComponent.Jump)
            {
                PlayerActions.PlayerJump(gameTime, velocityComponent);
            }
            if (networkInputComponent.MoveBackward)
            {
                PlayerActions.AcceleratePlayerBackwards(gameTime, velocityComponent);
            }
        }
        public void glide()
        {
            GravityComponent gravComp = (GravityComponent)this.level.getPlayer().getComponent(GlobalVars.GRAVITY_COMPONENT_NAME);

            gravComp.setGravity(gravComp.x, (Glide_Gravity_Decrease));
            glideActive = true;
        }
Exemple #5
0
        public override void Execute(Entity entity)
        {
            GravityComponent gravityComponent = entity.gravityComponent;

            gravityComponent.fallVelocity = entity.statsComponent.GetTotalStat(StatID.InitJumpVel);
            gravityComponent.inAir        = true;
        }
        public override void Update(float deltaTime)
        {
            if (!hasRunOnce)
            {
                level.getInputSystem().addKey(glideKey);

                //level.getInputSystem().addKey(blockSpawnKey);
                level.getInputSystem().addKey(speedyKey);

                level.getInputSystem().addKey(cycleDownPowerupKey);
                //level.getInputSystem().addKey(cycleUpPowerupKey);
                level.getInputSystem().addKey(equippedPowerupKey);

                level.getInputSystem().addKey(bounceKey);

                hasRunOnce = true;
            }
            if (glideActive)
            {
                VelocityComponent velComp = (VelocityComponent)this.level.getPlayer().getComponent(GlobalVars.VELOCITY_COMPONENT_NAME);
                if (velComp.y > maxVelocity)
                {
                    velComp.setVelocity(velComp.x, maxVelocity);
                }
                glideTimer = glideTimer - deltaTime;
                if (glideTimer < 0.0f)
                {
                    GravityComponent gravComp = (GravityComponent)this.level.getPlayer().getComponent(GlobalVars.GRAVITY_COMPONENT_NAME);
                    gravComp.setGravity(gravComp.x, GlobalVars.STANDARD_GRAVITY);
                    glideActive = false;
                    glideTimer  = glideDuration;
                }
            }

            if (speedyTimer > 0)
            {
                if (level.getPlayer() == null)
                {
                    return;
                }
                speedyTimer -= deltaTime;
                if (!level.getPlayer().hasComponent(GlobalVars.VELOCITY_COMPONENT_NAME))
                {
                    return;
                }
                VelocityComponent velComp = (VelocityComponent)this.level.getPlayer().getComponent(GlobalVars.VELOCITY_COMPONENT_NAME);
                if (speedyTimer <= 0 || Math.Abs(velComp.x) < GlobalVars.SPEEDY_SPEED)
                {
                    velComp.setVelocity(0, velComp.y);
                    speedyTimer  = -1;
                    speedyActive = false;
                    if (!level.getPlayer().hasComponent(GlobalVars.PLAYER_INPUT_COMPONENT_NAME))
                    {
                        level.getPlayer().addComponent(new PlayerInputComponent(level.getPlayer()));
                    }
                }
            }

            checkForInput();
        }
        public static Entity NewBasePlayer(String model, int gamePadIndex, Vector3 transformPos, Texture2D texture, String typeName)
        {
            Entity             player             = EntityFactory.NewEntity(typeName);
            TransformComponent transformComponent = new TransformComponent(player, transformPos);
            ModelComponent     modelComponent     = new ModelComponent(player, AssetManager.Instance.GetContent <Model>(model));
            VelocityComponent  velocityComponent  = new VelocityComponent(player);
            CollisionComponent collisionComponent = new CollisionComponent(player, new BoxVolume(EntityFactory.CreateBoundingBox(modelComponent.Model)));
            PlayerComponent    playerComponent    = new PlayerComponent(player);
            FrictionComponent  frictionComponent  = new FrictionComponent(player);
            TextureComponent   textureComponent   = new TextureComponent(player, texture);
            GravityComponent   gravityComponent   = new GravityComponent(player);
            EffectComponent    effectComponent    = new EffectComponent(player, AssetManager.Instance.GetContent <Effect>("Shading"));

            ComponentManager.Instance.AddComponentToEntity(player, modelComponent);
            ComponentManager.Instance.AddComponentToEntity(player, transformComponent);
            ComponentManager.Instance.AddComponentToEntity(player, velocityComponent);
            ComponentManager.Instance.AddComponentToEntity(player, collisionComponent, typeof(CollisionComponent));
            ComponentManager.Instance.AddComponentToEntity(player, playerComponent);
            ComponentManager.Instance.AddComponentToEntity(player, frictionComponent);
            ComponentManager.Instance.AddComponentToEntity(player, textureComponent);
            ComponentManager.Instance.AddComponentToEntity(player, gravityComponent);
            ComponentManager.Instance.AddComponentToEntity(player, effectComponent);

            TransformHelper.SetInitialModelPos(modelComponent, transformComponent);
            TransformHelper.SetBoundingBoxPos(collisionComponent, transformComponent);

            //TransformHelper.SetInitialModelPos(modelComponent, transformComponent);
            //TransformHelper.SetInitialBoundingSpherePos(collisionComponent, transformComponent);

            return(player);
        }
        /**
         * X roaming
         */
        // TODO: Bias based on liquid mass in right/left cells
        private static void ApplyXVelocityChanges(ref GravityComponent grav, float dt)
        {
            Vector2 position  = grav.transform.GetPosition();
            Vector2 newChange = new Vector2(grav.velocity.x, grav.velocity.y);

            if (Mathf.Abs(grav.velocity.x) < MIN_X_VELOCITY / 2 * dt)
            {
                newChange.x += RandomXVelocity() * dt;
            }
            grav.velocity = newChange;
        }
        public void DisableGravity(GravityComponent comp)
        {
            if (!comp.Enabled)
            {
                return;
            }
            comp.Enabled = false;

            var gridId  = EntityManager.GetComponent <TransformComponent>(comp.Owner).GridID;
            var message = new GravityChangedMessage(gridId, false);

            RaiseLocalEvent(message);
        }
Exemple #10
0
    //Gets force magnitude between this object and other object
    float CalculateGravityForce(GravityComponent otherActor)
    {
        //check to make sure we never divide by 0
        if (Vector3.Distance(transform.position, otherActor.transform.position) == 0)
        {
            return(0.0f);
        }

        //F = Gm1m2/r2  //g=6.67408*10^-11
        float F = ((6.67408e-11f) * (rb.mass) * (otherActor.GetComponent <Rigidbody>().mass))
                  / (Vector3.Distance(transform.position, otherActor.transform.position));

        //Debug.Log(F*1000000);
        return(F * 1000000);
    }
Exemple #11
0
	private void OnOreSizeChanged(object data)
	{
		Vector3 v = Vector3.zero;
		HandleVector<int>.Handle handle = GameComps.Gravities.GetHandle(base.gameObject);
		if (handle.IsValid())
		{
			GravityComponent data2 = GameComps.Gravities.GetData(handle);
			v = data2.velocity;
		}
		RemoveFaller();
		if (!KPrefabID.HasTag(GameTags.Stored))
		{
			AddFaller(v);
		}
	}
Exemple #12
0
        public void glide()
        {
            if (level.getPlayer() == null)
            {
                return;
            }
            if (!level.getPlayer().hasComponent(GlobalVars.GRAVITY_COMPONENT_NAME))
            {
                return;
            }
            GravityComponent gravComp = ( GravityComponent )this.level.getPlayer().getComponent(GlobalVars.GRAVITY_COMPONENT_NAME);

            gravComp.setGravity(gravComp.x, (Glide_Gravity_Decrease));
            glideActive = true;
        }
Exemple #13
0
        public CollisionResolver(GravityComponent grav, Vector2 desiredPosition)
        {
            this.grav            = grav;
            this.currentPosition = grav.transform.position;
            this.desiredPosition = desiredPosition;

            bestDistance = float.PositiveInfinity;
            bestPosition = currentPosition;

            KCollider2D collider = grav.transform.GetComponent <KCollider2D>();

            if (collider != null)
            {
                this.bounds = collider.bounds;
                bounds.Expand(0.05f); // Apply breathing room
            }
        }
        public static void HandleCollisionFromAbove(GameTime gameTime, Entity entity, float diff)
        {
            VelocityComponent  velocityComponent  = ComponentManager.Instance.GetComponentOfEntity <VelocityComponent>(entity);
            GravityComponent   gravity            = ComponentManager.Instance.GetComponentOfEntity <GravityComponent>(entity);
            TransformComponent transformComponent = ComponentManager.Instance.GetComponentOfEntity <TransformComponent>(entity);

            //var diffY = blockY - playerY;

            if (velocityComponent != null)
            {
                if (velocityComponent.Velocity.Y < 0)
                {
                    // if we collide with an acceleration downwards then we want a counter force up.
                    velocityComponent.Velocity.Y += (Math.Abs(velocityComponent.Velocity.Y)) + (diff / 4);
                }
                gravity.HasJumped = false;
            }
        }
        /**
         * Reverse gravity application (floatation)
         */
        private static void ApplyYVelocityChanges(ref GravityComponent grav, float dt)
        {
            GravityComponents.Tuning tuning = TuningData <GravityComponents.Tuning> .Get();

            float   yExtent  = Helpers.GetYExtent(grav);
            Vector2 position = (Vector2)grav.transform.GetPosition() + Vector2.up * (yExtent + 0.01f);

            float distanceToSurface = Helpers.GetLiquidSurfaceDistanceAbove(position);

            if (distanceToSurface != float.PositiveInfinity && distanceToSurface > 2 * yExtent)
            {
                Vector2 target = position + Vector2.up * distanceToSurface;
                Mathf.SmoothDamp(position.y, target.y, ref grav.velocity.y, 1f, tuning.maxVelocityInLiquid, dt);
            }
            else if (grav.velocity.y > 0)
            {
                Mathf.SmoothDamp(position.y, position.y, ref grav.velocity.y, 5f, tuning.maxVelocityInLiquid, dt);
            }
        }
Exemple #16
0
        public void DisableGravity(GravityComponent comp)
        {
            if (!comp.Enabled)
            {
                return;
            }
            comp.Enabled = false;

            var gridId = Transform(comp.Owner).GridUid;

            if (gridId == null)
            {
                return;
            }

            var message = new GravityChangedMessage(gridId.Value, false);

            RaiseLocalEvent(message);
        }
Exemple #17
0
    public void RemoveGravityActor(GravityComponent actor)
    {
        List <GravityComponent> templist = new List <GravityComponent>();

        foreach (GravityComponent gravActor in ActorsInGravityWell)
        {
            if (gravActor != actor)
            {
                templist.Add(gravActor);
            }
        }
        ActorsInGravityWell.Clear();
        foreach (GravityComponent gravActor in templist)
        {
            if (!ActorsInGravityWell.Contains(gravActor))
            {
                ActorsInGravityWell.Add(gravActor);
            }
        }
    }
    protected override void OnPrefabInit(HandleVector <int> .Handle h)
    {
        FallerComponent data     = GetData(h);
        Vector3         position = data.transform.GetPosition();
        int             num      = Grid.PosToCell(position);

        data.cellChangedCB = delegate
        {
            OnSolidChanged(h);
        };
        float num2 = 0f - GravityComponent.GetRadius(data.transform) - 0.07f;
        int   num3 = Grid.PosToCell(new Vector3(position.x, position.y + num2, position.z));
        bool  flag = Grid.IsValidCell(num3) && Grid.Solid[num3] && data.initialVelocity.sqrMagnitude == 0f;

        if ((Grid.IsValidCell(num) && Grid.Solid[num]) || flag)
        {
            data.solidChangedCB = delegate
            {
                OnSolidChanged(h);
            };
            int      height   = 2;
            Vector2I vector2I = Grid.CellToXY(num);
            vector2I.y--;
            if (vector2I.y < 0)
            {
                vector2I.y = 0;
                height     = 1;
            }
            else if (vector2I.y == Grid.HeightInCells - 1)
            {
                height = 1;
            }
            data.partitionerEntry = GameScenePartitioner.Instance.Add("Faller", data.transform.gameObject, vector2I.x, vector2I.y, 1, height, GameScenePartitioner.Instance.solidChangedLayer, data.solidChangedCB);
            GameComps.Fallers.SetData(h, data);
        }
        else
        {
            GameComps.Fallers.SetData(h, data);
            AddGravity(data.transform, data.initialVelocity);
        }
    }
        public void EnableGravity(GravityComponent comp)
        {
            if (comp.Enabled)
            {
                return;
            }

            var gridId = Transform(comp.Owner).GridUid;

            Dirty(comp);

            if (gridId == null)
            {
                return;
            }

            comp.Enabled = true;
            var message = new GravityChangedEvent(gridId.Value, true);

            RaiseLocalEvent(message);
        }
Exemple #20
0
 public void manageGlideTimer(float deltaTime)
 {
     if (glideActive && level.getPlayer() != null)
     {
         VelocityComponent velComp = ( VelocityComponent )this.level.getPlayer().getComponent(GlobalVars.VELOCITY_COMPONENT_NAME);
         if (velComp.y > maxVelocity)
         {
             velComp.setVelocity(velComp.x, maxVelocity);
         }
         glideTimer = glideTimer - deltaTime;
         if (glideTimer < 0.0f)
         {
             GravityComponent gravComp = ( GravityComponent )this.level.getPlayer().getComponent(GlobalVars.GRAVITY_COMPONENT_NAME);
             if (gravComp != null)
             {
                 gravComp.setGravity(gravComp.x, GlobalVars.STANDARD_GRAVITY);
             }
             glideActive = false;
             glideTimer  = glideDuration;
         }
     }
 }
        //Create AI Player
        public static Entity NewAiPlayer(String model, Vector3 transformPos, Texture2D texture)
        {
            Entity             player             = EntityFactory.NewEntity(GameEntityFactory.AI_PLAYER);
            TransformComponent transformComponent = new TransformComponent(player, transformPos);
            ModelComponent     modelComponent     = new ModelComponent(player, AssetManager.Instance.GetContent <Model>(model));
            VelocityComponent  velocityComponent  = new VelocityComponent(player);
            CollisionComponent collisionComponent = new CollisionComponent(player, new BoxVolume(EntityFactory.CreateBoundingBox(modelComponent.Model)));
            PlayerComponent    playerComponent    = new PlayerComponent(player);
            FrictionComponent  frictionComponent  = new FrictionComponent(player);
            TextureComponent   textureComponent   = new TextureComponent(player, texture);
            GravityComponent   gravityComponent   = new GravityComponent(player);
            AiComponent        aiComponent        = new AiComponent(player);
            LightComponent     lightComponent     = new LightComponent(player, new Vector3(0, 7, -5), Color.White.ToVector4(), 10f, Color.Blue.ToVector4(), 0.2f, Color.White.ToVector4(), 1000f);
            EffectComponent    effectComponent    = new EffectComponent(player, AssetManager.Instance.GetContent <Effect>("Shading"));



            ComponentManager.Instance.AddComponentToEntity(player, modelComponent);
            ComponentManager.Instance.AddComponentToEntity(player, transformComponent);
            ComponentManager.Instance.AddComponentToEntity(player, velocityComponent);
            ComponentManager.Instance.AddComponentToEntity(player, collisionComponent, typeof(CollisionComponent));
            ComponentManager.Instance.AddComponentToEntity(player, playerComponent);
            ComponentManager.Instance.AddComponentToEntity(player, frictionComponent);
            ComponentManager.Instance.AddComponentToEntity(player, textureComponent);
            ComponentManager.Instance.AddComponentToEntity(player, gravityComponent);
            ComponentManager.Instance.AddComponentToEntity(player, aiComponent);
            ComponentManager.Instance.AddComponentToEntity(player, effectComponent);
            ComponentManager.Instance.AddComponentToEntity(player, lightComponent);

            //TransformHelper.SetInitialModelPos(modelComponent, transformComponent);
            //TransformHelper.SetBoundingBoxPos(collisionComponent, transformComponent);

            TransformHelper.SetInitialModelPos(modelComponent, transformComponent);
            TransformHelper.SetBoundingBoxPos(collisionComponent, transformComponent);

            return(player);
        }
        private void PushSourceAwayFromTarget(GameTime gameTime, Entity sourceEntity, Entity targetEntity)
        {
            CollisionComponent sourceCollisionComponent = ComponentManager.Instance.GetComponentOfEntity <CollisionComponent>(sourceEntity);
            CollisionComponent targetCollisionComponent = ComponentManager.Instance.GetComponentOfEntity <CollisionComponent>(targetEntity);
            GravityComponent   sourceGravityComponent   = ComponentManager.Instance.GetComponentOfEntity <GravityComponent>(sourceEntity);
            TransformComponent sourceTransformComponent = ComponentManager.Instance.GetComponentOfEntity <TransformComponent>(sourceEntity);

            if (sourceCollisionComponent.BoundingVolume.Center.X < targetCollisionComponent.BoundingVolume.Center.X)
            {
                CollisionActions.AccelerateColliderRightwards(gameTime, sourceEntity);
            }
            else
            {
                CollisionActions.AccelerateColliderLeftwards(gameTime, sourceEntity);
            }
            if (sourceCollisionComponent.BoundingVolume.Center.Z < targetCollisionComponent.BoundingVolume.Center.Z)
            {
                CollisionActions.AccelerateColliderBackwards(gameTime, sourceEntity);
            }
            else
            {
                CollisionActions.AccelerateColliderForwards(gameTime, sourceEntity);
            }
        }
        // TODO: Check for potential bug with 1-tile width water
        static void Prefix(ref GravityComponents __instance, float dt)
        {
            gravComponentState.Clear();

            var data = __instance.GetDataList();

            for (int i = 0; i < data.Count; i++)
            {
                GravityComponent grav = data[i];
                if (!Helpers.ShouldFloat(grav.transform))
                {
                    continue;
                }

                ApplyXVelocityChanges(ref grav, dt);
                ApplyYVelocityChanges(ref grav, dt);

                Vector3 pos         = grav.transform.GetPosition();
                Vector3 newPosition = (Vector2)pos + grav.velocity * dt;

                // Resolve collisions
                CollisionResolver resolver = new CollisionResolver(grav, newPosition);
                resolver.ResolveCollisions();

                // Apply the new gravity/position
                newPosition   = resolver.bestPosition;
                newPosition.z = pos.z;
                grav          = resolver.grav;

                grav.transform.SetPosition(newPosition);
                grav.elapsedTime += dt;

                gravComponentState.Add(i, grav);
                data[i] = NULL_COMPONENT;
            }
        }
Exemple #24
0
        protected Point ExecuteState(GameTime gameTime, Point matrixPosition, Vector3 position, VelocityComponent aiVelocity, GravityComponent gravity, AiComponent aiComponent)
        {
            //Get the block at the AI's current position
            var currentBlock = GetBlock(matrixPosition);

            // Debug
            //WriteWorld(worldMatrix);

            // Get the "real" values of the next block (destination) and the players "real" position
            // to make the move to the next block:
            //int row = 0;

            //if (matrixPosition.Y < worldMatrix.GetLength(1) - 1)
            //    row = matrixPosition.Y + 1;
            //else
            //    row = matrixPosition.Y;

            //var decision = ChooseBlock(worldMatrix, row);
            //var destinationBlock = GetBlock(decision);

            int row = 0;

            if (matrixPosition.Y < worldMatrix.GetLength(1) - 1)
            {
                row = matrixPosition.Y + 1;
            }
            else
            {
                row = matrixPosition.Y;
            }

            if (targetBlockTile.Y <= matrixPosition.Y)
            {
                targetBlockTile = ChooseBlock(worldMatrix, row);
                targetBlockPos  = GetBlock(targetBlockTile);
            }

            // Execute the move to the next block
            ExecuteMove(gameTime, currentBlock, targetBlockPos, position, aiVelocity, gravity, aiComponent);

            // We look to see if the player is in the same block in the "real" world as
            // in the matrix. if he is, we "wait" until the move is completed and return the same
            // position, or we make the move.
            // TODO: Need to fix
            if (currentBlock.Z + 50 <= position.Z)
            {
                return(targetBlockTile);
            }
            else
            {
                return(matrixPosition);
            }
        }
Exemple #25
0
 //Gest unit vector towards desired direction
 Vector3 CalculateGravityDirection(GravityComponent otherActor)
 {
     return(Vector3.Normalize(otherActor.transform.position - transform.position));
 }
Exemple #26
0
 public static float GetYExtent(GravityComponent component)
 {
     return(Mathf.Max(0.2f, component.radius));
 }
Exemple #27
0
 private void HandleGravityShutdown(EntityUid uid, GravityComponent component, ComponentShutdown args)
 {
     DisableGravity(component);
 }
Exemple #28
0
        //You must have an Update.
        //Always read in deltaTime, and only deltaTime (it's the time that's passed since the last frame)
        //Use deltaTime for things like changing velocity or changing position from velocity
        //This is where you do anything that you want to happen every frame.
        //There is a chance that your system won't need to do anything in update. Still have it.
        public override void Update(float deltaTime)
        {
            foreach (Entity e in getApplicableEntities())
            {
                PositionComponent       platPos     = (PositionComponent)e.getComponent(GlobalVars.POSITION_COMPONENT_NAME);
                ColliderComponent       platCol     = (ColliderComponent)e.getComponent(GlobalVars.COLLIDER_COMPONENT_NAME);
                VelocityComponent       platVel     = ( VelocityComponent )e.getComponent(GlobalVars.VELOCITY_COMPONENT_NAME);
                MovingPlatformComponent movPlatComp = ( MovingPlatformComponent )e.getComponent(GlobalVars.MOVING_PLATFORM_COMPONENT_NAME);

                float mySpeed = platVel.x;

                if (movPlatComp.vertical)
                {
                    mySpeed = platVel.y;
                }

                //If it's been stopped for more than one frame, try changing the direction and see if it can move that way instead.
                if (mySpeed == 0)
                {
                    float newSpeed = GlobalVars.MOVING_PLATFORM_SPEED;

                    if (!movPlatComp.wasStoppedLastFrame)
                    {
                        newSpeed = GlobalVars.MOVING_PLATFORM_SPEED;
                    }
                    else
                    {
                        newSpeed = -GlobalVars.MOVING_PLATFORM_SPEED;
                    }

                    if (movPlatComp.vertical)
                    {
                        platVel.y = newSpeed;
                    }
                    else
                    {
                        platVel.x = newSpeed;
                    }

                    movPlatComp.wasStoppedLastFrame = true;
                }
                else if (movPlatComp.wasStoppedLastFrame)
                {
                    movPlatComp.wasStoppedLastFrame = false;
                }

                float checkBuffer = 3;

                float upperLeftX  = platCol.getX(platPos) - platCol.width / 2;
                float upperRightX = platCol.getX(platPos) + platCol.width / 2;
                float upperY      = platCol.getY(platPos) - platCol.height / 2 - checkBuffer;

                System.Drawing.PointF leftPoint  = new System.Drawing.PointF(upperLeftX, upperY);
                System.Drawing.PointF rightPoint = new System.Drawing.PointF(upperRightX, upperY);
                List <Entity>         aboveEnts  = level.getCollisionSystem().findObjectsBetweenPoints(leftPoint, rightPoint);

                foreach (Entity otherEnt in aboveEnts)
                {
                    if (!stoppingEntities.Contains(otherEnt.GetType()) && otherEnt.hasComponent(GlobalVars.VELOCITY_COMPONENT_NAME))
                    {
                        PositionComponent otherPos = (PositionComponent)otherEnt.getComponent(GlobalVars.POSITION_COMPONENT_NAME);
                        VelocityComponent otherVel = ( VelocityComponent )otherEnt.getComponent(GlobalVars.VELOCITY_COMPONENT_NAME);
                        ColliderComponent otherCol = ( ColliderComponent )otherEnt.getComponent(GlobalVars.COLLIDER_COMPONENT_NAME);

                        System.Drawing.PointF grav = new System.Drawing.PointF(0.0f, 0.0f);
                        if (otherEnt.hasComponent(GlobalVars.GRAVITY_COMPONENT_NAME))
                        {
                            GravityComponent otherGrav = ( GravityComponent )otherEnt.getComponent(GlobalVars.GRAVITY_COMPONENT_NAME);
                            grav = new System.Drawing.PointF(otherGrav.x, otherGrav.y);
                        }

                        if (movPlatComp.vertical)
                        {
                            if ((platVel.y == 0 || platVel.y <= 0 && (otherVel.y + grav.Y * deltaTime) >= platVel.y) || (platVel.y >= 0 && (otherVel.y + grav.Y * deltaTime) <= platVel.y))
                            {
                                otherVel.y = platVel.y - grav.Y * deltaTime;
                            }

                            level.getMovementSystem().changePosition(otherPos, otherCol.getX(otherPos), platCol.getY(platPos) - platCol.height / 2 - otherCol.height / 2 - 1, false, false);
                        }
                        else
                        {
                            if ((platVel.x == 0 || platVel.x <= 0 && (otherVel.x + grav.X * deltaTime) >= platVel.x) || (platVel.x >= 0 && (otherVel.x + grav.X * deltaTime) <= platVel.y))
                            {
                                otherVel.x = platVel.x - grav.X * deltaTime;
                            }

                            if (otherEnt is RunningGame.Entities.Player)
                            {
                                level.getMovementSystem().changePosition(otherPos, otherCol.getX(otherPos) + platVel.x * deltaTime, platCol.getY(platPos) - platCol.height / 2 - otherCol.height / 2 - 3, false, false);
                            }
                            else
                            {
                                level.getMovementSystem().changePosition(otherPos, otherCol.getX(otherPos), platCol.getY(platPos) - platCol.height / 2 - otherCol.height / 2 - 0, false, false);
                            }
                        }
                        if (otherEnt.hasComponent(GlobalVars.VEL_TO_ZERO_COMPONENT_NAME))
                        {
                            VelToZeroComponent velZedComp = (VelToZeroComponent)otherEnt.getComponent(GlobalVars.VEL_TO_ZERO_COMPONENT_NAME);
                            velZedComp.blockSlow = true;
                        }
                    }
                }
            }
        }
Exemple #29
0
 public void Update(GameTime gameTime, ref Point matrixPosition, Vector3 Position, VelocityComponent aiVelocity, GravityComponent gravity, AiComponent aiComponent)
 {
     worldMatrix       = GameService.Instance.GameWorld;
     worldEntityMatrix = GameService.Instance.EntityGameWorld;
     matrixPosition    = ExecuteState(gameTime, matrixPosition, Position, aiVelocity, gravity, aiComponent);
 }
Exemple #30
0
 protected void ExecuteMove(GameTime gameTime, Vector3 currentBlock, Vector3 nextBlock, Vector3 position, VelocityComponent velocity, GravityComponent gravity, AiComponent aiComponent)
 {
     PlayerActions.AcceleratePlayerForwards(gameTime, velocity);
     if (aiComponent.CurrentState == State.Winning)
     {
         if (Random.Next(0, 11) == 1) //20% chance to make random move
         {
             Console.WriteLine("RandomMove ");
             if (Random.Next(0, 2) == 1) //50% chance to go left or right
             {
                 PlayerActions.AcceleratePlayerLeftwards(gameTime, velocity);
                 if (!gravity.HasJumped)
                 {
                     PlayerActions.PlayerJump(gameTime, velocity, null);
                     gravity.HasJumped = true;
                 }
             }
             PlayerActions.AcceleratePlayerRightwards(gameTime, velocity);
             if (!gravity.HasJumped)
             {
                 PlayerActions.PlayerJump(gameTime, velocity, null);
                 gravity.HasJumped = true;
             }
             return;
         }
     }
     Console.WriteLine("Regular move");
     if (currentBlock.X < nextBlock.X) //if the block that AI wants to go to is "lower" X value AKA left of the current we need to jump left
     {
         PlayerActions.AcceleratePlayerLeftwards(gameTime, velocity);
         if (!gravity.HasJumped)
         {
             PlayerActions.PlayerJump(gameTime, velocity, null);
             gravity.HasJumped = true;
         }
     }
     if (currentBlock.X > nextBlock.X) //if the block that AI wants to go to is "higher" X value AKA right of the current we need to jump right
     {
         PlayerActions.AcceleratePlayerRightwards(gameTime, velocity);
         if (!gravity.HasJumped)
         {
             PlayerActions.PlayerJump(gameTime, velocity, null);
             gravity.HasJumped = true;
         }
     }
     if (currentBlock.X == nextBlock.X)
     {
         PlayerActions.AcceleratePlayerForwards(gameTime, velocity);
         if (!gravity.HasJumped)
         {
             PlayerActions.PlayerJump(gameTime, velocity, null);
             gravity.HasJumped = true;
         }
     }
 }