Merge remote-tracking branch 'origin/developer' into feature/Controller
Added support for second controller # Conflicts: # CrystalPoint.cpp # CrystalPoint.h # CrystalPoint.vcxproj # CrystalPoint.vcxproj.filters
This commit is contained in:
+106
-55
@@ -5,23 +5,33 @@
|
||||
#include <cstring>
|
||||
#include "WorldHandler.h"
|
||||
#include "Player.h"
|
||||
#include "Cursor.h"
|
||||
#include "Menu.h"
|
||||
#include "Text.h"
|
||||
#include "Vector.h"
|
||||
#include "Button.h"
|
||||
|
||||
int CrystalPoint::width = 0;
|
||||
int CrystalPoint::height = 0;
|
||||
|
||||
SoundSystem CrystalPoint::sound_system;
|
||||
bool state = false;
|
||||
|
||||
|
||||
|
||||
void CrystalPoint::init()
|
||||
{
|
||||
player = Player::getInstance();
|
||||
worldhandler = WorldHandler::getInstance();
|
||||
//cursor = Cursor::getInstance();
|
||||
cursor = Cursor::getInstance();
|
||||
|
||||
menu = new Menu();
|
||||
buildMenu();
|
||||
|
||||
lastFrameTime = 0;
|
||||
state = true;
|
||||
|
||||
glClearColor(0.7f, 0.7f, 1.0f, 1.0f);
|
||||
|
||||
mousePosition = Vec2f(width / 2, height / 2);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,9 +49,10 @@ void CrystalPoint::draw()
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
|
||||
worldhandler->draw();
|
||||
player->draw();
|
||||
|
||||
if(!state)
|
||||
menu->draw();
|
||||
//cursor->draw();
|
||||
|
||||
glutSwapBuffers();
|
||||
@@ -54,68 +65,86 @@ void CrystalPoint::update()
|
||||
float deltaTime = frameTime - lastFrameTime;
|
||||
lastFrameTime = frameTime;
|
||||
|
||||
if (keyboardState.special[GLUT_KEY_LEFT] && !prevKeyboardState.special[GLUT_KEY_LEFT])
|
||||
worldhandler->PreviousWorld();
|
||||
if (keyboardState.special[GLUT_KEY_RIGHT] && !prevKeyboardState.special[GLUT_KEY_RIGHT])
|
||||
worldhandler->NextWorld();
|
||||
if (keyboardState.keys[27])
|
||||
exit(0);
|
||||
if (state)
|
||||
{
|
||||
if (keyboardState.special[GLUT_KEY_LEFT] && !prevKeyboardState.special[GLUT_KEY_LEFT])
|
||||
worldhandler->PreviousWorld();
|
||||
if (keyboardState.special[GLUT_KEY_RIGHT] && !prevKeyboardState.special[GLUT_KEY_RIGHT])
|
||||
worldhandler->NextWorld();
|
||||
if (keyboardState.keys[27])
|
||||
state = false;
|
||||
|
||||
Player* player = Player::getInstance();
|
||||
Player* player = Player::getInstance();
|
||||
|
||||
player->rotation.y += mouseOffset.x / 10.0f;
|
||||
player->rotation.x += mouseOffset.y / 10.0f;
|
||||
if (player->rotation.x > 90)
|
||||
player->rotation.x = 90;
|
||||
if (player->rotation.x < -90)
|
||||
player->rotation.x = -90;
|
||||
player->rotation.y += mouseOffset.x / 10.0f;
|
||||
player->rotation.x += mouseOffset.y / 10.0f;
|
||||
|
||||
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);
|
||||
float speed = 10;
|
||||
|
||||
Controller *leftcontroller = controller.getLeftController();
|
||||
if (leftcontroller != nullptr) {
|
||||
Vec2f *leftControllerJoystick = &leftcontroller->joystick;
|
||||
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 (leftcontroller->joystickButton) {
|
||||
controller.rumble(leftcontroller->controllerId, 100, 100);
|
||||
Controller *leftcontroller = controller.getLeftController();
|
||||
if (leftcontroller != nullptr) {
|
||||
Vec2f *leftControllerJoystick = &leftcontroller->joystick;
|
||||
|
||||
|
||||
if (leftcontroller->joystickButton) {
|
||||
controller.rumble(leftcontroller->controllerId, 100, 100);
|
||||
}
|
||||
|
||||
|
||||
if (leftControllerJoystick->y > 0.3) {
|
||||
player->setPosition(270, leftControllerJoystick->y * deltaTime, false);
|
||||
}
|
||||
else if (leftControllerJoystick->y < -0.3) {
|
||||
player->setPosition(90, leftControllerJoystick->y * -1 * deltaTime, false);
|
||||
}
|
||||
if (leftControllerJoystick->x > 0.3) {
|
||||
player->setPosition(180, leftControllerJoystick->x * deltaTime, false);
|
||||
}
|
||||
else if (leftControllerJoystick->x < -0.3) {
|
||||
player->setPosition(0, leftControllerJoystick->x * -1 * deltaTime, false);
|
||||
}
|
||||
|
||||
player->leftWeapon->rotateWeapon(Vec3f(leftcontroller->ypr.y + 140, 0, -leftcontroller->ypr.z));
|
||||
|
||||
}
|
||||
Controller *rightcontroller = controller.getRightController();
|
||||
if(rightcontroller != nullptr){
|
||||
Vec2f *rightControllerJoystick = &rightcontroller->joystick;
|
||||
if (rightControllerJoystick->y > 0.3 || rightControllerJoystick->y < -0.3) {
|
||||
player->rotation.x += rightcontroller->joystick.y/2;
|
||||
}
|
||||
|
||||
if (rightControllerJoystick->x > 0.3 || rightControllerJoystick->x < -0.3) {
|
||||
player->rotation.y += rightcontroller->joystick.x/2;
|
||||
}
|
||||
}
|
||||
|
||||
if (leftControllerJoystick->y > 0.3) {
|
||||
player->setPosition(270, leftControllerJoystick->y*deltaTime, false);
|
||||
}
|
||||
else if (leftControllerJoystick->y < -0.3) {
|
||||
player->setPosition(90, leftControllerJoystick->y*-1 * deltaTime, false);
|
||||
}
|
||||
if (leftControllerJoystick->x > 0.3) {
|
||||
player->setPosition(180, leftControllerJoystick->x*deltaTime, false);
|
||||
}
|
||||
else if (leftControllerJoystick->x < -0.3) {
|
||||
player->setPosition(0, leftControllerJoystick->x*-1 * deltaTime, false);
|
||||
}
|
||||
|
||||
player->leftWeapon->rotateWeapon(Vec3f(leftcontroller->ypr.y + 140, 0, -leftcontroller->ypr.z));
|
||||
if (player->rotation.x > 90)
|
||||
player->rotation.x = 90;
|
||||
if (player->rotation.x < -90)
|
||||
player->rotation.x = -90;
|
||||
|
||||
if (!worldhandler->isPlayerPositionValid())
|
||||
player->position = oldPosition;
|
||||
player->position.y = worldhandler->getHeight(player->position.x, player->position.z) + 1.7f;
|
||||
worldhandler->update(deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
menu->update();
|
||||
cursor->update(cursor->mousePosition + mouseOffset);
|
||||
}
|
||||
|
||||
|
||||
if (!worldhandler->isPlayerPositionValid())
|
||||
player->position = oldPosition;
|
||||
|
||||
player->position.y = worldhandler->getHeight(player->position.x, player->position.z) + 1.7f;
|
||||
|
||||
worldhandler->update(deltaTime);
|
||||
|
||||
mousePosition = mousePosition + mouseOffset;
|
||||
//cursor->update(mousePosition);
|
||||
|
||||
mouseOffset = Vec2f(0, 0);
|
||||
prevKeyboardState = keyboardState;
|
||||
glutPostRedisplay();
|
||||
@@ -123,6 +152,28 @@ void CrystalPoint::update()
|
||||
sound_system.SetListener(player->position, Vec3f(), Vec3f());
|
||||
}
|
||||
|
||||
void CrystalPoint::buildMenu()
|
||||
{
|
||||
Button* start = new Button("Resume", Vec2f(1920 / 2 - 50, 1080 / 2 - 30), 100, 50);
|
||||
auto toWorld = [](Button* b)
|
||||
{
|
||||
state = true;
|
||||
};
|
||||
start->addAction(toWorld);
|
||||
menu->AddMenuElement(start);
|
||||
|
||||
|
||||
Button* test = new Button("Exit", Vec2f(1920 / 2 - 50, 1080 / 2 + 30), 100, 50);
|
||||
test->addAction([](Button* b)
|
||||
{
|
||||
exit(0);
|
||||
});
|
||||
menu->AddMenuElement(test);
|
||||
Text* t = new Text("Pause", Vec2f(1920 / 2 - Util::glutTextWidth("Pause") / 2, 1080 / 2 - 75));
|
||||
t->setColor(Vec3f(255, 255, 0));
|
||||
menu->AddMenuElement(t);
|
||||
}
|
||||
|
||||
|
||||
|
||||
KeyboardState::KeyboardState()
|
||||
|
||||
Reference in New Issue
Block a user