Ejemplo n.º 1
0
        // This method was shamelessly copy pasted from OpenTK samples.
        public static Sfx Load(string filename)
        {
            Sfx result = new Sfx();

            result.Buffer = AL.GenBuffer();
            result.Source = AL.GenSource();

            Stream       stream = File.Open(filename, FileMode.Open);
            BinaryReader reader = new BinaryReader(stream);

            reader.ReadChars(4); // RIFF?
            reader.ReadInt32();  // riff chunk size
            reader.ReadChars(4); // WAVE?
            reader.ReadChars(4); // "fmt "? Why so many checks!

            reader.ReadInt32();  // format chunk size
            reader.ReadInt16();  // audio format... -.-"
            int channels = reader.ReadInt16();
            int rate     = reader.ReadInt32();

            reader.ReadInt32(); // byte rate ? WTF
            reader.ReadInt16(); // block align
            int bps = reader.ReadInt16();

            reader.ReadChars(4); // some other useless stuff
            reader.ReadInt32();  // moar stuff

            byte[] data = reader.ReadBytes((int)reader.BaseStream.Length);

            // Double ternarity! All the way! What does it mean???
            ALFormat format = (channels == 1 ? bps == 8 ? ALFormat.Mono8 : ALFormat.Mono16 : bps == 8 ? ALFormat.Stereo8 : ALFormat.Stereo16);

            AL.BufferData(result.Buffer, format, data, data.Length, rate);
            AL.Source(result.Source, ALSourcei.Buffer, result.Buffer);

            return(result);
        }
Ejemplo n.º 2
0
        static void Main()
        {
            rnd = new Random();

            epicWINdow         = new GameWindow(640, 360, GraphicsMode.Default, "BRAINS!!!");
            epicWINdow.Icon    = new Icon("Graphics/brains.ico");
            epicWINdow.Visible = true;

            epicSfxContext = new AudioContext();

            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.Blend);
            GL.BlendEquation(BlendEquationMode.FuncAdd);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            GL.ClearColor(0, 0, 0, 1);

            leBrnTexName  = LoadTexturr("Graphics/leBrn.png");
            leCopTexName  = LoadTexturr("Graphics/leCop.png");
            leZmbTexName  = LoadTexturr("Graphics/leZmb.png");
            leShtTexName  = LoadTexturr("Graphics/leSht.png");
            leCtyTexName  = LoadTexturr("Graphics/leCty.png");
            leIcnTexName  = LoadTexturr("Graphics/leIcn.png");
            leNmbTexName  = LoadTexturr("Graphics/leNmb.png");
            leBadTextName = LoadTexturr("Graphics/leBad.png");
            leWinTexName  = LoadTexturr("Graphics/leWin.png");
            leEndTexName  = LoadTexturr("Graphics/leEnd.png");

            pewPewSnd     = Sfx.Load("Sounds/pewPew.wav");
            tumTumSnd     = Sfx.Load("Sounds/tumTum.wav");
            timTimSnd     = Sfx.Load("Sounds/timTim.wav");
            chompChompSnd = Sfx.Load("Sounds/chompChomp.wav");

            Quit = false;

            int score = 0;
            int level = 1;

            while (!Quit && PLAY())
            {
                while (GAEM(level, ref score))
                {
                    if (score < 0)
                    {
                        score = 0;
                    }

                    if (level < 10)
                    {
                        WIN(level, score);
                        level++;
                    }
                    else
                    {
                        FINALE(level, score);
                        level = 0;
                    }
                }

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

                LOSE(level, score);

                level = 1;
                score = 0;
            }

            GL.DeleteTexture(leBrnTexName);
            GL.DeleteTexture(leCopTexName);
            GL.DeleteTexture(leZmbTexName);
            GL.DeleteTexture(leShtTexName);
            GL.DeleteTexture(leCtyTexName);
            GL.DeleteTexture(leIcnTexName);
            GL.DeleteTexture(leNmbTexName);

            GL.DeleteTexture(leBadTextName);
            GL.DeleteTexture(leWinTexName);
            GL.DeleteTexture(leEndTexName);

            pewPewSnd.Unload();
            tumTumSnd.Unload();
            timTimSnd.Unload();
            chompChompSnd.Unload();
        }