starting to work on actual levels

This commit is contained in:
Alexandre 2025-02-20 20:39:00 +01:00
parent e0acddbdc5
commit 41c76bddf4
63 changed files with 214 additions and 12 deletions

BIN
bin/back

Binary file not shown.

53
levels/level_00/room_0 Normal file
View File

@ -0,0 +1,53 @@
Blocks :
[-16.0, -1.0, -16.0, 32.0, 1.0, 32.0, 0.0, 0.0, 128, 192, 128]
[-15.0, 0.0, -15.0, 2.0, 10.0, 2.0, 0.0, 0.0, 128, 128, 128]
[-15.0, 0.0, 13.0, 2.0, 10.0, 2.0, 0.0, 0.0, 128, 128, 128]
[13.0, 0.0, -15.0, 2.0, 10.0, 2.0, 0.0, 0.0, 128, 128, 128]
[13.0, 0.0, 13.0, 2.0, 10.0, 2.0, 0.0, 0.0, 128, 128, 128]
Entities:
[-0.5, 5.0, -0.5, 1.0, 1.0, 1.0, 0.0, 0.0, 255, 255, 0, 10, 0, 0]
[-11.0, 0.0, -1.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 255, 255, 1, 0, 6, welcome here, 222, 222, 222]
[9.0, 0.0, -1.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 255, 0, 1, 0, 6, collect coins to advance, 222, 222, 111]
[-1.0, 0.0, -11.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 0, 0, 1, 0, 6, if HP goes to 0 its game over, 222, 222, 111]
[-1.0, 0.0, 9.0, 2.0, 2.0, 2.0, 0.0, 0.0, 0, 0, 255, 1, 0, 6, enjoy, 222, 222, 111]
Weight :
0
$
blocks:
[x, y, z, w, h, d, rhz, rvt, r, g, b]
teleporters:
[x, y, z, w, h, d, rhz, rvt, r, g, b, dest_chx, dest_chy]
entities:
[x, y, z, w, h, d, rhz, rvt, r, g, b, hp, damage, entityType ..]
// Entity types are :
// 0 (coin) -> damage equals the coin's value
// 1 (still explosive)
// 2 (seeking explosive)
// 3 (shooting still explosive)
// if entityType = 4 (moving platform)
[.. amplitude_x, amplitude_y, amplitude_z, mult, divd, phase] with
amplitude_{x,y,z} = double[>= 0.0]
{mult,divd} = int
{phase} = int[0, 360]
// else if entityType = 5 (linear moving platform)
[.. amplitude_x, amplitude_y, amplitude_z, speed_x, speed_y, speed_z] with
amplitude_{x,y,z} = double[>= 0.0]
speed_{x,y,z} = double
// else if entityType = 6 (text box)
[.. text, tred, tgreen, tblue] with
text = {char*}
// else if entityType = 7 (warp text box)
[.. dest_folder, room_count, text, tred, tgreen, tblue] with
{dest_folder,text} = {char*} (length <= 50)
{r,g,b} = int[0-256]
else
[..]

45
levels/level_00/room_1 Normal file
View File

@ -0,0 +1,45 @@
Blocks :
[-16.0, -1.0, -16.0, 32.0, 1.0, 32.0, 0.0, 0.0, 128, 128, 128]
[-1.0, 0.0, -15.0, 2.0, 10.0, 2.0, 0.0, 0.0, 128, 128, 128]
[-1.0, 0.0, 13.0, 2.0, 10.0, 2.0, 0.0, 0.0, 128, 128, 128]
[-15.0, 0.0, -1.0, 2.0, 10.0, 2.0, 0.0, 0.0, 128, 128, 128]
[13.0, 0.0, -1.0, 2.0, 10.0, 2.0, 0.0, 0.0, 128, 128, 128]
Entities:
[-2.0, 5.0, -2.0, 4.0, 1.0, 4.0, 0.0, 0.0, 255, 255, 255, 1, 0, 4, 0.0, 3.0, 0.0, 4, 1, 0]
[-0.5, 13.0, -0.5, 1.0, 1.0, 1.0, 0.0, 0.0, 255, 255, 0, 10, 0, 0]
Weight :
50
$
blocks:
[x, y, z, w, h, d, rhz, rvt, r, g, b]
teleporters:
[x, y, z, w, h, d, rhz, rvt, r, g, b, dest_chx, dest_chy]
entities:
[x, y, z, w, h, d, rhz, rvt, r, g, b, hp, damage, entityType ..]
if entityType = 4 (moving platform)
[.. amplitude_x, amplitude_y, amplitude_z, mult, divd, phase] with
amplitude_{x,y,z} = double[>= 0.0]
{mult,divd} = int
{phase} = int[0, 360]
else if entityType = 5 (linear moving platform)
[.. amplitude_x, amplitude_y, amplitude_z, speed_x, speed_y, speed_z] with
amplitude_{x,y,z} = double[>= 0.0]
speed_{x,y,z} = double
else if entityType = 6 (text box)
[.. text] with
text = {char*}
else if entityType = 7 (warp text box)
[.. dest_folder, room_count, text, r, g, b] with
{dest_folder,text} = {char*} (length <= 50)
{r,g,b} = int[0-256]
else
[..]

