Exemplo n.º 1
0
        public void processEvents(Tile cur)
        {
            if(Game1.DEBUG)
                Console.WriteLine("Processing Events!");

            Event[] ce = cur.getEvents();

            if(Game1.DEBUG)
            Console.WriteLine("Found " + ce.Length + " events!");

            for (int i = 0; i < ce.Length; i++)
            {
                Game1.addToEventQueue(ce[i]);
            }

            for(int i = 0; i < monstertiles.Count; i++)
                if(cur.getMapX() == monstertiles[i].getMapX() && cur.getMapY() == monstertiles[i].getMapY())
                {
                    Event e = new Event();
                    e.setEventType(EventType.BATTLE_TILE);
                    e.addProperty("battlemap", battlemap.GetFilePath());
                    e.addProperty("enemytexture", monstertiles[i].getTexture().Name);
                    e.addProperty("index", Convert.ToString(i));
                    Game1.addToEventQueue(e);
                }
        }
Exemplo n.º 2
0
        public bool LoadMap(StreamReader file, String filename, ToolMap toolmap)
        {
            this.filename = filename;
            bool success = false;
            bool gotxandy = false;
            int x = 0;
            int y = 0;
            int playerx = -1;
            int playery = -1;

            using (XmlReader reader = XmlReader.Create(file))
            {
                while (reader.Read() && !gotxandy)
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            if (reader.Name == "MAP")
                            {
                                x = Convert.ToInt32(reader["x"]);
                                y = Convert.ToInt32(reader["y"]);
                                if(reader["playerx"] != null && reader["playery"] != null)
                                {
                                    playerx = Convert.ToInt32(reader["playerx"]);
                                    playery = Convert.ToInt32(reader["playery"]);
                                }

                                gotxandy = true;
                            }
                            break;
                    }
                }
            }

            xtiles = x;
            ytiles = y;

            map = new Tile[x][];
            for(int i = 0; i < x; i++)
                map[i] = new Tile[y];

            file.BaseStream.Position = 0;
            int tilex = 0;
            int tiley = 0;
            bool inEvent = false;
            Event current = new Event();
            using (XmlReader reader = XmlReader.Create(file))
            {
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            if (reader.Name == "MONSTER")
                            {
                                //file.WriteLine("<MONSTER type=\"" + monstertiles[i].getType() + "\" x=\"" +
                                //    monstertiles[i].getMapX() + "\" y=\"" + monstertiles[i].getMapY() + "\" />");
                                hasmonsters = true;
                                String type = reader["type"];
                                tilex = Convert.ToInt32(reader["x"]);
                                tiley = Convert.ToInt32(reader["y"]);

                                if (Game1.DEBUG)
                                    Console.WriteLine("Adding Monster!!, monstertiles.Count=" + monstertiles.Count);

                                monstertiles.Add(new Tile(tilex, tiley, 0, 0, 0, toolmap.getTool(type)));
                            }
                            if (reader.Name == "TILE")
                            {
                                tilex = Convert.ToInt32(reader["x"]);
                                tiley = Convert.ToInt32(reader["y"]);

                                String type = reader["type"];
                                Tool tiletool = toolmap.getTool(type);
                                map[tilex][tiley] = new Tile(tilex, tiley, tilex, tiley, 0, tiletool);
                            }
                            else if (reader.Name == "EVENT")
                            {
                                String eventtype = reader["type"];
                                current.setEventType((EventType)Enum.Parse(typeof(EventType), eventtype));
                                inEvent = true;
                            }
                            else if (reader.Name == "DATA")
                            {
                                if (inEvent)
                                {
                                    XmlReader tempreader = reader.ReadSubtree();
                                    String propname = "";
                                    while(tempreader.Read())
                                        switch (tempreader.NodeType)
                                        {
                                            case XmlNodeType.Element:
                                                propname = tempreader.Name;
                                                break;
                                            case XmlNodeType.Text:
                                                current.addProperty(propname, tempreader.Value);
                                                break;
                                        }
                                }
                            }
                            break;
                        case XmlNodeType.EndElement:
                            if (reader.Name == "EVENT")
                            {
                                if(Game1.DEBUG)
                                Console.WriteLine("Adding event!");

                                map[tilex][tiley].addEvent(current);
                                inEvent = false;
                                current = new Event();
                            }
                            break;
                    }
                }
            }

            if (playertile == null)
                playertile = toolmap.getPlayerTile();

            if (playerx > 0 && playery > 0)
                setPlayerLocation(map[playerx][playery]);

            success = true;

            return success;
        }
