コード例 #1
0
        public void Load(ContentManager content)
        {
            AnimatedTexture animation = new AnimatedTexture(Vector2.Zero, 0, 1, 1);

            animation.Load(content, "zombie", 4, 5);

            sprite.Add(animation, 16, 0);
        }
コード例 #2
0
        public void Load(ContentManager content)
        {
            AnimatedTexture animation = new AnimatedTexture(Vector2.Zero, 0, 1, 1);

            animation.Load(content, "walk", 12, 20);

            jumpSound                = content.Load <SoundEffect>("Jump");
            jumpSoundInstance        = jumpSound.CreateInstance();
            playerDeathSound         = content.Load <SoundEffect>("player_death");
            playerDeathSoundInstance = playerDeathSound.CreateInstance();

            playerSprite.Add(animation, 0, -5);
            playerSprite.position = Respawn;
        }
コード例 #3
0
        public override void Update(ContentManager Content, GameTime gameTime)
        {
            if (isLoaded == false)
            {
                font = Content.Load <SpriteFont>("Arial");

                var viewportAdapter = new BoxingViewportAdapter(game1.Window, game1.GraphicsDevice, ScreenWidth, ScreenHeight);
                camera          = new Camera2D(viewportAdapter);
                camera.Position = new Vector2(0, ScreenHeight);

                map         = Content.Load <TiledMap>("Project_Map");
                mapRenderer = new TiledMapRenderer(game1.GraphicsDevice);

                player.Load(Content);

                foreach (TiledMapTileLayer layer in map.TileLayers)
                {
                    if (layer.Name == "Collision")
                    {
                        collisionLayer = layer;
                    }
                    if (layer.Name == "Spikes")
                    {
                        spikeLayer = layer;
                    }
                }

                foreach (TiledMapObjectLayer layer in map.ObjectLayers)
                {
                    if (layer.Name == "Enemies")
                    {
                        foreach (TiledMapObject obj in layer.Objects)
                        {
                            Enemy enemy = new Enemy(this);
                            enemy.Load(Content);
                            enemy.Position = new Vector2(obj.Position.X, obj.Position.Y);
                            enemies.Add(enemy);
                        }
                    }
                    if (layer.Name == "Goal")
                    {
                        TiledMapObject obj = layer.Objects[0];
                        if (obj != null)
                        {
                            AnimatedTexture anim = new AnimatedTexture(Vector2.Zero, 0, 1, 1);
                            anim.Load(Content, "chest", 1, 1);
                            goal = new Sprite();
                            goal.Add(anim, 0, 5);
                            goal.position = new Vector2(obj.Position.X, obj.Position.Y);
                        }
                    }
                    if (layer.Name == "Key")
                    {
                        TiledMapObject key = layer.Objects[0];
                        if (key != null)
                        {
                            AnimatedTexture keyAnim = new AnimatedTexture(Vector2.Zero, 0, 1, 1);
                            keyAnim.Load(Content, "Key", 1, 1);
                            keys = new Sprite();
                            keys.Add(keyAnim, 0, 5);
                            keys.position = new Vector2(key.Position.X, key.Position.Y);
                        }
                    }
                }

                gameMusic                  = Content.Load <SoundEffect>("Superhero_violin_no_intro");
                gameMusicInstance          = gameMusic.CreateInstance();
                gameMusicInstance.IsLooped = true;
                gameMusicInstance.Play();

                zombieDeath         = Content.Load <SoundEffect>("zombie_death");
                zombieDeathInstance = zombieDeath.CreateInstance();
                keyJingle           = Content.Load <SoundEffect>("key_collect");
                keyJingleInstance   = keyJingle.CreateInstance();
                chestOpen           = Content.Load <SoundEffect>("chest_opened");
                chestOpenInstance   = chestOpen.CreateInstance();

                arialFont = Content.Load <SpriteFont>("Arial");
                heart     = Content.Load <Texture2D>("heart");
                keyIcon   = Content.Load <Texture2D>("Key - Icon");
                lives     = 3;

                isLoaded = true;
            }

            float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            player.Update(deltaTime);
            camera.Position = player.Position - new Vector2(ScreenWidth / 2, ScreenHeight / 2);

            if (keyLost == true)
            {
                timer += deltaTime;
                if (timer >= 3.0f)
                {
                    keyLost = false;
                    timer   = 0f;
                }
            }

            if (score <= 0)
            {
                score = 0;
            }

            foreach (Enemy e in enemies)
            {
                e.Update(deltaTime);
            }

            CheckCollisions();

            if (lives <= 0 || keyCollected == true && chestInteracted == true)
            {
                if (keyCollected == true && chestInteracted == true)
                {
                    score += 3;
                    chestOpen.Play();
                }
                _2D_Platformer.StateManager.ChangeState("GAMEOVER");
                enemies.Clear();
                gameMusicInstance.Stop();
                keyCollected = false;

                isLoaded = false;
            }
        }
コード例 #4
0
 public void Add(AnimatedTexture animation, int xOffset = 0, int yOffset = 0)
 {
     animations.Add(animation);
     animationOffsets.Add(new Vector2(xOffset, yOffset));
 }