diff --git a/src/main.c b/src/main.c index 9a53584..f05ad28 100644 --- a/src/main.c +++ b/src/main.c @@ -3,6 +3,7 @@ # include # include # include +#include # include "msg_fr.h" # include "itemsizes.h" # include "gamesettings.h" @@ -14,6 +15,13 @@ extern bopti_image_t grass_tile; extern bopti_image_t stone_tile; extern bopti_image_t coal_tile; extern bopti_image_t steel_tile; +extern bopti_image_t wood_tile; +extern bopti_image_t skin1_player_left1; +extern bopti_image_t skin1_player_left2; +extern bopti_image_t skin1_player_right1; +extern bopti_image_t skin1_player_right2; + +int x, y, pos, hour, animation, orient, timing; void drawselectedgame(int selected) { dclear(C_WHITE); @@ -24,7 +32,28 @@ void drawselectedgame(int selected) { 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 int * terrain) { +void addtree(int pos, unsigned short int * terrain, int n){ + int i; + srand(clock()); + for(i=pos-rand()%11;i!=pos;i++){ + terrain[i*WORLD_WIDTH+(n>>3)] = 5; + } +} +void addtrees(unsigned short int * terrain){ + int n, i; + for(n=0;n!=WORLD_WIDTH;n++){ + if(rand()%11 == 1){ + for(i=0;i!=WORLD_HEIGHT;i++){ + if(terrain[i*WORLD_WIDTH+(n>>3)] != 0){ + pos = i; + break; + } + } + addtree(pos, terrain, n); + } + } +} +void mappartdisplaying(int x, int y, unsigned short int * terrain, int player) { 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; @@ -44,6 +73,62 @@ void mappartdisplaying(int x, int y, unsigned short int * terrain) { dimage(px, py, &coal_tile); break; case 4: dimage(px, py, &steel_tile); break; + case 5: + dimage(px, py, &wood_tile); break; + } + px += 8; + } + py += 8; + px = sx; + } + switch(player){ + case 1: + dimage(60, 24, &skin1_player_right1); break; + case 2: + dimage(60, 24, &skin1_player_right2); break; + case 3: + dimage(60, 24, &skin1_player_left1); break; + case 4: + dimage(60, 24, &skin1_player_left2); break; + } +} +int exists(unsigned short int * terrain, short type) { + int i; + for(i=0;i!=WORLD_WIDTH*WORLD_HEIGHT;i++){ + if(terrain[i]==type){ + return 1; + } + } + return 0; +} +int pointoverrectangle(int x1, int y1, int x2, int y2, int x, int y){ + if ((x >= x1 && x<=x2) && (y >= y1 && y<=y2)){ + return 1; + } + return 0; +} +void collisiononmap(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, type_over; + dclear(C_WHITE); + for(cy = 0;cy != ty;cy++){ + for(cx = 0;cx != tx;cx++){ + type = terrain[(firsttile_y+cy)*WORLD_WIDTH+(firsttile_x+cx)]; + type_over = terrain[(firsttile_y+cy-1)*WORLD_WIDTH+(firsttile_x+cx)]; + switch(type){ + case 1: + if(type_over == 0){dimage(px, py, &grass_tile);}else{dimage(px, py, &soil_tile);} break; + case 2: + dimage(px, py, &stone_tile); break; + case 3: + dimage(px, py, &coal_tile); break; + case 4: + dimage(px, py, &steel_tile); break; + case 5: + dimage(px, py, &wood_tile); break; } px += 8; } @@ -51,7 +136,6 @@ void mappartdisplaying(int x, int y, unsigned short int * terrain) { px = sx; } } -int x, y; int main(void) { dclear(C_WHITE); dimage(16, TITLE_IMAGE_MARGIN, &title_img); @@ -59,10 +143,10 @@ int main(void) { dupdate(); int key = 0, game = 0, selected = 0, i; unsigned short terrain[WORLD_WIDTH*WORLD_HEIGHT]; - while(key != KEY_EXIT){ - key=getkey().key; + while(keydown(KEY_EXIT) == 0){ ////////// TITLE SCREEN ////////// if(game == 0){ + key=getkey().key; if(key==KEY_EXE){ drawselectedgame(selected); game = 1; @@ -70,6 +154,7 @@ int main(void) { } ////////// GAME CHOOSING SCREEN ////////// else if(game == 1){ + key=getkey().key; if(key==KEY_DOWN){ if(selected>3)] != 0){ - y = i * 8; - break; - } - } + generateworld(terrain, WORLD_WIDTH, WORLD_HEIGHT, (int)((rand() % ((WORLD_HEIGHT - 20) - (WORLD_HEIGHT - 30) + 1)) + WORLD_HEIGHT - 30), WORLD_HEIGHT - 30, WORLD_HEIGHT - 20, 4, 2); + dtext(1, 1, C_BLACK, "Adding trees"); + ///// Add trees ///// + addtrees(terrain); + ///////////////////// + x = 200; + for(i=0;i!=WORLD_HEIGHT;i++){ + if(terrain[i*WORLD_WIDTH+(x>>3)] != 0){ + y = i * 8; + break; + } + } game = 3; + hour = 0; + timing = 0; }else if(game == 3){ - if(key==KEY_RIGHT){ + clearevents(); + if(keydown(KEY_RIGHT)){ x++; - }else if(key==KEY_LEFT){ + if(animation == 0 && timing == 5){ + animation = 1; + timing = 0; + }else if(animation == 1 && timing == 5){ + animation = 0; + timing = 0; + } + timing++; + orient = 1; + }else if(keydown(KEY_LEFT)){ x--; - }else if(key==KEY_UP){ + if(animation == 0 && timing == 5){ + animation = 1; + timing = 0; + }else if(animation == 1 && timing == 5){ + animation = 0; + timing = 0; + } + timing++; + orient = 3; + } + clearevents(); + if(keydown(KEY_UP)){ y--; - }else if(key==KEY_DOWN){ + }else if(keydown(KEY_DOWN)){ y++; } + clearevents(); + if(keydown(KEY_SHIFT)){ + // + } + if(exists(terrain, 5)==0){ + addtrees(terrain); + } // dtext(1, 1, C_BLACK, "test"); - mappartdisplaying(x, y, terrain); + mappartdisplaying(x, y, terrain, orient+animation); dupdate(); + sleep_ms(20); } + clearevents(); } return 1; } diff --git a/src/worldgen.h b/src/worldgen.h index 8620f30..de1569a 100644 --- a/src/worldgen.h +++ b/src/worldgen.h @@ -3,6 +3,8 @@ 1 - Soil. 2 - Stone. 3 - Coal. + 4 - Steel. + 5 - Wood. */ void generateworld(unsigned short terrain[], int w, int h, int genstart, int genmin, int genmax, int someof, int type) {