public void Draw(GameTime gameTime, GraphicsDevice graphicsDevice, SpriteBatch spriteBatch)
        {
            switch (_currentMap)
            {
                case SimulationScreenMap.Urban: _playerGame.UrbanMap.Draw(gameTime); break;
                case SimulationScreenMap.Country: _playerGame.CountryMap.Draw(gameTime); break;
                case SimulationScreenMap.Ocean: _playerGame.OceanMap.Draw(gameTime); break;
            }

            spriteBatch.DrawLine(150, 0, 150, graphicsDevice.Viewport.Height, Color.White);
            spriteBatch.DrawLine(0, graphicsDevice.Viewport.Height - 100, graphicsDevice.Viewport.Width,
                graphicsDevice.Viewport.Height - 100, Color.White);

            /* Area selection */
            Rectangle areaSelectionUrban = new Rectangle(5, graphicsDevice.Viewport.Height - 148, 43, 43);
            Rectangle areaSelectionCountry = new Rectangle(53, graphicsDevice.Viewport.Height - 148, 43, 43);
            Rectangle areaSelectionOcean = new Rectangle(101, graphicsDevice.Viewport.Height - 148, 43, 43);
            spriteBatch.DrawRectangle(0, graphicsDevice.Viewport.Height - 174, 150, 75, Color.White);
            spriteBatch.FillRectangle(areaSelectionUrban, (_currentMap == SimulationScreenMap.Urban ?
                Color.LightGray : Color.Gray));
            spriteBatch.DrawRectangle(areaSelectionUrban, Color.White);
            spriteBatch.FillRectangle(areaSelectionCountry, (_currentMap == SimulationScreenMap.Country ?
                Color.LightGray : Color.Gray));
            spriteBatch.DrawRectangle(areaSelectionCountry, Color.White);
            spriteBatch.FillRectangle(areaSelectionOcean, (_currentMap == SimulationScreenMap.Ocean ?
                Color.LightGray : Color.Gray));
            spriteBatch.DrawRectangle(areaSelectionOcean, Color.White);
        }
Example #2
0
 public void Draw(SpriteBatch spriteBatch)
 {
     spriteBatch.FillRectangle(Position, Size, BaseColor);
     spriteBatch.DrawRectangle(Position, Size, BorderColor);
     spriteBatch.DrawString(Font, Label + ": " + CurrentValue + " / " + MaxValue,
         new Vector2(Position.X + 1, Position.Y + Size.Y - Font.MeasureString(Label + ": " +
         CurrentValue + " / " + MaxValue).Y), TextColor);
 }
Example #3
0
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if (BackgroundColor.HasValue)
                spriteBatch.DrawRectangle(new Rectangle((int)Position.X, (int)Position.Y, Size.X, Size.Y), BackgroundColor.Value * Alpha);
            
            if (BackgroundTexture != null)
                spriteBatch.Draw(BackgroundTexture, new Rectangle((int)Position.X, (int)Position.Y, Size.X, Size.Y), Color.White * Alpha);

            base.Draw(gameTime, spriteBatch);
        }
 public void Draw(SpriteBatch sb, GameTime gameTime)
 {
     foreach (Enemy e in Enemies)
     {
         e.Draw(sb, gameTime);
         if (e != closestEnemy) continue;
         sb.DrawRectangle(e.HitBox, Color.Red);
     /*
         Stencil.Write("D: " + Math.Round((e.Center - player.Center).Length(), 1, MidpointRounding.AwayFromZero), sb, e.X + 4, e.Y + e.Height - 3, 0.5f);
         Stencil.Write("A: " + Math.Round(MathHelper.ToDegrees(player.Center.Angle(e.Center)), 1, MidpointRounding.AwayFromZero), sb, e.X + 4, e.Y + e.Height + 9, 0.5f);
         Stencil.Write("L: " + e.Health, sb, e.X + 4, e.Y + e.Height + 21, 0.5F);
     */
         if (e.Center.Y > 0)
             sb.DrawLine(e.Center, player.Center, Color.Red);
     }
 }
        protected override void Draw()
        {
            GraphicsDevice.Clear(Microsoft.Xna.Framework.Color.Black);

            if (MapEditorGlobals.CurrentActiveTexture == null)
                return;

            var spriteBatch = new SpriteBatch(GraphicsDevice);

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
            spriteBatch.Draw(MapEditorGlobals.CurrentActiveTexture, new Vector2(0, 0), Microsoft.Xna.Framework.Color.White);

            spriteBatch.DrawRectangle(MapEditorGlobals.RectangleSelectedTiles, Microsoft.Xna.Framework.Color.Yellow, 4f);

            spriteBatch.End();
        }
Example #6
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, null, ServiceManager.Camera.GetTransformation());

            foreach (var entity in ServiceManager.EntityCollection.Entities)
            {
                // Local players can be moved automatically, then report their status if needed
                var skinComponent = entity.GetComponent<SkinComponent>();
                // TODO: Make it so we can get the sprite descriptors from the sprite service.
                var spriteDescriptor = entity.GetComponent<SpriteComponent>().SpriteDescriptor;
                var transformComponent = entity.GetComponent<TransformComponent>();

                Rectangle bbox = new Rectangle(
                    (int)(transformComponent.LocalPosition.X + spriteDescriptor.BoundingBox.X),
                    (int)(transformComponent.LocalPosition.Y + spriteDescriptor.BoundingBox.Y),
                    spriteDescriptor.BoundingBox.Width,
                    spriteDescriptor.BoundingBox.Height);

                spriteBatch.DrawRectangle(bbox, Color.White, 2f);
            }

            spriteBatch.End();
        }