Exemplo n.º 3
0
        private void processEvents(GameTime gameTime)
        {
            while (eventqueue.Count > 0)
            {
                Event e = eventqueue.Dequeue();
                if (e.getEventType() == EventType.MAP_TRANSITION)
                {
                    String mapfile = e.getProperty("mapfile");
                    int x = Convert.ToInt32(e.getProperty("x"));
                    int y = Convert.ToInt32(e.getProperty("y"));

                    //if(DEBUG)
                    Console.WriteLine("Processing Map Transition Event for " + mapfile + " x=" + x + ",y=" + y);

                    if(mapfile.Contains("dragon"))
                    {
                        if (!currSong.Equals(cave))
                        {
                            MediaPlayer.Stop();
                            PlayMusic(cave);
                            currSong = cave;
                        }
                    }
                    else
                    {
                        if (!currSong.Equals(town))
                        {
                            MediaPlayer.Stop();
                            PlayMusic(town);
                            currSong = town;
                        }
                    }
                    map = getMap(mapfile, x, y);
                    if(DEBUG)
                    Console.WriteLine("Reached 2");

                    Game1.playstate = PlayState.WORLD;
                    map.setEnemySpawnTime((int)gameTime.TotalGameTime.TotalMilliseconds);
                }
                else if (e.getEventType() == EventType.BATTLE_TILE)
                {
                    int x = map.getPlayerTile().getMapX();
                    int y = map.getPlayerTile().getMapY();
                    playstate = PlayState.BATTLE;
                    String file = map.filename;
                    int ind = Convert.ToInt32(e.getProperty("index"));
                    Console.WriteLine("index=" + ind + " monstertiles.count = " + map.getMonsterTilesCount());
                    map.RemoveMonsterTile(Convert.ToInt32(e.getProperty("index")));
                    map = getMap(e.getProperty("battlemap"), 8, 8);
                    //map.removePlayer();

                    Enemy[] enemies;
                    Player px = new Player();
                    if(file.Contains("-m2"))
                    {
                        Enemy m = null;
                        if (!party.hasItem(Item.DRAGON_SKULL))
                            m = new Enemy(new Player(px.getNewEnemy("WARRIOR"), Sprite.ENEMY_2, "Dragon Cat", 7), Item.DRAGON_SKULL);
                        else
                            m = new Enemy(new Player(px.getNewEnemy("WARRIOR"), Sprite.ENEMY_1, "Ninja Pu", 1), Item.HP_POTION_100);

                        enemies = new Enemy[] { m };
                        enemy1RightFaceFile = enemies[0].player.sprite.GetRightFaceImage();
                        enemy1RightFace = Content.Load<Texture2D>(enemy1RightFaceFile);
                        enemy1RightFaceFileHit = enemies[0].player.sprite.GetRightFaceHitImage();
                        enemy1RightFaceHit = Content.Load<Texture2D>(enemy1RightFaceFileHit);
                        playerLeftFaceFile = party.partyMembers[0].sprite.GetLeftFaceImage();
                        playerLeftFace = Content.Load<Texture2D>(playerLeftFaceFile);
                        playerLeftFaceFileHit = party.partyMembers[0].sprite.GetLeftFaceHitImage();
                        playerLeftFaceHit = Content.Load<Texture2D>(playerLeftFaceFileHit);
                    }
                    else
                    {
                        enemies = new Enemy[] { new Enemy(new Player(px.getNewEnemy("WARRIOR"), Sprite.ENEMY_1, "Ninja Pu", 1), Item.HP_POTION_100) };
                        enemy1RightFaceFile = enemies[0].player.sprite.GetRightFaceImage();
                        enemy1RightFace = Content.Load<Texture2D>(enemy1RightFaceFile);
                        enemy1RightFaceFileHit = enemies[0].player.sprite.GetRightFaceHitImage();
                        enemy1RightFaceHit = Content.Load<Texture2D>(enemy1RightFaceFileHit);
                        playerLeftFaceFile = party.partyMembers[0].sprite.GetLeftFaceImage();
                        playerLeftFace = Content.Load<Texture2D>(playerLeftFaceFile);
                        playerLeftFaceFileHit = party.partyMembers[0].sprite.GetLeftFaceHitImage();
                        playerLeftFaceHit = Content.Load<Texture2D>(playerLeftFaceFileHit);
                    }

                    bs = new BattleSequence(party, enemies , Content.Load<SpriteFont>("gameFont"),map, x,y,file);
                    bs.Start();
                    //bs = null;

                    PlayMusic(battle);
                    currSong = battle;
                    /*String mapfile = e.getProperty("mapfile");
                    int x = Convert.ToInt32(e.getProperty("x"));
                    int y = Convert.ToInt32(e.getProperty("y"));
                    */
                }
                else if (e.getEventType() == EventType.WAITFORNPC)
                {
                    currentevent = e;
                    playstate = PlayState.WAITFORNPC;
                }
                else if (e.getEventType() == EventType.NPCQUEST)
                {
                    currentevent = e;
                    playstate = PlayState.NPCQUEST;
                }
                else if (e.getEventType() == EventType.MESSAGE)
                {
                    currentevent = e;
                    playstate = PlayState.MESSAGE;
                }
                else if (e.getEventType() == EventType.WIN_GAME)
                {
                    currentevent = e;
                    state = GameState.GAMEOVER;
                    playstate = PlayState.GAMEOVER_WIN;
                }
                else if (e.getEventType() == EventType.LOSE_GAME)
                {
                    currentevent = e;
                    state = GameState.GAMEOVER;
                    playstate = PlayState.GAMEOVER_LOSE;
                }
                else if (e.getEventType() == EventType.QUESTRETURN)
                {
                    String questid = e.getProperty("questid");
                    if (!party.questCompleted(questid))
                    {
                        Quest q = quests[questid];

                        if (party.hasItem(q.getQuestItem()))
                        {
                            party.removeItem(q.getQuestItem());
                            party.completeQuest(q);

                            Event m = new Event();
                            m.setEventType(EventType.MESSAGE);
                            m.addProperty("text", q.getQuestCompleteText());
                            addToEventQueue(m);

                            Event n = new Event();
                            n.setEventType(EventType.WIN_GAME);
                            addToEventQueue(n);

                        }
                        else
                        {
                            Event m = new Event();
                            m.setEventType(EventType.MESSAGE);
                            m.addProperty("text", "You have not completed this\nquest yet.");
                            addToEventQueue(m);
                        }
                    }
                    else
                        playstate = PlayState.WORLD;
                }
            }
        }
