public void buildBoxes()
        {
            List <Dictionary <string, string> > levelString = FlxXMLReader.readObjectsFromTmxFile("Lemonade/levels/slf2/" + Lemonade_Globals.location + "/" + Lemonade_Globals.location + "_level" + FlxG.level.ToString() + ".tmx",
                                                                                                  "map",
                                                                                                  "boxes",
                                                                                                  FlxXMLReader.NONE);

            foreach (Dictionary <string, string> nodes in levelString)
            {
                foreach (KeyValuePair <string, string> kvp in nodes)
                {
                    //Console.Write("Level String -- Key = {0}, Value = {1}, ", kvp.Key, kvp.Value);
                }
                //Console.Write("\r\n");
            }

            foreach (var item in levelString)
            {
                if (item.ContainsKey("pointsX"))
                {
                    MovingPlatform movingPlatform = new MovingPlatform(Int32.Parse(item["x"]), Int32.Parse(item["y"]));
                    movingPlatform.solid  = true;
                    movingPlatform.@fixed = true;

                    movingPlatforms.add(movingPlatform);

                    FlxPath xpath = new FlxPath(null);
                    //xpath.add(Int32.Parse(item["x"]), Int32.Parse(item["y"]));
                    xpath.addPointsUsingStrings(item["pointsX"], item["pointsY"]);
                    movingPlatform.followPath(xpath, 150, FlxSprite.PATH_YOYO, false);
                    movingPlatform.pathCornering = 0.0f;
                }
            }
        }
Пример #2
0
        public Player(int X = 0, int Y = 0)
            : base(X, Y)
        {
            maxVelocity = new FlxPoint(100, 100);
            drag = new FlxPoint(500, 500);
            makeGraphic(40, 40, FlxColor.CADETBLUE);

            _currPos = new FlxPoint(x, y);
            _lastPos = new FlxPoint(x, y);
            _nodes = new List<FlxPoint>();
            _nodes.Add(_lastPos);
            _nodes.Add(_currPos);
            _path = new FlxPath(_nodes);

            footsteps = new FlxEmitter(x + width / 2, y + height / 2, 0, this);
            footsteps.makeParticles(FlxG.content.Load<Texture2D>("footsteps"), true, 25, 0f, 0f);
            footsteps.setXSpeed();
            footsteps.setYSpeed();

            _indoors = false;
        }