Example #7
0
        public void Draw(SpriteBatch spriteBatch)
        {
            SpriteEffects spriteEffect;
            if (velocity.X < 0)
            {
                spriteEffect = SpriteEffects.FlipHorizontally;
            }
            else { spriteEffect = SpriteEffects.None; }

            if (Math.Abs(velocity.X) < 30)
            {
                currentAnimation.Active = false;
                currentAnimation.currentFrame = 0;
                playerSprite.Flip = spriteEffect;
                playerSprite.Draw(spriteBatch);
            }
            else //we are running
            {
                currentAnimation.Active = true;
                currentAnimation = runningAnimation;
                currentAnimation.spriteEffects = spriteEffect;
                currentAnimation.Draw(spriteBatch);
            }

            spriteBatch.DrawRectangle(playerBounds, Color.Red);

             #if DEBUG
            spriteBatch.DrawRectangle(playerBounds,Color.Red);
             #endif
        }
Example #8
0
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            base.Draw(gameTime, spriteBatch);

            if (HighlightedMove == null)
                return;

            var sine = (1.0F + (float)(Math.Sin((float)gameTime.TotalGameTime.TotalSeconds * 6.0F) * 1.0F)) / 2.0F;
            spriteBatch.DrawRectangle(GetAnimalRectangle(HighlightedMove.From), Color.Black * Math.Max(0.0F, sine * 0.25F));
            spriteBatch.DrawRectangle(GetAnimalRectangle(HighlightedMove.To), Color.Black * Math.Max(0.0F, sine * 0.25F));
        }
Example #9
0
        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(this.texture, guidePosition, guideSourceRect, Color.White);
            //spriteBatch.Draw(this.texture, guidePosition, Color.White);

            // DEBUG: Draw locations of buttons and tabs
            if (Settings.SHOW_HITBOXES)
            {
                Vector2 openButtonPosition, closeButtonPosition, tab1, tab2, tab3, tab4, tabSize;
                tabSize = new Vector2(Settings.CALLOUT_TAB_WIDTH, Settings.CALLOUT_TAB_HEIGHT);
                if (this.IsLeftward)
                {
                    openButtonPosition = Settings.CALLOUT_OPEN_BUTTON_LEFT;
                    closeButtonPosition = Settings.CALLOUT_CLOSE_BUTTON_LEFT;
                    if (this.IsUpsideDown)
                    {
                        tab1 = -Settings.CALLOUT_TAB1_BUTTON;
                        tab2 = -Settings.CALLOUT_TAB2_BUTTON;
                        tab3 = -Settings.CALLOUT_TAB3_BUTTON;
                        tab4 = -Settings.CALLOUT_TAB4_BUTTON;
                    }
                    else
                    {
                        tab1 = Settings.CALLOUT_TAB1_BUTTON_LEFT;
                        tab2 = Settings.CALLOUT_TAB2_BUTTON_LEFT;
                        tab3 = Settings.CALLOUT_TAB3_BUTTON_LEFT;
                        tab4 = Settings.CALLOUT_TAB4_BUTTON_LEFT;
                    }
                }
                else
                {
                    openButtonPosition = Settings.CALLOUT_OPEN_BUTTON;
                    closeButtonPosition = Settings.CALLOUT_CLOSE_BUTTON;
                    if (this.IsUpsideDown)
                    {
                        tab1 = -Settings.CALLOUT_TAB1_BUTTON_LEFT;
                        tab2 = -Settings.CALLOUT_TAB2_BUTTON_LEFT;
                        tab3 = -Settings.CALLOUT_TAB3_BUTTON_LEFT;
                        tab4 = -Settings.CALLOUT_TAB4_BUTTON_LEFT;
                    }
                    else
                    {
                        tab1 = Settings.CALLOUT_TAB1_BUTTON;
                        tab2 = Settings.CALLOUT_TAB2_BUTTON;
                        tab3 = Settings.CALLOUT_TAB3_BUTTON;
                        tab4 = Settings.CALLOUT_TAB4_BUTTON;
                    }
                }
                if (this.CurrentState == Guide.GuideState.CLOSED)
                {
                    spriteBatch.DrawCircle(this.ParentZoomCircle.position + openButtonPosition, Settings.CALLOUT_DETECTION_RADIUS, 64, Color.Pink);
                }
                else if (this.CurrentState == Guide.GuideState.OPEN)
                {
                    spriteBatch.DrawCircle(this.ParentZoomCircle.position + closeButtonPosition, Settings.CALLOUT_DETECTION_RADIUS, 64, Color.Pink);
                    spriteBatch.DrawRectangle(this.ParentZoomCircle.position + new Vector2(tab1.X - tabSize.X / 2, tab1.Y - tabSize.Y / 2), tabSize, Color.Pink, 1f);
                    spriteBatch.DrawRectangle(this.ParentZoomCircle.position + new Vector2(tab2.X - tabSize.X / 2, tab2.Y - tabSize.Y / 2), tabSize, Color.Pink, 1f);
                    spriteBatch.DrawRectangle(this.ParentZoomCircle.position + new Vector2(tab3.X - tabSize.X / 2, tab3.Y - tabSize.Y / 2), tabSize, Color.Pink, 1f);
                    spriteBatch.DrawRectangle(this.ParentZoomCircle.position + new Vector2(tab4.X - tabSize.X / 2, tab4.Y - tabSize.Y / 2), tabSize, Color.Pink, 1f);
                }
            }
        }
