diff options
Diffstat (limited to 'src/yabs_core.cpp')
-rw-r--r-- | src/yabs_core.cpp | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/src/yabs_core.cpp b/src/yabs_core.cpp index c6fdb1a..31cfa3c 100644 --- a/src/yabs_core.cpp +++ b/src/yabs_core.cpp @@ -7,6 +7,7 @@ /*********************************/ #include <raylib.h> +#include <raymath.h> #include <stdlib.h> #include <iostream> #include <strings.h> @@ -127,31 +128,35 @@ int tick(TickObjs& tobjs, Scene3D& scene_3d) { YABS_DOUBLEPI - scene_3d.rotation.x, 0}); Matrix transform = MatrixMultiply(translation, rotation2); + // apply camera rotation scene_3d.camera.target.x = scene_3d.camera.position.x - transform.m12; scene_3d.camera.target.y = scene_3d.camera.position.y - transform.m13; scene_3d.camera.target.z = scene_3d.camera.position.z - transform.m14; - // shoot - range = {{ - scene_3d.camera.target.x, - scene_3d.camera.target.y, - scene_3d.camera.target.z - }, { - scene_3d.camera.target.x + 1.5f, - scene_3d.camera.target.y + 5.5f, - scene_3d.camera.target.z + 1.5f - }}; + range = { + {scene_3d.camera.target.x - 10.5f, + scene_3d.camera.target.y - 1.0f, + scene_3d.camera.target.z - 10.5f}, + {scene_3d.camera.target.x + 10.5f, + scene_3d.camera.target.y + 1.5f, + scene_3d.camera.target.z + 10.5f} + }; if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) { - for (auto it = tobjs.vEnemyBounds.begin(); it != tobjs.vEnemyBounds.end(); ++it) { - if(CheckCollisionBoxes(range, *(*it))) { // :^} + for (auto i = 0; i < tobjs.vEnemyBounds.size(); ++i) { + if(CheckCollisionBoxes(range, *tobjs.vEnemyBounds[i])) { // :^} std::cerr << "hit enemy\n"; break ; - // erase() invalidates iterators, we have to break - // empty space + //std::cout << "r: " << + //"{" << range.min.x<< "," << range.min.x << "," << range.min.z << "}," << + //"{" << range.max.x<< "," << range.max.x << "," << range.max.z << "}\n"; + //std::cout << "b: " << + //"{" << (*it)->min.x<< "," << (*it)->min.x << "," << (*it)->min.z << "}," << + //"{" << (*it)->max.x << ","<< (*it)->max.x << "," << (*it)->max.z << "}\n"; } } + std::cerr << "missed\n"; } return (1); } @@ -201,17 +206,17 @@ void init_game() for (int i = 0; i < ENEMIES_N; i++) { Enemy * e = new Enemy(); - e->enemyStartPos.x = rand() % 32; + e->enemyStartPos.x = GetRandomValue(20, 40); e->enemyStartPos.y = 1.0f; - e->enemyStartPos.z = rand() % 32; + e->enemyStartPos.z = GetRandomValue(20, 40); e->enemyBoxPos.x = e->enemyStartPos.x; e->enemyBoxPos.y = e->enemyStartPos.y; e->enemyBoxPos.z = e->enemyStartPos.z; e->enemyBoxSize = cubeSize; e->active = true; e->enemyBounds = { - {e->enemyBoxPos.x - 2.5f, 0.0f, e->enemyBoxPos.z - 2.5f}, - {e->enemyBoxPos.x + 2.5f, 2.5f, e->enemyBoxPos.z + 2.5f} + {e->enemyBoxPos.x -2.5f, 0.0f, e->enemyBoxPos.z-2.5f}, + {e->enemyBoxPos.x+2.5f, 2.5f, e->enemyBoxPos.z+2.5f} }; robjs.vEnemyPos.push_back(&e->enemyBoxPos); tobjs.vEnemyBounds.push_back(&e->enemyBounds); |