当前位置: 首页>>代码示例>>C#>>正文


C# Game.Dist方法代码示例

本文整理汇总了C#中Game.Dist方法的典型用法代码示例。如果您正苦于以下问题:C# Game.Dist方法的具体用法?C# Game.Dist怎么用?C# Game.Dist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Game的用法示例。


在下文中一共展示了Game.Dist方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnNewFrameDraw3d

    public override void OnNewFrameDraw3d(Game game, float deltaTime)
    {
        for (int i = 0; i < game.entitiesCount; i++)
        {
            Entity e = game.entities[i];
            if (e == null)
            {
                continue;
            }
            if (e.drawText == null)
            {
                continue;
            }
            if (e.networkPosition != null && (!e.networkPosition.PositionLoaded))
            {
                continue;
            }
            int kKey = i;
            EntityDrawText p = game.entities[i].drawText;
            float posX = - game.platform.MathSin(e.position.roty) * p.dx + e.position.x;
            float posY = p.dy + e.position.y;
            float posZ = game.platform.MathCos(e.position.roty) * p.dz + e.position.z;
            //todo if picking
            if ((game.Dist(game.player.position.x, game.player.position.y, game.player.position.z, posX, posY, posZ) < 20)
                || game.keyboardState[Game.KeyAltLeft] || game.keyboardState[Game.KeyAltRight])
            {
                string text = p.text;
                {

                    float shadow = (game.one * game.GetLight(game.platform.FloatToInt(posX), game.platform.FloatToInt(posZ), game.platform.FloatToInt(posY))) / Game.maxlight;

                    game.GLPushMatrix();
                    game.GLTranslate(posX, posY, posZ);

                    game.GLRotate(180, 1, 0, 0);
                    game.GLRotate(e.position.roty * 360 / (2 * Game.GetPi()), 0, 1, 0);
                    float scale = game.one * 5 / 1000;
                    game.GLScale(scale, scale, scale);

                    FontCi font = new FontCi();
                    font.family = "Arial";
                    font.size = 14;
                    game.Draw2dText(text, font, -game.TextSizeWidth(text, 14) / 2, 0, IntRef.Create(Game.ColorFromArgb(255, 255, 255, 255)), true);

                    game.GLPopMatrix();
                }
            }
        }
    }
开发者ID:MagistrAVSH,项目名称:manicdigger,代码行数:49,代码来源:DrawText.ci.cs

示例2: OnNewFrameDraw3d

    public override void OnNewFrameDraw3d(Game game, float dt)
    {
        for (int i = 0; i < game.entitiesCount; i++)
        {
            Entity entity = game.entities[i];
            if (entity == null) { continue; }
            if (entity.bullet == null) { continue; }

            Bullet_ b = entity.bullet;
            if (b.progress < 1)
            {
                b.progress = 1;
            }

            float dirX = b.toX - b.fromX;
            float dirY = b.toY - b.fromY;
            float dirZ = b.toZ - b.fromZ;
            float length = game.Dist(0, 0, 0, dirX, dirY, dirZ);
            dirX /= length;
            dirY /= length;
            dirZ /= length;

            float posX = b.fromX;
            float posY = b.fromY;
            float posZ = b.fromZ;
            posX += dirX * (b.progress + b.speed * dt);
            posY += dirY * (b.progress + b.speed * dt);
            posZ += dirZ * (b.progress + b.speed * dt);
            b.progress += b.speed * dt;

            entity.sprite.positionX = posX;
            entity.sprite.positionY = posY;
            entity.sprite.positionZ = posZ;

            if (b.progress > length)
            {
                game.entities[i] = null;
            }
        }
    }
开发者ID:MagistrAVSH,项目名称:manicdigger,代码行数:40,代码来源:Bullet.ci.cs