Example #10
0
 public void DrawSelf(SpriteBatch spriteBatch, Color color)
 {
     spriteBatch.DrawRectangle(_bbox, color);
 }
 public void Draw(SpriteBatch sb, GameTime gameTime)
 {
     background.Draw(sb);
     sb.DrawRectangle(player.HitBox, Color.Red);
     phases.Draw(sb, gameTime);
     player.Draw(sb, gameTime);
 }
Example #12
0
		public override void Draw( SpriteBatch spriteBatch, float alpha ) {
			Color dynamicColor = new Color( new Vector4( ColorFgDefault.ToVector3(), alpha ) );
			Vector2 drawPos = Position;
			Vector2 textSize = SpriteFont.MeasureString( Text );
			string[] Lines = Text.Split( new char[] { '\n' } );

			if( ColorBgDefault != Color.Transparent ) {
				Color dynBg = new Color( new Vector4( ColorBgDefault.ToVector3(), alpha ) );
				mButtonArea = new Rectangle( (int)Position.X - Value, (int)Position.Y - Value, ControlSize.X, ControlSize.Y );
				if( ControlSize.X == 0 )
					mButtonArea.Width = (int)textSize.X + 5;
				if( ControlSize.Y == 0 )
					mButtonArea.Height = (int)textSize.Y + 5;

				if( mTextureBlank == null )
					mTextureBlank = EngineCore.ContentLoader.Load<Texture2D>( @"Interface\blank" );

				spriteBatch.Draw( mTextureBlank, mButtonArea, dynBg );
				if( BorderColor != Color.Transparent ) {
					Texture2D tex = DrawHelper.Rect2Texture( 1, 1, 0, BorderColor );
					spriteBatch.DrawRectangle( tex, mButtonArea, 1, BorderColor );
				}
			} else
				mButtonArea = new Rectangle( mButtonArea.X, mButtonArea.Y, ControlSize.X, ControlSize.Y );

			for( int i = 0; i < Lines.Length; i++ ) {
				if( i > 0 )
					drawPos.Y += SpriteFont.LineSpacing;
				spriteBatch.DrawString( SpriteFont, Lines[ i ], drawPos, dynamicColor );
			}

		}
 public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
 {
     spriteBatch.FillRectangle(Position, Size, (Hovered ? Color.LightBlue : Color.Blue));
     spriteBatch.DrawRectangle(Position, Size, Color.Black);
 }