53
levels/level_00/room_2 Normal file
View File

@ -0,0 +1,53 @@
Blocks :
[-16.0, -1.0, -16.0, 32.0, 1.0, 32.0, 0.0, 0.0, 128, 128, 128]
[-15.0, 0.0, -15.0, 2.0, 10.0, 2.0, 0.0, 0.0, 128, 128, 128]
[-15.0, 0.0, 13.0, 2.0, 10.0, 2.0, 0.0, 0.0, 128, 128, 128]
[13.0, 0.0, -15.0, 2.0, 10.0, 2.0, 0.0, 0.0, 128, 128, 128]
[13.0, 0.0, 13.0, 2.0, 10.0, 2.0, 0.0, 0.0, 128, 128, 128]
Entities:
[-2.0, 5.0, -2.0, 4.0, 1.0, 4.0, 0.0, 0.0, 255, 255, 255, 1, 0, 5, 0.0, 3.0, 0.0, 0.0, 3.0, 0.0]
[-14.0, 15.0, -14.0, 1.0, 1.0, 1.0, 0.0, 0.0, 192, 192, 0, 3, 0, 0]
[-14.0, 15.0, 12.0, 1.0, 1.0, 1.0, 0.0, 0.0, 192, 192, 0, 3, 0, 0]
[12.0, 15.0, -14.0, 1.0, 1.0, 1.0, 0.0, 0.0, 192, 192, 0, 3, 0, 0]
[12.0, 15.0, 12.0, 1.0, 1.0, 1.0, 0.0, 0.0, 192, 192, 0, 3, 0, 0]
Weight :
50
$
blocks:
[x, y, z, w, h, d, rhz, rvt, r, g, b]
teleporters:
[x, y, z, w, h, d, rhz, rvt, r, g, b, dest_chx, dest_chy]
entities:
[x, y, z, w, h, d, rhz, rvt, r, g, b, hp, damage, entityType ..]
// Entity types are :
// 0 (coin) -> damage equals the coin's value
// 1 (still explosive)
// 2 (seeking explosive)
// 3 (shooting still explosive)
// if entityType = 4 (moving platform)
[.. amplitude_x, amplitude_y, amplitude_z, mult, divd, phase] with
amplitude_{x,y,z} = double[>= 0.0]
{mult,divd} = int
{phase} = int[0, 360]
// else if entityType = 5 (linear moving platform)
[.. amplitude_x, amplitude_y, amplitude_z, speed_x, speed_y, speed_z] with
amplitude_{x,y,z} = double[>= 0.0]
speed_{x,y,z} = double
// else if entityType = 6 (text box)
[.. text, tred, tgreen, tblue] with
text = {char*}
// else if entityType = 7 (warp text box)
[.. dest_folder, room_count, text, tred, tgreen, tblue] with
{dest_folder,text} = {char*} (length <= 50)
{r,g,b} = int[0-256]
else
[..]

37
levels/level_00/room_3 Normal file
View File

@ -0,0 +1,37 @@
Blocks :
[-16.0, -1.0, -16.0, 32.0, 1.0, 32.0, 0.0, 0.0, 128, 128, 128]
Weight :
50
$
blocks:
[x, y, z, w, h, d, rhz, rvt, r, g, b]
teleporters:
[x, y, z, w, h, d, rhz, rvt, r, g, b, dest_chx, dest_chy]
entities:
[x, y, z, w, h, d, rhz, rvt, r, g, b, hp, damage, entityType ..]
if entityType = 4 (moving platform)
[.. amplitude_x, amplitude_y, amplitude_z, mult, divd, phase] with
amplitude_{x,y,z} = double[>= 0.0]
{mult,divd} = int
{phase} = int[0, 360]
else if entityType = 5 (linear moving platform)
[.. amplitude_x, amplitude_y, amplitude_z, speed_x, speed_y, speed_z] with
amplitude_{x,y,z} = double[>= 0.0]
speed_{x,y,z} = double
else if entityType = 6 (text box)
[.. text] with
text = {char*}
else if entityType = 7 (warp text box)
[.. dest_folder, room_count, text, r, g, b] with
{dest_folder,text} = {char*} (length <= 50)
{r,g,b} = int[0-256]
else
[..]

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 123 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

