Plate generation.
This commit is contained in:
52
src/gen.c
52
src/gen.c
@@ -1,6 +1,9 @@
|
||||
#include "include/gen.h"
|
||||
#include "include/col.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
Vec2 asth[WORLD_SZ][WORLD_SZ] = {
|
||||
{
|
||||
(Vec2){.x = 1, .y = 2},
|
||||
@@ -84,10 +87,45 @@ Vec2 asth[WORLD_SZ][WORLD_SZ] = {
|
||||
},
|
||||
};
|
||||
|
||||
Plate lith[NPLATES] = {
|
||||
(Plate){.col = COL_BLU,
|
||||
.nverts = 4,
|
||||
.verts = {(Pt){0, 0}, (Pt){7, 0}, (Pt){7, 5}, (Pt){4, 4}}},
|
||||
(Plate){COL_RED, 4, {(Pt){0, 0}, (Pt){4, 4}, (Pt){2, 7}, (Pt){0, 7}}},
|
||||
(Plate){COL_GRN, 4, {(Pt){4, 4}, (Pt){7, 5}, (Pt){7, 7}, (Pt){2, 7}}},
|
||||
};
|
||||
Plate lith[NPLATES];
|
||||
|
||||
// Find the point for an index to the edge of the world.
|
||||
Pt world_edge_idx_to_pt(int idx) {
|
||||
if (0 <= idx && idx < 8) {
|
||||
return (Pt){idx, 0};
|
||||
} else if (8 <= idx && idx < 16) {
|
||||
return (Pt){7, idx - 8};
|
||||
} else if (16 <= idx && idx < 24) {
|
||||
return (Pt){idx - 16, 0};
|
||||
} else if (24 <= idx && idx < 32) {
|
||||
return (Pt){7, idx - 24};
|
||||
} else {
|
||||
exit(122);
|
||||
}
|
||||
}
|
||||
|
||||
void gen_lith() {
|
||||
srand(time(NULL));
|
||||
|
||||
Pt p1 = {(rand() % 6) + 1, 0};
|
||||
Pt p2 = {(rand() % 6) + 1, 7};
|
||||
|
||||
lith[0] = (Plate){
|
||||
.col = COL_RED,
|
||||
.nverts = 4,
|
||||
.verts = {
|
||||
(Pt){0, 0},
|
||||
p1,
|
||||
p2,
|
||||
(Pt){0, 7},
|
||||
},
|
||||
};
|
||||
lith[1] = (Plate){.col = COL_RED,
|
||||
.nverts = 4,
|
||||
.verts = {
|
||||
p1,
|
||||
(Pt){7, 0},
|
||||
(Pt){7, 7},
|
||||
p2,
|
||||
}};
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#define WORLD_SZ 8
|
||||
#define NPLATES 3
|
||||
#define NPLATES 2
|
||||
|
||||
// A two dimensional vector.
|
||||
typedef struct {
|
||||
@@ -25,7 +25,7 @@ typedef struct {
|
||||
typedef struct {
|
||||
Col col; // The color the plate should be drawn as.
|
||||
uint8_t nverts; // The number of vertices the plate has.
|
||||
Pt verts[4]; // The vertices of the plate.
|
||||
Pt verts[10]; // The vertices of the plate.
|
||||
} Plate;
|
||||
|
||||
// The asthenosphere; contains a grid of force vectors.
|
||||
@@ -33,6 +33,6 @@ extern Vec2 asth[WORLD_SZ][WORLD_SZ];
|
||||
// The lithosphere; contians a list of plates.
|
||||
extern Plate lith[NPLATES];
|
||||
|
||||
void gen(void);
|
||||
void gen_lith(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#include "include/main.h"
|
||||
|
||||
#include "include/gen.h"
|
||||
#include "include/render.h"
|
||||
|
||||
#include <raylib.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
gen_lith();
|
||||
InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Terrin");
|
||||
SetTargetFPS(110);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ void render() {
|
||||
|
||||
// Convert the vertices from world coordinates (Pt) to screen
|
||||
// coordinates (Vector2).
|
||||
Vector2 screen_verts[4];
|
||||
Vector2 screen_verts[10];
|
||||
for (int j = 0; j < plate.nverts; j++) {
|
||||
screen_verts[j] = PointToVector2(plate.verts[j]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user