Example #14
0
        public ViewPortInfo DrawWorldViewPort(SpriteBatch spriteBatch, Vector2 center, float zoom, Rectangle destRectangle, Color color, SamplerState samplerState, SpriteFont spriteFont=null)
        {
            ViewPortInfo viewPortInfo = new ViewPortInfo();
            {
                viewPortInfo.pxTileWidth  = (int) Math.Ceiling(Map.TileWidth * zoom);
                viewPortInfo.pxTileHeight = (int) Math.Ceiling(Map.TileHeight * zoom);

                // Note about ActualZoom Property:
                // because there is a loss of data between to conversion from Map.pxTileWidth * Zoom -> (int)
                // we need to determine what was the actual level of zoom that was applied to the tiles and use that
                // this ensures that entities that will be drawn will be placed correctly on the screen.
                viewPortInfo.ActualZoom = viewPortInfo.pxTileWidth / Map.TileWidth;

                viewPortInfo.pxWidth = destRectangle.Width / viewPortInfo.ActualZoom;
                viewPortInfo.pxHeight = destRectangle.Height / viewPortInfo.ActualZoom;

                viewPortInfo.pxTopLeftX = center.X - viewPortInfo.pxWidth / 2.0f;
                viewPortInfo.pxTopLeftY = center.Y - viewPortInfo.pxHeight / 2.0f;

                viewPortInfo.TileCountX = (int) Math.Ceiling((double)viewPortInfo.pxWidth / Map.TileWidth) + 1;
                viewPortInfo.TileCountY = (int) Math.Ceiling((double)viewPortInfo.pxHeight / Map.TileHeight) + 1;

                // Prevent the View from going outisde of the WORLD coordinates.
                if (viewPortInfo.pxTopLeftX < 0) viewPortInfo.pxTopLeftX = 0;
                if (viewPortInfo.pxTopLeftY < 0) viewPortInfo.pxTopLeftY = 0;

                if (viewPortInfo.pxTopLeftX + viewPortInfo.pxWidth >= Map.pxWidth)
                    viewPortInfo.pxTopLeftX = Map.pxWidth - viewPortInfo.pxWidth;
                if (viewPortInfo.pxTopLeftY + viewPortInfo.pxHeight >= Map.pxHeight)
                    viewPortInfo.pxTopLeftY = Map.pxHeight - viewPortInfo.pxHeight;

                // Calculate any decimal displacement required (For Positions with decimal points).
                viewPortInfo.pxDispX = viewPortInfo.pxTopLeftX - ((int)viewPortInfo.pxTopLeftX / Map.TileWidth) * Map.TileWidth;
                viewPortInfo.pxDispY = viewPortInfo.pxTopLeftY - ((int)viewPortInfo.pxTopLeftY / Map.TileHeight) * Map.TileHeight;

                viewPortInfo.pxViewPortBounds = new Rectangle(
                    (int) Math.Ceiling(viewPortInfo.pxTopLeftX),
                    (int) Math.Ceiling(viewPortInfo.pxTopLeftY),
                    (int) Math.Ceiling(viewPortInfo.pxWidth),
                    (int) Math.Ceiling(viewPortInfo.pxHeight)
                );
            }

            // RENDER THE GAME WORLD TO THE VIEWPORT RENDER TARGET
            GraphicsDevice.SetRenderTarget(_inputBuffer);
            GraphicsDevice.Clear(Map.Background);

            // DRAW THE WORLD MAP
            OverallPerformance.StartTiming("TileRenderingTime");

            // Deferred Rendering should be fine for rendering tile as long as we draw tile layers one at a time
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, samplerState, null, null);
            {
                for (int layerIndex = 0; layerIndex < Map.TileLayers.Count; layerIndex++)
                {
                    // DRAW EACH LAYER
                    TileLayer tileLayer = Map.TileLayers[layerIndex];

                    if (tileLayer.Visible)
                    {
                        Color layerColor = new Color()
                        {
                            R = tileLayer.Color.R,
                            G = tileLayer.Color.G,
                            B = tileLayer.Color.B,
                            A = (byte)(tileLayer.Color.A * tileLayer.Opacity)
                        };

                        float depth = 1 - (layerIndex / 10000.0f);

                        for (int i = 0; i < viewPortInfo.TileCountX; i++)
                        {
                            for (int j = 0; j < viewPortInfo.TileCountY; j++)
                            {
                                int tileX = (int)(i + viewPortInfo.pxTopLeftX / Map.TileWidth);
                                int tileY = (int)(j + viewPortInfo.pxTopLeftY / Map.TileHeight);

                                int tileGid = tileLayer[tileX, tileY];

                                Rectangle pxTileDestRect = new Rectangle(
                                    (int) Math.Ceiling(i * viewPortInfo.pxTileWidth - viewPortInfo.pxDispX * viewPortInfo.ActualZoom),
                                    (int) Math.Ceiling(j * viewPortInfo.pxTileHeight - viewPortInfo.pxDispY * viewPortInfo.ActualZoom),
                                    (int) viewPortInfo.pxTileWidth,
                                    (int) viewPortInfo.pxTileHeight
                                );

                                if (tileGid != 0 && tileGid != -1)   // NULL or INVALID Tile Gid is ignored
                                {
                                    Tile tile = Map.Tiles[tileGid];

                                    spriteBatch.Draw(
                                        tile.sourceTexture,
                                        pxTileDestRect,
                                        tile.SourceRectangle,
                                        layerColor,
                                        0, Vector2.Zero,
                                        SpriteEffects.None,
                                        depth
                                    );
                                }

                                // DRAW THE TILE LAYER GRID IF ENABLE
                                if (DrawingOptions.ShowTileGrid && layerIndex == Map.TileLayers.Count - 1)
                                    spriteBatch.DrawRectangle(pxTileDestRect, Color.Black, 0);
                            }
                        }
                    }
                }
            }
            spriteBatch.End();

            OverallPerformance.StopTiming("TileRenderingTime");

            // Calculate the entity Displacement caused by pxTopLeft at a global scale to prevent jittering.
            // Each entity should be displaced by the *same amount* based on the pxTopLeftX/Y values
            // this is to prevent entities 'jittering on the screen' when moving the camera.
            float globalDispX = (int) Math.Ceiling(viewPortInfo.pxTopLeftX * viewPortInfo.ActualZoom);
            float globalDispY = (int) Math.Ceiling(viewPortInfo.pxTopLeftY * viewPortInfo.ActualZoom);

            // DRAW VISIBLE REGISTERED ENTITIES
            OverallPerformance.RestartTiming("TotalEntityRenderTime");
            spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, samplerState, null, null);
            {
                EntitiesOnScreen = Collider.GetIntersectingEntites(new FRectangle(viewPortInfo.pxViewPortBounds));

                // DRAW EACH ENTITIY THAT IS WITHIN THE SCREENS VIEWPORT
                foreach (Entity entity in EntitiesOnScreen)
                {
                    EntityRenderPerformance.RestartTiming(entity.Name);

                    if (!entity.Visible) continue;
                    entity.IsOnScreen = true;

                    // Determine the absolute position on the screen for entity position and the bounding box.
                    Vector2 pxAbsEntityPos = new Vector2(
                        entity.Pos.X * viewPortInfo.ActualZoom - globalDispX,
                        entity.Pos.Y * viewPortInfo.ActualZoom - globalDispY
                    );

                    FRectangle pxAbsBoundingBox = new FRectangle(
                        entity.CurrentBoundingBox.X * viewPortInfo.ActualZoom - globalDispX,
                        entity.CurrentBoundingBox.Y * viewPortInfo.ActualZoom - globalDispY,
                        entity.CurrentBoundingBox.Width * viewPortInfo.ActualZoom,
                        entity.CurrentBoundingBox.Height * viewPortInfo.ActualZoom
                    );

                    // DRAW ENTITY BOUNDING BOXES IF ENABLED
                    if (DrawingOptions.ShowBoundingBoxes)
                    {
                        spriteBatch.DrawRectangle(pxAbsBoundingBox.ToRectangle(), Color.Red, 0.0001f);
                        SpriteBatchExtensions.DrawCross(
                            spriteBatch,
                            new Vector2(
                                (int) Math.Ceiling(pxAbsEntityPos.X),
                                (int) Math.Ceiling(pxAbsEntityPos.Y)
                            ),
                            13, Color.Black, 0f);
                    }

                    // DRAW ENTITY DETAILS IF ENABLED (ENTITY DEBUG INFO)
                    if (DrawingOptions.ShowEntityDebugInfo)
                    {
                        SpriteBatchExtensions.DrawMultiLineString(
                            spriteBatch,
                            spriteFont,
                            entity.GetDebugInfo(),
                            (int) entity.CurrentBoundingBox.Width * 2,
                            4,
                            new Vector2(
                                pxAbsBoundingBox.X + pxAbsBoundingBox.Width/2,
                                pxAbsBoundingBox.Y + pxAbsBoundingBox.Height/2
                                ),
                            Color.Purple);
                    }

                    // DRAW EVERY GAMEDRAWABLE INSTANCE CURRENTLY ACTIVE IN THE ENTITIES DRAWABLE SET.
                    HashSet<GameDrawableInstance> drawableInstances = entity.Drawables.GetByState(entity.CurrentDrawableState);

                    if (drawableInstances != null)
                    {
                        foreach (GameDrawableInstance drawable in drawableInstances)
                        {
                            if (!drawable.Visible) continue;

                            // The relative position of the object should always be (X,Y) - (globalDispX, globalDispY). globalDispX and globalDispY
                            // are based on viewPortInfo.TopLeftX and viewPortInfo.TopLeftY. viewPortInfo.TopLeftX and viewPortInfo.TopLeftY have
                            // already been corrected in terms of the bounds of the WORLD map coordinates. This allows for panning at the edges.
                            Rectangle pxCurrentFrame = drawable.GetSourceRectangle(LastUpdateTime);

                            int pxObjectWidth = (int)Math.Ceiling(pxCurrentFrame.Width * entity.ScaleX * viewPortInfo.ActualZoom);
                            int pxObjectHeight = (int)Math.Ceiling(pxCurrentFrame.Height * entity.ScaleY * viewPortInfo.ActualZoom);

                            // Draw the Object based on the current Frame dimensions and the specified Object Width Height values.
                            Rectangle objectDestRect = new Rectangle(
                                    (int)Math.Ceiling(pxAbsEntityPos.X) + (int)Math.Ceiling(drawable.Offset.X * viewPortInfo.ActualZoom),
                                    (int)Math.Ceiling(pxAbsEntityPos.Y) + (int)Math.Ceiling(drawable.Offset.Y * viewPortInfo.ActualZoom),
                                    pxObjectWidth,
                                    pxObjectHeight
                            );

                            Vector2 drawableOrigin = new Vector2(
                                (float)Math.Ceiling(drawable.Drawable.Origin.X * pxCurrentFrame.Width),
                                (float)Math.Ceiling(drawable.Drawable.Origin.Y * pxCurrentFrame.Height)
                                );

                            Color drawableColor = new Color()
                            {
                                R = drawable.Color.R,
                                G = drawable.Color.G,
                                B = drawable.Color.B,
                                A = (byte)(drawable.Color.A * entity.Opacity)
                            };

                            // Layer depth should depend how far down the object is on the map (Relative to Y).
                            // Important to also take into account the animation layers for the entity.
                            float layerDepth = Math.Min(0.99f, 1 / (entity.Pos.Y + ((float)drawable.Layer / Map.pxHeight)));

                            // FINALLY ... DRAW
                            spriteBatch.Draw(
                                drawable.GetSourceTexture(LastUpdateTime),
                                objectDestRect,
                                pxCurrentFrame,
                                drawableColor,
                                drawable.Rotation,
                                drawableOrigin,
                                drawable.SpriteEffects,
                                layerDepth);

                            // DRAW BOUNDING BOXES OF EACH INDIVIDUAL DRAWABLE COMPONENT
                            if (DrawingOptions.ShowDrawableComponents)
                            {
                                Rectangle drawableComponentRect = new Rectangle(
                                    (int)Math.Floor(objectDestRect.X - objectDestRect.Width * drawable.Drawable.Origin.X),
                                    (int)Math.Floor(objectDestRect.Y - objectDestRect.Height * drawable.Drawable.Origin.Y),
                                    objectDestRect.Width, objectDestRect.Height);

                                SpriteBatchExtensions.DrawRectangle(
                                    spriteBatch, drawableComponentRect, Color.Blue, 0);
                            }
                        }
                    }

                    EntityRenderPerformance.StopTiming(entity.Name);
                }
            }
            spriteBatch.End();
            OverallPerformance.StopTiming("TotalEntityRenderTime");

            // APPLY GAME SHADERS TO THE RESULTANT IMAGE
            OverallPerformance.RestartTiming("TotalPostGameShaderRenderTime");
            foreach(PostGameShader postGameShader in GameShaders)
            {
                if (postGameShader.Enabled)
                {
                    postGameShader.ApplyShader(spriteBatch, viewPortInfo, LastUpdateTime, _inputBuffer, _outputBuffer);

                    // Swap buffers after each render.
                    _dummyBuffer = _inputBuffer;
                    _inputBuffer = _outputBuffer;
                    _outputBuffer = _dummyBuffer;
                }
            }
            OverallPerformance.StopTiming("TotalPostGameShaderRenderTime");

            // DRAW COLLIDER DEBUG INFORMATION IF ENABLED
            if (DrawingOptions.ShowColliderDebugInfo)
            {
                spriteBatch.Begin();
                Collider.DrawDebugInfo(viewPortInfo, spriteBatch, destRectangle, spriteFont, globalDispX, globalDispY);
                spriteBatch.End();
            }

            // DRAW THE VIEWPORT TO THE STANDARD SCREEN
            GraphicsDevice.SetRenderTarget(null);
            spriteBatch.Begin();
            {
                spriteBatch.Draw(_inputBuffer, destRectangle, color);
            }
            spriteBatch.End();

            return viewPortInfo;
        }
