⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 renderer.java

📁 NeHe用java与OpenGL结合教程源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                }

                if ((enemy[loop1].x > player.x) && (enemy[loop1].fy == enemy[loop1].y * 40)) {
                    enemy[loop1].x--;						// Move The Enemy Left
                }

                if ((enemy[loop1].y < player.y) && (enemy[loop1].fx == enemy[loop1].x * 60)) {
                    enemy[loop1].y++;						// Move The Enemy Down
                }

                if ((enemy[loop1].y > player.y) && (enemy[loop1].fx == enemy[loop1].x * 60)) {
                    enemy[loop1].y--;						// Move The Enemy Up
                }

                if (delay > (3 - level) && (hourglass.fx != 2))	// If Our Delay Is Done And Player Doesn't Have Hourglass
                {
                    delay = 0;								// Reset The Delay Counter Back To Zero
                    for (int loop2 = 0; loop2 < (stage * level); loop2++)	// Loop Through All The Enemies
                    {
                        if (enemy[loop2].fx < enemy[loop2].x * 60)	// Is Fine Position On X Axis Lower Than Intended Position?
                        {
                            enemy[loop2].fx += steps[adjust];	// If So, Increase Fine Position On X Axis
                            enemy[loop2].spin += steps[adjust];	// Spin Enemy Clockwise
                        }
                        if (enemy[loop2].fx > enemy[loop2].x * 60)	// Is Fine Position On X Axis Higher Than Intended Position?
                        {
                            enemy[loop2].fx -= steps[adjust];	// If So, Decrease Fine Position On X Axis
                            enemy[loop2].spin -= steps[adjust];	// Spin Enemy Counter Clockwise
                        }
                        if (enemy[loop2].fy < enemy[loop2].y * 40)	// Is Fine Position On Y Axis Lower Than Intended Position?
                        {
                            enemy[loop2].fy += steps[adjust];	// If So, Increase Fine Position On Y Axis
                            enemy[loop2].spin += steps[adjust];	// Spin Enemy Clockwise
                        }
                        if (enemy[loop2].fy > enemy[loop2].y * 40)	// Is Fine Position On Y Axis Higher Than Intended Position?
                        {
                            enemy[loop2].fy -= steps[adjust];	// If So, Decrease Fine Position On Y Axis
                            enemy[loop2].spin -= steps[adjust];	// Spin Enemy Counter Clockwise
                        }
                    }
                }

                // Are Any Of The Enemies On Top Of The Player?
                if ((enemy[loop1].fx == player.fx) && (enemy[loop1].fy == player.fy)) {
                    lives--;								// If So, Player Loses A Life

                    if (lives == 0)							// Are We Out Of Lives?
                    {
                        gameover = true;						// If So, gameover Becomes TRUE
                    }

                    resetObjects();							// Reset Player / Enemy Positions
                    dieSample.play(true, false);                   // Play The Death Sound
                }
            }

            if (moveRight && (player.x < 10) && (player.fx == player.x * 60) && (player.fy == player.y * 40)) {
                hline[player.x][player.y] = true;				// Mark The Current Horizontal Border As Filled
                player.x++;									// Move The Player Right
            }
            if (moveLeft && (player.x > 0) && (player.fx == player.x * 60) && (player.fy == player.y * 40)) {
                player.x--;									// Move The Player Left
                hline[player.x][player.y] = true;				// Mark The Current Horizontal Border As Filled
            }
            if (moveDown && (player.y < 10) && (player.fx == player.x * 60) && (player.fy == player.y * 40)) {
                vline[player.x][player.y] = true;				// Mark The Current Verticle Border As Filled
                player.y++;									// Move The Player Down
            }
            if (moveUp && (player.y > 0) && (player.fx == player.x * 60) && (player.fy == player.y * 40)) {
                player.y--;									// Move The Player Up
                vline[player.x][player.y] = true;				// Mark The Current Verticle Border As Filled
            }

            if (player.fx < player.x * 60)						// Is Fine Position On X Axis Lower Than Intended Position?
            {
                player.fx += steps[adjust];					// If So, Increase The Fine X Position
            }
            if (player.fx > player.x * 60)						// Is Fine Position On X Axis Greater Than Intended Position?
            {
                player.fx -= steps[adjust];					// If So, Decrease The Fine X Position
            }
            if (player.fy < player.y * 40)						// Is Fine Position On Y Axis Lower Than Intended Position?
            {
                player.fy += steps[adjust];					// If So, Increase The Fine Y Position
            }
            if (player.fy > player.y * 40)						// Is Fine Position On Y Axis Lower Than Intended Position?
            {
                player.fy -= steps[adjust];					// If So, Decrease The Fine Y Position
            }
        } else												// Otherwise
        {
            if (resetGame)									// If Spacebar Is Being Pressed
            {
                gameover = false;								// gameover Becomes FALSE
                filled = true;								// filled Becomes TRUE
                level = 1;									// Starting Level Is Set Back To One
                level2 = 1;									// Displayed Level Is Also Set To One
                stage = 0;									// Game Stage Is Set To Zero
                lives = 5;									// Lives Is Set To Five
                resetGame = false;
            }
        }

        if (filled)											// Is The Grid Filled In?
        {
            completerSample.play(true, false);                     // If So, Play The Level Complete Sound
            stage++;										// Increase The Stage
            if (stage > 3)									// Is The Stage Higher Than 3?
            {
                stage = 1;									// If So, Set The Stage To One
                level++;									// Increase The Level
                level2++;									// Increase The Displayed Level
                if (level > 3)								// Is The Level Greater Than 3?
                {
                    level = 3;								// If So, Set The Level To 3
                    lives++;								// Give The Player A Free Life
                    if (lives > 5)							// Does The Player Have More Than 5 Lives?
                    {
                        lives = 5;							// If So, Set Lives To Five
                    }
                }
            }

            resetObjects();									// Reset Player / Enemy Positions

            for (int loop1 = 0; loop1 < 11; loop1++)				// Loop Through The Grid X Coordinates
            {
                for (int loop2 = 0; loop2 < 11; loop2++)			// Loop Through The Grid Y Coordinates
                {
                    if (loop1 < 10)							// If X Coordinate Is Less Than 10
                    {
                        hline[loop1][loop2] = false;			// Set The Current Horizontal Value To FALSE
                    }
                    if (loop2 < 10)							// If Y Coordinate Is Less Than 10
                    {
                        vline[loop1][loop2] = false;			// Set The Current Vertical Value To FALSE
                    }
                }
            }
        }

        // If The Player Hits The Hourglass While It's Being Displayed On The Screen
        if ((player.fx == hourglass.x * 60) && (player.fy == hourglass.y * 40) && (hourglass.fx == 1)) {
            // Play Freeze Enemy Sound
            freezeSample.play(false, true);
            hourglass.fx = 2;									// Set The hourglass fx Variable To Two
            hourglass.fy = 0;									// Set The hourglass fy Variable To Zero
        }

        player.spin += 0.5f * steps[adjust];					// Spin The Player Clockwise
        if (player.spin > 360.0f)								// Is The spin Value Greater Than 360?
        {
            player.spin -= 360;								// If So, Subtract 360
        }

        hourglass.spin -= 0.25f * steps[adjust];				// Spin The Hourglass Counter Clockwise
        if (hourglass.spin < 0.0f)							// Is The spin Value Less Than 0?
        {
            hourglass.spin += 360.0f;							// If So, Add 360
        }

        hourglass.fy += steps[adjust];						// Increase The hourglass fy Variable
        if ((hourglass.fx == 0) && (hourglass.fy > 6000 / level))	// Is The hourglass fx Variable Equal To 0 And The fy
        {													// Variable Greater Than 6000 Divided By The Current Level?
            hourglassSample.play(false, false);	// If So, Play The Hourglass Appears Sound
            hourglass.x = Math.abs(random.nextInt()) % 10 + 1;						// Give The Hourglass A Random X Value
            hourglass.y = Math.abs(random.nextInt()) % 11;							// Give The Hourglass A Random Y Value
            hourglass.fx = 1;									// Set hourglass fx Variable To One (Hourglass Stage)
            hourglass.fy = 0;									// Set hourglass fy Variable To Zero (Counter)
        }

        if ((hourglass.fx == 1) && (hourglass.fy > 6000 / level))	// Is The hourglass fx Variable Equal To 1 And The fy
        {													// Variable Greater Than 6000 Divided By The Current Level?
            hourglass.fx = 0;									// If So, Set fx To Zero (Hourglass Will Vanish)
            hourglass.fy = 0;									// Set fy to Zero (Counter Is Reset)
        }

        if ((hourglass.fx == 2) && (hourglass.fy > 500 + (500 * level)))	// Is The hourglass fx Variable Equal To 2 And The fy
        {													// Variable Greater Than 500 Plus 500 Times The Current Level?
            freezeSample.stop();						// If So, Kill The Freeze Sound
            hourglass.fx = 0;									// Set hourglass fx Variable To Zero
            hourglass.fy = 0;									// Set hourglass fy Variable To Zero
        }

        delay++;											// Increase The Enemy Delay Counter
    }

    public void drawGLScene(GL gl) {
        gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);       //Clear The Screen And The Depth Buffer

        gl.glBindTexture(GL.GL_TEXTURE_2D, textures[0]);				// Select Our Font Texture
        gl.glColor3f(1.0f, 0.5f, 1.0f);								// Set Color To Purple
        glPrint(gl, 207, 24, 0, "GRID CRAZY");							// Write GRID CRAZY On The Screen
        gl.glColor3f(1.0f, 1.0f, 0.0f);								// Set Color To Yellow
        glPrint(gl, 20, 20, 1, "Level:" + level2);					// Write Actual Level Stats
        glPrint(gl, 20, 40, 1, "Stage:" + stage);						// Write Stage Stats


        if (gameover) {											// Is The Game Over?

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -