Check if weapon collision point is inside enemy and do weapon damage

This commit is contained in:
jancoow
2016-06-21 17:00:36 +02:00
parent 0a0fdfc8b1
commit 4249e35653
7 changed files with 33 additions and 7 deletions
+19 -1
View File
@@ -2,6 +2,7 @@
#include <cmath>
#include "Enemy.h"
#include "Model.h"
#include "Player.h"
#include <iostream>
Enemy::Enemy(const std::string &fileName,
@@ -75,6 +76,10 @@ void Enemy::collide(const Entity * entity)
position.z = difference.z + entity->position.z;
}
void Enemy::hit(int damage){
}
void Enemy::update(float delta)
{
music->SetPos(position, Vec3f());
@@ -117,5 +122,18 @@ void Enemy::update(float delta)
rotation.y = atan2f(dx, dz) * 180 / M_PI;
}
Player *player = Player::getInstance();
if(inObject(player->leftWeapon->collisionPoint)){
if(!isHit){
isHit = true;
hit(player->leftWeapon->damage);
}
}else if(inObject(player->rightWeapon->collisionPoint)){
if(!isHit){
isHit = true;
hit(player->rightWeapon->damage);
}
}else{
isHit = false;
}
}