示例3: OnNewFrameFixed

    public override void OnNewFrameFixed(Game game, NewFrameEventArgs args)
    {
        game.pushX = 0;
        game.pushY = 0;
        game.pushZ = 0;

        float LocalPlayerPositionX = game.player.position.x;
        float LocalPlayerPositionY = game.player.position.y;
        float LocalPlayerPositionZ = game.player.position.z;
        for (int i = 0; i < game.entitiesCount; i++)
        {
            Entity entity = game.entities[i];
            if (entity == null) { continue; }
            if (entity.push == null) { continue; }
            //Prevent players that aren't displayed from pushing
            if (entity.networkPosition != null && !entity.networkPosition.PositionLoaded) { continue; }
            float kposX = game.DeserializeFloat(entity.push.XFloat);
            float kposY = game.DeserializeFloat(entity.push.ZFloat);
            float kposZ = game.DeserializeFloat(entity.push.YFloat);
            if (entity.push.IsRelativeToPlayerPosition != 0)
            {
                kposX += LocalPlayerPositionX;
                kposY += LocalPlayerPositionY;
                kposZ += LocalPlayerPositionZ;
            }
            float dist = game.Dist(kposX, kposY, kposZ, LocalPlayerPositionX, LocalPlayerPositionY, LocalPlayerPositionZ);
            if (dist < game.DeserializeFloat(entity.push.RangeFloat))
            {
                float diffX = LocalPlayerPositionX - kposX;
                float diffY = LocalPlayerPositionY - kposY;
                float diffZ = LocalPlayerPositionZ - kposZ;
                game.pushX += diffX;
                game.pushY += diffY;
                game.pushZ += diffZ;
            }
        }
    }
开发者ID:MagistrAVSH,项目名称:manicdigger,代码行数:37,代码来源:Push.ci.cs

