コード例 #1
0
ファイル: GameLevel.cs プロジェクト: bootzin/Tijolator
 // desenhar os blocos do jogo
 public void Draw(Renderer2D renderer)
 {
     foreach (var tile in Bricks)
     {
         if (!tile.Destroyed)
         {
             tile.Draw(renderer);
         }
     }
 }
コード例 #2
0
 // desenhar o objeto utilizando a classe de renderização
 public void Draw(Renderer2D renderer)
 {
     renderer.DrawTexture(Sprite, Position, Size, Rotation, Color);
 }
コード例 #3
0
        //Método responsável por inicializar todos os recursos utilizados no jogo
        public void Init()
        {
            // carregar sons
            var bgm = ResourceManager.LoadSound("resources/bgm.mp3", "bgm", true);

            SoundEngine.Instance.PlaySound(bgm);

            ResourceManager.LoadSound("resources/bleep.wav", "bleepPaddle");
            ResourceManager.LoadSound("resources/powerup.wav", "powerup");
            ResourceManager.LoadSound("resources/solid.wav", "solid");
            ResourceManager.LoadSound("resources/bleep.mp3", "bleepBrick");

            //carregar shaders
            ResourceManager.LoadShader("shaders/sprite.vert", "shaders/sprite.frag", "sprite");
            ResourceManager.LoadShader("shaders/particle.vert", "shaders/particle.frag", "particle");
            ResourceManager.LoadShader("shaders/postProcessing.vert", "shaders/postProcessing.frag", "postProcessing");

            //instanciar a matriz de projeção ortogonal
            var projection = Matrix4.CreateOrthographicOffCenter(0, Width, Height, 0, -1, 1);

            // instanciar o renderizador padrão de texturas
            var spriteshader   = ResourceManager.GetShader("sprite");
            var particleshader = ResourceManager.GetShader("particle");

            spriteshader.SetInteger("image", 0, true);
            spriteshader.SetMatrix4("projection", projection, true);
            particleshader.SetInteger("sprite", 0, true);
            particleshader.SetMatrix4("projection", projection, true);
            Renderer = new Renderer2D(spriteshader);

            // carregar as texturas do jogo
            ResourceManager.LoadTexture("resources/ball.png", "ball");
            ResourceManager.LoadTexture("resources/paddle.png", "paddle");
            ResourceManager.LoadTexture("resources/block.png", "block", false);
            ResourceManager.LoadTexture("resources/block_solid.png", "block_solid", false);
            ResourceManager.LoadTexture("resources/background.jpg", "breakout_bg", false);

            ResourceManager.LoadTexture("resources/particle.png", "particle");

            ResourceManager.LoadTexture("resources/speed.png", "speed");
            ResourceManager.LoadTexture("resources/meteor.png", "comet");
            ResourceManager.LoadTexture("resources/width.png", "padIncrease");
            ResourceManager.LoadTexture("resources/shrink.png", "padDecrease");
            ResourceManager.LoadTexture("resources/multiply.png", "multiply");
            ResourceManager.LoadTexture("resources/sticky.png", "sticky");
            ResourceManager.LoadTexture("resources/confuse.png", "confuse");
            ResourceManager.LoadTexture("resources/skull.png", "chaos");

            //carregar os níveis disponíveis no jogo
            GameLevel one = new GameLevel();

            one.Load("levels/one.lvl", Width, Height / 2);
            GameLevel two = new GameLevel();

            two.Load("levels/two.lvl", Width, Height / 2);
            GameLevel three = new GameLevel();

            three.Load("levels/three.lvl", Width, Height / 2);
            GameLevel four = new GameLevel();

            four.Load("levels/four.lvl", Width, Height / 2);
            GameLevel five = new GameLevel();

            five.Load("levels/five.lvl", Width, Height / 2);
            GameLevel six = new GameLevel();

            six.Load("levels/six.lvl", Width, Height / 2);
            Levels.Add(one);
            Levels.Add(two);
            Levels.Add(three);
            Levels.Add(four);
            Levels.Add(five);
            Levels.Add(six);
            Level = 4;

            // instanciar jogador
            const float offset         = 84f;
            Vector2     playerStartPos = new Vector2((Width / 2) - (PLAYER_SIZE.X / 2), Height - PLAYER_SIZE.Y - offset);

            Player = new GameObject(playerStartPos, PLAYER_SIZE, ResourceManager.GetTex("paddle"));

            // instanciar bola
            Vector2 ballStartPos = playerStartPos + new Vector2((Player.Size.X / 2f) - BALL_RADIUS, -BALL_RADIUS * 2f);

            Ball = new BallObject(ballStartPos, BALL_RADIUS, ResourceManager.GetTex("ball"), Color.Pink.ToVector3(), velocity: new Vector2(GetRandomBallSpeed(), Difficulty.BallUpSpeed));
            Balls.Add(Ball);

            // instanciar gerador de partículas para efeito de "rastro"
            ParticleGenerator = new ParticleGenerator(ResourceManager.GetShader("particle"), ResourceManager.GetTex("particle"), 500);

            // instanciar classe responsável pelos efeitos de pós-processamento
            PostProcessor = new PostProcessor(ResourceManager.GetShader("postProcessing"), Width, Height);

            // iniciar renderizador de texto
            TextRenderer = new TextRenderer(Width, Height);
            TextRenderer.Load("fonts/ocraext.TTF", 24);

            // iniciar overlay para tela de "pause"
            Overlay = new Texture2D();
            Overlay.Generate(Width, Height, IntPtr.Zero);

            // setar a posição inicial do mouse para o meio da tela
            var point = PointToScreen(new Point(Width / 2, Height / 2));

            Mouse.SetPosition(point.X, point.Y);

            // estado inicial do jogo deve ser o menu
            State = GameState.Menu;
        }