示例#1
0
文件: Match3.cs 项目: Nekketsu/CS50G
        public override async Task Load()
        {
            Sounds.Add("music", await Audio.NewSource("sounds/music3.mp3"));
            Sounds.Add("select", await Audio.NewSource("sounds/select.wav"));
            Sounds.Add("error", await Audio.NewSource("sounds/error.wav"));
            Sounds.Add("match", await Audio.NewSource("sounds/match.wav"));
            Sounds.Add("clock", await Audio.NewSource("sounds/clock.wav"));
            Sounds.Add("game-over", await Audio.NewSource("sounds/game-over.wav"));
            Sounds.Add("next-level", await Audio.NewSource("sounds/next-level.wav"));

            Textures = new Dictionary <string, Image>
            {
                ["main"]       = await Graphics.NewImage("graphics/match3.png"),
                ["background"] = await Graphics.NewImage("graphics/background.png"),
            };

            var util = new Util();

            Frames = new Dictionary <string, Quad[][]>
            {
                // divided into sets for each tile type in this game, instead of one large
                // table of Quads
                ["tiles"] = util.GenerateTileQuads(Textures["main"])
            };

            // this time, we're keeping our fonts in a global table for readability
            Fonts = new Dictionary <string, Font>
            {
                ["small"]  = await Graphics.NewFont("fonts/font.ttf", 8),
                ["medium"] = await Graphics.NewFont("fonts/font.ttf", 16),
                ["large"]  = await Graphics.NewFont("fonts/font.ttf", 32)
            };


            // set music to loop and start
            Sounds["music"].Looping = true;
            await Sounds["music"].Play();

            Timer = new GameEngine.Timers.Timer();

            // initialize state machine with all state-returning functions
            StateMachine = new StateMachine(new Dictionary <string, State>
            {
                ["start"]      = new StartState(),
                ["begin-game"] = new BeginGameState(),
                ["play"]       = new PlayState(),
                ["game-over"]  = new GameOverState()
            });

            await StateMachine.Change("start");

            // keep track of scrolling our background on the X axis
            backgroundX = 0;
        }
示例#2
0
        public override async Task Load()
        {
            Textures = new Dictionary <string, Image>
            {
                ["tiles"]                 = await Graphics.NewImage("graphics/tilesheet.png"),
                ["background"]            = await Graphics.NewImage("graphics/background.png"),
                ["character-walk"]        = await Graphics.NewImage("graphics/character_walk.png"),
                ["character-swing-sword"] = await Graphics.NewImage("graphics/character_swing_sword.png"),
                ["hearts"]                = await Graphics.NewImage("graphics/hearts.png"),
                ["switches"]              = await Graphics.NewImage("graphics/switches.png"),
                ["entities"]              = await Graphics.NewImage("graphics/entities.png"),
            };

            var utils = new Utils();

            Frames = new Dictionary <string, Quad[]>
            {
                ["tiles"]                 = utils.GenerateQuads(Textures["tiles"], 16, 16),
                ["character-walk"]        = utils.GenerateQuads(Textures["character-walk"], 16, 32),
                ["character-swing-sword"] = utils.GenerateQuads(Textures["character-swing-sword"], 32, 32),
                ["entities"]              = utils.GenerateQuads(Textures["entities"], 16, 16),
                ["hearts"]                = utils.GenerateQuads(Textures["hearts"], 16, 16),
                ["switches"]              = utils.GenerateQuads(Textures["switches"], 16, 18),
            };

            Fonts = new Dictionary <string, Font>
            {
                ["small"]         = await Graphics.NewFont("fonts/font.ttf", 8),
                ["medium"]        = await Graphics.NewFont("fonts/font.ttf", 16),
                ["large"]         = await Graphics.NewFont("fonts/font.ttf", 32),
                ["gothic-medium"] = await Graphics.NewFont("fonts/GothicPixels.ttf", 16),
                ["gothic-large"]  = await Graphics.NewFont("fonts/GothicPixels.ttf", 32),
                ["zelda"]         = await Graphics.NewFont("fonts/zelda.otf", 64),
                ["zelda-small"]   = await Graphics.NewFont("fonts/zelda.otf", 32),
            };

            Sounds.Add("music", await Audio.NewSource("sounds/music.mp3"));
            Sounds.Add("sword", await Audio.NewSource("sounds/sword.wav"));
            Sounds.Add("hit-enemy", await Audio.NewSource("sounds/hit_enemy.wav"));
            Sounds.Add("hit-player", await Audio.NewSource("sounds/hit_player.wav"));
            Sounds.Add("door", await Audio.NewSource("sounds/door.wav"));

            var gameObjectDefs = new GameObjectDefs();

            GameObjectDefs = gameObjectDefs.Defs;

            var entityDefs = new EntityDefs();

            EntityDefs = entityDefs.Defs;

            Graphics.SetFont(Fonts["small"]);

            Timer = new GameEngine.Timers.Timer();
            Event = new Event();

            StateMachine = new StateMachine(new Dictionary <string, State>
            {
                ["start"]     = new StartState(),
                ["play"]      = new PlayState(),
                ["game-over"] = new GameOverState()
            });
            await StateMachine.Change("start");

            Sounds["music"].Looping = true;
            await Sounds["music"].Play();
        }
