Remco 9 жил өмнө
parent
commit
9f455be8d6
4 өөрчлөгдсөн 8 нэмэгдсэн , 22 устгасан
  1. 3 16
      Enemy.cpp
  2. 1 3
      Enemy.h
  3. 1 1
      Main.cpp
  4. 3 2
      World.cpp

+ 3 - 16
Enemy.cpp

@@ -28,9 +28,7 @@ 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);
-	canAttack = false;
-	lastAttacked = 0;
-	
+	attack = false;	
 }
 
 
@@ -82,17 +80,6 @@ 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());
@@ -112,7 +99,7 @@ void Enemy::update(float delta)
 		length = sqrt(dx*dx + dz*dz);
 		if (length > 1)
 		{
-			canAttack = false;
+			attack = false;
 
 			dx /= length;
 			dz /= length;
@@ -125,7 +112,7 @@ void Enemy::update(float delta)
 		}
 		else
 		{	
-			canAttack = true;
+			attack = true;
 		}
 		rotation.y = atan2f(dx, dz) * 180 / M_PI;		
 	}

+ 1 - 3
Enemy.h

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

+ 1 - 1
Main.cpp

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

+ 3 - 2
World.cpp

@@ -334,9 +334,10 @@ void World::update(float elapsedTime)
 			}
 		}
 
-		if (enemy->attack())
+		if (enemy->attack)
 		{			
-			player->HpDown(enemy->damage);
+			remove = true;
+			continue;
 		}
 		enemy->position.y = getHeight(enemy->position.x, enemy->position.z) + 2.0f;