示例#1
0
        public virtual LightColour GetLightBrightness(Map map, double x, double y)
        {
            Vector2d origin = new Vector2d(OriginX, OriginY);
            Vector2d dest   = new Vector2d(x, y);

            Vector2d diff = dest - origin;

            if (diff.Length > myRange)
            {
                return(LightColour.Default);
            }

            RayTraceResult res = RayTrace.Trace(map, origin, dest, false);

            float brightness = 1.0f;

            foreach (TileCrossInfo info in res.CrossedTiles)
            {
                brightness -= (float)((info.IsSolid ? myRange : 1.0) / myRange) * (float)info.Duration;

                if (brightness <= 0)
                {
                    return(LightColour.Default);
                }
            }

            return(new LightColour(LightColour.R * brightness, LightColour.G * brightness, LightColour.B * brightness));
        }
示例#2
0
    private IEnumerator Avoid()
    {
        RayTraceResult SelectResult = null;

        foreach (RayTraceResult result in FrontRayResult)
        {
            if (!result.isHit)
            {
                SelectResult = result;
                break;
            }
        }
        if (SelectResult != null)
        {
            Vector3 outDirection = Quaternion.Euler(0, 0, SelectResult.angle) * transform.up;
            Car.SetSteering(SelectResult.angle);
            while (Vector3.Angle(transform.up, outDirection) >= 3)
            {
                yield return(null);
            }
            ChangeAction(MoveTo());
        }
        else
        {
            ChangeAction(Brake());
        }
    }
示例#3
0
 private void Awake()
 {
     Car            = GetComponent <CarBase>();
     FrontRayResult = new RayTraceResult[FrontRayCount];
     for (int i = 0; i < FrontRayCount; i++)
     {
         FrontRayResult[i] = new RayTraceResult();
     }
 }