示例4: OnNewFrameFixed

    public override void OnNewFrameFixed(Game game, NewFrameEventArgs args)
    {
        float one = 1;
        float dt = args.GetDt();

        if (game.guistate == GuiState.MapLoading) { return; }

        bool angleup = false;
        bool angledown = false;
        float overheadcameraanglemovearea = one * 5 / 100;
        float overheadcameraspeed = 3;
        game.controls.wantsjump = game.guistate == GuiState.Normal && game.GuiTyping == TypingState.None && game.keyboardState[game.GetKey(GlKeys.Space)];
        game.controls.wantsjumphalf = false;
        game.controls.shiftkeydown = game.guistate == GuiState.Normal && game.GuiTyping == TypingState.None && game.keyboardState[game.GetKey(GlKeys.ShiftLeft)];
        game.controls.movedx = 0;
        game.controls.movedy = 0;
        game.controls.moveup = false;
        game.controls.movedown = false;
        if (game.guistate == GuiState.Normal)
        {
            if (game.GuiTyping == TypingState.None)
            {
                if (game.reachedwall_1blockhigh && (game.AutoJumpEnabled || (!game.platform.IsMousePointerLocked())))
                {
                    game.controls.wantsjump = true;
                }
                if (game.reachedHalfBlock)
                {
                    game.controls.wantsjumphalf = true;
                }
                if (game.overheadcamera)
                {
                    CameraMove m = new CameraMove();
                    if (game.keyboardState[game.GetKey(GlKeys.A)]) { game.overheadcameraK.TurnRight(dt * overheadcameraspeed); }
                    if (game.keyboardState[game.GetKey(GlKeys.D)]) { game.overheadcameraK.TurnLeft(dt * overheadcameraspeed); }
                    if (game.keyboardState[game.GetKey(GlKeys.W)]) { angleup = true; }
                    if (game.keyboardState[game.GetKey(GlKeys.S)]) { angledown = true; }
                    game.overheadcameraK.Center.X = game.player.position.x;
                    game.overheadcameraK.Center.Y = game.player.position.y;
                    game.overheadcameraK.Center.Z = game.player.position.z;
                    m.Distance = game.overheadcameradistance;
                    m.AngleUp = angleup;
                    m.AngleDown = angledown;
                    game.overheadcameraK.Move(m, dt);
                    float toDest = game.Dist(game.player.position.x, game.player.position.y, game.player.position.z,
                    game.playerdestination.X + one / 2, game.playerdestination.Y - one / 2, game.playerdestination.Z + one / 2);
                    if (toDest >= 1)
                    {
                        game.controls.movedy += 1;
                        if (game.reachedwall)
                        {
                            game.controls.wantsjump = true;
                        }
                        //player orientation
                        float qX = game.playerdestination.X - game.player.position.x;
                        float qY = game.playerdestination.Y - game.player.position.y;
                        float qZ = game.playerdestination.Z - game.player.position.z;
                        float angle = game.VectorAngleGet(qX, qY, qZ);
                        game.player.position.roty = Game.GetPi() / 2 + angle;
                        game.player.position.rotx = Game.GetPi();
                    }
                }
                else if (game.enable_move)
                {
                    if (game.keyboardState[game.GetKey(GlKeys.W)]) { game.controls.movedy += 1; }
                    if (game.keyboardState[game.GetKey(GlKeys.S)]) { game.controls.movedy += -1; }
                    if (game.keyboardState[game.GetKey(GlKeys.A)]) { game.controls.movedx += -1; game.localplayeranimationhint.leanleft = true; game.localstance = 1; }
                    else { game.localplayeranimationhint.leanleft = false; }
                    if (game.keyboardState[game.GetKey(GlKeys.D)]) { game.controls.movedx += 1; game.localplayeranimationhint.leanright = true; game.localstance = 2; }
                    else { game.localplayeranimationhint.leanright = false; }
                    if (!game.localplayeranimationhint.leanleft && !game.localplayeranimationhint.leanright) { game.localstance = 0; }

                    game.controls.movedx += game.touchMoveDx;
                    game.controls.movedy += game.touchMoveDy;
                }
            }
            if (game.controls.freemove || game.SwimmingEyes())
            {
                if (game.GuiTyping == TypingState.None && game.keyboardState[game.GetKey(GlKeys.Space)])
                {
                    game.controls.moveup = true;
                }
                if (game.GuiTyping == TypingState.None && game.keyboardState[game.GetKey(GlKeys.ControlLeft)])
                {
                    game.controls.movedown = true;
                }
            }
        }
    }
开发者ID:MagistrAVSH,项目名称:manicdigger,代码行数:89,代码来源:CameraKeys.ci.cs

示例5: PickEntity

    void PickEntity(Game game, Line3D pick, BlockPosSide[] pick2, IntRef pick2count)
    {
        game.SelectedEntityId = -1;
        game.currentlyAttackedEntity = -1;
        float one = 1;
        for (int i = 0; i < game.entitiesCount; i++)
        {
            if (game.entities[i] == null)
            {
                continue;
            }
            if (i == game.LocalPlayerId)
            {
                continue;
            }
            if (game.entities[i].drawModel == null)
            {
                continue;
            }
            Entity p_ = game.entities[i];
            if (p_.networkPosition == null)
            {
                continue;
            }
            if (!p_.networkPosition.PositionLoaded)
            {
                continue;
            }
            if (!p_.usable)
            {
                continue;
            }
            float feetposX = p_.position.x;
            float feetposY = p_.position.y;
            float feetposZ = p_.position.z;

            float dist = game.Dist(feetposX, feetposY, feetposZ, game.player.position.x, game.player.position.y, game.player.position.z);
            if (dist > 5)
            {
                continue;
            }

            //var p = PlayerPositionSpawn;
            Box3D bodybox = new Box3D();
            float h = p_.drawModel.ModelHeight;
            float r = one * 35 / 100;

            bodybox.AddPoint(feetposX - r, feetposY + 0, feetposZ - r);
            bodybox.AddPoint(feetposX - r, feetposY + 0, feetposZ + r);
            bodybox.AddPoint(feetposX + r, feetposY + 0, feetposZ - r);
            bodybox.AddPoint(feetposX + r, feetposY + 0, feetposZ + r);

            bodybox.AddPoint(feetposX - r, feetposY + h, feetposZ - r);
            bodybox.AddPoint(feetposX - r, feetposY + h, feetposZ + r);
            bodybox.AddPoint(feetposX + r, feetposY + h, feetposZ - r);
            bodybox.AddPoint(feetposX + r, feetposY + h, feetposZ + r);

            float[] p;
            float localeyeposX = game.EyesPosX();
            float localeyeposY = game.EyesPosY();
            float localeyeposZ = game.EyesPosZ();
            p = Intersection.CheckLineBoxExact(pick, bodybox);
            if (p != null)
            {
                //do not allow to shoot through terrain
                if (pick2count.value == 0 || (game.Dist(pick2[0].blockPos[0], pick2[0].blockPos[1], pick2[0].blockPos[2], localeyeposX, localeyeposY, localeyeposZ)
                    > game.Dist(p[0], p[1], p[2], localeyeposX, localeyeposY, localeyeposZ)))
                {
                    game.SelectedEntityId = i;
                    if (game.cameratype == CameraType.Fpp || game.cameratype == CameraType.Tpp)
                    {
                        game.currentlyAttackedEntity = i;
                    }
                }
            }
        }
    }
