Пример #1
0
 /// <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()
 {
     brush          = new PrimitiveLine(GraphicsDevice);
     options        = new Options(this);
     textureManager = new TextureManager(this, Content);
     resolution     = new Resolution(graphics, ScreenMode.tv720p);
     newMap();
     base.Initialize();
 }
Пример #2
0
 /// <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()
 {
     brush = new PrimitiveLine(GraphicsDevice);
     options = new Options(this);
     textureManager = new TextureManager(this, Content);
     resolution = new Resolution(graphics, ScreenMode.tv720p);
     newMap();
     base.Initialize();
 }
Пример #3
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
            switch (currentState)
            {
                #region Leveleditor
            case Enums.State.Leveleditor:
                #region Draw background items
                foreach (BackgroundItemStruct backgroundItem in CurrentLevel.backgroundItems)
                {
                    Texture2D texture = textureManager.getTexture(backgroundItem.texturePath);
                    if (texture == null)
                    {
                        texture = textureManager.getTexture("backgrnditem");
                    }
                    Vector2 textureDimensions = new Vector2(texture.Width, texture.Height),
                            scale             = new Vector2(backgroundItem.scale),
                            origin            = scale * textureDimensions / 2;
                    spriteBatch.Draw(texture, new Vector2(backgroundItem.location.X - offset.X, resolution.ScreenHeight - (backgroundItem.location.Y - offset.Y)),
                                     null, Color.White, backgroundItem.rotation, origin, scale, SpriteEffects.None, 0f);
                }
                #endregion
                #region Draw spawns
                foreach (SpawnPoint spawn in CurrentLevel.spawns)
                {
                    Texture2D texture = textureManager.getTexture(spawn.type);
                    if (texture == null)
                    {
                        texture = textureManager.getTexture("enemy");
                    }
                    spriteBatch.Draw(texture, new Vector2(spawn.loc.X - offset.X, resolution.ScreenHeight - (spawn.loc.Y - offset.Y)),
                                     null, Color.White, 0f, new Vector2(texture.Width / 2, texture.Height / 2), 1f, SpriteEffects.None, 0f);
                }
                #endregion
                #region Draw game items
                foreach (GameItem item in CurrentLevel.items)
                {
                    Texture2D texture = textureManager.getTexture(item.name);
                    //if texture manager has item, draw with texture, otherwise hand draw with brush
                    if (texture != null)
                    {
                        Vector2 textureDimensions = new Vector2(texture.Width, texture.Height),
                                scale             = item.polygonType == PhysicsPolygonType.Circle ?
                                                    new Vector2(item.radius) / textureDimensions :
                                                    item.sideLengths / textureDimensions,
                                origin = scale * textureDimensions / 2;
                        spriteBatch.Draw(texture, new Vector2(item.loc.X - offset.X, resolution.ScreenHeight - (item.loc.Y - offset.Y)),
                                         null, Color.White, item.rotation, origin, scale, SpriteEffects.None, 0f);
                    }
                    else
                    {
                        brush.ClearVectors();
                        switch (item.polygonType)
                        {
                        case PhysicsPolygonType.Rectangle:
                            brush.AddVector(new Vector2(item.loc.X - offset.X - item.sideLengths.X / 2, resolution.ScreenHeight - (item.loc.Y - offset.Y - item.sideLengths.Y / 2)));
                            brush.AddVector(new Vector2(item.loc.X - offset.X - item.sideLengths.X / 2, resolution.ScreenHeight - (item.loc.Y - offset.Y + item.sideLengths.Y / 2)));
                            brush.AddVector(new Vector2(item.loc.X - offset.X + item.sideLengths.X / 2, resolution.ScreenHeight - (item.loc.Y - offset.Y + item.sideLengths.Y / 2)));
                            brush.AddVector(new Vector2(item.loc.X - offset.X + item.sideLengths.X / 2, resolution.ScreenHeight - (item.loc.Y - offset.Y - item.sideLengths.Y / 2)));
                            brush.AddVector(new Vector2(item.loc.X - offset.X - item.sideLengths.X / 2, resolution.ScreenHeight - (item.loc.Y - offset.Y - item.sideLengths.Y / 2)));
                            brush.Render(spriteBatch);
                            break;

                        case PhysicsPolygonType.Circle:
                            brush.AddVector(new Vector2(item.loc.X - offset.X - item.radius, resolution.ScreenHeight - (item.loc.Y - offset.Y + item.radius)));
                            brush.AddVector(new Vector2(item.loc.X - offset.X + item.radius, resolution.ScreenHeight - (item.loc.Y - offset.Y + item.radius)));
                            brush.AddVector(new Vector2(item.loc.X - offset.X + item.radius, resolution.ScreenHeight - (item.loc.Y - offset.Y - item.radius)));
                            brush.AddVector(new Vector2(item.loc.X - offset.X - item.radius, resolution.ScreenHeight - (item.loc.Y - offset.Y - item.radius)));
                            brush.Render(spriteBatch);
                            break;
                            //case PhysicsPolygonType.Polygon:
                            //    foreach (Vector2 vertex in item.vertices)
                            //        brush.AddVector(vertex);
                            //    brush.Render(spriteBatch);
                            //    break;
                        }
                    }
                }
                #endregion
                break;

                #endregion
                #region worldeditor
            case Enums.State.Worldeditor:
                foreach (Level level in levels)
                {
                    spriteBatch.DrawString(font, level.name, new Vector2(level.loc.X, level.loc.Y), Color.Black);

                    List <Level> adjacentLevels = new List <Level>();
                    foreach (int adjlevel in level.adjacent)
                    {
                        adjacentLevels.Add(levels[adjlevel]);
                    }
                    foreach (Level adjlevel in adjacentLevels)
                    {
                        PrimitiveLine brush = new PrimitiveLine(GraphicsDevice);
                        brush.AddVector(level.loc);
                        brush.AddVector(adjlevel.loc);
                        brush.Position = Vector2.Zero;
                        brush.Render(spriteBatch);
                    }
                }
                break;
                #endregion
            }
            spriteBatch.End();
            base.Draw(gameTime);
        }
