示例#1
0
文件: Circle.cs 项目: vb0067/LGame
        private bool Intersects(RectBox other)
        {
            RectBox box    = other;
            Circle  circle = this;

            if (box.Contains(x + radius, y + radius))
            {
                return(true);
            }

            float x1 = box.GetX();
            float y1 = box.GetY();
            float x2 = box.GetX() + box.GetWidth();
            float y2 = box.GetY() + box.GetHeight();

            Line[] lines = new Line[4];
            lines[0] = new Line(x1, y1, x2, y1);
            lines[1] = new Line(x2, y1, x2, y2);
            lines[2] = new Line(x2, y2, x1, y2);
            lines[3] = new Line(x1, y2, x1, y1);

            float r2 = circle.GetRadius() * circle.GetRadius();

            Vector2f pos = new Vector2f(circle.GetCenterX(), circle.GetCenterY());

            for (int i = 0; i < 4; i++)
            {
                float dis = lines[i].DistanceSquared(pos);
                if (dis < r2)
                {
                    return(true);
                }
            }

            return(false);
        }
示例#2
0
        private void Load(Stream ins0, string tileSetsLocation)
        {
            screenRect = LSystem.screenRect;

            tilesLocation = tileSetsLocation;

            try
            {
                XMLDocument doc = XMLParser.Parse(ins0);
                XMLElement docElement = doc.GetRoot();

                string orient = docElement.GetAttribute("orientation", "");
                if (!"orthogonal".Equals(orient))
                {
                    throw new Exception(
                            "Only orthogonal maps supported, found " + orient);
                }

                width = docElement.GetIntAttribute("width", 0);
                height = docElement.GetIntAttribute("height", 0);
                tileWidth = docElement.GetIntAttribute("tilewidth", 0);
                tileHeight = docElement.GetIntAttribute("tileheight", 0);

                XMLElement propsElement = (XMLElement)docElement
                        .GetChildrenByName("properties");
                if (propsElement != null)
                {
                    props = new TMXProperty();
                    List<XMLElement> property = propsElement.List("property");
                    for (int i = 0; i < property.Count; i++)
                    {
                        XMLElement propElement = property[i];
                        string name = propElement.GetAttribute("name", null);
                        string value_ren = propElement.GetAttribute("value", null);
                        props.SetProperty(name, value_ren);
                    }
                }

                if (loadTileSets)
                {
                    TMXTileSet tileSet = null;
                    TMXTileSet lastSet = null;

                    List<XMLElement> setNodes = docElement.List("tileset");
                    for (int i_0 = 0; i_0 < setNodes.Count; i_0++)
                    {
                        XMLElement current = setNodes[i_0];

                        tileSet = new TMXTileSet(this, current, true);
                        tileSet.index = i_0;

                        if (lastSet != null)
                        {
                            lastSet.SetLimit(tileSet.firstGID - 1);
                        }
                        lastSet = tileSet;

                        CollectionUtils.Add(tileSets, tileSet);
                    }
                }

                List<XMLElement> layerNodes = docElement.List("layer");
                for (int i_1 = 0; i_1 < layerNodes.Count; i_1++)
                {
                    XMLElement current_2 = layerNodes[i_1];
                    TMXLayer layer = new TMXLayer(this, current_2);
                    layer.index = i_1;

                    CollectionUtils.Add(layers, layer);
                }

                List<XMLElement> objectGroupNodes = docElement
                        .List("objectgroup");

                for (int i_3 = 0; i_3 < objectGroupNodes.Count; i_3++)
                {
                    XMLElement current_4 = objectGroupNodes[i_3];
                    TMXTileGroup objectGroup = new TMXTileGroup(current_4);
                    objectGroup.index = i_3;

                    CollectionUtils.Add(objectGroups, objectGroup);
                }

                defWidth = (int)(screenRect.GetWidth() / tileWidth);
                defHeight = (int)(screenRect.GetHeight() / tileHeight);

            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.StackTrace);
                throw new Exception("Failed to parse map", ex);
            }
        }
示例#3
0
 protected internal void DrawChar(SpriteBatch batch, float x, float y, RectBox glyph,
         RectBox cropping, LColor color)
 {
     batch.Draw(texture, x + cropping.x, y + cropping.y, glyph.GetWidth(),
             glyph.GetHeight(), glyph.GetX(), glyph.GetY(),
             glyph.GetWidth(), glyph.GetHeight(), color);
 }