示例#3
0
        public override async Task Load()
        {
            Sounds.Add("jump", await Audio.NewSource("sounds/jump.wav"));
            Sounds.Add("death", await Audio.NewSource("sounds/death.wav"));
            Sounds.Add("music", await Audio.NewSource("sounds/music.wav"));
            Sounds.Add("powerup-reveal", await Audio.NewSource("sounds/powerup-reveal.wav"));
            Sounds.Add("pickup", await Audio.NewSource("sounds/pickup.wav"));
            Sounds.Add("empty-block", await Audio.NewSource("sounds/empty-block.wav"));
            Sounds.Add("kill", await Audio.NewSource("sounds/kill.wav"));
            Sounds.Add("kill2", await Audio.NewSource("sounds/kill2.wav"));

            Textures = new Dictionary <string, Image>
            {
                ["tiles"]       = await Graphics.NewImage("graphics/tiles.png"),
                ["toppers"]     = await Graphics.NewImage("graphics/tile_tops.png"),
                ["bushes"]      = await Graphics.NewImage("graphics/bushes_and_cacti.png"),
                ["jump-blocks"] = await Graphics.NewImage("graphics/jump_blocks.png"),
                ["gems"]        = await Graphics.NewImage("graphics/gems.png"),
                ["backgrounds"] = await Graphics.NewImage("graphics/backgrounds.png"),
                ["green-alien"] = await Graphics.NewImage("graphics/green_alien.png"),
                ["creatures"]   = await Graphics.NewImage("graphics/creatures.png"),
            };

            var util = new Util();

            Frames = new Dictionary <string, Quad[]>
            {
                ["tiles"]       = util.GenerateQuads(Textures["tiles"], TileSize, TileSize),
                ["toppers"]     = util.GenerateQuads(Textures["toppers"], TileSize, TileSize),
                ["bushes"]      = util.GenerateQuads(Textures["bushes"], 16, 16),
                ["jump-blocks"] = util.GenerateQuads(Textures["jump-blocks"], 16, 16),
                ["gems"]        = util.GenerateQuads(Textures["gems"], 16, 16),
                ["backgrounds"] = util.GenerateQuads(Textures["backgrounds"], 256, 128),
                ["green-alien"] = util.GenerateQuads(Textures["green-alien"], 16, 20),
                ["creatures"]   = util.GenerateQuads(Textures["creatures"], 16, 16)
            };

            // these need to be added after gFrames is initialized because they refer to gFrames from within
            FrameSets = new Dictionary <string, Quad[][]>
            {
                ["tilesets"]   = util.GenerateTileSets(Frames["tiles"], TileSetsWide, TileSetsTall, TileSetWidth, TileSetHeight),
                ["toppersets"] = util.GenerateTileSets(Frames["toppers"], TopperSetsWide, TopperSetsTall, TileSetWidth, TileSetHeight)
            };

            Fonts = new Dictionary <string, Font>
            {
                ["small"]  = await Graphics.NewFont("fonts/font.ttf", 8),
                ["medium"] = await Graphics.NewFont("fonts/font.ttf", 16),
                ["large"]  = await Graphics.NewFont("fonts/font.ttf", 32),
                ["title"]  = await Graphics.NewFont("fonts/ArcadeAlternate.ttf", 32),
            };

            Timer = new GameEngine.Timers.Timer();

            StateMachine = new StateMachine(new Dictionary <string, State>
            {
                ["start"] = new StartState(),
                ["play"]  = new PlayState()
            });
            await StateMachine.Change("start");

            Sounds["music"].Looping = true;
            Sounds["music"].Volume  = 0.5;
            await Sounds["music"].Play();
        }