Пример #1
0
        public override void update(GameTime gameTime)
        {
            Vector2 temp = new Vector2();

            for (int i = 0; i < Firecracker.level.numberOfObjects(); i++)
            {
                GameObject theObj = Firecracker.level.objectAt(i);
                if (theObj.GetType() == typeof(NPCObject))
                {
                    if ((theObj.position - position).Length() < 80)
                    {
                        NPCObject person = (NPCObject)theObj;

                        person.wanderType = AIWanderType.AI_Freeze;
                        person.eventTime  = 1.2f;
                        temp = person.position;
                    }
                    peopleThatAreFozen.Add(temp);
                }
            }
            TimeTracker += (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (TimeTracker > 14.0f)
            {
                this.toBeDeleted = true;
            }
        }
Пример #2
0
        public override void update(GameTime gameTime)
        {
            personality(gameTime);
            if (m_bKillable)
            {
                m_fAge += (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            if (m_fAge >= m_fDeathAt)
            {
                diedNaturally = true;
                //Explosion exp = new Explosion(position + new Vector2(16.0f, 16.0f));
                //Firecracker.level.addObject(exp);
                //Explosion exp2 = new Explosion(position - new Vector2(16.0f, 16.0f));
                //Firecracker.level.addObject(exp2);

                if (Firecracker.engineInstance.numPeoples <= 500)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        Vector2 spawnPosition = position;
                        for (int j = 0; j < 5; j++)
                        {
                            //try 5 times to find a legal spawn position
                            spawnPosition = position + new Vector2((float)Firecracker.random.NextDouble() * 32 - 16, (float)Firecracker.random.NextDouble() * 32 - 16);
                            if (Terrain.Instance == null || Terrain.Instance.isPositionWalkable(spawnPosition))
                            {
                                break;
                            }
                            spawnPosition = position;
                        }

                        NPCObject newObject = new NPCObject(spawnPosition, this);
                        Firecracker.level.addObject(newObject);
                    }

                    HumanDeath newDeath = new HumanDeath(position);
                    Firecracker.level.addObject(newDeath);

                    toBeDeleted = true;
                }
            }

            // until we can see the cursor, don't worry about this.
            //if (Firecracker.engineInstance.m_MouseManager.IsMouseLeftPressed())
            //{
            //    FleeFromPoint(Firecracker.engineInstance.m_MouseManager.GetMousePos());
            //}

            base.update(gameTime);
        }
Пример #3
0
        public override void update(GameTime gameTime)
        {
            if (Math.Abs((position - m_vTargetPosition).Length()) <= 20)
            {
                // Asplode.
                BigExplosion exp = new BigExplosion(position);
                Firecracker.level.addObject(exp);
                this.toBeDeleted = true;

                Firecracker.level.attackSettlements(exp.position, 200);

                // find all the NPCs nearby and kill 'em all. MUAUAhahah.....ha
                for (int i = 0; i < Firecracker.level.numberOfObjects(); i++)
                {
                    GameObject theObj = Firecracker.level.objectAt(i);
                    if (theObj.GetType() == typeof(NPCObject))
                    {
                        if ((theObj.position - position).Length() < 120)
                        {
                            // kill this guy.
                            theObj.toBeDeleted = true;
                            HumanDeath newDeath = new HumanDeath(theObj.position);
                            Firecracker.level.addObject(newDeath);
                            if ((theObj.position - position).Length() < 60)
                            {
                                Explosion explosionDeath = new Explosion(theObj.position);
                                Firecracker.level.addObject(explosionDeath);
                            }
                        }
                        if ((theObj.position - position).Length() < 180)
                        {
                            NPCObject person = (NPCObject)theObj;
                            person.wanderType    = AIWanderType.AI_Scatter;
                            person.PointOfTerror = new Vector2(position.X, position.Y);
                            person.eventTime     = 1.2f;
                            person.FleeFromPoint(person.PointOfTerror);
                        }
                    }
                }
            }
            else
            {
                // Fly in
                Vector2 newPos = m_vTargetPosition - position;
                newPos.Normalize();
                newPos   *= (float)(m_fSpeed * gameTime.ElapsedGameTime.TotalSeconds);
                position += newPos;
            }

            base.update(gameTime);
        }
Пример #4
0
        public void ping()
        {
            for (int i = 0; i < Firecracker.level.numberOfObjects(); i++)
            {
                GameObject theObj = Firecracker.level.objectAt(i);
                if (theObj.GetType() == typeof(NPCObject))
                {
                    if ((theObj.position - position).Length() < 120)
                    {
                        NPCObject person = (NPCObject)theObj;

                        person.wanderType    = AIWanderType.AI_drawn;
                        person.PointOfTerror = new Vector2(position.X, position.Y);
                        person.eventTime     = 1.2f;
                        person.SwarmPoint(person.PointOfTerror);
                    }
                }
            }
        }
Пример #5
0
        public static NPCObject parseFrom(StreamReader input, SpriteSheetCollection spriteSheets)
        {
            if (input == null || spriteSheets == null)
            {
                return(null);
            }

            // get the object's position
            Variable position = Variable.parseFrom(input.ReadLine());

            if (position == null || !position.id.Equals("Position", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            // parse the sprite's position
            String[] positionData = position.value.Split(',');
            if (positionData.Length != 2)
            {
                return(null);
            }

            Vector2 newPosition;

            try
            {
                newPosition.X = Int32.Parse(positionData[0]);
                newPosition.Y = Int32.Parse(positionData[1]);
            }
            catch (Exception) { return(null); }


            // Get the layer depth of this sprite
            Variable layerDepth = Variable.parseFrom(input.ReadLine());

            if (layerDepth == null || !layerDepth.id.Equals("LayerDepth", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }


            // get the name of the spritesheet in which the sprite is found
            Variable spriteSheetName = Variable.parseFrom(input.ReadLine());

            if (spriteSheetName == null || !spriteSheetName.id.Equals("SpriteSheet Name", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }


            // create the object
            NPCObject newObject = new NPCObject(newPosition, (Sprite)null);

            // get the sprite's name
            newObject.AnimNameN = Variable.parseFrom(input.ReadLine());
            if (newObject.AnimNameN == null || !newObject.AnimNameN.id.Equals("Anim Name N", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }
            newObject.AnimNameE = Variable.parseFrom(input.ReadLine());
            if (newObject.AnimNameE == null || !newObject.AnimNameE.id.Equals("Anim Name E", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }
            newObject.AnimNameS = Variable.parseFrom(input.ReadLine());
            if (newObject.AnimNameS == null || !newObject.AnimNameS.id.Equals("Anim Name S", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }
            newObject.AnimNameW = Variable.parseFrom(input.ReadLine());
            if (newObject.AnimNameW == null || !newObject.AnimNameW.id.Equals("Anim Name W", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            Variable isKillable = Variable.parseFrom(input.ReadLine());

            if (isKillable == null || !isKillable.id.Equals("IsKillable", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }


            // get the object's sprite
            SpriteSheet spriteSheet = spriteSheets.getSpriteSheet(spriteSheetName.value);

            if (spriteSheet == null)
            {
                return(null);
            }


            newObject.m_bKillable = bool.Parse(isKillable.value);
            //newObject.sprite.m_SpriteDepth = float.Parse(layerDepth.value);
            newObject.SetIsDirectionBased(true);
            newObject.SetDirAnimation(AnimDirection.DIR_N, newObject.AnimNameN.value);
            newObject.SetDirAnimation(AnimDirection.DIR_E, newObject.AnimNameE.value);
            newObject.SetDirAnimation(AnimDirection.DIR_S, newObject.AnimNameS.value);
            newObject.SetDirAnimation(AnimDirection.DIR_W, newObject.AnimNameW.value);
            newObject.updateInitialValues();

            return(newObject);
        }
Пример #6
0
        public static Level readFrom(String fileName)
        {
            if (fileName == null || fileName.Length == 0)
            {
                return(null);
            }
            hasAnyLevelBeenLoaded = true;

            Level     level;
            LevelType type                   = DEFAULT_LEVEL_TYPE;
            int       gridSize               = DEFAULT_GRID_SIZE;
            Point     dimensions             = Point.Zero;
            int       numberOfCollisionEdges = 0;
            int       numberOfObjects        = 0;

            StreamReader input = null;

            try {
                input = File.OpenText(fileName);
            }
            catch (Exception) {
                return(null);
            }

            String data;

            // read initial header
            while ((data = input.ReadLine()) != null)
            {
                data = data.Trim();
                if (data.Length == 0)
                {
                    continue;
                }

                // read and verify level type
                String[] versionHeader = data.Split(':');
                if (versionHeader.Length != 2)
                {
                    return(null);
                }

                String typeString = versionHeader[0] = versionHeader[0].Trim();
                if (typeString.Equals(CARTESIAN_TYPE, StringComparison.OrdinalIgnoreCase))
                {
                    type = LevelType.Cartesian;
                }
                else if (typeString.Equals(ISOMETRIC_TYPE, StringComparison.OrdinalIgnoreCase))
                {
                    type = LevelType.Isometric;
                }
                else
                {
                    return(null);
                }

                // read and verify level version
                String   versionString = versionHeader[1].Trim();
                String[] versionData   = versionString.Split(' ');
                if (versionData.Length != 2)
                {
                    return(null);
                }
                if (!versionData[0].Equals("Version", StringComparison.OrdinalIgnoreCase))
                {
                    return(null);
                }
                try {
                    float version = float.Parse(versionData[1]);

                    if (version != LEVEL_VERSION)
                    {
                        return(null);
                    }
                }
                catch (Exception) { return(null); }

                break;
            }

            // read grid size
            while ((data = input.ReadLine()) != null)
            {
                data = data.Trim();
                if (data.Length == 0)
                {
                    continue;
                }

                // read and store grid size
                String[] gridHeader = data.Split(':');
                if (gridHeader.Length != 2)
                {
                    return(null);
                }
                if (!gridHeader[0].Trim().Equals("Grid Size", StringComparison.OrdinalIgnoreCase))
                {
                    return(null);
                }
                try {
                    gridSize = Int32.Parse(gridHeader[1].Trim());
                }
                catch (Exception) { return(null); }

                break;
            }

            // read map dimensions
            while ((data = input.ReadLine()) != null)
            {
                data = data.Trim();
                if (data.Length == 0)
                {
                    continue;
                }

                // read and store grid size
                String[] dimensionHeader = data.Split(':');
                if (dimensionHeader.Length != 2)
                {
                    return(null);
                }
                if (!dimensionHeader[0].Trim().Equals("Dimensions", StringComparison.OrdinalIgnoreCase))
                {
                    return(null);
                }
                String[] dimensionData = dimensionHeader[1].Split(',');
                if (dimensionData.Length != 2)
                {
                    return(null);
                }
                try {
                    dimensions.X = Int32.Parse(dimensionData[0].Trim());
                    dimensions.Y = Int32.Parse(dimensionData[1].Trim());
                }
                catch (Exception) { return(null); }

                break;
            }

            // read collision data header
            while ((data = input.ReadLine()) != null)
            {
                data = data.Trim();
                if (data.Length == 0)
                {
                    continue;
                }

                // verify header and parse number of collision edges
                String[] collisionHeader = data.Split(':');
                if (collisionHeader.Length != 2)
                {
                    return(null);
                }
                if (!collisionHeader[0].Trim().Equals("Collision Edges", StringComparison.OrdinalIgnoreCase))
                {
                    return(null);
                }
                try {
                    numberOfCollisionEdges = Int32.Parse(collisionHeader[1].Trim());
                }
                catch (Exception) { return(null); }

                break;
            }

            level = new Level(type, gridSize, dimensions);

            level.collisionData = Graph.parseFrom(input, numberOfCollisionEdges);

            // read objects header and number of objects
            while ((data = input.ReadLine()) != null)
            {
                String objectsHeader = data.Trim();
                if (objectsHeader.Length == 0)
                {
                    continue;
                }

                // separate header data
                String[] headerData = objectsHeader.Split(':');
                if (headerData.Length != 2)
                {
                    return(null);
                }

                // verify the objects header
                if (!headerData[0].Trim().Equals("Objects", StringComparison.OrdinalIgnoreCase))
                {
                    return(null);
                }

                // parse the number of objects
                try {
                    numberOfObjects = Int32.Parse(headerData[1].Trim());
                }
                catch (Exception) { return(null); }

                break;
            }

            // load the objects
            int currentObject = 0;

            while (currentObject < numberOfObjects)
            {
                data = input.ReadLine();
                String objectHeader = data.Trim();
                if (objectHeader.Length == 0)
                {
                    continue;
                }

                // parse object type
                String objectType;
                if (objectHeader[objectHeader.Length - 1] == ':')
                {
                    objectType = objectHeader.Substring(0, objectHeader.Length - 1);
                }
                else
                {
                    return(null);
                }

                // parse the object based on its type
                GameObject newObject = null;
                if (objectType.Equals("Static Object", StringComparison.OrdinalIgnoreCase))
                {
                    newObject = StaticObject.parseFrom(input, Firecracker.spriteSheets);
                }
                else if (objectType.Equals("Game Tile", StringComparison.OrdinalIgnoreCase))
                {
                    newObject = GameTile.parseFrom(input, Firecracker.spriteSheets);
                }
                else if (objectType.Equals("NPCObject", StringComparison.OrdinalIgnoreCase))
                {
                    newObject = NPCObject.parseFrom(input, Firecracker.spriteSheets);
                }
                else if (objectType.Equals("Player", StringComparison.OrdinalIgnoreCase))
                {
                    newObject = Player.parseFrom(input, Firecracker.spriteSheets);
                }
                else if (objectType.Equals("Settlement", StringComparison.OrdinalIgnoreCase))
                {
                    newObject = Settlement.parseFrom(input, Firecracker.spriteSheets);
                }
                else if (objectType.Equals("Terrain", StringComparison.OrdinalIgnoreCase))
                {
                    newObject = Terrain.parseFrom(input, Firecracker.spriteSheets);
                }
                // verify that the object was successfully parsed
                if (newObject != null)
                {
                    currentObject++;
                    level.addObject(newObject);
                }
                else
                {
                    return(null);
                }
            }

            input.Close();

            PopupNotification.instance.ShowNotification("Objective", "Destroy all of the humans before they multiply and acquire\n" +
                                                        "the technology to leave the island. The more you destroy,\n" +
                                                        "the more devastating abilities you will be able to use.", false);

            return(level);
        }