diff --git a/Enemy.cpp b/Enemy.cpp index d86a114..3f13f6f 100644 --- a/Enemy.cpp +++ b/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; } diff --git a/Enemy.h b/Enemy.h index 10b53d8..eb503b4 100644 --- a/Enemy.h +++ b/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(); diff --git a/Main.cpp b/Main.cpp index 786708f..086dc14 100644 --- a/Main.cpp +++ b/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(); diff --git a/World.cpp b/World.cpp index 79a23a2..4b05ab0 100644 --- a/World.cpp +++ b/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;