Beispiel #1
0
        /// <summary>
        /// Teleport <paramref name="pac"/> from <see cref="Position1"/> to
        /// <see cref="Position2"/> is pac's position if <see cref="Position1"/>
        /// or vice-versa.
        /// </summary>
        /// <param name="pac">The pac to teleport</param>
        /// <returns>Return <c>true</c> if pac did teleport, <c>false</c> otherwise</returns>
        /// <exception cref="TeleporterException">Thrown when the teleporte has not <see cref="Position2"/> set.</exception>
        public bool Teleport(Pac pac)
        {
            bool result = false;

            if (Activated)
            {
                if (Position2.Equals(new Vector2(-1, -1)))
                {
                    throw new TeleporterException("Teleporter destination has not been configured yet. Where does pac will go without a destination? Nowhere!");
                }

                if (pac.ConvertPositionToTileIndexes().Equals(Position1))
                {
                    pac.Position = new Vector2(Position2.X * Maze.SPRITE_DIMENSION, Position2.Y * Maze.SPRITE_DIMENSION);
                    result       = true;
                }
                else if (pac.ConvertPositionToTileIndexes().Equals(Position2))
                {
                    pac.Position = new Vector2(Position1.X * Maze.SPRITE_DIMENSION, Position1.Y * Maze.SPRITE_DIMENSION);
                    result       = true;
                }
            }

            // If pacman has been teleported, disable the teleporter until pac is away from the teleporter point
            // (this method prevent pac from teleporting in an infinite loop from one spot to another)
            if (result)
            {
                Activated = false;
                Vector2 currentPosition = pac.Position;
                pac.OnPositionChangedAction = (Vector2 position) =>
                {
                    if (!pac.ConvertPositionToTileIndexes().Equals(pac.ConvertPositionToTileIndexes(currentPosition)))
                    {
                        Activated = true;

                        // Delete the delegate
                        pac.OnPositionChangedAction = (Vector2 pos) => { };
                    }
                };
            }

            return(result);
        }
Beispiel #2
0
        // takes the current placed levelObjects and serializes it into the levelData format
        public static LevelData CreateLevelData()
        {
            if (LevelPlacer.generatedLevel != null && editLevel != null)
            {
                print("CreateLevelData");
                LevelDataMono level = LevelPlacer.generatedLevel;
                LevelData     l     = new LevelData(level.levelData.id);

                // save level info
                l.author     = level.levelData.author;
                l.id         = level.levelData.id;
                l.presetTime = DoubleToTwoDecimals(level.levelData.presetTime);
                l.title      = level.levelData.title;
                l.custom     = level.levelData.custom;

                // save moveArea mesh
                Vector3[]   verts    = level.moveArea.meshFilter.mesh.vertices;
                Position2[] posVerts = new Position2[verts.Length];
                for (int i = 0; i < verts.Length; i++)
                {
                    posVerts[i] = new Position2(verts[i].x, verts[i].y);
                }
                if (!posVerts.Equals(editLevel.moveVerticies))
                {
                    Debug.Log("Different Vertices");
                }
                l.moveVerticies = posVerts;
                l.moveTriangles = level.moveArea.meshFilter.mesh.triangles;

                // save spawn
                Vector3 spawnPos = level.spawn.transform.localPosition;
                l.objectData.spawnPosition = new Position2(spawnPos.x, spawnPos.y);

                // save finish
                Vector3 finishPos = level.finish.transform.localPosition;
                l.objectData.finishPosition = new Position2(finishPos.x, finishPos.y);

                // save turrets
                foreach (Turret t in level.turrets)
                {
                    Position2  turretPosition = new Position2(t.transform.localPosition.x, t.transform.localPosition.y);
                    TurretData td             = new TurretData(turretPosition);
                    td.rotation     = new Position3(t.transform.rotation.eulerAngles.x, t.transform.rotation.eulerAngles.y, t.transform.rotation.eulerAngles.z);
                    td.shotDelay    = FloatToTwoDecimals(t.shotDelay);
                    td.shotSpeed    = FloatToTwoDecimals(t.shotSpeed);
                    td.startupDelay = FloatToTwoDecimals(t.startupDelay);
                    td.constantFire = t.constantFire;
                    l.objectData.turretData.Add(td);
                }

                // save attractors
                foreach (Attractor a in level.attractors)
                {
                    Position2     aPosition = new Position2(a.transform.localPosition.x, a.transform.localPosition.y);
                    AttractorData ad        = new AttractorData(aPosition);
                    ad.pullStrength = (int)a.maxPullForce;
                    ad.radius       = (int)a.pullRadius;
                    l.objectData.attractorData.Add(ad);
                }

                // save portals
                foreach (Portal p in level.portals)
                {
                    Position2  pPosition = new Position2(p.transform.localPosition.x, p.transform.localPosition.y);
                    PortalData pd        = new PortalData(pPosition, p.portalID);
                    pd.portalID       = p.portalID;
                    pd.linkedPortalID = p.linkedPortalID;
                    l.objectData.portalData.Add(pd);
                }

                // save speedstrips
                foreach (SpeedStrip s in level.speedStrips)
                {
                    Position2      pPosition = new Position2(s.transform.localPosition.x, s.transform.localPosition.y);
                    SpeedStripData sd        = new SpeedStripData(pPosition);
                    sd.rotation     = new Position3(s.transform.rotation.eulerAngles.x, s.transform.rotation.eulerAngles.y, s.transform.rotation.eulerAngles.z);
                    sd.pushStrength = (int)s.accelSpeed;
                    l.objectData.speedStripData.Add(sd);
                }

                foreach (Bouncer b in level.bouncers)
                {
                    Position2   bPosition = new Position2(b.transform.localPosition.x, b.transform.localPosition.y);
                    BouncerData bd        = new BouncerData(bPosition);
                    bd.rotation   = new Position3(b.transform.rotation.eulerAngles.x, b.transform.rotation.eulerAngles.y, b.transform.rotation.eulerAngles.z);
                    bd.bounciness = b.bounciness;
                    bd.width      = b.width;
                    l.objectData.bouncerData.Add(bd);
                }

                return(l);
            }
            return(null);
        }
Beispiel #3
0
 public bool Equals(HexagonNode other)
 {
     return(Position1.Equals(other.Position1) && Position2.Equals(other.Position2) && Position3.Equals(other.Position3));
 }