From: <mag...@us...> - 2010-09-13 16:32:44
|
Revision: 117 http://thezombieengine.svn.sourceforge.net/thezombieengine/?rev=117&view=rev Author: magarcias Date: 2010-09-13 16:32:37 +0000 (Mon, 13 Sep 2010) Log Message: ----------- Game levels Modified Paths: -------------- branches/rnsshoot/inc/shootem/shootemapp.h branches/rnsshoot/src/shootem/shootemapp.cc Modified: branches/rnsshoot/inc/shootem/shootemapp.h =================================================================== --- branches/rnsshoot/inc/shootem/shootemapp.h 2010-09-13 15:38:06 UTC (rev 116) +++ branches/rnsshoot/inc/shootem/shootemapp.h 2010-09-13 16:32:37 UTC (rev 117) @@ -74,6 +74,9 @@ PlayerState playerState; + int gameLevel; + + void ResetLevel(); void ResetGame(); //fire @@ -103,6 +106,8 @@ nArray<Tile> tiles; + float min_x, max_x, min_z, max_z; + //props struct Prop { @@ -120,6 +125,7 @@ enum EnemyState { ES_Alive, + ES_Hit, ES_Dying, }; @@ -128,13 +134,17 @@ vector3 vecPos; vector3 vecScale; vector4 color; + EnemyState state; + int hitPoints; + float fTimeElapsed; }; nArray<Enemy> enemies; float fEnemySpeed; + float fEnemyHitTime; float fEnemyDyingTime; void TickEnemies(float fTimeElapsed); @@ -144,6 +154,7 @@ Enemy* CheckEnemies(const vector3& pos, float fDistance); void OnEnemyHit(Enemy* enemy); void OnPlayerHit(); + void OnLevelEnd(); //resources nRef<nMesh2> refMeshGround; Modified: branches/rnsshoot/src/shootem/shootemapp.cc =================================================================== --- branches/rnsshoot/src/shootem/shootemapp.cc 2010-09-13 15:38:06 UTC (rev 116) +++ branches/rnsshoot/src/shootem/shootemapp.cc 2010-09-13 16:32:37 UTC (rev 117) @@ -18,13 +18,13 @@ this->bWireframe = false; this->bCameraOrtho = false; - this->vecEye.set(0,5,-2); - this->vecRot.set(n_deg2rad(60),0,0); //looking down 30 degrees - this->vecPlayerPos.set(0,0,0); - this->vecCameraOffset.set(0,5,-2); + this->vecCameraOffset.set(0,7,-2); this->fCameraThreshold = 1.f; + this->vecEye = this->vecPlayerPos + this->vecCameraOffset; + this->vecRot.set(n_deg2rad(60),0,0); //looking down 30 degrees + this->fPlayerSpeed = 5.f; this->fPlayerSize = 1.f; @@ -35,31 +35,52 @@ this->fProjectileSpeed = 10.f; this->fEnemySpeed = 3.f; - this->fEnemyDyingTime = 1.; + this->fEnemyHitTime = .2f; + this->fEnemyDyingTime = 1.f; + //initial level + this->gameLevel = 1; + this->ResetLevel(); +} + +//------------------------------------------------------------------------------ + +void ShootemApp::ResetLevel() +{ + //initialize player + this->vecPlayerPos.set(0,0,0); + + this->fEnemySpeed = 3.f + float(gameLevel - 1); + //initialize ground - const int numTiles = 4; + int numTiles = 4 + gameLevel; this->tiles.SetFixedSize(numTiles); - const vector4 colors[numTiles] = { vector4(1.0f, 1.0f, 1.0f, 1.0f), - vector4(0.0f, 1.0f, 0.0f, 1.0f), - vector4(0.0f, 1.0f, 1.0f, 1.0f), - vector4(1.0f, 0.0f, 0.0f, 1.0f) }; - vector3 tilePos( -5.f, 0.f, -5.f ); + min_x = -5.f; + min_z = -5.f; + max_x = min_x + 10.f;//tilesize + max_z = min_z + 10.f * numTiles;//tilesize + const vector4 colors[] = { vector4(1.0f, 1.0f, 1.0f, 1.0f), + vector4(0.0f, 1.0f, 0.0f, 1.0f), + vector4(0.0f, 1.0f, 1.0f, 1.0f), + vector4(1.0f, 0.0f, 0.0f, 1.0f), + vector4(1.0f, 0.0f, 1.0f, 0.0f) }; + + vector3 tilePos( min_x, 0.f, min_z ); + for (int index=0; index<numTiles; index++) { this->tiles[index].vecPos = tilePos; this->tiles[index].vecScale.set( 10.f, 0.f, 10.f ); - this->tiles[index].color = colors[index]; + this->tiles[index].color = colors[index % sizeof(colors)]; tilePos.z += 10.f; } -#if 1 + //initialize props { - const int numPropsPerTile = 10; - //int propIndex = 0; + int numPropsPerTile = 10 + 2 * gameLevel; for (int tileIndex=0; tileIndex<numTiles; tileIndex++) { Tile& tile = this->tiles[tileIndex]; @@ -72,12 +93,12 @@ newProp.vecPos.z = min_z + n_rand_real(1.f) * tile.vecScale.z;//tilesize_z newProp.vecScale.set(1,1,1); newProp.highlight = false; - //TODO- check for collision + //TODO- check for collision with other props? + this->props.Append(newProp); } } } -#endif //initialize items (shoot and pick, or just pick) @@ -181,6 +202,8 @@ //update player position vector3 playerPos = this->vecPlayerPos + vecMove; + playerPos.x = n_clamp(playerPos.x, min_x, max_x);//adjust to tilesize + Prop* prop = this->CheckProps(playerPos, this->fPlayerSize); if (prop) { @@ -193,6 +216,12 @@ this->vecPlayerPos = playerPos; + //end of level? + if (this->vecPlayerPos.z > max_z) + { + this->OnLevelEnd(); + } + //check for collisions with enemies Enemy* enemy = this->CheckEnemies(playerPos, this->fPlayerSize); if (enemy) @@ -252,7 +281,7 @@ } proj.vecPos += proj.vecDir * this->fProjectileSpeed * fTimeElapsed; - + //TODO- check for collisions Enemy* enemy = this->CheckEnemies(proj.vecPos, proj.vecSize.x); if (enemy) @@ -339,9 +368,12 @@ //the spawn point is a fixed number of units in front of the player //they follow a fixed trajectory (a path) and can shoot projectiles - const int numEnemies = 5; + int numEnemies = 5 + (gameLevel - 1) * 3; vector3 vecPos = this->vecPlayerPos; vecPos.z += 10.f; + + if (vecPos.z > max_z) return; + //float min_x = -5.f; //do { vecPos.x = 1.f;//min_x + n_rand_real(1.f) * 10.f; @@ -351,6 +383,7 @@ { Enemy newEnemy; newEnemy.state = ES_Alive; + newEnemy.hitPoints = this->gameLevel; newEnemy.vecPos = vecPos; newEnemy.vecScale.set(1.f,1.f,1.f); newEnemy.color.set(1,0,0,1); @@ -376,12 +409,24 @@ Enemy& enemy = this->enemies.At(index); switch (enemy.state) { + case ES_Hit: + enemy.fTimeElapsed += fTimeElapsed; + if (enemy.fTimeElapsed > this->fEnemyHitTime) + enemy.state = ES_Alive; + //fall through + case ES_Alive: { vector3 vecMove(0,0,-1); vecMove.x = float(n_sgn(this->vecPlayerPos.x - enemy.vecPos.x)); + vecMove.norm(); vecMove *= this->fEnemySpeed * fTimeElapsed; enemy.vecPos += vecMove; + if (enemy.vecPos.z < this->vecPlayerPos.z - 10.f) + { + this->enemies.EraseQuick(index); + continue; + } } break; @@ -421,7 +466,12 @@ void ShootemApp::OnEnemyHit(Enemy* enemy) { n_assert(enemy); - enemy->state = ES_Dying; + enemy->hitPoints--; + if (enemy->hitPoints > 0) + enemy->state = ES_Hit; + else + enemy->state = ES_Dying; + enemy->fTimeElapsed = 0.f; } @@ -435,6 +485,14 @@ //------------------------------------------------------------------------------ +void ShootemApp::OnLevelEnd() +{ + this->gameLevel++; + this->ResetLevel(); +} + +//------------------------------------------------------------------------------ + void ShootemApp::DrawEnemies() { this->BeginDraw( this->refShaderColor, this->refMeshCylinder ); @@ -447,10 +505,10 @@ Enemy& enemy = this->enemies.At(index); vector4 color(enemy.color); + if (enemy.state == ES_Hit) + color.lerp(vector4(1,1,0,1), enemy.fTimeElapsed / this->fEnemyHitTime); if (enemy.state == ES_Dying) - { color.lerp(enemy.color, vector4(0,0,0,1), enemy.fTimeElapsed / this->fEnemyDyingTime ); - } this->refShaderColor->SetVector4( nShaderState::MatDiffuse, color ); @@ -458,7 +516,7 @@ matWorld.scale(enemy.vecScale); matWorld.scale(vector3(.5f,.5f,.5f)); matWorld.rotate_x(n_deg2rad(90.f)); - matWorld.translate(enemy.vecPos); + matWorld.translate(enemy.vecPos + vector3(0,1,0)); this->Draw(matWorld); } @@ -547,7 +605,7 @@ //score //debug text - str.Format("Projectiles.Size = %d", this->projectiles.Size()); + str.Format("Projectiles = %d, Enemies = %d", this->projectiles.Size(), this->enemies.Size()); gfxServer->Text( str.Get(), vector4(1.f,1.f,0,1), -1.f, 1.f - rowheight );//lower-left corner } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |