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
+3
View File
@@ -151,6 +151,9 @@ void CrystalPoint::update()
}
else
{
if (keyboardState.keys[27]){
glutExit();
}
menu->update();
cursor->update(cursor->mousePosition + mouseOffset);
}
+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;
}
}
+3
View File
@@ -19,11 +19,14 @@ public:
int xp;
bool attack;
bool isHit;
void update(float);
void draw();
void inEyeSight(Vec3f &);
void collide(const Entity *entity);
void hit(int damage);
private:
int hit_sound_id;
};
+2 -2
View File
@@ -15,10 +15,10 @@ Player::Player()
level = 1;
crystals = 0;
leftWeapon = new Weapon("models/weapons/ZwaardMetTextures/TextureZwaard.obj", 1, position, rotation, Vec3f(4.5, -8, -1), Vec3f(-2.0f, 6.0f, -2.1f), Vec2f(170, 70), Vec2f(20, -80));
leftWeapon = new Weapon("models/weapons/ZwaardMetTextures/TextureZwaard.obj", 1, position, rotation, Vec3f(4.5, -8, -1), Vec3f(-2.0f, 6.0f, -2.1f), Vec3f(-2.0f, 0.5f, -2.1f), Vec2f(170, 70), Vec2f(20, -80));
leftWeapon->rotateWeapon(Vec3f(150, 0, 60));
rightWeapon = new Weapon("models/weapons/ZwaardMetTextures/TextureZwaard.obj", 1, position, rotation, Vec3f(0.5, -8, -1), Vec3f(-2.0f, 6.0f, -2.1f), Vec2f(170, 70), Vec2f(20, -80));
rightWeapon = new Weapon("models/weapons/ZwaardMetTextures/TextureZwaard.obj", 1, position, rotation, Vec3f(0.5, -8, -1), Vec3f(-2.0f, 6.0f, -2.1f), Vec3f(-2.0f, 0.5f, -2.1f), Vec2f(170, 70), Vec2f(20, -80));
rightWeapon->rotateWeapon(Vec3f(150, 0, 60));
}
+3 -2
View File
@@ -10,7 +10,7 @@
Weapon::Weapon(std::string modelFilename, float scale, Vec3f location, Vec2f rotation,
Vec3f offsetPlayer, Vec3f ankerPoint,
Vec3f offsetPlayer, Vec3f ankerPoint, Vec3f collisionPoint,
Vec2f maxRotation, Vec2f minRotation){
weaponmodel = Model::load(modelFilename);
rotate(rotation);
@@ -21,6 +21,7 @@ Weapon::Weapon(std::string modelFilename, float scale, Vec3f location, Vec2f rot
this->ankerPoint = ankerPoint;
this->maxRotation = maxRotation;
this->minRotation = minRotation;
this->collisionPoint = collisionPoint;
};
Weapon::~Weapon(){
@@ -72,7 +73,7 @@ void Weapon::draw(){
//Test code for finding anker point
glColor3ub(255, 255, 0);
glTranslatef(ankerPoint.x, ankerPoint.y, ankerPoint.z);
glTranslatef(collisionPoint.x, collisionPoint.y, collisionPoint.z);
glBegin(GL_LINES);
glVertex2f(0, 4);
glVertex2f(0, -4);
+2 -2
View File
@@ -12,7 +12,7 @@
class Weapon {
public:
Weapon(std::string modelFilename, float scale, Vec3f location, Vec2f rotation,
Vec3f offsetPlayer, Vec3f ankerPoint,
Vec3f offsetPlayer, Vec3f ankerPoint, Vec3f collisionPoint,
Vec2f maxRotation, Vec2f minXRotation);
~Weapon();
@@ -26,7 +26,7 @@ public:
float scale;
Vec3f position, rotation, rotationWeapon;
Vec3f offsetPlayer, ankerPoint;
Vec3f offsetPlayer, ankerPoint, collisionPoint;
Vec2f maxRotation, minRotation;
};
+1
View File
@@ -351,3 +351,4 @@ bool World::isPlayerPositionValid()
}
return true;
}