Пример #3
0
        public CarPark(int xPos, int yPos)
            : base(xPos, yPos)
        {
            loadGraphic("putt/carPark", true, false, 256, 224);

            _path = new FlxPath();
            _path.add(0, 0);
            _path.add(13, 28);
            _path.add(39, 19);
            _path.add(63, 55);
            _path.add(84, 104);
            _path.add(83, 144);
            _path.add(103, 175);
            _path.add(105, 130);
            _path.add(110, 103);
            _path.add(132, 81);
            _path.add(156, 70);
            _path.add(165, 81);
            _path.add(173, 102);
            _path.add(176, 124);
            _path.add(179, 141);
            _path.add(181, 139);
            _path.add(186, 115);
            _path.add(201, 76);
            _path.add(225, 61);
            _path.add(800, 33);



            record = false;

            ball = new FlxSprite(0, 0);
            ball.loadGraphic("putt/ball_8x8", true, false, 8, 8);
            ball.frame = 2;

            ballPositionCounter = 0;

            ball.pathCornering = 100;



            ballPositions = new List <Vector2>();

            ballPositions.Add(new Vector2(8, 31));
            ballPositions.Add(new Vector2(8, 31));
            ballPositions.Add(new Vector2(8, 31));
            ballPositions.Add(new Vector2(7, 31));
            ballPositions.Add(new Vector2(7, 31));
            ballPositions.Add(new Vector2(7, 31));
            ballPositions.Add(new Vector2(7, 31));
            ballPositions.Add(new Vector2(7, 30));
            ballPositions.Add(new Vector2(7, 29));
            ballPositions.Add(new Vector2(11, 27));
            ballPositions.Add(new Vector2(17, 24));
            ballPositions.Add(new Vector2(20, 23));
            ballPositions.Add(new Vector2(23, 22));
            ballPositions.Add(new Vector2(27, 22));
            ballPositions.Add(new Vector2(31, 23));
            ballPositions.Add(new Vector2(37, 24));
            ballPositions.Add(new Vector2(43, 26));
            ballPositions.Add(new Vector2(48, 28));
            ballPositions.Add(new Vector2(53, 30));
            ballPositions.Add(new Vector2(58, 32));
            ballPositions.Add(new Vector2(64, 36));
            ballPositions.Add(new Vector2(73, 44));
            ballPositions.Add(new Vector2(79, 49));
            ballPositions.Add(new Vector2(86, 55));
            ballPositions.Add(new Vector2(92, 62));
            ballPositions.Add(new Vector2(97, 70));
            ballPositions.Add(new Vector2(101, 80));
            ballPositions.Add(new Vector2(107, 95));
            ballPositions.Add(new Vector2(109, 106));
            ballPositions.Add(new Vector2(113, 118));
            ballPositions.Add(new Vector2(116, 130));
            ballPositions.Add(new Vector2(121, 140));
            ballPositions.Add(new Vector2(126, 149));
            ballPositions.Add(new Vector2(132, 161));
            ballPositions.Add(new Vector2(136, 167));
            ballPositions.Add(new Vector2(138, 170));
            ballPositions.Add(new Vector2(139, 172));
            ballPositions.Add(new Vector2(139, 173));
            ballPositions.Add(new Vector2(139, 169));
            ballPositions.Add(new Vector2(137, 166));
            ballPositions.Add(new Vector2(135, 161));
            ballPositions.Add(new Vector2(134, 154));
            ballPositions.Add(new Vector2(133, 146));
            ballPositions.Add(new Vector2(132, 138));
            ballPositions.Add(new Vector2(131, 125));
            ballPositions.Add(new Vector2(130, 117));
            ballPositions.Add(new Vector2(130, 108));
            ballPositions.Add(new Vector2(130, 100));
            ballPositions.Add(new Vector2(131, 92));
            ballPositions.Add(new Vector2(137, 87));
            ballPositions.Add(new Vector2(141, 80));
            ballPositions.Add(new Vector2(144, 78));
            ballPositions.Add(new Vector2(146, 77));
            ballPositions.Add(new Vector2(149, 76));
            ballPositions.Add(new Vector2(152, 76));
            ballPositions.Add(new Vector2(156, 76));
            ballPositions.Add(new Vector2(161, 78));
            ballPositions.Add(new Vector2(163, 82));
            ballPositions.Add(new Vector2(164, 88));
            ballPositions.Add(new Vector2(165, 95));
            ballPositions.Add(new Vector2(166, 103));
            ballPositions.Add(new Vector2(166, 116));
            ballPositions.Add(new Vector2(166, 123));
            ballPositions.Add(new Vector2(168, 128));
            ballPositions.Add(new Vector2(169, 130));
            ballPositions.Add(new Vector2(171, 130));
            ballPositions.Add(new Vector2(171, 130));
            ballPositions.Add(new Vector2(172, 128));
            ballPositions.Add(new Vector2(172, 122));
            ballPositions.Add(new Vector2(173, 116));
            ballPositions.Add(new Vector2(175, 110));
            ballPositions.Add(new Vector2(177, 103));
            ballPositions.Add(new Vector2(179, 96));
            ballPositions.Add(new Vector2(182, 85));
            ballPositions.Add(new Vector2(184, 79));
            ballPositions.Add(new Vector2(186, 73));
            ballPositions.Add(new Vector2(189, 67));
            ballPositions.Add(new Vector2(192, 61));
            ballPositions.Add(new Vector2(199, 54));
            ballPositions.Add(new Vector2(201, 51));
            ballPositions.Add(new Vector2(204, 48));
            ballPositions.Add(new Vector2(207, 45));
            ballPositions.Add(new Vector2(211, 44));
            ballPositions.Add(new Vector2(213, 44));
            ballPositions.Add(new Vector2(216, 44));
            ballPositions.Add(new Vector2(220, 45));
            ballPositions.Add(new Vector2(224, 49));
            ballPositions.Add(new Vector2(227, 53));
            ballPositions.Add(new Vector2(230, 60));
            ballPositions.Add(new Vector2(232, 68));
            ballPositions.Add(new Vector2(234, 75));
            ballPositions.Add(new Vector2(235, 77));
            ballPositions.Add(new Vector2(235, 77));
            ballPositions.Add(new Vector2(235, 77));
            ballPositions.Add(new Vector2(235, 75));
            ballPositions.Add(new Vector2(235, 69));
            ballPositions.Add(new Vector2(234, 62));
            ballPositions.Add(new Vector2(233, 56));
            ballPositions.Add(new Vector2(233, 50));
            ballPositions.Add(new Vector2(235, 44));
            ballPositions.Add(new Vector2(238, 37));
            ballPositions.Add(new Vector2(243, 31));
            ballPositions.Add(new Vector2(252, 21));
            ballPositions.Add(new Vector2(262, 15));
            ballPositions.Add(new Vector2(272, 10));
            ballPositions.Add(new Vector2(280, 7));
            ballPositions.Add(new Vector2(287, 5));
            ballPositions.Add(new Vector2(292, 4));

            ballPositionCounter = 0;
        }
