forked from mibi88/Builder
20220628 - Scrolling en cours de développement.
This commit is contained in:
parent
e46be95995
commit
cb5cd406d4
|
@ -0,0 +1,77 @@
|
|||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <time.h>
|
||||
|
||||
# define WORLD_WIDTH 256 // World width.
|
||||
# define WORLD_HEIGHT 64 // World height.
|
||||
# define SCREEN_WIDTH 128 // Screen width.
|
||||
# define SCREEN_HEIGHT 64 // Screen height.
|
||||
|
||||
void mappartdisplaying(int x, int y, unsigned short int * terrain) {
|
||||
int firsttile_x = x>>3, firsttile_y = y>>3;
|
||||
int base_x = firsttile_x*8, base_y = firsttile_y*8;
|
||||
int sx = base_x - x, sy = base_y - y, tx = (SCREEN_WIDTH>>3) + 1, ty = (SCREEN_HEIGHT>>3) + 1;
|
||||
int cx, cy, px = sx, py = sy;
|
||||
unsigned short type;
|
||||
for(cy = 0;cy != ty;cy++){
|
||||
for(cx = 0;cx != tx;cx++){
|
||||
type = terrain[cy*tx+px];
|
||||
printf("%d, %d, %d, %d\n", type, (cy*tx+px), cx, cy);
|
||||
if(type == 1){
|
||||
printf("soil : %d, %d\n", px, py);
|
||||
}else if(type == 2){
|
||||
printf("stone : %d, %d\n", px, py);
|
||||
}else if(type == 3){
|
||||
printf("coal : %d, %d\n", px, py);
|
||||
}else{
|
||||
printf("other : %d, %d\n", px, py);
|
||||
}
|
||||
px += 8;
|
||||
}
|
||||
py += 8;
|
||||
px = sx;
|
||||
}
|
||||
}
|
||||
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() % 11;
|
||||
if(t==0){
|
||||
terrain[i*w+x] = someof;
|
||||
}else{
|
||||
terrain[i*w+x] = type;
|
||||
}
|
||||
}
|
||||
}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--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
unsigned short terrain[WORLD_WIDTH*WORLD_HEIGHT];
|
||||
int i, x = 403, y = 403;
|
||||
for(i=0;i!=WORLD_WIDTH*WORLD_HEIGHT;i++){
|
||||
terrain[i] = 0;
|
||||
}
|
||||
srand(clock());
|
||||
generateworld(terrain, WORLD_WIDTH, WORLD_HEIGHT, (int)((rand() % ((WORLD_HEIGHT - 40) - (WORLD_HEIGHT - 60) + 1)) + WORLD_HEIGHT - 60), WORLD_HEIGHT - 60, WORLD_HEIGHT - 40, 0, 1);
|
||||
srand(clock());
|
||||
generateworld(terrain, WORLD_WIDTH, WORLD_HEIGHT, (int)((rand() % ((WORLD_HEIGHT - 25) - (WORLD_HEIGHT - 40) + 1)) + WORLD_HEIGHT - 40), WORLD_HEIGHT - 40, WORLD_HEIGHT - 25, 3, 2);
|
||||
mappartdisplaying(x, y, terrain);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue