Forráskód Böngészése

Merge pull request #10 from CrystalPointA4/enemy

Enemy
Kenneth van Ewijk 9 éve
szülő
commit
527394f635
11 módosított fájl, 47 hozzáadás és 34 törlés
  1. 5 5
      CrystalPoint.cpp
  2. 16 0
      Enemy.cpp
  3. 3 0
      Enemy.h
  4. 0 2
      Entity.cpp
  5. 1 1
      HeightMap.cpp
  6. 2 0
      LevelObject.cpp
  7. 1 2
      Player.cpp
  8. 4 11
      World.cpp
  9. 7 5
      worlds/fire.json
  10. 3 3
      worlds/ice.json
  11. 5 5
      worlds/worlds.json

+ 5 - 5
CrystalPoint.cpp

@@ -17,7 +17,7 @@ void CrystalPoint::init()
 
 	lastFrameTime = 0;
 
-	glClearColor(0.7, 0.7, 1.0, 1.0);
+	glClearColor(0.7f, 0.7f, 1.0f, 1.0f);
 
 	mousePosition = Vec2f(width / 2, height / 2);
 }
@@ -67,20 +67,20 @@ void CrystalPoint::update()
 	if (player->rotation.x < -90)
 		player->rotation.x = -90;
 
-	float speed = 1;
+	float speed = 10;
 
 	Vec3f oldPosition = player->position;
 	if (keyboardState.keys['a']) player->setPosition(0, deltaTime*speed, false);
 	if (keyboardState.keys['d']) player->setPosition(180, deltaTime*speed, false);
 	if (keyboardState.keys['w']) player->setPosition(90, deltaTime*speed, false);
 	if (keyboardState.keys['s']) player->setPosition(270, deltaTime*speed, false);
-	//if (keyboardState.keys['q']) player->setPosition(1, deltaTime*speed, true);
-	//if (keyboardState.keys['e']) player->setPosition(-1, deltaTime*speed, true);
+	if (keyboardState.keys['q']) player->setPosition(1, deltaTime*speed, true);
+	if (keyboardState.keys['e']) player->setPosition(-1, deltaTime*speed, true);
 
 	if (!worldhandler->isPlayerPositionValid())
 		player->position = oldPosition;
 
-	player->position.y = worldhandler->getHeight(player->position.x, player->position.z) + 0.7f;
+	player->position.y = worldhandler->getHeight(player->position.x, player->position.z) + 1.7f;
 
 	worldhandler->update(deltaTime);
 

+ 16 - 0
Enemy.cpp

@@ -48,6 +48,22 @@ void Enemy::draw()
 	glPopMatrix();
 }
 
+void Enemy::inEyeSight(Vec3f & TargetPosition)
+{
+	if (position.Distance(TargetPosition) <= radius)
+	{
+		hasTarget = true;
+		target = TargetPosition;
+	}
+	else
+		hasTarget = false;
+}
+
+bool Enemy::hasCollison(Vec3f &)
+{
+	
+}
+
 void Enemy::update(float delta)
 {
 	if (hasTarget)

+ 3 - 0
Enemy.h

@@ -16,5 +16,8 @@ public:
 
 	void update(float);
 	void draw();
+
+	void inEyeSight(Vec3f &);
+	bool hasCollison(Vec3f &);
 };
 

+ 0 - 2
Entity.cpp