Пример #4
0
 /**
  * Tells this object to stop following the path its on.
  *
  * @param	DestroyPath		Tells this function whether to call destroy on the path object.  Default value is false.
  */
 public void stopFollowingPath(bool DestroyPath=false)
 {
     pathSpeed = 0;
     if(DestroyPath && (path != null))
     {
         path.destroy();
         path = null;
     }
 }
Пример #5
0
        /**
         * Call this function to give this object a path to follow.
         * If the path does not have at least one node in it, this function
         * will log a warning message and return.
         *
         * @param	Path		The <code>FlxPath</code> you want this object to follow.
         * @param	Speed		How fast to travel along the path in pixels per second.
         * @param	Mode		Optional, controls the behavior of the object following the path using the path behavior constants.  Can use multiple flags at once, for example PATH_YOYO|PATH_HORIZONTAL_ONLY will make an object move back and forth along the X axis of the path only.
         * @param	AutoRotate	Automatically point the object toward the next node.  Assumes the graphic is pointing upward.  Default behavior is false, or no automatic rotation.
         */
        public void followPath(FlxPath Path, float Speed = 100, uint Mode = PATH_FORWARD, bool AutoRotate = false)
        {
            if (Path.nodes.Count <= 0)
            {
                FlxG.log("WARNING: Paths need at least one node in them to be followed.");
                return;
            }

            path = Path;
            pathSpeed = FlxU.abs(Speed);
            _pathMode = Mode;
            _pathRotate = AutoRotate;

            //get starting node
            if ((_pathMode == PATH_BACKWARD) || (_pathMode == PATH_LOOP_BACKWARD))
            {
                _pathNodeIndex = path.nodes.Count - 1;
                _pathInc = -1;
            }
            else
            {
                _pathNodeIndex = 0;
                _pathInc = 1;
            }
        }
Пример #6
0
 /// <summary>
 /// Override to null out variables manually
 /// </summary>
 public override void destroy()
 {
     velocity = null;
     acceleration = null;
     drag = null;
     maxVelocity = null;
     scrollFactor = null;
     _point = null;
     _rect = null;
     last = null;
     //cameras = null;
     if (path != null)
         path.destroy();
     path = null;
 }
Пример #7
0
        /// <summary>
        /// Instantiates a <code>FlxObject</code>
        /// </summary>
        /// <param name="X">X-coordinate of the object in space</param>
        /// <param name="Y">y-coordinate of the object in space</param>
        /// <param name="Width">Desired width of the rectangle</param>
        /// <param name="Height">Desired height of the rectangle</param>
        public FlxObject(float X = 0, float Y = 0, float Width = 0, float Height = 0)
            : base()
        {
            x = X;
            y = Y;
            last = new FlxPoint(x, y);
            width = Width;
            height = Height;
            mass = 1.0f;
            elasticity = 0.0f;

            health = 1;

            immovable = false;
            moves = true;

            touching = NONE;
            wasTouching = NONE;
            allowCollisions = ANY;

            velocity = new FlxPoint();
            acceleration = new FlxPoint();
            drag = new FlxPoint();
            maxVelocity = new FlxPoint(10000, 10000);

            angle = 0;
            angularVelocity = 0;
            angularAcceleration = 0;
            angularDrag = 0;
            maxAngular = 10000;

            scrollFactor = new FlxPoint(1, 1);
            _flicker = false;
            _flickerTimer = 0;

            _point = new FlxPoint();
            _rect = new FlxRect();

            path = null;
            pathSpeed = 0;
            pathAngle = 0;
        }