示例#4
0
        public override void Update()
        {
            //Sync the noclip var with the physics engine
            EnablePhysics = !noClip;

            var lookUnits = LookVelocity;         // * Time.DeltaTime;
            var moveUnits = MoveSpeed;            // * Time.DeltaTime;

            if (GameClient.isPaused == false)
            {
                if (InputManager.IsPressed("move.sprint"))
                {
                    MoveSpeed = SprintSpeed;
                }
                else
                {
                    MoveSpeed = MoveVelocity;
                }
            }

            // get our movement basis vectors
            Vector3 forward, up, right;

            TransformBasisVector(Vector3.Forward, out forward);
            TransformBasisVector(Vector3.Right, out right);
            if (camera.rotation.X >= 0.0f)
            {
                TransformBasisVector(Vector3.Down, out up);
            }
            else
            {
                TransformBasisVector(Vector3.Up, out up);
            }

            if (GameClient.isPaused == false)
            {
                #region Input
                // check keyboard for which direction to move
                Vector3 move       = Vector3.Zero;
                Vector3 moveVector = Vector3.Zero;
                if (InputManager.IsPressed("move.forward"))
                {
                    moveVector += Vector3.Forward;

                    move += forward;
                    move += up;
                }
                if (InputManager.IsPressed("move.back"))
                {
                    moveVector += Vector3.Backward;

                    move -= forward;
                    move -= up;
                }
                if (InputManager.IsPressed("move.right"))
                {
                    moveVector += Vector3.Left;

                    move += right;
                }
                if (InputManager.IsPressed("move.left"))
                {
                    moveVector += Vector3.Right;

                    move -= right;
                }
                //jumping / flying
                if (InputManager.IsPressed("move.jump"))
                {
                    if (noClip)
                    {
                        moveVector += Vector3.Up;

                        move += Vector3.Up;
                    }
                    else if (IsGrounded)
                    {
                        //handle jump
                        moveVector += Vector3.Up;

                        move += Vector3.Up * JumpForce * 0.3f / MoveSpeed;
                    }
                }
                //sneaking / flying down
                if (InputManager.IsPressed("move.sneak"))
                {
                    if (noClip)
                    {
                        moveVector -= Vector3.Up;

                        move -= Vector3.Up;
                    }
                    else
                    {
                        //handle sneak
                        moveVector -= Vector3.Up;

                        move -= Vector3.Up;

                        MoveSpeed = SneakSpeed;
                    }
                }

                #region Hotbar Slot Handling
                //Change the slot
                //Controller support
                if (InputManager.Released("hotbar.right") || InputManager.MouseScrollWheel < 0)
                {
                    HeldSlot += 1;
                    HeldSlot  = FastMath.Normalise(HeldSlot, 0, 9);
                }
                if (InputManager.Released("hotbar.left") || InputManager.MouseScrollWheel > 0)
                {
                    HeldSlot -= 1;
                    HeldSlot  = FastMath.Normalise(HeldSlot, 0, 9);
                }

                //Slot based on keypress
                if (InputManager.Released("hotbar.one"))
                {
                    HeldSlot = 0;
                }
                if (InputManager.Released("hotbar.two"))
                {
                    HeldSlot = 1;
                }
                if (InputManager.Released("hotbar.three"))
                {
                    HeldSlot = 2;
                }
                if (InputManager.Released("hotbar.four"))
                {
                    HeldSlot = 3;
                }
                if (InputManager.Released("hotbar.five"))
                {
                    HeldSlot = 4;
                }
                if (InputManager.Released("hotbar.six"))
                {
                    HeldSlot = 5;
                }
                if (InputManager.Released("hotbar.seven"))
                {
                    HeldSlot = 6;
                }
                if (InputManager.Released("hotbar.eight"))
                {
                    HeldSlot = 7;
                }
                if (InputManager.Released("hotbar.nine"))
                {
                    HeldSlot = 8;
                }
                #endregion

                // check mouse for rotating
                float lx = InputManager.MouseDeltaX * LookVelocity * GameSettings.MouseSensitivity;
                float ly = InputManager.MouseDeltaY * LookVelocity * GameSettings.MouseSensitivity;

                if (GameSettings.HeadBobbing)
                {
                    headBob.X    += move.X * Time.DeltaTime;
                    headBob.Y    += move.Z * Time.DeltaTime;
                    camera.offset = new Vector3(0, (float)Math.Sin(headBob.X * 5f) * 0.0625f, (float)Math.Sin(headBob.Y * 5f) * 0.125f);
                }

                // move and rotate the camera
                //move.Normalize();
                ApplyForce(move * moveUnits);
                camera.Rotate(lx, ly);
                camera.position = position + eyePosition;

                rotation     = camera.rotation;
                headRotation = new Vector2(camera.Yaw, camera.Pitch);

                #endregion

                #region Block Handling
                //Handle the block selection
                Vector2 mouseloc = new Vector2(GameClient.ViewWidth / 2 + lx, GameClient.ViewHeight / 2 + ly);

                LookingDir = RaytraceUtils.GetRay(mouseloc, camera.ViewMatrix, camera.ProjectionMatrix, GameClient.Viewport);

                rayHit = RaytraceUtils.RayTraceBlocks(LookingDir);

                if (rayHit != null && rayHit.typeOfHit == RayTraceResult.Type.BLOCK)
                {
                    SelectedBlock = rayHit.hitVec.ToVector3Int();
                }

                //Block placing / breaking
                if (BlockCooldownTimer <= 0f)
                {
                    if (InputManager.IsPressed("item.break") && rayHit != null && GameClient.theWorld.GetBlockIdAt(RaytraceUtils.GetBreakBlock(rayHit)) != 0)
                    {
                        //TODO: breaking logic
                        GameClient.theWorld.SetBlockAt(RaytraceUtils.GetBreakBlock(rayHit), 0, (uint)BlockBreakReason.PLAYER_CREATIVE);
                        BlockCooldownTimer = BlockCooldown;
                        SelectedBlock      = RaytraceUtils.GetBreakBlock(rayHit);
                    }

                    //Block placement
                    if (InputManager.IsPressed("item.use") && rayHit != null && GameClient.theWorld.GetBlockIdAt(RaytraceUtils.GetPlaceBlock(rayHit)) == BlockManager.AIR.Id && !Intersects(position, HeldBlock, RaytraceUtils.GetPlaceBlock(rayHit)))
                    {
                        //GameClient.theWorld.SetBlockAt(RaytraceUtils.GetPlaceBlock(rayHit), HeldBlock, (byte)BlockPlaceReason.PLAYER);
                        BlockCooldownTimer = BlockCooldown;
                        SelectedBlock      = RaytraceUtils.GetPlaceBlock(rayHit);
                        ItemManager.GetItem(inventory.items[HeldSlot].ItemID).OnUse(this, RaytraceUtils.GetBreakBlock(rayHit), SelectedBlock, BlockPlaceReason.PLAYER);
                    }
                }
                else
                {
                    BlockCooldownTimer -= GameClient.RawDeltaTime;

                    if (!InputManager.IsPressed("item.break") && !InputManager.IsPressed("item.use"))
                    {
                        //none of the buttons are held
                        //reset the timer
                        BlockCooldownTimer = 0f;
                    }
                }

                //Orthographic camera mode
                if (InputManager.IsPressed("debug.hotkey") && InputManager.Released("debug.orthographic"))
                {
                    Ortho = !Ortho;
                }

                //Highlight the block after placing
                if (rayHit != null && rayHit.typeOfHit == RayTraceResult.Type.BLOCK)
                {
                    Block id = BlockManager.GetBlock(GameClient.theWorld.GetBlockIdAt(SelectedBlock));

                    RenderUtils.RenderBox(id.GetBoundingBox(SelectedBlock).Offset(new Vector3(-0.5f, -0.5f, -0.5f)), GameSettings.BlockOutlineColor, GameSettings.BlockOutlineWidth);
                }
                #endregion

                // update previous states
                InputManager.CenterMouse();

                //Snooping
                Snooper.Snoop("move.totaldistance", Vector3.Distance(previousPosition, position));
            }

            previousPosition = position;
            base.Update();
        }