Builder_for_CG/src/main.c

104 lines
2.7 KiB
C

# 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;
extern bopti_image_t soil_tile;
extern bopti_image_t stone_tile;
extern bopti_image_t coal_tile;
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), C_BLACK, WORLDSEL_EMPTY);
}
drect(1, WORLDSEL_MARGIN+selected*(LINEHEIGHT)-(int)(LINEPADDING/2), 128, WORLDSEL_MARGIN+(selected+1)*(LINEHEIGHT)-(int)(LINEPADDING/2), C_INVERT);
dupdate();
}
void mappartdisplaying(int x, int y, unsigned short 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[(int *)(cy*tx+px)];
switch(type){
case 1:
dimage(px, py, &soil_tile);
}
px += 8;
}
py += 8;
px = sx;
}
}
int main(void) {
dclear(C_WHITE);
dimage(16, TITLE_IMAGE_MARGIN, &title_img);
dtext(1, TITLE_MARGIN, C_BLACK, TITLE_START);
dupdate();
int key = 0, game = 0, selected = 0, i, x, y;
unsigned short terrain[WORLD_WIDTH*WORLD_HEIGHT];
while(key != KEY_EXIT){
key=getkey().key;
////////// TITLE SCREEN //////////
if(game == 0){
if(key==KEY_EXE){
drawselectedgame(selected);
game = 1;
}
}
////////// GAME CHOOSING SCREEN //////////
else if(game == 1){
if(key==KEY_DOWN){
if(selected<GAMESNUM - 1){
selected++;
}else{
selected = 0;
}
drawselectedgame(selected);
}else if(key==KEY_UP){
if(selected>0){
selected--;
}else{
selected = GAMESNUM - 1;
}
drawselectedgame(selected);
}else if(key==KEY_EXE){
dclear(C_WHITE);
game = 2;
}
}else if(game == 2){
dtext(1, 1, C_BLACK, WORLDSEL_EMPTY);
dupdate();
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);
game = 3;
}else if(game == 3){
x = 0;
y = 0;
dclear(C_WHITE);
if(key==KEY_RIGHT){
//
}
mappartdisplaying(0, 256, terrain);
dupdate();
}
}
return 1;
}