Пример #8
0
        override public void create()
        {
            FlxG.backColor = FlxColor.ToColor("dedbc3");
            base.create();

            _world = new World(new Vector2(0, 98.0f));

            charactersGrp   = new FlxGroup();
            blocksGrp       = new FlxGroup();
            movingBlocksGrp = new FlxGroup();
            doors           = new FlxGroup();
            crates          = new FlxGroup();


            //Dictionary<string,string> levelAttrs = FlxXMLReader.readAttributesFromOelFile("ogmo/level1.oel", "level/grid");
            //FlxTilemap tiles = new FlxTilemap();
            //tiles.useExtraMiddleTiles = false;
            //tiles.auto = FlxTilemap.AUTO;
            //tiles.indexOffset = -1;
            //tiles.loadMap(levelAttrs["grid"], FlxG.Content.Load<Texture2D>("level1_tiles"), 10, 10);
            //tiles.setScrollFactors(0, 0);
            //tiles.boundingBoxOverride = true;

            //blocksGrp.add(tiles);

            List <Dictionary <string, string> > lblocks = FlxXMLReader.readNodesFromOelFile("ogmo/level1.oel", "level/grid");

            foreach (Dictionary <string, string> nodes in lblocks)
            {
                FarTileblock t = new FarTileblock(Convert.ToInt32(nodes["x"]) + (Convert.ToInt32(nodes["w"]) / 2), Convert.ToInt32(nodes["y"]) + (Convert.ToInt32(nodes["h"]) / 2), Convert.ToInt32(nodes["w"]), Convert.ToInt32(nodes["h"]), _world);
                t.auto = FlxTilemap.AUTO;
                t.loadTiles("level1_tiles", 10, 10, 0);
                blocksGrp.add(t);
                t._body.BodyType = BodyType.Static;


                FlxTileblock t2 = new FlxTileblock(Convert.ToInt32(nodes["x"]), Convert.ToInt32(nodes["y"]), Convert.ToInt32(nodes["w"]), Convert.ToInt32(nodes["h"]));
                t2.auto = FlxTilemap.AUTO;
                t2.loadTiles("level1_tiles", 10, 10, 0);
                blocksGrp.add(t2);
            }

            List <Dictionary <string, string> > blocks = FlxXMLReader.readNodesFromOelFile("ogmo/level1.oel", "level/tileblocks");

            foreach (Dictionary <string, string> nodes in blocks)
            {
                if (nodes["Name"] == "elevator")
                {
                    MovingBlock block = new MovingBlock(Convert.ToInt32(nodes["x"]), Convert.ToInt32(nodes["y"]));
                    block.loadGraphic("level1_specialBlock", false, true, 40, 20);
                    movingBlocksGrp.add(block);

                    FlxPath xpath = new FlxPath(null);
                    xpath.add(Convert.ToInt32(nodes["x"]) + 20, Convert.ToInt32(nodes["y"]) + 10);
                    xpath.addPointsUsingStrings(nodes["pathNodesX"], nodes["pathNodesY"], 20, 10);
                    block.followPath(xpath, 80, FlxObject.PATH_FORWARD, false);
                }
                if (nodes["Name"] == "door")
                {
                    Door door = new Door(Convert.ToInt32(nodes["x"]), Convert.ToInt32(nodes["y"]) - 100);
                    doors.add(door);
                }
                //foreach (var item in nodes)
                //{
                //    Console.WriteLine("{0} {1}", item.Key, item.Value);
                //}
            }
            //bat = new Bat(x, y);
            //actors.add(bat);
            //Console.WriteLine("Building a bat {0} {1} {2} {3}", x, y, PathNodesX, PathNodesY);

            //if (PathNodesX != "" && PathNodesY != "")
            //{
            //    Console.WriteLine("Building a path {0} {1} {2}", PathNodesX, PathNodesY, PathCornering);

            //    FlxPath xpath = new FlxPath(null);
            //    xpath.add(x, y);
            //    xpath.addPointsUsingStrings(PathNodesX, PathNodesY);
            //    bat.followPath(xpath, PathSpeed, PathType, false);
            //    bat.pathCornering = PathCornering;


            //}



            Andre andre = new Andre(0, 0);

            charactersGrp.add(andre);

            Liselot liselot = new Liselot(40, 40);

            charactersGrp.add(liselot);

            Army army = new Army(30, 20);

            charactersGrp.add(army);

            Inspector inspector = new Inspector(50, 50);

            charactersGrp.add(inspector);

            Worker worker = new Worker(60, 60);

            charactersGrp.add(worker);

            Chef chef = new Chef(100, 30);

            charactersGrp.add(chef);


            FlxTileblock bg = new FlxTileblock(0, 0, 240, 800);

            bg.auto = FlxTileblock.RANDOM;
            bg.loadTiles("level1_shelfTile", 80, 80, 0);
            add(bg);

            bg      = new FlxTileblock(640, 0, 240, 800);
            bg.auto = FlxTileblock.RANDOM;
            bg.loadTiles("level1_shelfTile", 80, 80, 0);
            add(bg);

            for (int i = 0; i < 5; i++)
            {
                SmallCrate c = new SmallCrate((int)FlxU.random(0, FlxG.width), (int)FlxU.random(0, FlxG.height - 100));
                crates.add(c);
            }

            for (int i = 0; i < 5; i++)
            {
                Bottle b = new Bottle((int)FlxU.random(0, FlxG.width), (int)FlxU.random(0, FlxG.height - 100));
                crates.add(b);
            }
            for (int i = 0; i < 55; i++)
            {
                Fruit f = new Fruit((int)FlxU.random(0, FlxG.width), (int)FlxU.random(0, FlxG.height - 100), _world);
                f._body.ApplyLinearImpulse(new Vector2(20, 2120));


                crates.add(f);
            }


            add(doors);
            add(charactersGrp);
            add(blocksGrp);
            add(movingBlocksGrp);
            add(crates);

            FlxG.showHud();
            FlxG.setHudTextPosition(1, FlxG.width / 2, 10);
            FlxG.setHudTextScale(1, 3);
        }
