diff --git a/CrystalPoint.cpp b/CrystalPoint.cpp index 17f2cf7..478f8b1 100644 --- a/CrystalPoint.cpp +++ b/CrystalPoint.cpp @@ -130,6 +130,14 @@ void CrystalPoint::update() player->hit = true; } + if(player->isHit){ + controller.rumble(leftcontroller->controllerId, 50, 250); + } + + if(!leftcontroller->lastMagetSwitch && leftcontroller->magnetSwitch){ + worldhandler -> teleportRandom(); + } + } if(rightcontroller != nullptr){ Vec2f *rightControllerJoystick = &rightcontroller->joystick; @@ -153,6 +161,15 @@ void CrystalPoint::update() player->NextRightWeapon(); } + if(player->isHit){ + controller.rumble(rightcontroller->controllerId, 50, 250); + player->isHit = false; + } + + if(!rightcontroller->lastMagetSwitch && rightcontroller->magnetSwitch){ + worldhandler -> teleportRandom(); + } + player->rightWeapon->rotateWeapon(Vec3f(rightcontroller->ypr.y + 140, 0, -rightcontroller->ypr.z)); } diff --git a/Main.cpp b/Main.cpp index e9abf25..639f450 100644 --- a/Main.cpp +++ b/Main.cpp @@ -6,7 +6,8 @@ #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" - +#include +#include #include "Cursor.h" void configureOpenGL(void); @@ -15,11 +16,15 @@ CrystalPoint* app; bool justMoved = false; + + int main(int argc, char* argv[]) { app = new CrystalPoint(); glutInit(&argc, argv); + srand (time(NULL)); + configureOpenGL(); app->init(); diff --git a/Player.cpp b/Player.cpp index d650a02..962fbc9 100644 --- a/Player.cpp +++ b/Player.cpp @@ -86,6 +86,7 @@ void Player::draw() { void Player::HpDown(int damage) { int newHealth = health - damage; + isHit = true; if (newHealth <= 0) { exit(0); diff --git a/Player.h b/Player.h index 17bbe49..94b2392 100644 --- a/Player.h +++ b/Player.h @@ -41,6 +41,7 @@ public: int crystals; bool hit; + bool isHit; float speed; diff --git a/World.cpp b/World.cpp index f7259ad..f3b66ee 100644 --- a/World.cpp +++ b/World.cpp @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include "WorldHandler.h" World::World(const std::string &fileName) @@ -220,7 +222,12 @@ World::World(const std::string &fileName) } } - +Vec2f World::randomPosition(void){ + int randNum = rand()%(entities.size() + 1); + Vec3f position = entities[randNum]->position; + Vec2f position2 = Vec2f(position.x+100, position.y+100); + return position2; +} World::~World() { delete heightmap; diff --git a/World.h b/World.h index 9dbebcf..7b7b75c 100644 --- a/World.h +++ b/World.h @@ -41,6 +41,7 @@ public: bool isPlayerPositionValid(); float getHeight(float x, float y); void addLevelObject(LevelObject* obj); + Vec2f randomPosition(void); std::pair getObjectFromValue(int i); }; diff --git a/WorldHandler.cpp b/WorldHandler.cpp index 0b3fe21..eae74c9 100644 --- a/WorldHandler.cpp +++ b/WorldHandler.cpp @@ -93,6 +93,13 @@ void WorldHandler::update(float deltaTime) world->update(deltaTime); } +void WorldHandler::teleportRandom(){ + Vec2f randomposition = world->randomPosition(); + printf("test %d %d", randomposition.x, randomposition.y); + Player::getInstance()->position = Vec3f(randomposition.x, randomposition.y, world->getHeight(randomposition.x, randomposition.y)); + Player::getInstance()->setPosition(50,50,true); +} + bool WorldHandler::isPlayerPositionValid(void) { if(!loadingWorld) diff --git a/WorldHandler.h b/WorldHandler.h index 0cde251..fd63b74 100644 --- a/WorldHandler.h +++ b/WorldHandler.h @@ -23,6 +23,7 @@ public: void draw(void); void update(float deltaTime); + void teleportRandom(); bool isPlayerPositionValid(void); float getHeight(float x, float y);