Jeff Molofee - NeHe's OpenGL Tutorials
Здесь есть возможность читать онлайн «Jeff Molofee - NeHe's OpenGL Tutorials» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.
- Название:NeHe's OpenGL Tutorials
- Автор:
- Жанр:
- Год:неизвестен
- ISBN:нет данных
- Рейтинг книги:3 / 5. Голосов: 1
-
Избранное:Добавить в избранное
- Отзывы:
-
Ваша оценка:
- 60
- 1
- 2
- 3
- 4
- 5
NeHe's OpenGL Tutorials: краткое содержание, описание и аннотация
Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «NeHe's OpenGL Tutorials»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.
NeHe's OpenGL Tutorials — читать онлайн бесплатно полную книгу (весь текст) целиком
Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «NeHe's OpenGL Tutorials», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.
Интервал:
Закладка:
if (lives==0) // Are We Out Of Lives?
{
gameover=TRUE; // If So, gameover Becomes TRUE
}
ResetObjects(); // Reset Player / Enemy Positions
PlaySound("Data/Die.wav", NULL, SND_SYNC); // Play The Death Sound
}
}
Now we can move the player. In the first line of code below we check to see if the right arrow is being pressed, player.x is less than 10 (don't want to go off the grid), that player.fx equals player.x times 60 (lined up with a grid crossing on the x-axis, and that player.fy equals player.y times 40 (player is lined up with a grid crossing on the y-axis).
If we didn't make sure the player was at a crossing, and we allowed the player to move anyways, the player would cut right through the middle of boxes, just like the enemies would have done if we didn't make sure they were lined up with a vertical or horizontal line. Checking this also makes sure the player is done moving before we move to a new location.
If the player is at a grid crossing (where a vertical and horizontal lines meet) and he's not to far right, we mark the current horizontal line that we are on as being traced over. We then increase the player.x value by one, causing the new player position to be one box to the right.
We do the same thing while moving left, down and up. When moving left, we make sure the player wont be going off the left side of the grid. When moving down we make sure the player wont be leaving the bottom of the grid, and when moving up we make sure the player doesn't go off the top of the grid.
When moving left and right we make the horizontal line (hline[ ] [ ]) under us TRUE meaning it's been traced. When moving up and down we make the vertical line (vline[ ] [ ]) under us TRUE meaning it has been traced.
if (keys[VK_RIGHT] && (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 (keys[VK_LEFT] && (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 (keys[VK_DOWN] && (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 (keys[VK_UP] && (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
}
We increase / decrease the player fine fx and fy variables the same way we increase / decreased the enemy fine fx and fy variables.
If the player fx value is less than the player x value times 60 we increase the player fx position by the step speed our game is running at based on the value of adjust.
If the player fx value is greater than the player x value times 60 we decrease the player fx position by the step speed our game is running at based on the value of adjust.
If the player fy value is less than the player y value times 40 we increase the player fy position by the step speed our game is running at based on the value of adjust.
If the player fy value is greater than the player y value times 40 we decrease the player fy position by the step speed our game is running at based on the value of adjust.
if (player.fx
{
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.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
}
}
If the game is over the following bit of code will run. We check to see if the spacebar is being pressed. If it is we set gameover to FALSE (starting the game over). We set filled to TRUE. This causes the game to think we've finished a stage, causing the player to be reset, along with the enemies.
We set the starting level to 1, along with the actual displayed level (level2). We set stage to 0. The reason we do this is because after the computer sees that the grid has been filled in, it will think you finished a stage, and will increase stage by 1. Because we set stage to 0, when the stage increases it will become 1 (exactly what we want). Lastly we set lives back to 5.
else // Otherwise
{
if (keys[' ']) // 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
}
}
The code below checks to see if the filled flag is TRUE (meaning the grid has been filled in). filled can be set to TRUE one of two ways. Either the grid is filled in completely and filled becomes TRUE or the game has ended but the spacebar was pressed to restart it (code above).
If filled is TRUE, the first thing we do is play the cool level complete tune. I've already explained how PlaySound() works. This time we'll be playing the Complete .WAV file in the DATA directory. Again, we use SND_SYNC so that there is a delay before the game starts on the next stage.
After the sound has played, we increase stage by one, and check to make sure stage isn't greater than 3. If stage is greater than 3 we set stage to 1, and increase the internal level and visible level by one.
If the internal level is greater than 3 we set the internal leve (level) to 3, and increase lives by 1. If you're amazing enough to get past level 3 you deserve a free life :). After increasing lives we check to make sure the player doesn't have more than 5 lives. If lives is greater than 5 we set lives back to 5.
if (filled) // Is The Grid Filled In?
{
PlaySound("Data/Complete.wav", NULL, SND_SYNC); // 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
}
}
}
We then reset all the objects (such as the player and enemies). This places the player back at the top left corner of the grid, and gives the enemies random locations on the grid.
Читать дальшеИнтервал:
Закладка:
Похожие книги на «NeHe's OpenGL Tutorials»
Представляем Вашему вниманию похожие книги на «NeHe's OpenGL Tutorials» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.
Обсуждение, отзывы о книге «NeHe's OpenGL Tutorials» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.