Commit 5e16efaf52149a865637e1fe077321b35973ad98

Authored by Olav Kjartan Larseng
1 parent 2606cc59

added gameplay, highscore, lives, gameover

Showing 84 changed files with 633 additions and 255 deletions   Show diff stats
SpaceShooterV4/SpaceShooterV4.vcxproj
... ... @@ -107,7 +107,7 @@
107 107 <Link>
108 108 <GenerateDebugInformation>true</GenerateDebugInformation>
109 109 <SubSystem>Console</SubSystem>
110   - <AdditionalLibraryDirectories>D:\csmaster\OpenGL Projects\glew-2.1.0-win32\glew-2.1.0\lib\Release\x64;D:\csmaster\OpenGL Projects\soil\Simple OpenGL Image Library\projects\VC9\x64\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
  110 + <AdditionalLibraryDirectories>D:\csmaster\OpenGL Projects\Projects\SpaceShooterV4\SpaceShooterV4\SpaceShooterV4\lib;D:\csmaster\OpenGL Projects\Projects\SpaceShooterV4\SpaceShooterV4\SpaceShooterV4\lib\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
111 111 <AdditionalDependencies>SOIL.lib;opengl32.lib;glu32.lib;glew32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
112 112 </Link>
113 113 </ItemDefinitionGroup>
... ...
SpaceShooterV4/app/main.cpp
... ... @@ -13,6 +13,9 @@
13 13 #include <memory>
14 14 #include <iostream>
15 15 #include "../include/Text.h"
  16 +#include <cstdlib>
  17 +#include <sstream>
  18 +
16 19  
17 20 std::shared_ptr<GameManager> gm;
18 21 siut::FpsCounter counter;
... ... @@ -23,8 +26,12 @@ bool keyPressed[30];
23 26 int mousePosX, mousePosY;
24 27 float moveX, moveY;
25 28 Text _text;
  29 +Text _textStart;
  30 +Text _highScore;
  31 +Text _currentScore;
26 32  
27 33 bool isDown = false;
  34 +bool pIsDown = false;
28 35  
29 36 void init()
30 37 {
... ... @@ -52,6 +59,17 @@ void init()
52 59 keyPressed[i]=false;
53 60 }
54 61  
  62 +void drawText(const std::string& text, const glm::vec3& pos, const glm::vec3& color)
  63 +{
  64 + // Draw the text
  65 + char buffer[80];
  66 + glColor3f(color.x, color.y, color.z);
  67 + sprintf_s(buffer, text.c_str());
  68 + _text.setPos(pos.x, pos.y, pos.z);
  69 + _text.printString(buffer, Text::FONT_NORMAL);
  70 + glClearColor(0, 0, 0, 1);
  71 +}
  72 +
