Added endgame.
This commit is contained in:
parent
6ae19043fb
commit
25b8960b92
@ -11944,7 +11944,7 @@
|
||||
<zPosition>34</zPosition>
|
||||
<targetIdGreen>-</targetIdGreen>
|
||||
<targetIdBlue>-</targetIdBlue>
|
||||
<distance>10</distance>
|
||||
<distance>2</distance>
|
||||
<isBiggerThan>false</isBiggerThan>
|
||||
<objectNum>0</objectNum>
|
||||
<luaScript>sunStart.lua</luaScript>
|
||||
@ -11956,11 +11956,11 @@
|
||||
<name>sunUpdate</name>
|
||||
<undo>false</undo>
|
||||
<xPosition>-216</xPosition>
|
||||
<yPosition>20</yPosition>
|
||||
<yPosition>27.5</yPosition>
|
||||
<zPosition>34</zPosition>
|
||||
<targetIdGreen>-</targetIdGreen>
|
||||
<targetIdBlue>-</targetIdBlue>
|
||||
<distance>10</distance>
|
||||
<distance>12</distance>
|
||||
<isBiggerThan>false</isBiggerThan>
|
||||
<objectNum>0</objectNum>
|
||||
<luaScript>sunUpdate.lua</luaScript>
|
||||
|
@ -13,7 +13,7 @@ function trigger(objectToChange)
|
||||
local time = os.clock()
|
||||
global.sunStartTime = time
|
||||
global.triggeredSunStart = true
|
||||
|
||||
level:activateEndgame()
|
||||
print("sunStart")
|
||||
end
|
||||
end
|
||||
|
@ -7,7 +7,7 @@ function trigger(objectToChange)
|
||||
return
|
||||
end
|
||||
|
||||
local maxTimeDiff = 5
|
||||
local maxTimeDiff = 20
|
||||
local timeDiff = os.clock()- global.sunStartTime
|
||||
if(timeDiff > maxTimeDiff)then
|
||||
timeDiff = maxTimeDiff
|
||||
|
5
level.cc
5
level.cc
@ -41,6 +41,7 @@ void Level::load() {
|
||||
.addFunction("resetPlayer", &Level::resetPlayer)
|
||||
.addFunction("movePlayer", &Level::movePlayer)
|
||||
.addFunction("setSunDirection", &Level::setSunDirection)
|
||||
.addFunction("activateEndgame", &Level::activateEndgame)
|
||||
.endClass();
|
||||
//Push the level to Lua as a global variable
|
||||
luabridge::push(luaState, this);
|
||||
@ -272,3 +273,7 @@ Terrain* Level::getTerrain() {
|
||||
Skydome* Level::getSkydome() {
|
||||
return &skydome;
|
||||
}
|
||||
|
||||
void Level::activateEndgame(){
|
||||
physics.activateEndgame();
|
||||
}
|
||||
|
1
level.hh
1
level.hh
@ -61,6 +61,7 @@ class Level {
|
||||
void resetPlayer();
|
||||
void movePlayer(float xPosition, float yPosition, float zPosition);
|
||||
void setPlayerIndex(int index);
|
||||
void activateEndgame();
|
||||
private:
|
||||
lua_State* luaState=nullptr;
|
||||
std::vector<Object*> objects;
|
||||
|
27
physics.cc
27
physics.cc
@ -44,14 +44,17 @@ void Physics::takeUpdateStep(float timeDiff)
|
||||
}
|
||||
}
|
||||
|
||||
if(endgame)
|
||||
{
|
||||
currentDirection = playerBall->getCenterOfMassPosition();
|
||||
currentDirection.setY(0);
|
||||
currentDirection.normalize();
|
||||
}
|
||||
btVector3 position = currentDirection;
|
||||
|
||||
btVector3 position = cameraBody->getCenterOfMassPosition() - playerBall->getCenterOfMassPosition(); //gets a vector from the player to the camera
|
||||
position = currentDirection;
|
||||
position.normalize();
|
||||
position *= cameraDistance;
|
||||
position += playerBall->getCenterOfMassPosition(); //is the position cameraDistance away from the player in the direction of the camera
|
||||
|
||||
//prevent the camera from being dragged along on the ground
|
||||
|
||||
btVector3 dir = cameraBody->getCenterOfMassPosition() - position;
|
||||
float str = 50 * dir.length() / cameraBody->getInvMass(); //getInvMass() returns the inverted mass
|
||||
@ -66,6 +69,9 @@ void Physics::takeUpdateStep(float timeDiff)
|
||||
position.normalize();
|
||||
cameraBody->setLinearVelocity(position*20);
|
||||
}
|
||||
|
||||
|
||||
|
||||
world->stepSimulation(timeDiff);
|
||||
}
|
||||
else
|
||||
@ -630,6 +636,19 @@ void Physics::forceMoveCamera(btVector3 newPosition)
|
||||
cameraBody->setCenterOfMassTransform(btTransform(btQuaternion(0,0,0,1),newPosition));
|
||||
}
|
||||
|
||||
void Physics::activateEndgame()
|
||||
{
|
||||
if(endgame)
|
||||
return;
|
||||
endgame = true;
|
||||
positionConstraint cons;
|
||||
cons.body = playerBall;
|
||||
cons.strength = 1;
|
||||
cons.position = playerBall->getCenterOfMassPosition() + btVector3(0,15,0);
|
||||
playerBall->setGravity(btVector3(0,0,0));
|
||||
allPositionConstraints.push_back(cons);
|
||||
}
|
||||
|
||||
void Physics::kill() //delete dynamically allocated memory
|
||||
{
|
||||
if (world == NULL) {
|
||||
|
@ -77,6 +77,7 @@ class Physics {
|
||||
void prepareCollisionDetection();
|
||||
bool playerWithGround();
|
||||
bool playerWithObject();
|
||||
void activateEndgame();
|
||||
void forcePlayer(glm::vec3 newPosition);
|
||||
|
||||
struct positionConstraint{btRigidBody* body; float strength; btVector3 position;};
|
||||
@ -86,6 +87,7 @@ class Physics {
|
||||
float resetHight = 0;
|
||||
bool simulationActive = true;
|
||||
bool sinking = true;
|
||||
bool endgame = false;
|
||||
btVector3 currentDirection = btVector3(1,1,1);
|
||||
btRigidBody* playerBall; //allows for easier access to the ball
|
||||
btRigidBody* terrainBody; //duh
|
||||
|
Loading…
Reference in New Issue
Block a user