Exemplo n.º 4
0
        private void playGame(GameTime gameTime)
        {
            if(playstate != PlayState.WAITFORNPC && playstate != PlayState.MESSAGE)
                catchInput(gameTime, false);

            Tile playertile = map.getPlayerTile();
            int currenttime = (int)gameTime.TotalGameTime.TotalMilliseconds;

                if (playstate == PlayState.WAITFORNPC)
                {
                    if(DEBUG)
                    Console.WriteLine("WAITING FOR NPC!");

                    Event e = currentevent;

                    String questid = e.getProperty("questid");
                    if (!party.questInProgressOrCompleted(questid))
                    {
                        String model = e.getProperty("npctexture");
                        String spawnx = e.getProperty("x");
                        String spawny = e.getProperty("y");
                        String goalx = e.getProperty("goalx");
                        String goaly = e.getProperty("goaly");
                        int goalxint = Convert.ToInt32(goalx);
                        int goalyint = Convert.ToInt32(goaly);

                        /*
                        String questid = e.getProperty("questid");
                        String questreturnmap = e.getProperty("questret");
                        String questretx = e.getProperty("questretx");
                        String questrety = e.getProperty("questrety");
                        */

                        map.addNPC(model, Convert.ToInt32(spawnx), Convert.ToInt32(spawny), toolmap.getTool("PRINCESS"));
                        Tile npc = map.getNPC(model);
                        if (npc != null)
                        {
                            if (goalxint == npc.getMapX() && goalyint == npc.getMapY())
                            {
                                if(DEBUG)
                                    Console.WriteLine("Made it to the goal.. NPC");
                                //String questid = e.getProperty("questid");
                                String questreturnmap = e.getProperty("questret");
                                String questretx = e.getProperty("questretx");
                                String questrety = e.getProperty("questrety");

                                Event newev = new Event();
                                newev.setEventType(EventType.NPCQUEST);
                                newev.addProperty("npctexture", model);
                                newev.addProperty("questid", questid);
                                newev.addProperty("questret", questreturnmap);
                                newev.addProperty("questretx", questretx);
                                newev.addProperty("questrety", questrety);

                                addToEventQueue(newev);
                            }
                            //havent reached goal yet...
                            else if ((currenttime - lastmonstermove) > MONSTER_MOVE_DELAY)
                            {

                                Tile astartile = null;
                                Tile best = processAStar(map.getTileAt(goalxint, goalyint), npc);
                                if (best != null)
                                {
                                    astartile = best;
                                    Tile next = getNextStep(best);
                                    map.setNPCLocation(model, next);
                                    map.refreshTiles();
                                    edited = true;
                                }
                                else
                                    Console.WriteLine("Best is null!");

                                lastmonstermove = currenttime;
                            }
                        }
                        else
                        {
                            playstate = PlayState.WORLD;
                        }
                    }
                    else
                    {
                        playstate = PlayState.WORLD;
                    }
                }
                else if (playstate == PlayState.INVENTORY)
                {
                    KeyboardState kb = Keyboard.GetState();
                    if(kb.IsKeyDown(Keys.Space))
                    {
                        playstate = PlayState.WORLD;
                    }
                }
                else if (playstate == PlayState.NPCQUEST)
                {
                    if (DEBUG)
                        Console.WriteLine("Entered PlayGame NPCQUEST Section");

                    Event e = currentevent;
                    String model = e.getProperty("npctexture");
                    String questid = e.getProperty("questid");
                    String questreturnmap = e.getProperty("questret");
                    String questretx = e.getProperty("questretx");
                    String questrety = e.getProperty("questrety");

                    if (DEBUG)
                    {
                        Console.WriteLine("party already done quest??? -> " + party.questInProgressOrCompleted(questid));
                    }

                    if (quests.ContainsKey(questid) && !party.questInProgressOrCompleted(questid))
                    {
                        if (DEBUG)
                            Console.WriteLine("Quest can proceeed!");

                        Quest q = quests[questid];
                        party.addQuest(q);

                        Event x = new Event();
                        x.setEventType(EventType.MESSAGE);
                        x.addProperty("text", q.getQuestText());
                        x.addProperty("removenpconcomplete", model);
                        addToEventQueue(x);

                        TileMap returnmap = getMap(q.getReturnMap(), -1, -1);

                        Event j = new Event();
                        j.setEventType(EventType.QUESTRETURN);
                        j.addProperty("questid", q.getQuestID());
                        returnmap.addTileEvent(j, q.getReturnX(), q.getReturnY());
                    }
                }
                else if (playstate == PlayState.MESSAGE)
                {
                    if (!setmessage)
                    {
                        String text = currentevent.getProperty("text");
                        Message m = new Message(text, whitepixel, font);
                        map.setMessage(m);
                        setmessage = true;
                    }

                    KeyboardState kb = Keyboard.GetState();
                    if (kb.IsKeyDown(Keys.Space))
                    {
                        setmessage = false;
                        playstate = PlayState.WORLD;
                        map.removeMessage();

                        String removenpcid = currentevent.getProperty("removenpconcomplete");
                        if (removenpcid != null)
                            map.removeNPC(removenpcid);
                    }

                    //Console.WriteLine("Would Be Printing: " + text);
                }
                else
                {
                    map.tryMonsterSpawn(currenttime);

                    Tile[] monsters = map.getMonsters();
                    if ((currenttime - lastmonstermove) > MONSTER_MOVE_DELAY)
                    {
                        for (int i = 0; i < monsters.Length && playstate == PlayState.WORLD; i++)
                        {
                            Tile astartile = null;
                            Tile best = processAStar(playertile, monsters[i]);
                            if (best != null)
                            {
                                astartile = best;
                                Tile next = getNextStep(best);
                                map.setMonsterLocation(i, next);
                                map.refreshTiles();
                                edited = true;
                            }
                            else
                                Console.WriteLine("Best is null!");
                        }

                        lastmonstermove = currenttime;
                    }
                }
        }