Пример #4
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
            switch (currentState)
            {
                #region Leveleditor
                case Enums.State.Leveleditor:
                    #region Draw background items
                    foreach (BackgroundItemStruct backgroundItem in CurrentLevel.backgroundItems)
                    {
                        Texture2D texture = textureManager.getTexture(backgroundItem.texturePath);
                        if (texture == null)
                            texture = textureManager.getTexture("backgrnditem");
                        Vector2 textureDimensions = new Vector2(texture.Width, texture.Height),
                                scale = new Vector2(backgroundItem.scale),
                                origin = scale * textureDimensions / 2;
                        spriteBatch.Draw(texture, new Vector2(backgroundItem.location.X - offset.X, resolution.ScreenHeight - (backgroundItem.location.Y-offset.Y)),
                            null, Color.White, backgroundItem.rotation, origin, scale, SpriteEffects.None, 0f);
                    }
                    #endregion
                    #region Draw spawns
                    foreach (SpawnPoint spawn in CurrentLevel.spawns)
                    {
                        Texture2D texture = textureManager.getTexture(spawn.type);
                        if (texture == null)
                            texture = textureManager.getTexture("enemy");
                        spriteBatch.Draw(texture, new Vector2(spawn.loc.X - offset.X, resolution.ScreenHeight - (spawn.loc.Y - offset.Y)),
                            null, Color.White, 0f, new Vector2(texture.Width/2, texture.Height/2), 1f, SpriteEffects.None, 0f);
                    }
                    #endregion
                    #region Draw game items
                    foreach(GameItem item in CurrentLevel.items)
                    {
                        Texture2D texture = textureManager.getTexture(item.name);
                        //if texture manager has item, draw with texture, otherwise hand draw with brush
                        if (texture != null)
                        {
                            Vector2 textureDimensions = new Vector2(texture.Width, texture.Height),
                                scale = item.polygonType == PhysicsPolygonType.Circle ?
                                    new Vector2(item.radius) / textureDimensions :
                                    item.sideLengths / textureDimensions,
                                origin = scale * textureDimensions / 2;
                            spriteBatch.Draw(texture, new Vector2(item.loc.X - offset.X, resolution.ScreenHeight - (item.loc.Y-offset.Y)),
                                null, Color.White, item.rotation, origin, scale, SpriteEffects.None, 0f);
                        }
                        else
                        {
                            brush.ClearVectors();
                            switch (item.polygonType)
                            {
                                case PhysicsPolygonType.Rectangle:
                                    brush.AddVector(new Vector2(item.loc.X - offset.X - item.sideLengths.X / 2, resolution.ScreenHeight - (item.loc.Y - offset.Y - item.sideLengths.Y / 2)));
                                    brush.AddVector(new Vector2(item.loc.X - offset.X - item.sideLengths.X / 2, resolution.ScreenHeight - (item.loc.Y - offset.Y + item.sideLengths.Y / 2)));
                                    brush.AddVector(new Vector2(item.loc.X - offset.X + item.sideLengths.X / 2, resolution.ScreenHeight - (item.loc.Y - offset.Y + item.sideLengths.Y / 2)));
                                    brush.AddVector(new Vector2(item.loc.X - offset.X + item.sideLengths.X / 2, resolution.ScreenHeight - (item.loc.Y - offset.Y - item.sideLengths.Y / 2)));
                                    brush.AddVector(new Vector2(item.loc.X - offset.X - item.sideLengths.X / 2, resolution.ScreenHeight - (item.loc.Y - offset.Y - item.sideLengths.Y / 2)));
                                    brush.Render(spriteBatch);
                                    break;
                                case PhysicsPolygonType.Circle:
                                    brush.AddVector(new Vector2(item.loc.X - offset.X - item.radius, resolution.ScreenHeight - (item.loc.Y - offset.Y + item.radius)));
                                    brush.AddVector(new Vector2(item.loc.X - offset.X + item.radius, resolution.ScreenHeight - (item.loc.Y - offset.Y + item.radius)));
                                    brush.AddVector(new Vector2(item.loc.X - offset.X + item.radius, resolution.ScreenHeight - (item.loc.Y - offset.Y - item.radius)));
                                    brush.AddVector(new Vector2(item.loc.X - offset.X - item.radius, resolution.ScreenHeight - (item.loc.Y - offset.Y - item.radius)));
                                    brush.Render(spriteBatch);
                                    break;
                                //case PhysicsPolygonType.Polygon:
                                //    foreach (Vector2 vertex in item.vertices)
                                //        brush.AddVector(vertex);
                                //    brush.Render(spriteBatch);
                                //    break;
                            }
                        }
                    }
                    #endregion
                    break;
                #endregion
                #region worldeditor
                case Enums.State.Worldeditor:
                    foreach (Level level in levels)
                    {
                        spriteBatch.DrawString(font, level.name, new Vector2(level.loc.X, level.loc.Y), Color.Black);

                        List<Level> adjacentLevels = new List<Level>();
                        foreach (int adjlevel in level.adjacent)
                            adjacentLevels.Add(levels[adjlevel]);
                        foreach (Level adjlevel in adjacentLevels)
                        {
                            PrimitiveLine brush = new PrimitiveLine(GraphicsDevice);
                            brush.AddVector(level.loc);
                            brush.AddVector(adjlevel.loc);
                            brush.Position = Vector2.Zero;
                            brush.Render(spriteBatch);
                        }
                    }
                break;
                #endregion
            }
            spriteBatch.End();
            base.Draw(gameTime);
        }