Remco před 9 roky
rodič
revize
fea7728139
4 změnil soubory, kde provedl 29 přidání a 13 odebrání
  1. 16 3
      Enemy.cpp
  2. 3 1
      Enemy.h
  3. 3 2
      Main.cpp
  4. 7 7
      World.cpp

+ 16 - 3
Enemy.cpp

@@ -28,7 +28,9 @@ Enemy::Enemy(const std::string &fileName,
 	hasTarget = false;
 	hit_sound_id = CrystalPoint::GetSoundSystem().LoadSound(fileMusic.c_str(), false);
 	music = CrystalPoint::GetSoundSystem().GetSound(hit_sound_id);
-	attack = false;
+	canAttack = false;
+	lastAttacked = 0;
+	
 }
 
 
@@ -80,6 +82,17 @@ void Enemy::collide(const Entity * entity)
 	position.z = difference.z + entity->position.z;
 }
 
+bool Enemy::attack()
+{
+	float timeNow = glutGet(GLUT_ELAPSED_TIME)/1000.0f;
+	if (canAttack && timeNow - lastAttacked > 0.8)
+	{
+		lastAttacked = timeNow;
+		return true;
+	}
+	return false;
+}
+
 void Enemy::update(float delta)
 {
 	music->SetPos(position, Vec3f());
@@ -99,7 +112,7 @@ void Enemy::update(float delta)
 		length = sqrt(dx*dx + dz*dz);
 		if (length > 1)
 		{
-			attack = false;
+			canAttack = false;
 
 			dx /= length;
 			dz /= length;
@@ -112,7 +125,7 @@ void Enemy::update(float delta)
 		}
 		else
 		{	
-			attack = true;
+			canAttack = true;
 		}
 		rotation.y = atan2f(dx, dz) * 180 / M_PI;		
 	}

+ 3 - 1
Enemy.h

@@ -19,7 +19,9 @@ public:
 	float health;
 	float damage;
 	int xp;
-	bool attack;
+	bool canAttack;
+	float lastAttacked;
+	bool attack();
 
 	void update(float);
 	void draw();

+ 3 - 2
Main.cpp

@@ -79,8 +79,9 @@ void configureOpenGL()
 {
 	//Init window and glut display mode
 	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
-	glutInitWindowSize(1440, 900);
-	//glutInitWindowPosition(glutGet(GLUT_WINDOW_WIDTH) / 2 - 800/2, glutGet(GLUT_WINDOW_HEIGHT) / 2 - 600/2);
+	glutInitWindowSize(1440, 900);	
+	//glutPositionWindow((glutGet(GLUT_SCREEN_WIDTH) / 2) - (glutGet(GLUT_WINDOW_WIDTH) / 2), (glutGet(GLUT_SCREEN_HEIGHT) / 2) - (glutGet(GLUT_WINDOW_HEIGHT) / 2));
+
 	glutCreateWindow("Crystal Point");	
 	//glutFullScreen();
 

+ 7 - 7
World.cpp

@@ -313,7 +313,7 @@ void World::update(float elapsedTime)
 
 		//Al deze code zou in enemy moeten staan
 		enemy->inEyeSight(player->position);
-
+		
 
 		enemy->update(elapsedTime);
 		if (enemy->hasTarget)
@@ -326,12 +326,11 @@ void World::update(float elapsedTime)
 					break;
 				}
 			}
+		}
 
-			if (enemy->attack)
-			{
-				remove = true;
-				continue;
-			}
+		if (enemy->attack())
+		{			
+			player->HpDown(enemy->damage);
 		}
 		enemy->position.y = getHeight(enemy->position.x, enemy->position.z) + 2.0f;
 		
@@ -342,7 +341,8 @@ void World::update(float elapsedTime)
 	if (remove)
 	{
 		player->XpUp(enemies[count]->xp);
-		delete enemies[count];		
+		delete enemies[count];
+		
 		enemies.erase(enemies.begin() + count);
 		player->HpUp(10);		
 	}