コード例 #1
0
        protected override void Execute(List <InputEntity> entities)
        {
            foreach (var entity in entities)
            {
                var horizontalDirection = entity.playerAvatarInput.horizontalDirection;
                var jump = entity.playerAvatarInput.jump;

                var playerEntity = gameContext.playerAvatarEntity;

                playerEntity.rigidbody.speedX = horizontalDirection * 5;

                if (jump && AvatarUtils.IsOnFloor(playerEntity, gameContext))
                {
                    playerEntity.rigidbody.speedY = -15;
                }

                entity.Destroy();
            }
        }
コード例 #2
0
        public void Execute()
        {
            foreach (var entity in allMovablesGroup.GetEntities())
            {
                if (entity.rigidbody.speedX != 0 || entity.rigidbody.speedY != 0)
                {
                    var newX = entity.position.x + entity.rigidbody.speedX;
                    var newY = entity.position.y + entity.rigidbody.speedY;

                    var newTilePosition = TilePositionComponent.TransformWorldPositionToTilePosition(new IntVector2(newX, newY));

                    if (TileUtils.IsSolid(newX, newY, gameContext))
                    {
                        if (entity.rigidbody.speedY > 0)
                        {
                            entity.rigidbody.speedY = 0;
                            newY = newTilePosition.ToTopLeftWorldPosition().y - 1;
                        }
                    }

                    entity.ReplacePosition(newX, newY);
                }

                if (entity.rigidbody.useGravity)
                {
                    if (!AvatarUtils.IsOnFloor(entity, gameContext))
                    {
                        entity.rigidbody.speedY++;
                        if (entity.rigidbody.speedY > 10)
                        {
                            entity.rigidbody.speedY = 10;
                        }
                    }
                    else
                    {
                        entity.rigidbody.speedY = 0;
                    }
                }
            }
        }