Example #15
0
        public override void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            spriteBatch.Begin();
            player.Draw(spriteBatch, gameTime);
            //Kenneth: Test av tegning av "Rock", merk at draw i Sprite nå har fått overloaded draw med scaling
            rock.Draw(spriteBatch, new Vector2(Game.Window.ClientBounds.Width / 2, Game.Window.ClientBounds.Height / 2),gameTime, 0.7f);
            particleEmitter.Draw(spriteBatch, gameTime);    //Bare test av denne particleEmitter-tingen. Fungerer ikke bra nok.

            //Her tegner jeg gridnettet som Debugging, trenger naturlig nok ikke å være synlig i spillverden :)
            for (int i = 0; i < collisionGrid.Count; i++ )
            {
                spriteBatch.DrawRectangle(collisionGrid.ElementAt(i).rectangle, collisionGrid.ElementAt(i).Color, 1f);
            }
            spriteBatch.DrawRectangle(mouseCollisionRectangle, Color.Green);
            if (pauseMenu.Open)
            {
                pauseMenu.Draw(spriteBatch, gameTime);
            }
            spriteBatch.End();
        }
        public void Draw(SpriteBatch batch, Texture2D Graphic)
        {
            if (Opacity <= 0) return;

            switch (Shape)
            {
                case ParticleShape.Circle:
                    batch.DrawCircle(Position, CurrentSize, 20, Color.FromNonPremultiplied(BackColor.R, BackColor.G, BackColor.B, Opacity), CurrentSize);
                    break;

                case ParticleShape.Square:
                    batch.DrawRectangle(new Rectangle((Int32)Position.X, (Int32)Position.Y, (Int32)CurrentSize, (Int32)CurrentSize), Color.FromNonPremultiplied(BackColor.R, BackColor.G, BackColor.B, Opacity), CurrentSize);
                    break;

                case ParticleShape.Texture:
                    batch.Draw(Graphic, Position, Graphic.Bounds, Color.FromNonPremultiplied(255, 255, 255, Opacity));
                    break;

                default:
                    break;
            }
        }