Пример #9
0
        override public void create()
        {
            base.create();

            FlxG.resetHud();

            makeCave(1.0f, Color.White);

            FlxSprite avatar = new FlxSprite(0, FlxG.height - 64);

            avatar.loadGraphic(FlxG.Content.Load <Texture2D>("flixel/surt/race_or_die"), true, false, 64, 64);
            avatar.addAnimation("Static", new int[] { 2 }, 0, true);
            avatar.play("Static");
            avatar.setScrollFactors(0, 0);

            add(avatar);

            p = new FlxPath(null);
            addPathPointWithMarker(40.0f, 40.0f, 0);
            addPathPointWithMarker(522.67800098f, 342.106739267f, 1);
            addPathPointWithMarker(582.8467536f, 603.25142048f, 2);
            addPathPointWithMarker(531.13384868f, 263.27163512f, 3);
            addPathPointWithMarker(1447.02681801f, 449.15789055f, 4);
            addPathPointWithMarker(1201.74908191f, 528.33347167f, 5);
            addPathPointWithMarker(147.07640576f, 672.46462447f, 6);
            addPathPointWithMarker(199.62346884f, 584.58110087f, 7);
            addPathPointWithMarker(108.19931517f, 355.52333218f, 8);
            addPathPointWithMarker(698.584671041f, 174.70156601f, 9);

            for (int i = 0; i < 9; i++)
            {
                FlxLine line = new FlxLine(0, 0, new Vector2(p.nodes[i].X, p.nodes[i].Y), new Vector2(p.nodes[i + 1].X, p.nodes[i + 1].Y), Color.White, 2);
                add(line);
            }

            car = new FlxSprite(40, 40);
            car.loadGraphic(FlxG.Content.Load <Texture2D>("flixel/surt/race_or_die"), true, false, 64, 64);
            //car.addAnimation("Static", new int[] { 8 }, 0, true);
            //car.play("Static");
            car.frame = 8;
            car.setDrags(5, 5);
            add(car);

            car.path            = p;
            car.pathCornering   = 5.0f;
            car.pathAngleOffset = 180;
            //car.pathSpeed = 500.0f;
            car.followPath(p, 250.0f, FlxSprite.PATH_LOOP_FORWARD, true);

            FlxG.follow(car, 5.0f);
            FlxG.followBounds(0, 0, 100 * 16, 100 * 16);


            for (int i = 0; i < 7; i++)
            {
                p = new FlxPath(null);
                p.add(40.0f, 40.0f);
                p.add(522.67800098f + FlxU.random(1, 100), 342.106739267f + FlxU.random(1, 100));
                p.add(582.8467536f, 603.25142048f + FlxU.random(1, 1200));
                p.add(531.13384868f, 263.27163512f + FlxU.random(1, 1200));
                p.add(1447.02681801f, 449.15789055f + FlxU.random(1, 1200));
                p.add(1201.74908191f, 528.33347167f + FlxU.random(1, 1200));
                p.add(147.07640576f, 672.46462447f + FlxU.random(1, 1200));
                p.add(199.62346884f, 584.58110087f + FlxU.random(1, 1200));
                p.add(108.19931517f, 355.52333218f + FlxU.random(1, 1200));
                p.add(698.584671041f, 174.70156601f + FlxU.random(1, 2100));


                car = new FlxSprite(40, 40);
                car.loadGraphic(FlxG.Content.Load <Texture2D>("flixel/surt/race_or_die"), true, false, 64, 64);
                //car.addAnimation("Static", new int[] { 8 }, 0, true);
                //car.play("Static");
                car.frame = 6 + i;
                car.setDrags(5, 5);
                add(car);

                car.path            = p;
                car.pathCornering   = 5.0f;
                car.pathAngleOffset = 180;
                //car.pathSpeed = 500.0f;
                car.followPath(p, 50.0f + (i * 30), FlxSprite.PATH_LOOP_FORWARD, true);
            }
        }
