ItemEditor convertRectangleItem(RectangleItem old)
        {
            var editor =
                (ItemEditor)Activator.CreateInstance(getType(@"Gleed2D.Plugins.RectangleItemEditor, Gleed2D.Plugins"));

            var @new = (RectangleItemProperties)editor.ItemProperties;

            copyPropertiesFromOldToNew(old, @new);

            @new.Width     = old.Width;
            @new.Height    = old.Height;
            @new.FillColor = old.FillColor;

            return(editor);
        }
示例#2
0
 private void DrawRectangle(XGraphics gfx, RectangleItem rectangle)
 {
     if (rectangle.IsFilled)
     {
         var pen = new XPen(XColor.FromArgb(rectangle.Stroke.Alpha, rectangle.Stroke.Red, rectangle.Stroke.Green, rectangle.Stroke.Blue),
                            X(rectangle.StrokeThickness == 0.0 ? XUnit.FromMillimeter(defaultStrokeThickness).Value : rectangle.StrokeThickness))
         {
             LineCap = XLineCap.Round
         };
         var brush = new XSolidBrush(XColor.FromArgb(rectangle.Fill.Alpha, rectangle.Fill.Red, rectangle.Fill.Green, rectangle.Fill.Blue));
         gfx.DrawRectangle(pen, brush, X(rectangle.X), Y(rectangle.Y), X(rectangle.Width), Y(rectangle.Height));
     }
     else
     {
         var pen = new XPen(XColor.FromArgb(rectangle.Stroke.Alpha, rectangle.Stroke.Red, rectangle.Stroke.Green, rectangle.Stroke.Blue),
                            X(rectangle.StrokeThickness == 0.0 ? XUnit.FromMillimeter(defaultStrokeThickness).Value : rectangle.StrokeThickness))
         {
             LineCap = XLineCap.Round
         };
         gfx.DrawRectangle(pen, X(rectangle.X), Y(rectangle.Y), X(rectangle.Width), Y(rectangle.Height));
     }
 }
        public Boolean isCollidingWithFloor(Vector2 position, float width, float height)
        {
            Boolean collided = false;

            foreach (Level level in levelList)
            {
                foreach (Layer layer in level.Layers)
                {
                    if (layer.Name.Equals("collisions"))
                    {
                        //found the collision layer
                        foreach (Item item in layer.Items)
                        {
                            if (item.GetType().Name.Equals("RectangleItem"))
                            {
                                RectangleItem rectangleItem = (RectangleItem)item;
                                //iterating through each item in the collision layer
                                Vector2 collisionItemPosition = item.Position;
                                float   collisionWidth        = rectangleItem.Width;
                                float   collisionHeight       = rectangleItem.Height;

                                Boolean tempCollided = isCollidingWithFloorLayer(position, width, height, collisionItemPosition, collisionWidth, collisionHeight);
                                if (tempCollided)
                                {
                                    collided = true;
                                }
                            }
                        }
                    }
                }
            }
            if (collided)
            {
                //System.Console.WriteLine("Is colliding with floor");
            }

            return(collided);
        }
        public List <AABB> loadAxisAlignedBoxes(TextureItem item, string property)
        {
            List <AABB> axisAlignedBoxes = new List <AABB>();
            int         numberToLoad     = 1;
            int         numberOfLoaded   = 0;
            bool        loadNext         = true;

            while (loadNext)
            {
                string tempProperty = property + numberToLoad.ToString();

                if (item.CustomProperties.ContainsKey(tempProperty))
                {
                    if (item.CustomProperties[tempProperty].type == typeof(Item))
                    {
                        Console.WriteLine(tempProperty + " Loaded");
                        RectangleItem rectangleItem  = (RectangleItem)item.CustomProperties[tempProperty].value;
                        AABB          axisAlignedBox = new AABB(rectangleItem.Position, rectangleItem.Width, rectangleItem.Height);
                        axisAlignedBoxes.Add(axisAlignedBox);
                        numberToLoad++;
                        numberOfLoaded++;
                    }
                }
                else
                {
                    loadNext = false;
                }
            }

            if (numberOfLoaded == 0)
            {
                axisAlignedBoxes = null;
                //Console.WriteLine("Did not load AxisAlignedBoxes");
            }
            return(axisAlignedBoxes);
        }
