Esempio n. 1
0
 private void StartPlane()
 {
     plane = new Plane();
     plane.Size = 40;
     plane.X = 0;
     Random rand = new Random();
     plane.Y = rand.Next(0, gPnlField.Height - plane.Size - 50);
     plane.FieldArea = gPnlField.ClientRectangle;
     plane.HitTimes = 0;
     plane.IsHit = false;
     plane.Speed = 5;
     g = this.gPnlField.CreateGraphics();
     plane.Draw(g);
 }
Esempio n. 2
0
        private void AddBlock(float dist)
        {
            string name = VanillaChunk.byteToString[Selector.SelectedId];
            if (name == "") { return; }

            if (this.GetSelectedNPC() != null) { return; }

            /* Determine the face */
            Ray ray = this.mStateMgr.Camera.GetCameraToViewportRay(0.5f, 0.5f);
            Vector3 realIntersection = ray.GetPoint(dist);
            Vector3 absPosBlock = this.SelectedBlockPos * Cst.CUBE_SIDE;

            int index = 0;
            float minDist = -1;
            Vector3[] points = VanillaMultiBlock.blockPointCoords;
            for (int i = 0; i < points.Length; i += 4)
            {
                Plane p = new Plane(points[i] + absPosBlock, points[i + 1] + absPosBlock, points[i + 2] + absPosBlock);
                Vector3 intersection = ray.GetPoint(- (p.d + Vector3Sum(p.normal * ray.Origin)) / Vector3Sum(p.normal * ray.Direction));

                float actDist = (realIntersection - intersection).SquaredLength;    // No need to take the real distance

                if (minDist < 0 || actDist < minDist)
                {
                    minDist = actDist;
                    index = i / 4;
                }
            }

            BlockFace face = (BlockFace)index;
            Vector3 addedBlockPos = this.SelectedBlockPos;

            switch (face)
            {
                case BlockFace.underFace:
                    addedBlockPos.y--;
                    break;
                case BlockFace.upperFace:
                    addedBlockPos.y++;
                    break;
                case BlockFace.leftFace:
                    addedBlockPos.x--;
                    break;
                case BlockFace.rightFace:
                    addedBlockPos.x++;
                    break;
                case BlockFace.backFace:
                    addedBlockPos.z--;
                    break;
                default:    // frontFace
                    addedBlockPos.z++;
                    break;
            }

            if (addedBlockPos == MainWorld.AbsToRelative(this.mStateMgr.Camera.Position) || !(this.mWorld.getIsland().getBlock(addedBlockPos, false) is Air) ||
               (this.mStateMgr.MainState.CharacMgr.MainPlayer != null && this.mStateMgr.MainState.CharacMgr.MainPlayer.CollisionMgr.GetHitPoints().Any
               (v => MathHelper.isInBlock(addedBlockPos * Cst.CUBE_SIDE, v, Cst.CUBE_SIDE)))) { return; }

            this.mWorld.getIsland().setBlockAt(addedBlockPos, name, true);
            this.mWorld.onCreation(addedBlockPos);

            if (!this.mStateMgr.GameInfo.IsInEditorMode)
                this.Inventory.removeAt(Selector.SelectorPos, 3, 1);
        }
Esempio n. 3
0
        //Draw minimap
        void Minimap_RenderUI( EControl sender, GuiRenderer renderer )
        {
            Rect screenMapRect = sender.GetScreenRectangle();

            Bounds initialBounds = Map.Instance.InitialCollisionBounds;
            Rect mapRect = new Rect( initialBounds.Minimum.ToVec2(), initialBounds.Maximum.ToVec2() );

            Vec2 mapSizeInv = new Vec2( 1, 1 ) / mapRect.Size;

            //draw units
            Vec2 screenPixel = new Vec2( 1, 1 ) / new Vec2( EngineApp.Instance.VideoMode.Size.ToVec2() );

            foreach( Entity entity in Map.Instance.Children )
            {
                RTSUnit unit = entity as RTSUnit;
                if( unit == null )
                    continue;

                Rect rect = new Rect( unit.MapBounds.Minimum.ToVec2(), unit.MapBounds.Maximum.ToVec2() );

                rect -= mapRect.Minimum;
                rect.Minimum *= mapSizeInv;
                rect.Maximum *= mapSizeInv;
                rect.Minimum = new Vec2( rect.Minimum.X, 1.0f - rect.Minimum.Y );
                rect.Maximum = new Vec2( rect.Maximum.X, 1.0f - rect.Maximum.Y );
                rect.Minimum *= screenMapRect.Size;
                rect.Maximum *= screenMapRect.Size;
                rect += screenMapRect.Minimum;

                //increase 1 pixel
                rect.Maximum += new Vec2( screenPixel.X, -screenPixel.Y );

                ColorValue color;

                if( playerFaction == null || unit.Intellect == null || unit.Intellect.Faction == null )
                    color = new ColorValue( 1, 1, 0 );
                else if( playerFaction == unit.Intellect.Faction )
                    color = new ColorValue( 0, 1, 0 );
                else
                    color = new ColorValue( 1, 0, 0 );

                renderer.AddQuad( rect, color );
            }

            //Draw camera borders
            {
                Camera camera = RendererWorld.Instance.DefaultCamera;

                if( camera.Position.Z > 0 )
                {

                    Plane groundPlane = new Plane( 0, 0, 1, 0 );

                    Vec2[] points = new Vec2[ 4 ];

                    for( int n = 0; n < 4; n++ )
                    {
                        Vec2 p = Vec2.Zero;

                        switch( n )
                        {
                        case 0: p = new Vec2( 0, 0 ); break;
                        case 1: p = new Vec2( 1, 0 ); break;
                        case 2: p = new Vec2( 1, 1 ); break;
                        case 3: p = new Vec2( 0, 1 ); break;
                        }

                        Ray ray = camera.GetCameraToViewportRay( p );

                        float scale;
                        groundPlane.RayIntersection( ray, out scale );

                        Vec3 pos = ray.GetPointOnRay( scale );
                        if( ray.Direction.Z > 0 )
                            pos = ray.Origin + ray.Direction.GetNormalize() * 10000;

                        Vec2 point = pos.ToVec2();

                        point -= mapRect.Minimum;
                        point *= mapSizeInv;
                        point = new Vec2( point.X, 1.0f - point.Y );
                        point *= screenMapRect.Size;
                        point += screenMapRect.Minimum;

                        points[ n ] = point;
                    }

                    for( int n = 0; n < 4; n++ )
                        renderer.AddLine( points[ n ], points[ ( n + 1 ) % 4 ], new ColorValue( 1, 1, 1 ),
                            screenMapRect );
                }
            }
        }
Esempio n. 4
0
        bool GetGameAreaCursorPosition( out Vec2 position )
        {
            position = Vec2.Zero;

            Plane plane = new Plane( 0, 0, 1, 0 );

            Ray ray = RendererWorld.Instance.DefaultCamera.GetCameraToViewportRay(
                EngineApp.Instance.MousePosition );
            if( float.IsNaN( ray.Direction.X ) )
                return false;

            float scale;
            if( !plane.RayIntersection( ray, out scale ) )
                return false;

            position = ray.GetPointOnRay( scale ).ToVec2();
            return true;
        }