BIN
res/money.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

BIN
res/steel.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -164,7 +164,7 @@ bool is_visible(cube_0* cb, double offx, double offy, double offz) {
void gl_renderAll(unsigned int shaderProgram, unsigned int fragmentShader, unsigned int VAO, unsigned int VBO, room* rtd, double offx, double offy, double offz) { void gl_renderAll(unsigned int shaderProgram, unsigned int fragmentShader, unsigned int VAO, unsigned int VBO, room* rtd, double offx, double offy, double offz) {
if(rtd != NULL) { if(rtd != NULL) {
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textures[0]); glBindTexture(GL_TEXTURE_2D, textures[5]);
for(int k = 0; k < rtd->map_size; k++) { for(int k = 0; k < rtd->map_size; k++) {
if(is_visible(rtd->map[k], offx, offy, offz)) { if(is_visible(rtd->map[k], offx, offy, offz)) {
gl_renderCube(shaderProgram, fragmentShader, VAO, VBO, rtd->map[k], offx, offy, offz); gl_renderCube(shaderProgram, fragmentShader, VAO, VBO, rtd->map[k], offx, offy, offz);

View File

@ -41,7 +41,7 @@ void init_ent_generator(int n) {
} }
hashtbl_entities[0].id = 0; hashtbl_entities[0].id = 0;
hashtbl_entities[0].tex = 0; hashtbl_entities[0].tex = 3;
hashtbl_entities[0].name = "Coin"; // 0 = default hashtbl_entities[0].name = "Coin"; // 0 = default
hashtbl_entities[0].updatePos = &speen; hashtbl_entities[0].updatePos = &speen;
hashtbl_entities[0].onHit = &money; hashtbl_entities[0].onHit = &money;
@ -69,14 +69,14 @@ void init_ent_generator(int n) {
hashtbl_entities[3].onDeath = NULL; hashtbl_entities[3].onDeath = NULL;
hashtbl_entities[4].id = 4; hashtbl_entities[4].id = 4;
hashtbl_entities[4].tex = 0; hashtbl_entities[4].tex = 4;
hashtbl_entities[4].name = "SinePlatform"; hashtbl_entities[4].name = "SinePlatform";
hashtbl_entities[4].updatePos = &moving_xyz; hashtbl_entities[4].updatePos = &moving_xyz;
hashtbl_entities[4].onHit = &translatePlayer; hashtbl_entities[4].onHit = &translatePlayer;
hashtbl_entities[4].onDeath = NULL; hashtbl_entities[4].onDeath = NULL;
hashtbl_entities[5].id = 5; hashtbl_entities[5].id = 5;
hashtbl_entities[5].tex = 0; hashtbl_entities[5].tex = 4;
hashtbl_entities[5].name = "LinePlatform"; hashtbl_entities[5].name = "LinePlatform";
hashtbl_entities[5].updatePos = &moving_xyz_line; hashtbl_entities[5].updatePos = &moving_xyz_line;
hashtbl_entities[5].onHit = &translatePlayerLine; hashtbl_entities[5].onHit = &translatePlayerLine;
@ -228,9 +228,10 @@ void init_hashtbl() {
printf("+1\n"); fflush(stdout); printf("+1\n"); fflush(stdout);
visited = hashtbl_generate(1789); visited = hashtbl_generate(1789);
printf("+1\n"); fflush(stdout); printf("+1\n"); fflush(stdout);
build_starting_chunk(player_chx, player_chy); //generate_nearby_chunks(0);
//build_starting_chunk(player_chx, player_chy);
printf("+1\n"); fflush(stdout); printf("+1\n"); fflush(stdout);
current_room = hashtbl_find_opt(visited, player_chx, player_chy); //current_room = hashtbl_find_opt(visited, player_chx, player_chy);
printf("+1\n"); fflush(stdout); printf("+1\n"); fflush(stdout);
total_weight = 0; total_weight = 0;
printf("+1\n"); fflush(stdout); printf("+1\n"); fflush(stdout);
@ -523,6 +524,8 @@ void parse_one_room(int id, char* filename) {
printf("3/3...\n"); printf("3/3...\n");
fflush(stdout); fflush(stdout);
align_to(ptr, 'W');
pool[id].weight = read_int(ptr, true); pool[id].weight = read_int(ptr, true);
total_weight += pool[id].weight; total_weight += pool[id].weight;
@ -587,6 +590,9 @@ void parse_rooms(int n_rooms, char* folder) {
printf("\nDone.\n"); printf("\nDone.\n");
free(name); free(name);
printf("Total sum : %d\n", total_weight); printf("Total sum : %d\n", total_weight);
generate_nearby_chunks(0);
current_room = hashtbl_find_opt(visited, player_chx, player_chy);
} }
// has to be a multiple of both room_width and room_depth // has to be a multiple of both room_width and room_depth
@ -624,15 +630,18 @@ void generate_nearby_chunks(int render_dist) {
for(int w = -render_dist; w <= render_dist; w++) { for(int w = -render_dist; w <= render_dist; w++) {
for(int h = -render_dist; h <= render_dist; h++) { for(int h = -render_dist; h <= render_dist; h++) {
if(!hashtbl_mem(visited, player_chx + w, player_chy + h)) { if(!hashtbl_mem(visited, player_chx + w, player_chy + h)) {
printf("generating (%d, %d)... ", player_chx + w, player_chy + h); printf("generating (%d, %d)... ", player_chx + w, player_chy + h); fflush(stdout);
//build_starting_chunk(player_chx + w, player_chy + h); //build_starting_chunk(player_chx + w, player_chy + h);
int pick = rand()%total_weight; int pick = rand()%total_weight;
printf("R = %d ", pick); if(w == 0 && h == 0) { // 1st room will always be room_0
pick = -1;
}
printf("R = %d ", pick); fflush(stdout);
int sum = 0; int sum = 0;
for(int k = 0; k < pool_size; k++) { for(int k = 0; k < pool_size; k++) {
sum += pool[k].weight; sum += pool[k].weight;
if(pick < sum) { if(pick < sum) {
printf("chose %d\n", k); printf("chose %d\n", k); fflush(stdout);
room* new = malloc(sizeof(room)); room* new = malloc(sizeof(room));
copy_room(pool[k].area, new, player_chx + w, player_chy + h); copy_room(pool[k].area, new, player_chx + w, player_chy + h);
//generate_terrain(new); //generate_terrain(new);

View File

@ -54,9 +54,9 @@ void reset_everything(GLFWwindow *window, int count, char* folder) {
parse_rooms(count, folder); parse_rooms(count, folder);
interface_set(-1);*/ interface_set(-1);*/
camx = /*2*room_width*player_chx+*/2.0; camx = /*2*room_width*player_chx+*/0.0;
camy = 5.0; camy = 5.0;
camz = /*2*room_depth*player_chy+*/2.0; camz = /*2*room_depth*player_chy+*/0.0;
player_chx = 0; player_chx = 0;
player_chy = 0; player_chy = 0;
@ -246,7 +246,7 @@ void processInput(GLFWwindow *window, float dtime) {
if(glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS) { if(glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS) {
if(!isMenuOpen() && !rPress) { if(!isMenuOpen() && !rPress) {
rPress = true; rPress = true;
reset_everything(window, 7, "templates/"); reset_everything(window, 4, "levels/level_00/");
} }
} else { } else {
rPress = false; rPress = false;
@ -437,6 +437,9 @@ int main_alt() {
generate_texture(0, "res/white.png", PNG); generate_texture(0, "res/white.png", PNG);
generate_texture(1, "res/question_block.png", PNG); generate_texture(1, "res/question_block.png", PNG);
generate_texture(2, "res/exclamation_block.png", PNG); generate_texture(2, "res/exclamation_block.png", PNG);
generate_texture(3, "res/money.png", PNG);
generate_texture(4, "res/container.jpg", JPG);
generate_texture(5, "res/steel.jpeg", JPEG);
printf("-----------------------------------------------------------------------------------------------\n"); fflush(stdout); printf("-----------------------------------------------------------------------------------------------\n"); fflush(stdout);

View File

@ -305,6 +305,8 @@ void gl_drawChar(unsigned int fragShader, char ch, float x, float y, float size,
gl_drawRect(fragShader, x-size/2-width, y-width, size+2*width, 2*width, r, g, b); gl_drawRect(fragShader, x-size/2-width, y-width, size+2*width, 2*width, r, g, b);
gl_drawRect(fragShader, x-size/2-width, y-size-width, 2*width, size+2*width, r, g, b); gl_drawRect(fragShader, x-size/2-width, y-size-width, 2*width, size+2*width, r, g, b);
gl_drawRect(fragShader, x-size/2-width, y-size-width, size+2*width, 2*width, r, g, b); gl_drawRect(fragShader, x-size/2-width, y-size-width, size+2*width, 2*width, r, g, b);
} else if((int)ch >= 48 && (int)ch <= 57) {
gl_drawDigit(fragShader, (int)ch -48, x, y, size, r, g, b, width);
} }
} }