Esempio n. 1
0
        public Menu(int nmbrOfButtons, Vector2[] positions, int[] widths, int[] heights, string[] textures, Func <bool>[] func)
        {
            if (nmbrOfButtons != positions.Length || nmbrOfButtons != widths.Length || nmbrOfButtons != heights.Length || nmbrOfButtons != textures.Length - 1)
            {
                throw new Exception("The number of buttons don't corrispond to the number of parameters");
            }

            menuTex = new Texture2D[nmbrOfButtons + 1];      //+1 for the background
            menuBuf = new GraphicsBuffer[nmbrOfButtons + 1]; //+1 for the background

            //For the background
            menuTex[0]     = ContentPipe.LoadTexture(textures[0]);
            menuBuf[0]     = new GraphicsBuffer();
            menuBuf[0].IBO = GL.GenBuffer();
            menuBuf[0].VBO = GL.GenBuffer();
            menuBuf[0].Empty();

            for (int i = 0; i < nmbrOfButtons; i++)
            {
                menuTex[i + 1] = ContentPipe.LoadTexture(textures[i + 1]);

                menuBuf[i + 1]     = new GraphicsBuffer();
                menuBuf[i + 1].IBO = GL.GenBuffer();
                menuBuf[i + 1].VBO = GL.GenBuffer();
                menuBuf[i + 1].Empty();

                buttons.Add(new Button(positions[i], widths[i], heights[i], menuTex[i + 1], func[i]));
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Load in all the textures needed for the entity
 /// </summary>
 /// <param name="textureFilePaths">File paths for all the textures used</param>
 public void LoadTextures(int nmbrOfPaths, string[] textureFilePaths)
 {
     texture = new Texture2D[nmbrOfPaths];
     for (int i = 0; i < nmbrOfPaths; i++)
     {
         texture[i] = ContentPipe.LoadTexture(textureFilePaths[i]);
     }
 }
 /// <summary>
 /// Load in all the textures needed for the entity
 /// </summary>
 /// <param name="textureFilePaths">File paths for all the textures used</param>
 static public void LoadTextures()
 {
     texture = new Texture2D[bulletTex.Length];
     for (int i = 0; i < bulletTex.Length; i++)
     {
         texture[i] = ContentPipe.LoadTexture(bulletTex[i]);
     }
 }
Esempio n. 4
0
        public static void LoadMap(string fileName)
        {
            Texture2D floor = ContentPipe.LoadTexture("Floor.bmp");
            Texture2D wall  = ContentPipe.LoadTexture("Wall.bmp");

            try
            {
                // Create an instance of StreamReader to read from a file.
                // The using statement also closes the StreamReader.
                using (StreamReader sr = new StreamReader(fileName))
                {
                    string   line;
                    string[] size;
                    line = sr.ReadLine();
                    size = line.Split(',');
                    map  = new Terrain[Convert.ToInt32(size[0]), Convert.ToInt32(size[1])];
                    // Read and display lines from the file until the end of
                    // the file is reached.
                    int y = 0;
                    while ((line = sr.ReadLine()) != null)
                    {
                        for (int i = 0; i < line.Length; i++)
                        {
                            if (line[i] == '0')
                            {
                                map[i, y] = new Terrain(floor, true);
                            }
                            else if (line[i] == '1')
                            {
                                map[i, y] = new Terrain(wall, false);
                            }
                        }
                        y++;
                    }
                }
            }
            catch (Exception e)
            {
                // Let the user know what went wrong.
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 5
0
        private void Window_Load(object sender, EventArgs e)
        {
            floorTex     = ContentPipe.LoadTexture("Floor.bmp");
            wallTex      = ContentPipe.LoadTexture("Wall.bmp");
            bulletTex    = ContentPipe.LoadTexture("Bullet\\BulletUp.png");
            frogTex      = ContentPipe.LoadTexture("Frog\\Frog.png");
            explosionTex = ContentPipe.LoadTexture("Bullet\\Explosion.png");
            //Hud textures
            HUDTex[0] = ContentPipe.LoadTexture("HUD\\Heart.png");
            HUDTex[1] = ContentPipe.LoadTexture("HUD\\HeartCover.png");
            HUDTex[7] = ContentPipe.LoadTexture("HUD\\Minimap.png");
            HUDTex[2] = ContentPipe.LoadTexture("HUD\\BackCover.png");
            HUDTex[3] = floorTex;
            HUDTex[4] = wallTex;
            Map.LoadMap("Content\\map.txt");
            player            = new Player(new Vector2(200, 300), new Vector2(0, 0), Map.GetMap);
            HUDTex[5]         = player.GetTexture;
            HUDTex[6]         = ContentPipe.LoadTexture("HUD\\EnemyEntity.png");
            buffer.vertBuffer = new Vertex[0];

            Func <bool>[] func = new Func <bool>[2] {
                Start, Quit
            };
            //Main menu setup
            mainMenu = new Menu(2, MMbuttonPos, MMbuttonWidth, MMbuttonHeight, mainMenuTextureStrings, func);
            //In game menu setup
            func = new Func <bool>[3] {
                Resume, Restart, Quit
            };
            inGameMenu = new Menu(3, IGMButtonPos, IGMButtonWidth, IGMButtonHeight, inGameMenuTextureStrings, func);
            EntityController.SetupEntityController(ref player);
            for (int i = 0; i < nmbrOfFrogs; i++)
            {
                EntityController.AddEntity((new Vector2(rand.Next(0, (int)Map.GetSize.X * 10), rand.Next(0, (int)Map.GetSize.Y * 10))), new Vector2((float)rand.NextDouble(), (float)rand.NextDouble()), id);
                id++;
            }

            frogBuf     = new GraphicsBuffer();
            frogBuf.VBO = GL.GenBuffer();
            frogBuf.IBO = GL.GenBuffer();
            frogBuf.Empty();

            explosionBuf     = new GraphicsBuffer();
            explosionBuf.VBO = GL.GenBuffer();
            explosionBuf.IBO = GL.GenBuffer();
            explosionBuf.Empty();

            buffer.VBO = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, buffer.VBO);
            GL.BufferData <Vertex>(BufferTarget.ArrayBuffer, (IntPtr)(Vertex.SizeInBytes * buffer.vertBuffer.Length), buffer.vertBuffer, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

            buffer.indexBuffer = new uint[0];

            buffer.IBO = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, buffer.IBO);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(sizeof(uint) * (buffer.indexBuffer.Length)), buffer.indexBuffer, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);

            window.CursorVisible = false;
            buf = new GraphicsBuffer[2];
            for (int i = 0; i < buf.Length; i++)
            {
                buf[i]     = new GraphicsBuffer();
                buf[i].VBO = GL.GenBuffer();
                buf[i].IBO = GL.GenBuffer();
                buf[i].Empty();
            }

            for (int i = 0; i < bulletBuffer.Length; i++)
            {
                bulletBuffer[i]     = new GraphicsBuffer();
                bulletBuffer[i].VBO = GL.GenBuffer();
                bulletBuffer[i].IBO = GL.GenBuffer();
                bulletBuffer[i].Empty();
            }

            //Bullet controller setup
            BulletController.LoadTextures();
            HUD.SetupHUD(player.health, new Vector2(30, window.Height - 15), 5, window);
            for (int i = 0; i < HUDBuf.Length; i++)
            {
                HUDBuf[i]     = new GraphicsBuffer();
                HUDBuf[i].VBO = GL.GenBuffer();
                HUDBuf[i].IBO = GL.GenBuffer();
                HUDBuf[i].Empty();
            }

            mouseBuf.VBO = GL.GenBuffer();
            mouseBuf.IBO = GL.GenBuffer();
            mouseBuf.Empty();

            updateInterval = 20;
            sw.Start();
        }