开发者ID:YoungGames,项目名称:manicdigger,代码行数:77,代码来源:Picking.ci.cs

示例6: NextBullet


//.........这里部分代码省略.........

        if (ispistol && game.mouserightclick && (game.platform.TimeMillisecondsFromStart() - game.lastironsightschangeMilliseconds) >= 500)
        {
            game.IronSights = !game.IronSights;
            game.lastironsightschangeMilliseconds = game.platform.TimeMillisecondsFromStart();
        }

        IntRef pick2count = new IntRef();
        Line3D pick = new Line3D();
        GetPickingLine(game, pick, ispistolshoot);
        BlockPosSide[] pick2 = game.Pick(game.s, pick, pick2count);

        if (left)
        {
            game.handSetAttackDestroy = true;
        }
        else if (right)
        {
            game.handSetAttackBuild = true;
        }

        if (game.overheadcamera && pick2count.value > 0 && left)
        {
            //if not picked any object, and mouse button is pressed, then walk to destination.
            if (game.Follow == null)
            {
                //Only walk to destination when not following someone
                game.playerdestination = Vector3Ref.Create(pick2[0].blockPos[0], pick2[0].blockPos[1] + 1, pick2[0].blockPos[2]);
            }
        }
        bool pickdistanceok = (pick2count.value > 0); //&& (!ispistol);
        if (pickdistanceok)
        {
            if (game.Dist(pick2[0].blockPos[0] + one / 2, pick2[0].blockPos[1] + one / 2, pick2[0].blockPos[2] + one / 2,
                pick.Start[0], pick.Start[1], pick.Start[2]) > CurrentPickDistance(game))
            {
                pickdistanceok = false;
            }
        }
        bool playertileempty = game.IsTileEmptyForPhysics(
                  game.platform.FloatToInt(game.player.position.x),
                  game.platform.FloatToInt(game.player.position.z),
                  game.platform.FloatToInt(game.player.position.y + (one / 2)));
        bool playertileemptyclose = game.IsTileEmptyForPhysicsClose(
                  game.platform.FloatToInt(game.player.position.x),
                  game.platform.FloatToInt(game.player.position.z),
                  game.platform.FloatToInt(game.player.position.y + (one / 2)));
        BlockPosSide pick0 = new BlockPosSide();
        if (pick2count.value > 0 &&
            ((pickdistanceok && (playertileempty || (playertileemptyclose)))
            || game.overheadcamera)
            )
        {
            game.SelectedBlockPositionX = game.platform.FloatToInt(pick2[0].Current()[0]);
            game.SelectedBlockPositionY = game.platform.FloatToInt(pick2[0].Current()[1]);
            game.SelectedBlockPositionZ = game.platform.FloatToInt(pick2[0].Current()[2]);
            pick0 = pick2[0];
        }
        else
        {
            game.SelectedBlockPositionX = -1;
            game.SelectedBlockPositionY = -1;
            game.SelectedBlockPositionZ = -1;
            pick0.blockPos = new float[3];
            pick0.blockPos[0] = -1;
            pick0.blockPos[1] = -1;
开发者ID:YoungGames,项目名称:manicdigger,代码行数:67,代码来源:Picking.ci.cs

示例7: OnNewFrameDraw3d

    public override void OnNewFrameDraw3d(Game game, float deltaTime)
    {
        for (int i = 0; i < game.entitiesCount; i++)
        {
            Entity e = game.entities[i];
            if (e == null)
            {
                continue;
            }
            if (e.drawName == null)
            {
                continue;
            }
            if (i == game.LocalPlayerId)
            {
                continue;
            }
            if (e.networkPosition != null && (!e.networkPosition.PositionLoaded))
            {
                continue;
            }
            int kKey = i;
            DrawName p = game.entities[i].drawName;
            if (p.OnlyWhenSelected)
            {
                continue;
            }
            float posX = p.TextX + e.position.x;
            float posY = p.TextY + e.position.y + e.drawModel.ModelHeight + game.one * 7 / 10;
            float posZ = p.TextZ + e.position.z;
            //todo if picking
            if ((game.Dist(game.player.position.x, game.player.position.y, game.player.position.z, posX, posY, posZ) < 20)
                || game.keyboardState[Game.KeyAltLeft] || game.keyboardState[Game.KeyAltRight])
            {
                string name = p.Name;
                {

                    float shadow = (game.one * game.GetLight(game.platform.FloatToInt(posX), game.platform.FloatToInt(posZ), game.platform.FloatToInt(posY))) / Game.maxlight;
                    //do not interpolate player position if player is controlled by game world
                    //if (EnablePlayerUpdatePositionContainsKey(kKey) && !EnablePlayerUpdatePosition(kKey))
                    //{
                    //    posX = p.NetworkX;
                    //    posY = p.NetworkY;
                    //    posZ = p.NetworkZ;
                    //}
                    game.GLPushMatrix();
                    game.GLTranslate(posX, posY, posZ);
                    //if (p.Type == PlayerType.Monster)
                    //{
                    //    GLTranslate(0, 1, 0);
                    //}
                    ModDrawSprites.Billboard(game);
                    float scale = game.one * 2 / 100;
                    game.GLScale(scale, scale, scale);

                    //Color c = Color.FromArgb((int)(shadow * 255), (int)(shadow * 255), (int)(shadow * 255));
                    //Todo: Can't change text color because text has outline anyway.
                    if (p.DrawHealth)
                    {
                        game.Draw2dTexture(game.WhiteTexture(), -26, -11, 52, 12, null, 0, Game.ColorFromArgb(255, 0, 0, 0), false);
                        game.Draw2dTexture(game.WhiteTexture(), -25, -10, 50 * (game.one * p.Health), 10, null, 0, Game.ColorFromArgb(255, 255, 0, 0), false);
                    }
                    FontCi font = new FontCi();
                    font.family = "Arial";
                    font.size = 14;
                    game.Draw2dText(name, font, -game.TextSizeWidth(name, 14) / 2, 0, IntRef.Create(Game.ColorFromArgb(255, 255, 255, 255)), true);
                    //                        GL.Translate(0, 1, 0);
                    game.GLPopMatrix();
                }
            }
        }
    }
开发者ID:MagistrAVSH,项目名称:manicdigger,代码行数:72,代码来源:DrawPlayerNames.ci.cs


注:本文中的Game.Dist方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。