Example #17
0
 public void DrawDebugBoxes(SpriteBatch spriteBatch)
 {
     foreach (Rectangle r in _debugBoxes) {
         spriteBatch.DrawRectangle(r, Color.Blue);
     }
 }
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // Moves starting window location
            myForm = (System.Windows.Forms.Form)System.Windows.Forms.Control.FromHandle(this.Window.Handle);
            myForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            myForm.Location = new System.Drawing.Point(0, 0);

            // Explicitly set number of samples for antialiasing; may not be necessary
            //GraphicsDevice.PresentationParameters.MultiSampleCount = 16;
            //Debug.WriteLine(graphicsDevice.PresentationParameters.MultiSampleCount);

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            //planktonTarget = new RenderTarget2D(GraphicsDevice, (int)(CIRCLE_RADIUS + CIRCLE_RADIUS_OVERSCAN) * 2, (int)(Game1.CIRCLE_RADIUS + Game1.CIRCLE_RADIUS_OVERSCAN) * 2);

            // Create a new renderTarget to prerender before drawing on screen.
            PresentationParameters pp = GraphicsDevice.PresentationParameters;
            fullScreenTarget = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, true, GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24);

            maskTextureArray = new Color[(int)((Settings.CIRCLE_RADIUS + Settings.CIRCLE_RADIUS_OVERSCAN) * 2 * (Settings.CIRCLE_RADIUS + Settings.CIRCLE_RADIUS_OVERSCAN) * 2)];

            subtractAlpha = new BlendState();
            subtractAlpha.AlphaBlendFunction = BlendFunction.ReverseSubtract;
            subtractAlpha.AlphaSourceBlend = Blend.One;
            subtractAlpha.AlphaDestinationBlend = Blend.One;
            subtractAlpha.ColorBlendFunction = BlendFunction.ReverseSubtract;
            subtractAlpha.ColorSourceBlend = Blend.One;
            subtractAlpha.ColorDestinationBlend = Blend.One;

            // Initialize tools
            for (int i = 0; i < Settings.NUM_NUTRIENTTOOLS; i++)
            {
                nutrientTools.Enqueue(new NutrientTool(new Vector2(50, 350 + 100 * i)));
            }

            for (int i = 0; i < Settings.NUM_TEMPTOOLS; i++)
            {
                tempTools.Enqueue(new TempTool(new Vector2(50, 150 + i * 100)));
            }

            // Add datanames to the list
            //"T", "SiO2", "POSi"
            dataNames = new List<string>() { "PhyGrp1", "PhyGrp3", "PhyGrp4", "PhyGrp5" }; // PhyGrp data needs to be the first four
            if (Settings.SHOW_LIGHT)
                dataNames.Add("PAR");
            if (Settings.SHOW_NITRATE)
                dataNames.Add("NO3");
            if (Settings.SHOW_TEMP || Settings.NUM_TEMPTOOLS > 0)
                dataNames.Add("T");
            if (Settings.SHOW_SILICA || Settings.NUM_NUTRIENTTOOLS > 0)
                dataNames.Add("SiO2");

            // Set up data structure for all the data
            for (int i = 0; i < dataNames.Count; i++)
                theData.Add(dataNames[i], new Dictionary<int, byte[]>());

            // Draw a loading rectangle
            GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin();
            spriteBatch.DrawRectangle(new Rectangle(0, 0, 100, 100), Color.White);
            spriteBatch.End();
            base.Draw(new GameTime());

            // Load data from files
            FileStream[] fileStreams = new FileStream[dataNames.Count];
            for (int timestamp = 52704; timestamp <= 210384; timestamp += 1080)
            {
                Debug.WriteLine(string.Format("Reading data, {0}% complete...", ((float)timestamp - 52704.0) * 100.0 / (210384.0 - 52704.0)));

                for (int i = 0; i < dataNames.Count; i++)
                {
                    //// Read data from file into a float array
                    //float[] floats = new float[583200/4];
                    //byte[] fourBytes = new byte[4];
                    //fileStreams[i] = new FileStream(string.Format("Data\\{0}_{1}.data", dataNames[i], timestamp), FileMode.Open);
                    //Debug.WriteLine(string.Format("Reading {0}_{1}.data...", dataNames[i], timestamp));

                    //for (int j = 0; j < 583200/4; j++)
                    //{
                    //    // Read four bytes from the file
                    //    for (int k = 0; k < 4; k++)
                    //        fourBytes[k] = (byte)fileStreams[i].ReadByte();

                    //    // Convert four bytes to float (big-endian, so reverse it)
                    //    floats[j] = BitConverter.ToSingle(fourBytes.Reverse().ToArray(), 0);

                    //    // Check for NaN's
                    //    if (float.IsNaN(floats[j]))
                    //        floats[j] = 0;
                    //}

                    //// Add float data to the data structure
                    //theData[dataNames[i]].Add(timestamp, floats);

                    //// Done with this file
                    //fileStreams[i].Close();

                    // Read data from file
                    byte[] bytes = new byte[583200];
                    float[] floats = new float[583200 / 4];
                    byte[] fourBytes = new byte[4];
                    fileStreams[i] = new FileStream(string.Format("Data\\{0}_{1}.data", dataNames[i], timestamp), FileMode.Open);

                    // Read data from file into a byte array
                    fileStreams[i].Read(bytes, 0, 583200);

                    // Done with this file
                    fileStreams[i].Close();

                    //// Convert byte array to float array
                    //for (int j = 0; j < 583200 / 4; j++)
                    //{
                    //    // Read four bytes from the file
                    //    for (int k = 0; k < 4; k++)
                    //        fourBytes[k] = bytes[j*4+k];

                    //    // Convert four bytes to float (big-endian, so reverse it)
                    //    floats[j] = BitConverter.ToSingle(fourBytes.Reverse().ToArray(), 0);

                    //    // Check for NaN's
                    //    if (float.IsNaN(floats[j]))
                    //        floats[j] = 0;
                    //}

                    // Add byte array to the data structure
                    theData[dataNames[i]].Add(timestamp, bytes);

                }
                //Debug.WriteLine(timestamp);

                //// Save phytoplankton group distributions in a dictionary of timestamps
                //byte[][] values = new byte[4][];
                //for (int i = 0; i < 4; i++)
                //{
                //    values[i] = new byte[583200];
                //    fileStreams[i].Read(values[i], 0, 583200);
                //    fileStreams[i].Close();
                //}

                //phygrpData.Add(timestamp, values);

                // Load landmask data from file
                FileStream landmaskFS = new FileStream("Data\\landmask-2-540x270.data", FileMode.Open);
                landmaskFS.Read(landmaskArray, 0, 583200);
                landmaskFS.Close();
            }

            base.Initialize();

            // Initialize a TUIO client and set this LivingLiquid instance as a listener
            tuioClient = new TuioClient(3333);
            //Debug.WriteLine("Removing all TUIO listeners...");
            //tuioClient.removeAllTuioListeners();
            //Debug.WriteLine("Disconnecting TUIO client...is connected: " + tuioClient.isConnected());
            //tuioClient.disconnect();
            Debug.WriteLine("Adding TUIO listener......is connected: " + tuioClient.isConnected());
            tuioClient.addTuioListener(this);
            Debug.WriteLine("Connecting TUIO client...is connected: " + tuioClient.isConnected());
            tuioClient.connect();
            Debug.WriteLine("TUIO client connected: " + tuioClient.isConnected());

            // Initialize Tuio Time
            TuioTime.initSession();

            // Flag ready for input
            this.readyForInput = true;

            // Because the movie has greater than a 2:1 aspect ratio, need to vertically center on screen
            // This section locates a rectangle on screen where the movie should be displayed
            // (unless we're using a really weird narrow screen, in which case, redo this section)
            movieScale = (float)GraphicsDevice.Viewport.Width / (float)(video.Width);
            float movieScaledHeight = (float)(video.Height * movieScale);
            movieVerticalOffset = (GraphicsDevice.Viewport.Height - movieScaledHeight) / 2;
            movieDestination = new Rectangle(GraphicsDevice.Viewport.X,
                (int)(GraphicsDevice.Viewport.Y + movieVerticalOffset),
                GraphicsDevice.Viewport.Width,
                (int)movieScaledHeight);

            InitializeCircles();
        }
