Merge pull request #33 from CrystalPointA4/feature/weaponCollision
Feature/weapon collision
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#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();
|
||||
|
||||
@@ -86,6 +86,7 @@ void Player::draw() {
|
||||
void Player::HpDown(int damage)
|
||||
{
|
||||
int newHealth = health - damage;
|
||||
isHit = true;
|
||||
if (newHealth <= 0)
|
||||
{
|
||||
exit(0);
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
#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;
|
||||
|
||||
@@ -41,6 +41,7 @@ public:
|
||||
bool isPlayerPositionValid();
|
||||
float getHeight(float x, float y);
|
||||
void addLevelObject(LevelObject* obj);
|
||||
Vec2f randomPosition(void);
|
||||
std::pair<std::string, bool> getObjectFromValue(int i);
|
||||
|
||||
};
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
|
||||
void draw(void);
|
||||
void update(float deltaTime);
|
||||
void teleportRandom();
|
||||
|
||||
bool isPlayerPositionValid(void);
|
||||
float getHeight(float x, float y);
|
||||
|
||||
Reference in New Issue
Block a user