aboutsummaryrefslogtreecommitdiffstats
path: root/src/level
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/level.c39
-rw-r--r--src/leveldefines.h14
2 files changed, 51 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++;
diff --git a/src/leveldefines.h b/src/leveldefines.h
index 4cc52ec..f13e128 100644
--- a/src/leveldefines.h
+++ b/src/leveldefines.h
@@ -33,3 +33,17 @@
#define HALF_SCREEN_WIDTH SCREEN_WIDTH / 2
#define HALF_SCREEN_HEIGHT SCREEN_HEIGHT / 2
+
+const int collisionMap[8 * 10] =
+{
+ 1,1,1,1,1,1,1,1,
+ 1,1,1,1,0,0,0,1,
+ 1,1,1,1,0,1,0,1,
+ 2,2,1,0,0,0,0,3,
+ 1,2,1,0,1,1,3,1,
+ 2,0,0,0,1,1,3,3,
+ 1,0,1,0,0,1,1,1,
+ 1,0,0,0,1,1,1,1,
+ 1,1,1,1,1,1,1,1,
+ 1,1,1,1,1,1,1,1
+};