Added enemy damage

This commit is contained in:
jancoow
2016-06-22 01:37:47 +02:00
parent 5f31b2e602
commit 5b6e7b54c7
6 changed files with 13 additions and 118 deletions
+3
View File
@@ -125,6 +125,9 @@ void CrystalPoint::update()
leftcontroller->lastButton = leftcontroller->button;
controller.rumble(leftcontroller->controllerId, 100, 200);
player->NextLeftWeapon();
}else if(!leftcontroller->lastJoystickButton && leftcontroller->joystickButton){
leftcontroller->lastJoystickButton = leftcontroller->joystickButton;
player->hit = true;
}
}
-89
View File
@@ -1,89 +0,0 @@
//
// Created by janco on 6/21/16.
//
#include "Matrix.h"
Matrix::Matrix(int size = 4)
{
data = new float[size][size];
}
Matrix Matrix::identity()
{
Matrix m = new Matrix(4);
m.data[0,0] = 1;
m.data[1,1] = 1;
m.data[2,2] = 1;
m.data[3,3] = 1;
return m;
}
Matrix Matrix::rotation(float angle, Vector3 axis)
{
Matrix m = Matrix.identity();
float c = (float) Math.Cos((double) angle);
float s = (float) Math.Sin((double) angle);
m.data[0, 0] = (float) Math.Pow(axis.x, 2) * (1 - c) + c;
m.data[0, 1] = axis.x * axis.y * (1 - c) - axis.z * s;
m.data[0, 2] = axis.x * axis.z * (1 - c) - axis.y * s;
m.data[1, 0] = axis.x * axis.y * (1 - c) + axis.z * s;
m.data[1, 1] = (float)Math.Pow(axis.y, 2) * (1 - c) + c;
m.data[1, 2] = axis.y * axis.z * (1 - c) + axis.x * s;
m.data[2, 0] = axis.x * axis.z * (1 - c) + axis.y * s;
m.data[2, 1] = axis.y * axis.z * (1 - c) - axis.x * s;
m.data[2, 2] = (float)Math.Pow(axis.z, 2) * (1 - c) + c;
return m;
}
Matrix Matrix::translate(Vector3 offset)
{
Matrix m = Matrix.identity();
for(int i = 0; i < 3; i++)
{
m.data[i, 3] = offset.data[i];
}
return m;
}
Vec3f Matrix::operator * (Matrix mat, Vec3f vec)
{
Vec3f v = Vec3f(0,0,0);
for(int i = 0; i < 4; i++)
{
v.data[i] = 0;
for(int p = 0; p < 4; p++)
{
v.data[i] += mat.data[i, p] * vec.data[p];
}
}
return v;
}
Matrix Matrix::operator * (Matrix mat1, Matrix mat2)
{
Matrix m = Matrix.identity();
for (int i = 0; i < 4; i++)
{
for (int p = 0; p < 4; p++)
{
m.data[i, p] = 0;
for (int q = 0; q < 4; q++)
{
m.data[i, p] += mat1.data[i, q] * mat2.data[q, p];
}
}
}
return m;
}
};
-26
View File
@@ -1,26 +0,0 @@
//
// Created by janco on 6/21/16.
//
#ifndef CRYSTALPOINT_MATRIX_H
#define CRYSTALPOINT_MATRIX_H
class Matrix {
private:
public:
float *data;
Matrix(int i = 4);
~Matrix();
static Matrix rotation(int angle, Vec3f axis);
static Matrix identity(void);
static Matrix translate(Vec3f offset);
Matrix operator * (Matrix m1, Matrix m2);
Vec3f operator * (Matrix m, Vec3f v);
}
#endif //CRYSTALPOINT_MATRIX_H
+1
View File
@@ -18,6 +18,7 @@ Player::Player()
maxXp = 100;
level = 5;
crystals = 0;
hit = false;
loadWeapons();
+2
View File
@@ -40,6 +40,8 @@ public:
int level;
int crystals;
bool hit;
float speed;
void HpUp(int);
+7 -3
View File
@@ -304,6 +304,9 @@ void World::update(float elapsedTime)
enemy->update(elapsedTime);
if (enemy->hasTarget)
{
if(player->hit)
enemy->hit(player->leftWeapon->damage);
for (auto e : entities)
{
if (e->canCollide && e->inObject(enemy->position))
@@ -315,8 +318,7 @@ void World::update(float elapsedTime)
if (enemy->attack)
{
remove = true;
continue;
player->HpDown(enemy->damage / 4);
}
}
enemy->position.y = getHeight(enemy->position.x, enemy->position.z) + 2.0f;
@@ -330,7 +332,7 @@ void World::update(float elapsedTime)
if (remove)
{
delete enemies[count];
player->XpUp(enemies[count]->xp);
player->XpUp(enemies[count]->xp*2);
enemies.erase(enemies.begin() + count);
player->HpUp(10);
}
@@ -342,6 +344,8 @@ void World::update(float elapsedTime)
if (portal->enter(elapsedTime))
nextworld = true;
}
player->hit = false;
}