20220624 - Générateur de terrain fonctionnel, mais incomplet !

This commit is contained in:
mibi88 2022-06-24 20:01:40 +02:00
parent cfd9305620
commit 8b523dc388
3 changed files with 63 additions and 9 deletions

View File

@ -1 +1,5 @@
# define GAMESNUM 5 // How many games you can save (and play).
# define GAMESNUM 5 // How many games you can save (and play).
# define WORLDGEN_SOIL 8 // Blocks (y) of soil.
# define WORLD_WIDTH 256 // World width.
# define WORLD_HEIGHT 128 // World height.

View File

@ -1,8 +1,11 @@
#include <gint/display.h>
#include <gint/keyboard.h>
#include "msg_fr.h"
#include "itemsizes.h"
#include "gamesettings.h"
# include <gint/display.h>
# include <gint/keyboard.h>
# include <stdlib.h>
# include <time.h>
# include "msg_fr.h"
# include "itemsizes.h"
# include "gamesettings.h"
# include "worldgen.h"
extern bopti_image_t title_img;
@ -10,9 +13,9 @@ void drawselectedgame(int selected) {
dclear(C_WHITE);
// dimage(16, 8, &title_img);
for(int i=0;i!=GAMESNUM;i++){
dtext(1, WORLDSEL_MARGIN + i*(LINEHEIGHT+LINEPADDING), C_BLACK, WORLDSEL_EMPTY);
dtext(1, WORLDSEL_MARGIN + i*(LINEHEIGHT), C_BLACK, WORLDSEL_EMPTY);
}
drect(1, WORLDSEL_MARGIN+selected*(LINEHEIGHT+LINEPADDING), 128, WORLDSEL_MARGIN+selected*(LINEHEIGHT+LINEPADDING)+LINEHEIGHT, C_INVERT);
drect(1, WORLDSEL_MARGIN+selected*(LINEHEIGHT)-(int)(LINEPADDING/2), 128, WORLDSEL_MARGIN+(selected+1)*(LINEHEIGHT)-(int)(LINEPADDING/2), C_INVERT);
dupdate();
}
int main(void) {
@ -20,7 +23,7 @@ int main(void) {
dimage(16, TITLE_IMAGE_MARGIN, &title_img);
dtext(1, TITLE_MARGIN, C_BLACK, TITLE_START);
dupdate();
int key = 0, game = 0, selected = 0;
int key = 0, game = 0, selected = 0, i;
while(key != KEY_EXIT){
key=getkey().key;
////////// TITLE SCREEN //////////
@ -52,6 +55,17 @@ int main(void) {
}
}else if(game == 2){
unsigned short terrain[WORLD_WIDTH*WORLD_HEIGHT];
for(i=0;i!=WORLD_WIDTH*WORLD_HEIGHT;i++){
terrain[i] = 0;
}
srand(clock());
generateworld(terrain, WORLD_WIDTH, WORLD_HEIGHT, (int)rand() % 2, WORLD_HEIGHT - 20, WORLD_HEIGHT - 2, 0, 1);
srand(clock());
generateworld(terrain, WORLD_WIDTH, WORLD_HEIGHT, (int)rand() % 2, WORLD_HEIGHT - 35, WORLD_HEIGHT - 16, 3, 2);
game = 3;
}else if(game == 3){
dclear(C_WHITE);
dupdate();
}
}

36
src/worldgen.h Normal file
View File

@ -0,0 +1,36 @@
/*
0 - Nothing.
1 - Soil.
2 - Stone.
3 - Coal.
*/
void generateworld(unsigned short terrain[], int w, int h, int genstart, int genmin, int genmax, int someof, int type) {
int x = 0, y = genstart, n, i, a, t;
for(x=0;x!=w;x++){
srand(clock());
a = (int)rand() % 2;
if(a==0){
for(i=y;i!=h;i++){
srand(clock());
t = (int)rand() % 2;
if(t==0){
terrain[i*w+x] = type;
}else if(t==1){
terrain[i*w+x] = someof;
}
}
}else if(a==1){
for(i=y;i!=h;i++){
terrain[i*w+x] = type;
}
}
srand(clock());
n = (int)rand() % 2;
if(n==0 && y<genmax){
y++;
}else if(n==1 && y>genmin){
y--;
}
}
}