Merge pull request #29 from CrystalPointA4/feature/weaponCollision
Feature/weapon collision
This commit is contained in:
@@ -125,6 +125,9 @@ void CrystalPoint::update()
|
|||||||
leftcontroller->lastButton = leftcontroller->button;
|
leftcontroller->lastButton = leftcontroller->button;
|
||||||
controller.rumble(leftcontroller->controllerId, 100, 200);
|
controller.rumble(leftcontroller->controllerId, 100, 200);
|
||||||
player->NextLeftWeapon();
|
player->NextLeftWeapon();
|
||||||
|
}else if(!leftcontroller->lastJoystickButton && leftcontroller->joystickButton){
|
||||||
|
leftcontroller->lastJoystickButton = leftcontroller->joystickButton;
|
||||||
|
player->hit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
-89
@@ -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;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -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
|
|
||||||
@@ -18,6 +18,7 @@ Player::Player()
|
|||||||
maxXp = 100;
|
maxXp = 100;
|
||||||
level = 5;
|
level = 5;
|
||||||
crystals = 0;
|
crystals = 0;
|
||||||
|
hit = false;
|
||||||
|
|
||||||
loadWeapons();
|
loadWeapons();
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ public:
|
|||||||
int level;
|
int level;
|
||||||
int crystals;
|
int crystals;
|
||||||
|
|
||||||
|
bool hit;
|
||||||
|
|
||||||
float speed;
|
float speed;
|
||||||
|
|
||||||
void HpUp(int);
|
void HpUp(int);
|
||||||
|
|||||||
@@ -304,6 +304,9 @@ void World::update(float elapsedTime)
|
|||||||
enemy->update(elapsedTime);
|
enemy->update(elapsedTime);
|
||||||
if (enemy->hasTarget)
|
if (enemy->hasTarget)
|
||||||
{
|
{
|
||||||
|
if(player->hit)
|
||||||
|
enemy->hit(player->leftWeapon->damage);
|
||||||
|
|
||||||
for (auto e : entities)
|
for (auto e : entities)
|
||||||
{
|
{
|
||||||
if (e->canCollide && e->inObject(enemy->position))
|
if (e->canCollide && e->inObject(enemy->position))
|
||||||
@@ -315,8 +318,7 @@ void World::update(float elapsedTime)
|
|||||||
|
|
||||||
if (enemy->attack)
|
if (enemy->attack)
|
||||||
{
|
{
|
||||||
remove = true;
|
player->HpDown(enemy->damage / 4);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
enemy->position.y = getHeight(enemy->position.x, enemy->position.z) + 2.0f;
|
enemy->position.y = getHeight(enemy->position.x, enemy->position.z) + 2.0f;
|
||||||
@@ -330,7 +332,7 @@ void World::update(float elapsedTime)
|
|||||||
if (remove)
|
if (remove)
|
||||||
{
|
{
|
||||||
delete enemies[count];
|
delete enemies[count];
|
||||||
player->XpUp(enemies[count]->xp);
|
player->XpUp(enemies[count]->xp*2);
|
||||||
enemies.erase(enemies.begin() + count);
|
enemies.erase(enemies.begin() + count);
|
||||||
player->HpUp(10);
|
player->HpUp(10);
|
||||||
}
|
}
|
||||||
@@ -342,6 +344,8 @@ void World::update(float elapsedTime)
|
|||||||
if (portal->enter(elapsedTime))
|
if (portal->enter(elapsedTime))
|
||||||
nextworld = true;
|
nextworld = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
player->hit = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user