ソースを参照

Merge pull request #29 from CrystalPointA4/feature/weaponCollision

Feature/weapon collision
Kenneth van Ewijk 9 年 前
コミット
97d43a1249
6 ファイル変更13 行追加118 行削除
  1. 3 0
      CrystalPoint.cpp
  2. 0 89
      Matrix.cpp
  3. 0 26
      Matrix.h
  4. 1 0
      Player.cpp
  5. 2 0
      Player.h
  6. 7 3
      World.cpp

+ 3 - 0
CrystalPoint.cpp

@@ -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;
             }
 
 		}

+ 0 - 89
Matrix.cpp

@@ -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;
-    }
-};

+ 0 - 26
Matrix.h

@@ -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 - 0
Player.cpp

@@ -18,6 +18,7 @@ Player::Player()
 	maxXp = 100;
 	level = 5;
 	crystals = 0;
+    hit = false;
 
 	loadWeapons();
 

+ 2 - 0
Player.h

@@ -40,6 +40,8 @@ public:
 	int level;
 	int crystals;
 
+	bool hit;
+
 	float speed;
 
 	void HpUp(int);

+ 7 - 3
World.cpp

@@ -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;
 		
 }