示例#5
0
        ItemEditor convertRectangleItem( RectangleItem old )
        {
            var editor =
                (ItemEditor)Activator.CreateInstance(getType(@"Oglr.Plugins.RectangleItemEditor, Oglr.Plugins"));

            var @new = (RectangleItemProperties) editor.ItemProperties ;
            copyPropertiesFromOldToNew( old, @new );

            @new.Width = old.Width ;
            @new.Height = old.Height ;
            @new.FillColor = old.FillColor ;

            return editor ;
        }
示例#6
0
        public void loadLevel(Level level)
        {
            player1           = new Character();
            backgroundObjects = new List <BackgroundObject>();
            middleObjects     = new List <MiddleObject>();
            resourceObjects   = new List <MiddleObject>();
            collision         = false;
            List <TextureItem> textureItems;
            AABB           axisAlignedBox   = null;
            List <AABB>    axisAlignedBoxes = null;
            List <Polygon> polygons         = null;
            float          depthPosition    = 0.0f;
            string         name             = null;
            bool           isAnimated       = false;

            RectangleItem levelCollisionBox = (RectangleItem)level.getItemByName("LevelAABB");

            axisAlignedBox      = new AABB(levelCollisionBox.Position, levelCollisionBox.Width, levelCollisionBox.Height);
            this.axisAlignedBox = axisAlignedBox;

            /*
             * Load background objects
             * */
            textureItems = level.getTextureItems("ObjectType", "BackgroundObject");
            foreach (TextureItem item in textureItems)
            {
                polygons         = null;
                axisAlignedBoxes = null;

                axisAlignedBoxes = ResourceManager.getInstance.loadAxisAlignedBoxes(item, "CollisionBox"); //AABB
                polygons         = ResourceManager.getInstance.loadPolygons(item, "Polygon");              //Polygon
                name             = ResourceManager.getInstance.loadName(item, "Name");

                if (axisAlignedBoxes != null)
                {
                    backgroundObjects.Add(new BackgroundObject(item.texture, item.Position, item.Rotation, item.Origin, item.Scale, null, axisAlignedBoxes, name));
                }
                else if (polygons != null)
                {
                    backgroundObjects.Add(new BackgroundObject(item.texture, item.Position, item.Rotation, item.Origin, item.Scale, polygons, null, name));
                }
                else
                {
                    backgroundObjects.Add(new BackgroundObject(item.texture, item.Position, item.Rotation, item.Origin, item.Scale, null, null, name));
                }
            }

            /*
             * Load resource objects
             * */
            textureItems = level.getTextureItems("ObjectType", "ResourceObject");
            foreach (TextureItem item in textureItems)
            {
                depthPosition = ResourceManager.getInstance.loadDepthPosition(item, "DepthPosition");
                name          = ResourceManager.getInstance.loadName(item, "Name");

                resourceObjects.Add(new MiddleObject(item.texture, item.Position, item.Rotation, item.Origin, item.Scale, null, null, depthPosition, name));
            }

            /*
             * Load middle objects
             * */
            textureItems = level.getTextureItems("ObjectType", "MiddleObject");
            foreach (TextureItem item in textureItems)
            {
                polygons         = null;
                axisAlignedBoxes = null;

                axisAlignedBoxes = ResourceManager.getInstance.loadAxisAlignedBoxes(item, "CollisionBox"); //AABB
                polygons         = ResourceManager.getInstance.loadPolygons(item, "Polygon");              //Polygon
                depthPosition    = ResourceManager.getInstance.loadDepthPosition(item, "DepthPosition");
                name             = ResourceManager.getInstance.loadName(item, "Name");
                isAnimated       = ResourceManager.getInstance.loadIsAnimated(item, "IsAnimated");

                if (!isAnimated)
                {
                    if (axisAlignedBoxes != null)
                    {
                        middleObjects.Add(new MiddleObject(item.texture, item.Position, item.Rotation, item.Origin, item.Scale, null, axisAlignedBoxes, depthPosition, name));
                    }
                    else if (polygons != null)
                    {
                        middleObjects.Add(new MiddleObject(item.texture, item.Position, item.Rotation, item.Origin, item.Scale, polygons, null, depthPosition, name));
                    }
                    else
                    {
                        middleObjects.Add(new MiddleObject(item.texture, item.Position, item.Rotation, item.Origin, item.Scale, null, null, depthPosition, name));
                    }
                }
                else
                {
                    Texture2D[] animationSprites   = ResourceManager.getInstance.loadAnimationSprite(item, "AnimationPath");
                    int         numberOfAnimations = ResourceManager.getInstance.loadAnimationProperty(item, "NumberOfAnimations");
                    int[]       animationSpeeds    = ResourceManager.getInstance.loadAnimationProperty2(item, "AnimationSpeed");
                    int[]       numberOfFrames     = ResourceManager.getInstance.loadAnimationProperty2(item, "NumberOfFrames");
                    int[]       numberOfRows       = ResourceManager.getInstance.loadAnimationProperty2(item, "NumberOfRows");

                    if (name == "Player")
                    {
                        if (axisAlignedBoxes != null && polygons != null)
                        {
                            player1 = new Character(animationSprites, item.Position, new Vector2(4, 4), item.Rotation, item.Origin,
                                                    item.Scale, polygons, axisAlignedBoxes, numberOfAnimations, animationSpeeds, numberOfFrames, numberOfRows, depthPosition, name);
                        }
                        else if (axisAlignedBoxes != null)
                        {
                            player1 = new Character(animationSprites, item.Position, new Vector2(4, 4), item.Rotation, item.Origin,
                                                    item.Scale, null, axisAlignedBoxes, numberOfAnimations, animationSpeeds, numberOfFrames, numberOfRows, depthPosition, name);
                        }
                        else if (polygons != null)
                        {
                            player1 = new Character(animationSprites, item.Position, new Vector2(4, 4), item.Rotation, item.Origin,
                                                    item.Scale, polygons, null, numberOfAnimations, animationSpeeds, numberOfFrames, numberOfRows, depthPosition, name);
                        }

                        player1Shadow = new Shadow(ResourceManager.getInstance.getRuntimeTextures()["Shadow"], new Vector2(item.Position.X - 11, item.Position.Y - 8), item.Rotation, item.Origin, new Vector2(0.2f, 0.2f), "Shadow");

                        /*
                         * Initializes camera and set its view
                         * IMPORTANT: The item used here have to point to the player
                         * */
                        camera = new Camera(Matrix.Identity, new Vector2(Renderer.getInstance.getScreenCenter().X - item.Position.X,
                                                                         Renderer.getInstance.getScreenCenter().Y - item.Position.Y));

                        camera.setView(Matrix.CreateTranslation(new Vector3(camera.getPosition() - Renderer.getInstance.getScreenCenter(), 0f)) *
                                       Matrix.CreateTranslation(new Vector3(Renderer.getInstance.getScreenCenter(), 0f)));

                        Console.WriteLine("Camera: " + camera.getPosition());
                        Console.WriteLine("Player: " + item.Position);
                    }
                    else
                    {
                        if (axisAlignedBoxes != null)
                        {
                            middleObjects.Add(new MiddleObject(animationSprites, item.Position, item.Rotation, item.Origin, item.Scale, null,
                                                               axisAlignedBoxes, numberOfAnimations, animationSpeeds, numberOfFrames, numberOfRows, depthPosition, name));
                        }
                        else if (polygons != null)
                        {
                            middleObjects.Add(new MiddleObject(animationSprites, item.Position, item.Rotation, item.Origin, item.Scale, polygons,
                                                               null, numberOfAnimations, animationSpeeds, numberOfFrames, numberOfRows, depthPosition, name));
                        }
                        else
                        {
                            middleObjects.Add(new MiddleObject(animationSprites, item.Position, item.Rotation, item.Origin, item.Scale, null,
                                                               null, numberOfAnimations, animationSpeeds, numberOfFrames, numberOfRows, depthPosition, name));
                        }
                    }
                }
            }

            foreach (MiddleObject resourceObject in resourceObjects)
            {
                Random random = new Random();

                int placeHere = random.Next(2);
                Console.WriteLine("RANDOM1: " + placeHere);

                if (placeHere == 1)
                {
                    Texture2D texture2D = null;
                    Vector2   position  = resourceObject.Properties.getProperty <Vector2>("Position");
                    float     rotation  = resourceObject.Properties.getProperty <float>("Rotation");
                    Vector2   origin    = resourceObject.Properties.getProperty <Vector2>("Origin");
                    Vector2   scale     = resourceObject.Properties.getProperty <Vector2>("Scale");
                    float     depthPos  = resourceObject.Properties.getProperty <float>("DepthPosition");

                    int typeOfResource = random.Next(3);
                    Console.WriteLine("RANDOM2: " + typeOfResource);

                    if (typeOfResource == 0)
                    {
                        foreach (KeyValuePair <string, Texture2D> texture in ResourceManager.getInstance.getRuntimeTextures())
                        {
                            if (texture.Key == "Screw")
                            {
                                texture2D = texture.Value;
                                break;
                            }
                        }
                    }
                    else if (typeOfResource == 1)
                    {
                        foreach (KeyValuePair <string, Texture2D> texture in ResourceManager.getInstance.getRuntimeTextures())
                        {
                            if (texture.Key == "OilCan")
                            {
                                texture2D = texture.Value;
                                break;
                            }
                        }
                    }
                    else
                    {
                        foreach (KeyValuePair <string, Texture2D> texture in ResourceManager.getInstance.getRuntimeTextures())
                        {
                            if (texture.Key == "Cement")
                            {
                                texture2D = texture.Value;
                                break;
                            }
                        }
                    }

                    middleObjects.Add(new MiddleObject(texture2D, position, rotation, origin, scale, null, null, depthPos, resourceObject.Name));
                }
            }

            AudioManager.getInstance.stopSound(new Sound("Menu Music"));
            AudioManager.getInstance.playSound(new Sound("Level 1 ingame"), AudioManager.LEVEL1_INGAME);
        }
        internal static void addCustomPropertiesToLevel(Level level)
        {
            bool hasProperties = level.CustomProperties.ContainsKey(PROPERTY_WIDTH);

            addCustomProperty(PROPERTY_WIDTH, "1280", "play area width", level.CustomProperties);
            addCustomProperty(PROPERTY_HEIGHT, "720", "play area height", level.CustomProperties);
            addCustomProperty(PROPERTY_BACKDROP, "day", "backdrop template (day/night/...)", level.CustomProperties);
            addCustomProperty(PROPERTY_BOUNDED_LEFT, false, "add physical boundary to this side", level.CustomProperties);
            addCustomProperty(PROPERTY_BOUNDED_RIGHT, false, "add physical boundary to this side",level.CustomProperties);
            addCustomProperty(PROPERTY_BOUNDED_TOP, false, "add physical boundary to this side",level.CustomProperties);
            addCustomProperty(PROPERTY_BOUNDED_GROUND, true, "add physical boundary to this side",level.CustomProperties);
            addCustomProperty(PROPERTY_Y_LIMIT, true, "disable Y-scroll", level.CustomProperties);
            addCustomProperty(PROPERTY_CINEMATIC_BORDERS, true, "show black borders when rendering out-of-scene space (if disabled, parallaxbackgound is seen)",level.CustomProperties);
            addCustomProperty(PROPERTY_BALLBOMB_AMMO, "0", "ammo amount",level.CustomProperties);
            addCustomProperty(PROPERTY_AIRSTRIKE_AMMO, "0","ammo amount",level.CustomProperties);
            addCustomProperty(PROPERTY_MISSILE_AMMO, "0","ammo amount",level.CustomProperties);
            addCustomProperty(PROPERTY_BAZOOKA_AMMO, "0","ammo amount",level.CustomProperties);
            addCustomProperty(PROPERTY_GRENADELAUNCHER_AMMO, "0", "ammo amount", level.CustomProperties);
            addCustomProperty(PROPERTY_TITLE, "untitled", "title of the level, as seen when playing", level.CustomProperties);

            if (!hasProperties)
            {
                Layer l1 = new Layer("guides");
                onAddLayer(l1);
                l1.CustomProperties["include"].value = false;
                level.Layers.Add(l1);
                RectangleItem r1 = new RectangleItem(new Rectangle(0, -700, 1280, 700));
                r1.Name = "outline";
                l1.Items.Add(r1);
                Layer l2 = new Layer("structure");
                onAddLayer(l2);
                level.Layers.Add(l2);
                Layer l3 = new Layer("objectives");
                onAddLayer(l3);
                level.Layers.Add(l3);
            }
        }