Browse Source

enemy logic added to enemy and out of world

Remco 10 năm trước cách đây
mục cha
commit
c3fe041eb1
12 tập tin đã thay đổi với 50 bổ sung40 xóa
  1. 4 4
      CrystalPoint.cpp
  2. 16 0
      Enemy.cpp
  3. 3 0
      Enemy.h
  4. 2 2
      Entity.cpp
  5. 1 1
      Main.cpp
  6. 2 3
      Player.cpp
  7. 0 3
      Player.h
  8. 11 17
      World.cpp
  9. 1 1
      World.h
  10. 7 5
      worlds/fire.json
  11. 3 3
      worlds/ice.json
  12. 0 1
      worlds/worlds.json

+ 4 - 4
CrystalPoint.cpp

@@ -13,7 +13,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);
 }
@@ -85,13 +85,13 @@ void CrystalPoint::update()
 	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) + 1.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 &);
 };
 

+ 2 - 2
Entity.cpp

@@ -21,17 +21,17 @@ Entity::~Entity()
 
 void Entity::draw()
 {
+	//rotation.y += 0.05f;
 	if (model)
 	{
 		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);
-		glTranslatef(-model->center.x, 0, -model->center.z);
+		//glTranslatef(-model->center.x, 0, -model->center.z);
 
 		glEnable(GL_CULL_FACE);
 		glCullFace(GL_BACK);

+ 1 - 1
Main.cpp

@@ -57,7 +57,7 @@ void configureOpenGL()
 	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
 	glutInitWindowSize(800, 600);
 	glutCreateWindow("Crystal Point");
-	//glutFullScreen();
+	glutFullScreen();
 
 	//Depth testing
 	glEnable(GL_DEPTH_TEST);

+ 2 - 3
Player.cpp

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

+ 0 - 3
Player.h

@@ -22,7 +22,4 @@ public:
 
 	Model* leftWeapon;
 	Model* rightWeapon;
-
-
-	float speed;
 };

+ 11 - 17
World.cpp

@@ -29,10 +29,10 @@ World::World(const std::string &fileName)
 	if (!v["world"]["scale"].isNull())
 		scale = v["world"]["scale"].asFloat();
 
-	heightmap = new HeightMap(v["world"]["heightmap"].asString(), scale);
+	//heightmap = new HeightMap(v["world"]["heightmap"].asString(), scale);
 
-	if(!v["world"]["texture"].isNull())
-		heightmap->SetTexture(v["world"]["texture"].asString());
+	/*if(!v["world"]["texture"].isNull())
+		heightmap->SetTexture(v["world"]["texture"].asString());*/
 
 	player->position.x = v["player"]["startposition"][0].asFloat()*scale;
 	player->position.y = v["player"]["startposition"][1].asFloat()*scale;
@@ -87,12 +87,12 @@ World::World(const std::string &fileName)
 
 World::~World()
 {
-	delete heightmap;
+	//delete heightmap;
 }
 
 float World::getHeight(float x, float y)
 {
-	return heightmap->GetHeight(x, y);
+	//return heightmap->GetHeight(x, y);
 }
 
 void World::draw()
@@ -104,8 +104,9 @@ void World::draw()
 	float lightAmbient[4] = { 0.5, 0.5, 0.5, 1 };
 	glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
 
-	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
-	heightmap->Draw();
+	glColor4f(1.0f,1.0f, 1.0f, 1.0f);
+	//heightmap->Draw();
+
 
 	for (auto &enemy : enemies)
 		enemy->draw();
@@ -123,16 +124,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)
 		{

+ 1 - 1
World.h

@@ -17,7 +17,7 @@ public:
 	std::vector<Enemy*> enemies;
 
 	Player* player;
-	HeightMap* heightmap;
+	//HeightMap* heightmap;
 
 	void draw();
 	void update(float elapsedTime);

+ 7 - 5
worlds/fire.json

@@ -15,17 +15,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

@@ -5,12 +5,12 @@
     "scale": 2
    },
   "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",
@@ -20,7 +20,7 @@
   "enemies": [
     {
       "file": "models/squid/Blooper.obj",
-      "pos": [ 1, 2, -10 ],
+      "pos": [ 10, 2, -10 ],
       "scale": 0.01
     }
   ]

+ 0 - 1
worlds/worlds.json

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