55 73  
56 74 void display()
57 75 {
... ... @@ -62,81 +80,136 @@ void display()
62 80 gm->update(counter.fps());
63 81 gm->render();
64 82  
65   - if (keyPressed[KEY_ID_W] == true) gm->getSpaceShip()->moveForward();
66   - if (keyPressed[KEY_ID_A] == true)
  83 + if (gm->getSpaceshipLives() <= 0 && gm->gameStart)
67 84 {
68   - auto offset = gm->getSpaceShip()->moveLeft();
69   - gm->getCam()->moveLeft(offset);
70   - //gm->getSkybox()->moveLeft(offset);
  85 + gm->gameStart = false;
  86 + gm->getSpaceShip()->getMatrix()[3].y = -1000.0f;
  87 + pIsDown = false;
71 88 }
72   - if (keyPressed[KEY_ID_D] == true)
  89 +
  90 + if (gm->gameStart)
73 91 {
74   - auto offset = gm->getSpaceShip()->moveRight();
75   - gm->getCam()->moveRight(offset);
76   - //gm->getSkybox()->moveRight(offset);
  92 + if (keyPressed[KEY_ID_W] == true) gm->getSpaceShip()->moveForward();
  93 + if (keyPressed[KEY_ID_A] == true)
  94 + {
  95 + auto offset = gm->getSpaceShip()->moveLeft();
  96 + gm->getCam()->moveLeft(offset);
  97 + //gm->getSkybox()->moveLeft(offset);
  98 + }
  99 + if (keyPressed[KEY_ID_D] == true)
  100 + {
  101 + auto offset = gm->getSpaceShip()->moveRight();
  102 + gm->getCam()->moveRight(offset);
  103 + //gm->getSkybox()->moveRight(offset);
  104 + }
  105 + if (keyPressed[KEY_ID_S] == true) gm->getSpaceShip()->moveBackward();
  106 +
  107 + if (keyPressed[KEY_ID_C] == true && !isDown) {
  108 + gm->getSpaceShip()->changeWeapon();
  109 + keyPressed[KEY_ID_C] = false;
  110 + isDown = true;
  111 + }
  112 +
  113 + if (keyPressed[KEY_ID_SPACE] == true) gm->fireFromSpaceship();
  114 +
  115 + if (keyPressed[KEY_ID_X] == true)
  116 + {
  117 + auto offset = gm->getCam()->moveUp();
  118 + //gm->getSkybox()->moveUp(offset);
  119 + }
  120 + if (keyPressed[KEY_ID_Z] == true)
  121 + {
  122 + auto offset = gm->getCam()->moveDown();
  123 + //gm->getSkybox()->moveDown(offset);
  124 + }
  125 +
  126 + if (keyPressed[KEY_ID_H])
  127 + {
  128 + gm->getCam()->rotateLeft();
  129 + }
  130 +
  131 + if (keyPressed[KEY_ID_J])
  132 + {
  133 + gm->getCam()->rotateRight();
  134 + }
  135 +
  136 + if (keyPressed[KEY_ID_U])
  137 + {
  138 + gm->getCam()->rotateUp();
  139 + }
  140 +
  141 + if (keyPressed[KEY_ID_N])
  142 + {
  143 + gm->getCam()->rotateDown();
  144 + }
77 145 }
78   - if (keyPressed[KEY_ID_S] == true) gm->getSpaceShip()->moveBackward();
79   -
80   - if (keyPressed[KEY_ID_C] == true && !isDown) {
81   - gm->getSpaceShip()->changeWeapon();
82   - keyPressed[KEY_ID_C] = false;
83   - isDown = true;
  146 + else {
  147 + drawText("PRESS -P- TO PLAY",
  148 + glm::vec3(-0.1f, 0.0f, -1.0f),
  149 + glm::vec3(1.0f, 0.5f, 0.5f));
84 150 }
85 151  
86   - if (keyPressed[KEY_ID_SPACE] == true) gm->fireFromSpaceship();
87   -
88   - if (keyPressed[KEY_ID_X] == true)
89   - {
90   - auto offset = gm->getCam()->moveUp();
91   - //gm->getSkybox()->moveUp(offset);
92   - }
93   - if (keyPressed[KEY_ID_Z] == true)
  152 + if (keyPressed[KEY_ID_P] && !pIsDown)
94 153 {
95   - auto offset = gm->getCam()->moveDown();
96   - //gm->getSkybox()->moveDown(offset);
  154 + pIsDown = true;
  155 + gm->gameStart = true;
  156 + gm->getSpaceShip()->setLife(4.0);
  157 + gm->getSpaceShip()->getMatrix()[3].y = -15.0f;
  158 + gm->currentScore = 0.0;
  159 +
  160 + // Clear screen
  161 + auto enemies = gm->getAllObjectOfType<Enemy>();
  162 + for (auto& e: enemies) {
  163 + gm->removeSubObject(e);
  164 + }
  165 + gm->_enemies.clear();
  166 +
  167 + auto bullets = gm->getAllObjectOfType<Bullet>();
  168 + for (auto& b : bullets) {
  169 + gm->removeSubObject(b);
  170 + }
  171 + gm->_playerBullets.clear();
  172 + gm->_enemyBullets.clear();
97 173 }
98 174  
99   - if (keyPressed[KEY_ID_H])
100   - {
101   - gm->getCam()->rotateLeft();
102   - }
103 175  
104   - if (keyPressed[KEY_ID_J])
105   - {
106   - gm->getCam()->rotateRight();
107   - }
  176 + std::ostringstream highscore;
  177 + highscore << gm->getHighScore();
  178 + std::string hscore = highscore.str();
  179 +
  180 + std::ostringstream currentscore;
  181 + currentscore << gm->getCurrentScore();
  182 + std::string cscore = currentscore.str();
108 183  
109   - if (keyPressed[KEY_ID_U])
110   - {
111   - gm->getCam()->rotateUp();
112   - }
  184 + std::ostringstream lives;
  185 + lives << gm->getSpaceshipLives();
  186 + std::string slives = lives.str();
113 187  
114   - if (keyPressed[KEY_ID_N])
115   - {
116   - gm->getCam()->rotateDown();
117   - }
118 188  
119   - /* TEXT */
120   - //glPushMatrix();
121   - //glLoadIdentity();
122   - // Draw the text
123   - char buffer[80];
124   - glColor3f(1.0, 0.0, 0.0);
125   -
126   - sprintf_s(buffer, "WASD: Move, C: Change Weapon, Space: Shoot");
127   - _text.setPos(-0.5f, -0.5f, -1.0f);
128   - _text.printString(buffer, Text::FONT_NORMAL);
  189 + drawText("LIVES: " + slives,
  190 + glm::vec3(0.0f, 0.5f, -1.0f),
  191 + glm::vec3(1.0f, 0.0f, 0.0f));
129 192  
  193 + drawText("SCORE: " + cscore,
  194 + glm::vec3(0.35f, 0.5f, -1.0f),
  195 + glm::vec3(1.0f, 1.0f, 1.0f));
130 196  
131   - glClearColor(0, 0, 0, 1);
132   - glPopMatrix();
  197 + drawText("HIGHSCORE: " + hscore,
  198 + glm::vec3(-0.5f, 0.5f, -1.0f),
  199 + glm::vec3(1.0f, 1.0f, 1.0f));
133 200  
  201 +
  202 + drawText("WASD: Move, C: Change Weapon",
  203 + glm::vec3(-0.5f, -0.5f, -1.0f),
  204 + glm::vec3(0.7f, 0.0f, 0.7f));
  205 +
134 206  
135 207 glutSwapBuffers();
136 208 glutPostRedisplay();
137 209  
138 210 }
139 211  
  212 +
140 213 void keyDown(unsigned char key, int x, int y)
141 214 {
142 215 switch (key)
... ... @@ -195,6 +268,9 @@ void keyDown(unsigned char key, int x, int y)
195 268 case 'n':
196 269 keyPressed[KEY_ID_N] = true;
197 270 break;
  271 + case 'p':
  272 + keyPressed[KEY_ID_P] = true;
  273 + break;
198 274  
199 275 default:
200 276 glutPostRedisplay();
... ... @@ -251,6 +327,9 @@ void keyUp(unsigned char key, int x, int y)
251 327 case 'n':
252 328 keyPressed[KEY_ID_N] = false;
253 329 break;
  330 + case 'p':
  331 + //pIsDown = false;
  332 + keyPressed[KEY_ID_P] = false;
254 333  
255 334  
256 335 }
... ...
SpaceShooterV4/assets/shaders/water.frag
1   -uniform sampler2D tex_colormap;
  1 +uniform samplerCube tex_colormap;
2 2 varying vec4 texCoord;
3 3  
  4 +varying vec3 normal;
  5 +varying mat4 view;
  6 +varying vec4 eye;
  7 +
4 8 void main()
5 9 {
6 10  
7   - gl_FragColor = texture2D(tex_colormap, texCoord.xy);
8   - gl_FragColor.a = 0.4;
  11 + vec3 eyeCoord = vec3(eye);
  12 + eyeCoord.x = -eyeCoord.x;
  13 +
  14 + vec3 reflection = reflect(-normalize(eyeCoord), normal);
  15 +
  16 + gl_FragColor = textureCube(tex_colormap, reflection) /** texture2D(tex_colormap2, texCoord.xy)*/;
  17 + gl_FragColor.a = 0.9;
9 18 }
... ...
SpaceShooterV4/assets/shaders/water.vert
1 1 uniform float water_data;
2 2 varying vec4 texCoord;
3 3  
  4 +varying vec3 normal;
  5 +varying mat4 view;
  6 +varying vec4 eye;
  7 +
  8 +
4 9 void main()
5 10 {
6 11 vec4 pos = gl_Vertex;
  12 + view = gl_ModelViewMatrix;
  13 + eye = gl_ModelViewMatrix * pos;
  14 +
7 15 texCoord = gl_MultiTexCoord0;
8 16 float xpos = pos.x * 12.0;
9   - pos.x = xpos;
  17 + pos.x = xpos * 1.5;
10 18 pos.z = pos.z * 35.0;
11   - pos.y = -160.0 + (sin(pos.z + water_data) * 3.0);
12   - texCoord.x = texCoord.x + (water_data * 0.01);
  19 + pos.y = -120.0 + ((sin(pos.z + water_data) * 2.0)/2.0);
  20 + //texCoord.x = texCoord.x + (water_data * 0.01);
  21 + //texCoord.y = texCoord.y + (water_data * 0.05);
13 22  
  23 + normal = gl_NormalMatrix * gl_Normal;
14 24 gl_Position = gl_ModelViewProjectionMatrix * pos;
15 25 }
16 26 \ No newline at end of file
... ...
SpaceShooterV4/assets/textures/ame_siege/ame_siege.shader 0 → 100644
  1 +textures/skies/ame_siege
  2 +{
  3 + qer_editorimage env/ame_siege/siege_ft.tga
  4 + surfaceparm noimpact
  5 + surfaceparm nolightmap
  6 + q3map_sun 1.00 1.00 0.965 75 320 30
  7 + q3map_surfacelight 50
  8 + skyparms env/ame_siege/siege - -
  9 +}
... ...
SpaceShooterV4/assets/textures/ame_siege/readme 0 → 100644
  1 +Created by 'amethyst7' aka Chris Matz.
  2 +WEB site: http://amethyst7.gotdoofed.com
  3 +
  4 +You may use and distribute this sky box under the terms of the
  5 +GNU General Public License version 2.
... ...
SpaceShooterV4/assets/textures/ame_siege/siege_bk.tga 0 → 100644
No preview for this file type
SpaceShooterV4/assets/textures/ame_siege/siege_dn.tga 0 → 100644
No preview for this file type
SpaceShooterV4/assets/textures/ame_siege/siege_ft.tga 0 → 100644
No preview for this file type
SpaceShooterV4/assets/textures/ame_siege/siege_lf.tga 0 → 100644
No preview for this file type
SpaceShooterV4/assets/textures/ame_siege/siege_rt.tga 0 → 100644
No preview for this file type
SpaceShooterV4/assets/textures/ame_siege/siege_up.tga 0 → 100644
No preview for this file type
SpaceShooterV4/assets/textures/ame_siege/skybox_xn.png 0 → 100644

396 KB

SpaceShooterV4/assets/textures/ame_siege/skybox_xp.png 0 → 100644