aboutsummaryrefslogtreecommitdiffstats
path: root/src/level.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/level.c39
1 files changed, 37 insertions, 2 deletions
diff --git a/src/level.c b/src/level.c
index 87068ad..4207827 100644
--- a/src/level.c
+++ b/src/level.c
@@ -171,6 +171,34 @@ void drawPixel(S3L_PixelInfo* p) {
setPixel(p->x, p->y, r, g, b);
}
+static inline uint8_t collision(S3L_Vec4 worldPosition)
+{
+ worldPosition.x /= S3L_FRACTIONS_PER_UNIT;
+ worldPosition.z /= -S3L_FRACTIONS_PER_UNIT;
+
+ uint16_t index = worldPosition.z * 8 + worldPosition.x;
+
+ return collisionMap[index];
+}
+
+static inline void handleCollision(S3L_Vec4 *pos, S3L_Vec4 previousPos)
+{
+ S3L_Vec4 newPos = *pos;
+ newPos.x = previousPos.x;
+
+ if (collision(newPos))
+ {
+ newPos = *pos;
+ newPos.z = previousPos.z;
+
+ if (collision(newPos))
+ newPos = previousPos;
+ }
+
+ *pos = newPos;
+}
+
+
S3L_Transform3D modelTransform;
S3L_DrawConfig conf;
@@ -271,6 +299,7 @@ int main() {
S3L_rotationToDirections(scene.camera.transform.rotation, 50, &camF,
&camR, 0);
+ uint8_t coll = collision(levelModel.transform.translation);
const uint8_t* state = SDL_GetKeyboardState(NULL);
@@ -283,7 +312,13 @@ int main() {
else if (state[SDL_SCANCODE_D])
S3L_vec3Add(&scene.camera.transform.translation, camR);
- if (state[SDL_SCANCODE_K])
+ scene.camera.transform.translation.x =
+ scene.models[1].transform.translation.x - (cameraDirection.x) / S3L_FRACTIONS_PER_UNIT;
+
+ scene.camera.transform.translation.z =
+ scene.models[1].transform.translation.z - (cameraDirection.z) / S3L_FRACTIONS_PER_UNIT;
+
+ if (state[SDL_SCANCODE_SPACE])
newHeight = S3L_resolutionY + 4;
else if (state[SDL_SCANCODE_I])
newHeight = S3L_resolutionY - 4;
@@ -293,7 +328,7 @@ int main() {
newWidth = S3L_resolutionX + 4;
SDL_RenderClear(renderer);
- SDL_RenderCopy(renderer, texture, NULL, NULL);
+ SDL_RenderCopy(renderer,texture,NULL,NULL);
SDL_RenderPresent(renderer);
frame++;