Пример #10
0
        /**
         * Find a path through the tilemap.  Any tile with any collision flags set is treated as impassable.
         * If no path is discovered then a null reference is returned.
         *
         * @param	Start		The start point in world coordinates.
         * @param	End			The end point in world coordinates.
         * @param	Simplify	Whether to run a basic simplification algorithm over the path data, removing extra points that are on the same line.  Default value is true.
         * @param	RaySimplify	Whether to run an extra raycasting simplification algorithm over the remaining path data.  This can result in some close corners being cut, and should be used with care if at all (yet).  Default value is false.
         *
         * @return	A <code>FlxPath</code> from the start to the end.  If no path could be found, then a null reference is returned.
         */
        public FlxPath findPath(FlxPoint Start, FlxPoint End, bool Simplify=true, bool RaySimplify=false)
        {
            //figure out what tile we are starting and ending on.
            int startIndex = (int)((Start.y-y)/_tileHeight) * widthInTiles + (int)((Start.x-x)/_tileWidth);
            int endIndex = (int)((End.y-y)/_tileHeight) * widthInTiles + (int)((End.x-x)/_tileWidth);

            //check that the start and end are clear.
            if( ((_tileObjects[_data[startIndex]] as FlxTile).allowCollisions > 0) ||
                ((_tileObjects[_data[endIndex]] as FlxTile).allowCollisions > 0) )
                return null;

            //figure out how far each of the tiles is from the starting tile
            List<int> distances = computePathDistance(startIndex,endIndex);
            if(distances == null)
                return null;

            //then count backward to find the shortest path.
            List<FlxPoint> points = new List<FlxPoint>();
            walkPath(distances,endIndex,points);

            //reset the start and end points to be exact
            FlxPoint node;
            node = points[points.Count-1] as FlxPoint;
            node.x = Start.x;
            node.y = Start.y;
            node = points[0] as FlxPoint;
            node.x = End.x;
            node.y = End.y;

            //some simple path cleanup options
            if(Simplify)
                simplifyPath(points);
            if(RaySimplify)
                raySimplifyPath(points);

            //finally load the remaining points into a new path object and return it
            FlxPath path = new FlxPath();
            int i = points.Count - 1;
            while(i >= 0)
            {
                node = points[i--] as FlxPoint;
                if(node != null)
                    path.addPoint(node,true);
            }
            return path;
        }