Esempio n. 1
0
        private TileMap getMap(String mapfile, int playerx, int playery)
        {
            TileMap ret = null;
            if (maps.ContainsKey(mapfile))
            {
                ret = maps[mapfile];
                if(playerx != -1 && playery != -1)
                    ret.setPlayerLocation(ret.getTileAt(playerx, playery));
            }
            else
            {
                FileStream fileStream = new FileStream(@mapfile, FileMode.Open);
                StreamReader reader = new StreamReader(fileStream);
                ret = new TileMap(10, 10, 17, DEFAULT_X_TILES, DEFAULT_Y_TILES, whitepixel, toolmap, font, mapfile);
                ret.LoadMap(reader, mapfile, toolmap);

                if (playerx != -1 && playery != -1)
                ret.setPlayerLocation(ret.getTileAt(playerx, playery));

                maps.Add(mapfile, ret);
                reader.Close();
                fileStream.Close();
            }
            return ret;
        }
Esempio n. 2
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;
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            whitepixel  = new Texture2D(GraphicsDevice, 1, 1);
            whitepixel.SetData(new Color[] { Color.White });
            astartiles = new List<Tile>();
            astarwaypoint = Content.Load<Texture2D>("AStarWayPoint");
            edited = true;

            font = Content.Load<SpriteFont>("gameFont");
            titlefont = Content.Load<SpriteFont>("titleFont");
            helpText = Content.Load<SpriteFont>("worldText");

            evindicator = Content.Load<Texture2D>("AStarWayPoint");
            cave = Content.Load<Song>("cavemusic");
            town = Content.Load<Song>("Townmusic");
            battle = Content.Load<Song>("battlemusic");
            currSong = town;

            fire = Content.Load<Texture2D>("Tiles/FireBall");
            heal = Content.Load<Texture2D>("Tiles/HealBall");
            sword = Content.Load<Texture2D>("Tiles/SwordAttack1");

            firesound = Content.Load<SoundEffect>("FireballSound");
            healSound = Content.Load<SoundEffect>("Healing");
            swordSound = Content.Load<SoundEffect>("SwordAttack");

            /*tools = new Tool[2][];
            tools[0] = new Tool[4];
            tools[1] = new Tool[4];

            tools[0][0] = new Tool(TileType.GRASS, Content.Load<Texture2D>("Tiles/Grass"), false, 1);
            tools[0][1] = new Tool(TileType.TREES, Content.Load<Texture2D>("Tiles/Trees"), false, 2);
            tools[0][2] = new Tool(TileType.SWAMP, Content.Load<Texture2D>("Tiles/Swamp"), false, 4);
            tools[0][3] = new Tool(TileType.PLAYER, Content.Load<Texture2D>("Tiles/Player"), false, 0);
            tools[1][0] = new Tool(TileType.WATER, Content.Load<Texture2D>("Tiles/Water"), false, 6);
            tools[1][1] = new Tool(TileType.ROCKS, Content.Load<Texture2D>("Tiles/LavaRocks"), false, 8);
            tools[1][2] = new Tool(TileType.WALL, Content.Load<Texture2D>("Tiles/Wall"), true, 0);
            tools[1][3] = new Tool(TileType.MONSTER, Content.Load<Texture2D>("Tiles/Monster"), false, 0);
            */

            System.Collections.ArrayList tiles = new System.Collections.ArrayList();
            foreach (WorldTile t in Enum.GetValues(typeof(WorldTile)))
            {
                tiles.Add(t);

                if(DEBUG)
                Console.WriteLine(t.GetInformation());

                try
                {
                    Texture2D cur = Content.Load<Texture2D>(t.GetTexture());
                    if (cur != null && !texmap.ContainsKey(t.GetTexture()))
                        texmap.Add(t.GetTexture(), cur);
                }
                catch (Microsoft.Xna.Framework.Content.ContentLoadException e)
                {
                }

            }
            worldtiles = tiles.ToArray(typeof(WorldTile)) as WorldTile[];
            Array.Sort(worldtiles, delegate(WorldTile a, WorldTile b)
                                    {
                                        return a.ToString().CompareTo(b.ToString());
                                    });
            if(DEBUG)
            Console.WriteLine(worldtiles.Length);

            //map = new TileMap(10, 10, 17, 512, 512, whitepixel, tools[0][0]);
            toolmap = new ToolMap(578, 100, whitepixel, texmap, worldtiles, font, Window.Handle);
            if (!STARTPLAY)
            {
                toolmap.enable();
            }
            map = new TileMap(10, 10, 17, DEFAULT_X_TILES, DEFAULT_Y_TILES, whitepixel, toolmap, font, FIRSTMAP);
            if (STARTPLAY)
            {
                 FileStream fileStream = new FileStream(@FIRSTMAP, FileMode.Open);
                 StreamReader reader = new StreamReader(fileStream);
                 map.LoadMap(reader, FIRSTMAP, toolmap);
                 maps.Add(FIRSTMAP, map);
                 reader.Close();
                 fileStream.Close();

                 state = GameState.TITLE;
            }
            PlayMusic(Content.Load<Song>("Townmusic"));
            // TODO: use this.Content to load your game content here
        }
Esempio n. 4
0
 public BattleSequence(Party party, Enemy[] enemies, SpriteFont displayTextFont, TileMap battleMap, int xRet, int yRet, String retMap)
 {
     this.playerec = new BattleEntity[] { new BattleEntity(new Rectangle(366, 207, 32, 32), Game1.playerLeftFace, Game1.playerLeftFaceHit) };
     this.enemyrec = new BattleEntity[] { new BattleEntity(new Rectangle(111, 207, 32, 32), Game1.enemy1RightFace, Game1.enemy1RightFaceHit) };
     this.party = party;
     this.enemies = enemies;
     this.combatLog = new List<String>();
     this.combatLogFont = displayTextFont;
     this.currentActions = new Queue<BattleAction>();
     this.continueCombat = true;
     this.partyDead = false;
     this.enemiesDead= false;
     this.isWaiting = false;
     this.xRet = Convert.ToString(xRet);
     this.yRet = Convert.ToString(yRet);
     this.retMap = retMap;
     this.projectiles = new Queue<Projectile>();
     state = BattleStageType.ACTION;
     drawplayerhpattime = Int32.MaxValue;
 }