Example #19
0
        public void DrawHitboxes(SpriteBatch spriteBatch)
        {
            foreach (CollisionBox h in _collisionBoxes) {
                spriteBatch.DrawRectangle(h.rectangle, h.color);
            }

            foreach (var box in _geometry) {
                spriteBatch.DrawRectangle(box.rect, Color.White);
            }
        }
        public virtual void Draw(SpriteBatch spriteBatch)
        {
            if (IsAlive)
            {
                Sprite.Draw(spriteBatch, CenterPosition);

                if (Globals.ShowBounds)
                {
                    // BoundingCircle - green
                    spriteBatch.DrawCircle(new Vector2(BoundingCircle.Center.X, BoundingCircle.Center.Y), BoundingCircle.Radius, Color.Green, 1000);

                    // Bounding Rectangle - yellow
                    spriteBatch.DrawRectangle(new Rectangle((int)BoundingRectangle.Origin.X, (int)BoundingRectangle.Origin.Y, (int)BoundingRectangle.Size.X, (int)BoundingRectangle.Size.Y), Color.Yellow, false);

                    // Rectangle around entire sprite - red
                    TextureAtlas atlas = Sprite.TextureAtlas;
                    spriteBatch.DrawRectangle(new Rectangle((int)TopLeftPosition.X, (int)TopLeftPosition.Y, (int)((atlas.SingleTextureWidth) * Sprite.Scale.X), (int)(atlas.SingleTextureHeight * Sprite.Scale.Y)), Color.Red, false);
                }
            }
        }