Exemplo n.º 5
0
        public void Update(GameTime gameTime)
        {
            for (int i = 0; i < playerec.Length; i++)
                playerec[i].Update(gameTime);

            for (int i = 0; i < enemyrec.Length; i++)
                enemyrec[i].Update(gameTime);

            if (!drawprojectile && projectiles.Count > 0)
            {
                currentprojectile = projectiles.Dequeue();
                shotprojectileat = (int)gameTime.TotalGameTime.TotalMilliseconds;
                drawprojectile = true;
                drawplayerhpattime = shotprojectileat + 2 * PROJECTILE_TIME;
            }
            if (drawplayerhpattime < gameTime.TotalGameTime.TotalMilliseconds)
            {
                drawplayerhp = true;
            }
            if (drawplayerhp && drawplayerhpattime + 1000 < gameTime.TotalGameTime.TotalMilliseconds)
            {
                drawplayerhp = false;
                drawplayerhpattime = Int32.MaxValue;
            }
            if (drawprojectile)
            {
                currentprojectile.Update(gameTime);
                int curtime = (int)gameTime.TotalGameTime.TotalMilliseconds;
                if (curtime - shotprojectileat > PROJECTILE_TIME)
                {
                    drawprojectile = false;
                }
            }

            if (!drawprojectile)
            {
                switch (state)
                {
                    case BattleStageType.ACTION:
                        if (enemies[0].player.GetCurrentHealth() <= 0)
                        {
                            state = BattleStageType.WIN;
                        }
                        if (party.partyMembers[0].GetCurrentHealth() <= 0)
                        {
                           state =  BattleStageType.LOSE;

                        }

                        if (state == BattleStageType.ACTION)
                        {
                            aButton.Update();
                            itemButton.Update();
                            fleeButton.Update();
                            spellButton.Update();
                        }
                        break;
                    case BattleStageType.FIGHT:
                        while (this.currentActions.Count > 0)
                        {
                            BattleAction a = this.currentActions.Dequeue();
                            a.performAction(gameTime);
                        }
                        //this.state = BattleStageType.ACTION;
                        break;
                    case BattleStageType.FLEE:
                        Console.WriteLine("FLEE STAGE?");
                        Event e = new Event();
                        e.setEventType(EventType.MAP_TRANSITION);
                        e.addProperty("x", xRet);
                        e.addProperty("y", yRet);
                        e.addProperty("mapfile", retMap);
                        Game1.addToEventQueue(e);
                        this.continueCombat = false;
                        break;
                    case BattleStageType.LOSE:
                        Event e1 = new Event();
                        e1.setEventType(EventType.MAP_TRANSITION);
                        e1.addProperty("x", xRet);
                        e1.addProperty("y", yRet);
                        e1.addProperty("mapfile", retMap);
                        Game1.addToEventQueue(e1);
                        Event e2 = new Event();
                        e2.setEventType(EventType.LOSE_GAME);
                        Game1.addToEventQueue(e2);
                        break;
                    case BattleStageType.WIN:
                        party.partyMembers[0].inventory.AddItem(enemies[0].prize);
                        Event e3 = new Event();
                        e3.setEventType(EventType.MAP_TRANSITION);
                        e3.addProperty("x", xRet);
                        e3.addProperty("y", yRet);
                        e3.addProperty("mapfile", retMap);
                        Game1.addToEventQueue(e3);
                        Event e4 = new Event();
                        e4.setEventType(EventType.MESSAGE);
                        e4.addProperty("text", "You looted " + enemies[0].prize.name);
                        Game1.addToEventQueue(e4);

                        break;
                }
            }
        }