Merge branch 'escape001' of gitea.fishrungames.com:salmon-engine-projects/space-game001 into escape001
This commit is contained in:
commit
b633aa01f5
7 files changed
+25865
-16
No files matched your search
+26
-3
@@ -258,6 +258,7 @@ namespace ZL
|
||||
{
|
||||
if (currentLocation)
|
||||
{
|
||||
/*
|
||||
if (currentLocation->shadowMap) {
|
||||
CheckGlError(__FILE__, __LINE__);
|
||||
currentLocation->drawShadowDepthPass();
|
||||
@@ -265,10 +266,10 @@ namespace ZL
|
||||
currentLocation->drawGameWithShadows();
|
||||
CheckGlError(__FILE__, __LINE__);
|
||||
}
|
||||
else {
|
||||
else {*/
|
||||
currentLocation->drawGame();
|
||||
CheckGlError(__FILE__, __LINE__);
|
||||
}
|
||||
//}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -515,10 +516,24 @@ namespace ZL
|
||||
break;
|
||||
|
||||
case SDLK_p:
|
||||
x = x + 0.01;
|
||||
break;
|
||||
case SDLK_o:
|
||||
x = x - 0.01;
|
||||
break;
|
||||
|
||||
case SDLK_l:
|
||||
//currentLocation->carPosition += Eigen::Vector3f(0.f, 0.f, -1.f);
|
||||
currentLocation->inCar = !currentLocation->inCar;
|
||||
break;
|
||||
|
||||
case SDLK_w:
|
||||
case SDLK_s:
|
||||
case SDLK_a:
|
||||
case SDLK_d:
|
||||
if (currentLocation) currentLocation->handleKeyDown(event.key.keysym.sym);
|
||||
break;
|
||||
|
||||
case SDLK_RETURN:
|
||||
|
||||
default:
|
||||
@@ -547,7 +562,15 @@ namespace ZL
|
||||
}
|
||||
|
||||
if (event.type == SDL_KEYUP) {
|
||||
|
||||
switch (event.key.keysym.sym) {
|
||||
case SDLK_w:
|
||||
case SDLK_s:
|
||||
case SDLK_a:
|
||||
case SDLK_d:
|
||||
if (currentLocation) currentLocation->handleKeyUp(event.key.keysym.sym);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
+134
-13
@@ -16,6 +16,7 @@
|
||||
|
||||
namespace ZL
|
||||
{
|
||||
extern float x;
|
||||
extern const char* CONST_ZIP_FILE;
|
||||
|
||||
static constexpr float CAMERA_FOV_Y = 1.0f / 1.5f;
|
||||
@@ -36,6 +37,12 @@ namespace ZL
|
||||
roomMesh.data.RotateByMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(-M_PI * 0.5, Eigen::Vector3f::UnitY())).toRotationMatrix());
|
||||
roomMesh.RefreshVBO();
|
||||
|
||||
carTexture = std::make_unique<Texture>(CreateTextureDataFromPng("resources/e/car002.png", CONST_ZIP_FILE));
|
||||
carMesh.data = LoadFromTextFile02("resources/e/car001.txt", CONST_ZIP_FILE);
|
||||
//carMesh.data.RotateByMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(-M_PI * 0.5, Eigen::Vector3f::UnitY())).toRotationMatrix());
|
||||
carMesh.RefreshVBO();
|
||||
|
||||
|
||||
// Load static game objects
|
||||
gameObjects = GameObjectLoader::loadAndCreateGameObjects("resources/config2/gameobjects.json", renderer, CONST_ZIP_FILE);
|
||||
|
||||
@@ -149,6 +156,16 @@ namespace ZL
|
||||
roomMesh.data.RotateByMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(-M_PI * 0.5, Eigen::Vector3f::UnitY())).toRotationMatrix());
|
||||
roomMesh.RefreshVBO();
|
||||
|
||||
carTexture = std::make_unique<Texture>(CreateTextureDataFromPng("resources/e/car002.png", CONST_ZIP_FILE));
|
||||
carMesh.data = LoadFromTextFile02("resources/e/car001.txt", CONST_ZIP_FILE);
|
||||
carMesh.data.RotateByMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(M_PI * 0.5, Eigen::Vector3f::UnitY())).toRotationMatrix());
|
||||
carMesh.RefreshVBO();
|
||||
|
||||
carWheelTexture = std::make_unique<Texture>(CreateTextureDataFromPng("resources/e/Wheel_base002.png", CONST_ZIP_FILE));
|
||||
carWheelMesh.data = LoadFromTextFile02("resources/e/car_wheel001.txt", CONST_ZIP_FILE);
|
||||
carWheelMesh.data.RotateByMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(M_PI * 0.5, Eigen::Vector3f::UnitY())).toRotationMatrix());
|
||||
carWheelMesh.RefreshVBO();
|
||||
|
||||
gameObjects = GameObjectLoader::loadAndCreateGameObjects(gameObjectsPath, renderer, CONST_ZIP_FILE);
|
||||
|
||||
interactiveObjects = GameObjectLoader::loadAndCreateInteractiveObjects(interactiveObjectsPath, renderer, CONST_ZIP_FILE);
|
||||
@@ -216,7 +233,8 @@ void Location::setup()
|
||||
debugNavMeshes.clear();
|
||||
|
||||
roomMesh.data = VertexDataStruct();
|
||||
roomMesh.RefreshVBO();
|
||||
//roomMesh.data = LoadFromTextFile02("resources/w/road001.txt", CONST_ZIP_FILE);
|
||||
//roomMesh.RefreshVBO();
|
||||
roomTexture = std::make_unique<Texture>(CreateTextureDataFromPng("resources/w/room005.png", CONST_ZIP_FILE));
|
||||
|
||||
struct ModelAsset {
|
||||
@@ -343,6 +361,17 @@ void Location::setup()
|
||||
dialogueSystem.init(renderer, CONST_ZIP_FILE);
|
||||
dialogueSystem.loadDatabase("resources/dialogue/sample_dialogues.json");
|
||||
}
|
||||
|
||||
carTexture = std::make_unique<Texture>(CreateTextureDataFromPng("resources/e/car002.png", CONST_ZIP_FILE));
|
||||
carMesh.data = LoadFromTextFile02("resources/e/car001.txt", CONST_ZIP_FILE);
|
||||
carMesh.data.RotateByMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(M_PI * 0.5, Eigen::Vector3f::UnitY())).toRotationMatrix());
|
||||
carMesh.RefreshVBO();
|
||||
|
||||
carWheelTexture = std::make_unique<Texture>(CreateTextureDataFromPng("resources/e/Wheel_base002.png", CONST_ZIP_FILE));
|
||||
carWheelMesh.data = LoadFromTextFile02("resources/e/car_wheel001.txt", CONST_ZIP_FILE);
|
||||
carWheelMesh.data.RotateByMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(M_PI * 0.5, Eigen::Vector3f::UnitY())).toRotationMatrix());
|
||||
carWheelMesh.RefreshVBO();
|
||||
|
||||
}
|
||||
|
||||
void Location::setupNavigation()
|
||||
@@ -519,11 +548,14 @@ void Location::setup()
|
||||
|
||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(cameraInclination, Eigen::Vector3f::UnitX())).toRotationMatrix());
|
||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(cameraAzimuth, Eigen::Vector3f::UnitY())).toRotationMatrix());
|
||||
const Eigen::Vector3f& camTarget = player ? player->position : Eigen::Vector3f::Zero();
|
||||
Eigen::Vector3f camTarget = inCar ? carPosition : (player ? player->position : Eigen::Vector3f::Zero());
|
||||
renderer.TranslateMatrix({ -camTarget.x(), -camTarget.y(), -camTarget.z() });
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, roomTexture->getTexID());
|
||||
renderer.DrawVertexRenderStruct(roomMesh);
|
||||
if (roomMesh.data.PositionData.size() > 0)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, roomTexture->getTexID());
|
||||
renderer.DrawVertexRenderStruct(roomMesh);
|
||||
}
|
||||
|
||||
for (auto& [name, gameObj] : gameObjects) {
|
||||
if (name == roofObjectKey && !roofVisible) {
|
||||
@@ -533,21 +565,46 @@ void Location::setup()
|
||||
renderer.DrawVertexRenderStruct(gameObj.mesh);
|
||||
}
|
||||
|
||||
/*
|
||||
glBindTexture(GL_TEXTURE_2D, fireboxTexture->getTexID());
|
||||
renderer.DrawVertexRenderStruct(fireboxMesh);
|
||||
glBindTexture(GL_TEXTURE_2D, inaiTexture->getTexID());
|
||||
renderer.DrawVertexRenderStruct(inaiMesh);
|
||||
glBindTexture(GL_TEXTURE_2D, benchTexture->getTexID());
|
||||
renderer.DrawVertexRenderStruct(benchMesh);
|
||||
*/
|
||||
for (auto& intObj : interactiveObjects) {
|
||||
if (intObj.isActive) {
|
||||
intObj.draw(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
if (player) player->draw(renderer);
|
||||
renderer.PushMatrix();
|
||||
//renderer.LoadIdentity();
|
||||
renderer.TranslateMatrix(carPosition);
|
||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(carRotation, Eigen::Vector3f::UnitY())).toRotationMatrix());
|
||||
glBindTexture(GL_TEXTURE_2D, carTexture->getTexID());
|
||||
renderer.DrawVertexRenderStruct(carMesh);
|
||||
|
||||
if (carWheelTexture) {
|
||||
constexpr float track_width = 1.28f;
|
||||
constexpr float wheel_base = 2.25f;
|
||||
constexpr float shift = 0.6f;
|
||||
const Eigen::Vector3f wheelPositions[4] = {
|
||||
Eigen::Vector3f( track_width, 0.f - 0.21, -(wheel_base + shift)+1.25), // front right
|
||||
Eigen::Vector3f(-track_width, 0.f - 0.21, -(wheel_base + shift)+1.25), // front left
|
||||
Eigen::Vector3f( track_width, 0.f - 0.21, (wheel_base - shift)+1.1), // rear right
|
||||
Eigen::Vector3f(-track_width, 0.f - 0.21, (wheel_base - shift)+1.1) // rear left
|
||||
};
|
||||
const bool isFront[4] = { true, true, false, false };
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, carWheelTexture->getTexID());
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
renderer.PushMatrix();
|
||||
renderer.TranslateMatrix(wheelPositions[i]);
|
||||
if (isFront[i]) {
|
||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(carSteeringAngle, Eigen::Vector3f::UnitY())).toRotationMatrix());
|
||||
}
|
||||
renderer.DrawVertexRenderStruct(carWheelMesh);
|
||||
renderer.PopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
renderer.PopMatrix();
|
||||
|
||||
if (player && !inCar) player->draw(renderer);
|
||||
for (auto& npc : npcs) npc->draw(renderer);
|
||||
|
||||
//#ifdef SHOW_PATH
|
||||
@@ -759,7 +816,45 @@ void Location::setup()
|
||||
}
|
||||
for (auto& npc : npcs) npc->update(delta);
|
||||
|
||||
if (inCar) {
|
||||
float dt = static_cast<float>(delta) / 1000.0f;
|
||||
|
||||
if (keyForward) {
|
||||
carVelocity += carAcceleration * dt;
|
||||
}
|
||||
if (keyBackward) {
|
||||
carVelocity -= carAcceleration * dt;
|
||||
}
|
||||
|
||||
if (!keyForward && !keyBackward) {
|
||||
float resistance = carFriction * dt;
|
||||
if (carVelocity > 0.f) {
|
||||
carVelocity = max(0.f, carVelocity - resistance);
|
||||
} else if (carVelocity < 0.f) {
|
||||
carVelocity = min(0.f, carVelocity + resistance);
|
||||
}
|
||||
}
|
||||
|
||||
carVelocity = max(-carMaxReverseSpeed, min(carMaxSpeed, carVelocity));
|
||||
|
||||
if (std::abs(carVelocity) > 0.01f) {
|
||||
float speedFactor = carVelocity / carMaxSpeed;
|
||||
if (keyLeft) carRotation += carTurnRate * dt * speedFactor;
|
||||
if (keyRight) carRotation -= carTurnRate * dt * speedFactor;
|
||||
}
|
||||
|
||||
float targetSteer = (keyLeft ? 1.f : 0.f) - (keyRight ? 1.f : 0.f);
|
||||
targetSteer *= carMaxSteerAngle;
|
||||
float steerLerp = min(1.f, dt * 8.f);
|
||||
carSteeringAngle += (targetSteer - carSteeringAngle) * steerLerp;
|
||||
|
||||
Eigen::Vector3f forward(-std::sin(carRotation), 0.f, -std::cos(carRotation));
|
||||
carPosition += forward * carVelocity * dt;
|
||||
|
||||
if (player) {
|
||||
player->position = carPosition;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if player reached target interactive object
|
||||
if (targetInteractiveObject && player) {
|
||||
@@ -798,6 +893,10 @@ void Location::setup()
|
||||
return;
|
||||
}
|
||||
|
||||
if (inCar) {
|
||||
return;
|
||||
}
|
||||
|
||||
player->attackTarget = nullptr;
|
||||
|
||||
// Unproject click to ground plane (y=0) for Viola's walk target
|
||||
@@ -909,6 +1008,28 @@ void Location::setup()
|
||||
}
|
||||
}
|
||||
|
||||
void Location::handleKeyDown(int sdlKey)
|
||||
{
|
||||
switch (sdlKey) {
|
||||
case SDLK_w: keyForward = true; break;
|
||||
case SDLK_s: keyBackward = true; break;
|
||||
case SDLK_a: keyLeft = true; break;
|
||||
case SDLK_d: keyRight = true; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
void Location::handleKeyUp(int sdlKey)
|
||||
{
|
||||
switch (sdlKey) {
|
||||
case SDLK_w: keyForward = false; break;
|
||||
case SDLK_s: keyBackward = false; break;
|
||||
case SDLK_a: keyLeft = false; break;
|
||||
case SDLK_d: keyRight = false; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
bool Location::requestDialogueStart(const std::string& dialogueId)
|
||||
{
|
||||
return dialogueSystem.startDialogue(dialogueId);
|
||||
|
||||
@@ -39,6 +39,32 @@ namespace ZL
|
||||
Eigen::Matrix4f cameraViewMatrix = Eigen::Matrix4f::Identity();
|
||||
InteractiveObject* targetInteractiveObject = nullptr;
|
||||
|
||||
|
||||
std::shared_ptr<Texture> carTexture;
|
||||
VertexRenderStruct carMesh;
|
||||
std::shared_ptr<Texture> carWheelTexture;
|
||||
VertexRenderStruct carWheelMesh;
|
||||
Vector3f carPosition = Eigen::Vector3f(0.f, 0.f, 0.f);
|
||||
float carRotation = 0.f;
|
||||
|
||||
float carVelocity = 0.f;
|
||||
float carAcceleration = 20.0f;
|
||||
float carFriction = 6.0f;
|
||||
float carMaxSpeed = 20.0f;
|
||||
float carMaxReverseSpeed = 8.0f;
|
||||
float carTurnRate = 1.8f;
|
||||
|
||||
float carSteeringAngle = 0.f;
|
||||
float carMaxSteerAngle = 0.6f;
|
||||
|
||||
bool keyForward = false;
|
||||
bool keyBackward = false;
|
||||
bool keyLeft = false;
|
||||
bool keyRight = false;
|
||||
|
||||
bool inCar = false;
|
||||
|
||||
|
||||
ScriptEngine scriptEngine;
|
||||
Dialogue::DialogueSystem dialogueSystem;
|
||||
|
||||
@@ -68,6 +94,8 @@ namespace ZL
|
||||
void handleDown(int64_t fingerId, int eventX, int eventY, int mx, int my);
|
||||
void handleUp(int64_t fingerId, int mx, int my);
|
||||
void handleMotion(int64_t fingerId, int eventX, int eventY, int mx, int my);
|
||||
void handleKeyDown(int sdlKey);
|
||||
void handleKeyUp(int sdlKey);
|
||||
|
||||
bool requestDialogueStart(const std::string& dialogueId);
|
||||
void setDialogueFlag(const std::string& flag, int value);
|
||||
|
||||
Reference in new issue
Block a user