@@ -25,13 +25,11 @@ void Entity::draw()
 	{
 		glPushMatrix();
 
-
 		glTranslatef(position.x, position.y, position.z);
 		glRotatef(rotation.x, 1, 0, 0);
 		glRotatef(rotation.y, 0, 1, 0);
 		glRotatef(rotation.z, 0, 0, 1);
 		glScalef(scale, scale, scale);
-//collision gaat hierdoor kapot		glTranslatef(-model->center.x, 0, -model->center.z);
 
 		glEnable(GL_CULL_FACE);
 		glCullFace(GL_BACK);

+ 1 - 1
HeightMap.cpp

@@ -39,7 +39,7 @@ HeightMap::HeightMap(const std::string &file, World* world)
 
 			if (valueAt(x, y, GREEN) > 0)
 			{
-				world->addLevelObject(new LevelObject(world->getObjectFromValue(valueAt(x, y, GREEN)).first, Vec3f(x, heightAt(x, y), y), Vec3f(0, rand()%360, 0), 1, world->getObjectFromValue(valueAt(x, y, GREEN)).second));
+				world->addLevelObject(new LevelObject(world->getObjectFromValue(valueAt(x, y, GREEN)).first, Vec3f(x, heightAt(x, y), y), Vec3f(0, 0, 0), 1, world->getObjectFromValue(valueAt(x, y, GREEN)).second));
 			}
 
 			Vec3f normal = ca.cross(ba);

+ 2 - 0
LevelObject.cpp

@@ -7,6 +7,8 @@ LevelObject::LevelObject(const std::string &fileName, const Vec3f &position, con
 {
 	model = Model::load(fileName);
 	this->position = position;
+	this->position.x -= model->center.x;
+	this->position.z -= model->center.z;
 	this->rotation = rotation;
 	this->scale = scale;
 	this->canCollide = hasCollision;

+ 1 - 2
Player.cpp

@@ -44,8 +44,7 @@ void Player::setCamera()
 }
 
 void Player::setPosition(float angle, float fac, bool height)
-{
-	fac *= speed;
+{	
 	if (height)
 		position.y += angle*fac;
 	else

+ 4 - 11
World.cpp

@@ -118,7 +118,7 @@ World::World(const std::string &fileName)
 
 World::~World()
 {
-	delete heightmap;
+	//delete heightmap;
 }
 
 std::pair<std::string, bool> World::getObjectFromValue(int val)
@@ -166,16 +166,9 @@ void World::update(float elapsedTime)
 	{
 
 		//Al deze code zou in enemy moeten staan
-		if (enemy->position.Distance(player->position) <= enemy->radius)
-		{			
-			enemy->hasTarget = true;
-			enemy->target.x = player->position.x;
-			enemy->target.z = player->position.z;
-		}
-		else
-			enemy->hasTarget = false;
-
-		Vec3f oldpos = enemy->position;
+		enemy->inEyeSight(player->position);
+
+		
 		enemy->update(elapsedTime);
 		if (enemy->hasTarget)
 		{

+ 7 - 5
worlds/fire.json

@@ -14,17 +14,19 @@
 	    ]
    },
   "player": {
-    "startposition": [ 200, 40, 200 ]
+    "startposition": [ 0, 1.7, 0]
   },
   "objects": [
     {
       "file": "models/boom/Boom.obj",
-      "pos": [ 4, 0, -4 ]
+      "pos": [ 4, 0, -4 ],
+      "collide": "true"
     },
-	{
+    {
       "file": "models/boom/Boom.obj",
-      "pos": [ -4, 0, -4 ]
-    }
+      "pos": [ -4, 0, -4 ],
+      "collide": "true"
+     }
   ],
   "enemies": [
     {

+ 3 - 3
worlds/ice.json

@@ -11,12 +11,12 @@
 	]
    },
   "player": {
-    "startposition": [ 100, 20, 100 ]
+    "startposition": [ 0, 1.7, 0]
   },
   "objects": [
     {
       "file": "models/boom/Boom.obj",
-      "pos": [ 4, 0, -4 ]
+      "pos": [ 10, 0, -4 ]
     },
     {
       "file": "models/Teleporter/Teleporter.obj",
@@ -26,7 +26,7 @@
   "enemies": [
     {
       "file": "models/squid/Blooper.obj",
-      "pos": [ 1, 2, -10 ],
+      "pos": [ 10, 2, -10 ],
       "scale": 0.01
     }
   ]

+ 5 - 5
worlds/worlds.json

@@ -1,7 +1,7 @@
 {
-	"worlds": [
-			"worlds/small.json",
-			"worlds/ice.json",
-			"worlds/fire.json"
-	]
+  "worlds": [
+    "worlds/small.json",
+    "worlds/ice.json",
+    "worlds/fire.json"
+  ]
 }