Example #21
0
        private void DrawFullscreenMessage(SpriteBatch spriteBatch, string text)
        {
            spriteBatch.DrawRectangle(new Rectangle(0, 0, _controller.View.ViewSize.X, _controller.View.ViewSize.Y), Color.Black * 0.75F);

            var textSize = _font.Measure(text);
            DrawText(text, new Vector2((int)((_controller.View.ViewSize.X / 2.0F) - (textSize.X / 2.0F)),
                                       (int)((_controller.View.ViewSize.Y / 2.0F) - textSize.Y)));
        }
Example #22
0
 public void DrawTooltip(SpriteBatch spriteBatch, GraphicsDevice graphicsDevice)
 {
     if (!hasTooltip)
         return;
     MouseState mouseState = Mouse.GetState();
     int widthOfTooltip = graphicsDevice.Viewport.Width - mouseState.X - 18; // right padding, width of cursor
     bool tooltipToRightOfMouse = true;
     if (widthOfTooltip < 240)
     {
         tooltipToRightOfMouse = false;
         widthOfTooltip = mouseState.X - 5; // left padding
     }
     string[] tooltipLines = Skin.TooltipFont.WordWrap(Tooltip,
         widthOfTooltip);
     Vector2 tooltipSize = Skin.TooltipFont.MeasureStringMultiline(tooltipLines);
     tooltipSize.X += 2 * TooltipPadding;
     Vector2 tooltipLocation = new Vector2(mouseState.X + (tooltipToRightOfMouse ? 13 : 0),
         (mouseState.Y + tooltipSize.Y + 5 <
         graphicsDevice.Viewport.Height ? mouseState.Y : mouseState.Y - tooltipSize.Y));
     spriteBatch.FillRectangle(tooltipLocation, tooltipSize, Color.Beige);
     spriteBatch.DrawRectangle(tooltipLocation, tooltipSize, Color.Black);
     spriteBatch.DrawStrings(Skin.TooltipFont, tooltipLines, tooltipLocation + new Vector2(TooltipPadding, 0),
         Color.Black);
 }
        public void Draw(SpriteBatch spriteBatch)
        {
            if (world == null)
            {
                return;
            }

            foreach (var body in world.bodies)
            {
                var debugData = GetDebugDataForBody(body);
                foreach (var bodyPart in body.bodyParts)
                {
                    DrawShape(debugData, spriteBatch, bodyPart.shape, body.transform);
                }
            }

            foreach (var body in world.bodies)
            {
                var debugData = GetDebugDataForBody(body);

                var boundingBox = body.calculateBoundingBox();
                spriteBatch.DrawRectangle(scBoundingUtils.toXNARectangle(boundingBox), debugData.BodyBoundingBoxColor);

                // Draw rotation as a line.
                var rotated = new Vector2(debugData.BodyTransformRotationRadius, 0).Rotate(body.transform.rotation.radians);
                spriteBatch.DrawLine(body.transform.position, body.transform.position + rotated, debugData.BodyTransformRotationColor);

                // Draw position.
                var center = new Rectangle();
                center.Width = debugData.BodyTransformPositionExtents;
                center.Height = debugData.BodyTransformPositionExtents;
                center.X = (int)(body.transform.position.X - center.Width / 2.0f);
                center.Y = (int)(body.transform.position.Y - center.Height / 2.0f);
                spriteBatch.FillRectangle(center, debugData.BodyTransformPositionColor);

                // Draw linear velocity

                spriteBatch.DrawLine(body.transform.position, body.transform.position + body.linearVelocity, debugData.BodyLinearVelocityColor);
            }

            // Draw view bounds
            spriteBatch.DrawRectangle(scBoundingUtils.toXNARectangle(world.viewBounds), ViewBoundsColor);

            bodyMap.Clear();
        }