summaryrefslogtreecommitdiff
path: root/src/world.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/world.c')
-rw-r--r--src/world.c101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/world.c b/src/world.c
new file mode 100644
index 0000000..17e35b9
--- /dev/null
+++ b/src/world.c
@@ -0,0 +1,101 @@
+#include <raylib.h>
+#include <stdio.h>
+#include <math.h>
+
+#include "world.h"
+#include "globals.h"
+#include "player.h"
+
+Color colors[7] = {
+ GREEN,
+ BLUE,
+ RED,
+ YELLOW,
+ ORANGE,
+ PURPLE,
+ WHITE
+};
+
+void drawWorld(World *world)
+{
+ int cubeMaterial;
+ Color cubeColor;
+ for (int x=0;x<WORLD_WIDTH; x++)
+ for (int y=0;y<WORLD_HEIGHT; y++)
+ for (int z=0;z<WORLD_WIDTH; z++) {
+ cubeMaterial = world->map[y][x][z];
+ switch (cubeMaterial) {
+ case 1 ... 7:
+ cubeColor=colors[cubeMaterial-1];
+ draw:
+ DrawCube(
+ (Vector3){
+ (float)x,
+ (float)y,
+ (float)z
+ },
+ 1.0f, 1.0f, 1.0f,
+ cubeColor
+ );
+ DrawCubeWires(
+ (Vector3){
+ (float)x,
+ (float)y,
+ (float)z
+ },
+ 1.0f, 1.0f, 1.0f,
+ BLACK
+ );
+ break;
+ }
+ }
+}
+
+void handleCollision(World *world, Player *player)
+{
+ int posX, posY, posZ;
+ posX = (int)player->pos.x;
+ posY = (int)player->pos.y;
+ posZ = (int)player->pos.z;
+ //Floor check:
+ if (world->map[posY][posX][posZ]!=0) {
+ player->is_on_floor=1;
+ if (player->velocity.y < 0.0f) {
+ player->velocity.y = 0.0f;
+ }
+ } else {
+ player->is_on_floor=0;
+ }
+ if (world->map[posY][posX][posZ]!=0
+ && (float)posY!=player->pos.y) {
+ player->camera.position.y=(float)posY+2;
+ //player->velocity.y = 0.0f;
+ }
+}
+
+void handleGravity(World *world, Player *player)
+{
+ if (player->velocity.y > 0.0f) {
+ player->velocity.y *= 0.9f;
+ }
+ if (player->velocity.y <= 0.1f && player->velocity.y > 0.0f) {
+ player->velocity.y = 0.0f;
+ }
+ int posX, posY, posZ;
+ posX = (int)player->pos.x;
+ posY = (int)player->pos.y;
+ posZ = (int)player->pos.z;
+ printf(
+ "Player.pos.y:\t%d\n"
+ "Player.pos.x:\t%d\n"
+ "Player.pos.z:\t%d\n",
+ posY,
+ posX,
+ posZ
+ );
+ printf("%d\n", (int)world->map[posY][posX][posZ]);
+ if (player->velocity.y <= 0.0f
+ && world->map[posY][posX][posZ]==0) {
+ player->velocity.y -= 0.1f;
+ }
+}