Merge pull request #10 from CrystalPointA4/enemy

Enemy
This commit is contained in:
2016-06-03 11:31:33 +02:00
11 changed files with 46 additions and 33 deletions
+5 -5
View File
@@ -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
View File
@@ -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
View File
@@ -16,5 +16,8 @@ public:
void update(float);
void draw();
void inEyeSight(Vec3f &);
bool hasCollison(Vec3f &);
};
-2
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
+3 -10
View File
@@ -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;
enemy->inEyeSight(player->position);
Vec3f oldpos = enemy->position;
enemy->update(elapsedTime);
if (enemy->hasTarget)
{
+7 -5
View File
@@ -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
View File
@@ -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
View File
@@ -1,7 +1,7 @@
{
"worlds": [
"worlds/small.json",
"worlds/ice.json",
"worlds/fire.json"
]
"worlds": [
"worlds/small.json",
"worlds/ice.json",
"worlds/fire.json"
]
}