Add minimap and fix bug on building
This commit is contained in:
parent
caedac0e1c
commit
cdc175020c
|
@ -22,6 +22,7 @@ set(ASSETS)
|
|||
set(ASSETS_fx
|
||||
assets-fx/calccity.png
|
||||
assets-fx/large_tileset.png
|
||||
assets-fx/mini_tileset.png
|
||||
assets-fx/large_water.png
|
||||
assets-fx/title.png
|
||||
assets-fx/fn_keys.png
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
42
src/core.c
42
src/core.c
|
@ -175,12 +175,13 @@ void main_loop(struct calccity *calccity, struct camera *camera, struct map *map
|
|||
|
||||
// Get and manage input
|
||||
key = rtc_key();
|
||||
end = keyboard_managment(camera, key);
|
||||
keyboard_managment(camera, key);
|
||||
|
||||
// Menu gestion
|
||||
switch (key)
|
||||
{
|
||||
case KEY_F1: case KEY_F2:
|
||||
camera->zoom = 0;
|
||||
exit_build_mode(camera, &build_mode);
|
||||
|
||||
if (key == KEY_F1) building = menu_12(calccity, camera, map, &build_mode, 1);
|
||||
|
@ -214,8 +215,8 @@ void main_loop(struct calccity *calccity, struct camera *camera, struct map *map
|
|||
// Build validation
|
||||
if (key == KEY_SHIFT && can_build(calccity, camera, map, &building))
|
||||
{
|
||||
unsigned short loc_x = building.size[0] * floor(camera->cursor_x / (floor(camera->cursor_size[0] / 8) + 1));
|
||||
unsigned short loc_y = building.size[1] * floor(camera->cursor_y / (floor(camera->cursor_size[1] / 8) + 1));
|
||||
unsigned short loc_x = building.size[0] * floor(camera->x + camera->cursor_x / (floor(camera->cursor_size[0] / 8) + 1));
|
||||
unsigned short loc_y = building.size[1] * floor(camera->y + camera->cursor_y / (floor(camera->cursor_size[1] / 8) + 1));
|
||||
int index = 0;
|
||||
for (int y = loc_y; y < loc_y + building.size[1]; y ++)
|
||||
{
|
||||
|
@ -236,40 +237,55 @@ void main_loop(struct calccity *calccity, struct camera *camera, struct map *map
|
|||
}
|
||||
|
||||
|
||||
int keyboard_managment(struct camera *camera, const int key)
|
||||
void keyboard_managment(struct camera *camera, const int key)
|
||||
{
|
||||
|
||||
int end = 0;
|
||||
switch (key)
|
||||
{
|
||||
case KEY_UP:
|
||||
if (camera->cursor_y > 0) camera->cursor_y --;
|
||||
if (!camera->zoom && camera->cursor_y > 0) camera->cursor_y --;
|
||||
else if (camera->y > 0) camera->y --;
|
||||
break;
|
||||
|
||||
case KEY_RIGHT:
|
||||
if (camera->cursor_x < 14) camera->cursor_x ++;
|
||||
else if (camera->x < 42) camera->x ++;
|
||||
else
|
||||
{
|
||||
if (!camera->zoom && camera->x < 42) camera->x ++;
|
||||
if (camera->zoom && camera->x < 35) camera->x ++;
|
||||
}
|
||||
break;
|
||||
|
||||
case KEY_DOWN:
|
||||
if (camera->cursor_y < 6) camera->cursor_y ++;
|
||||
else if (camera->y < 46) camera->y ++;
|
||||
else
|
||||
{
|
||||
if (!camera->zoom && camera->y < 46) camera->y ++;
|
||||
if (camera->zoom && camera->y < 43) camera->y ++;
|
||||
}
|
||||
break;
|
||||
|
||||
case KEY_LEFT:
|
||||
if (camera->cursor_x > 0) camera->cursor_x --;
|
||||
if (!camera->zoom && camera->cursor_x > 0) camera->cursor_x --;
|
||||
else if (camera->x > 0) camera->x --;
|
||||
break;
|
||||
|
||||
case KEY_PLUS:
|
||||
camera->zoom = 0;
|
||||
break;
|
||||
|
||||
case KEY_MINUS:
|
||||
if (camera->x > 35) camera->x = 35;
|
||||
if (camera->y > 43) camera->y = 43;
|
||||
camera->zoom = 1;
|
||||
break;
|
||||
}
|
||||
return end;
|
||||
}
|
||||
|
||||
|
||||
bool can_build(struct calccity *calccity, struct camera *camera, struct map *map, struct building *building)
|
||||
{
|
||||
unsigned short loc_x = building->size[0] * floor(camera->cursor_x / (floor(camera->cursor_size[0] / 8) + 1));
|
||||
unsigned short loc_y = building->size[1] * floor(camera->cursor_y / (floor(camera->cursor_size[1] / 8) + 1));
|
||||
unsigned short loc_x = building->size[0] * floor(camera->x + camera->cursor_x / (floor(camera->cursor_size[0] / 8) + 1));
|
||||
unsigned short loc_y = building->size[1] * floor(camera->y + camera->cursor_y / (floor(camera->cursor_size[1] / 8) + 1));
|
||||
|
||||
// Not enougth money
|
||||
if (calccity->misc[0] < building->cost)
|
||||
|
|
|
@ -17,11 +17,11 @@ int rtc_key(void);
|
|||
// next_step : compute in-game time
|
||||
void next_step(struct calccity *calccity);
|
||||
|
||||
// main_loop : game main loop
|
||||
// main_loop : game main loop, manage key, menu, map actualization and building
|
||||
void main_loop(struct calccity *calccity, struct camera *camera, struct map *map);
|
||||
|
||||
// keyboard_managment : get the key, manage input and open menus
|
||||
int keyboard_managment(struct camera *camera, const int key);
|
||||
void keyboard_managment(struct camera *camera, const int key);
|
||||
|
||||
// can_build : test if the build is legit
|
||||
bool can_build(struct calccity *calccity, struct camera *camera, struct map *map, struct building *building);
|
||||
|
|
|
@ -19,8 +19,16 @@ void title_screen(void)
|
|||
void display_main(struct calccity *calccity, struct camera *camera, struct map *map, const int disp_cursor)
|
||||
{
|
||||
// Display map
|
||||
display_large_map(calccity, camera, map);
|
||||
display_around(calccity, camera, disp_cursor);
|
||||
if (camera->zoom == 0)
|
||||
{
|
||||
display_large_map(calccity, camera, map);
|
||||
display_around(calccity, camera, disp_cursor);
|
||||
}
|
||||
else
|
||||
{
|
||||
display_mini_map(camera, map);
|
||||
display_around(calccity, camera, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -34,6 +42,7 @@ void display_large_map(struct calccity *calccity, struct camera *camera, struct
|
|||
for (int x = 0; x < 8; x ++)
|
||||
{
|
||||
int cam_x = x + camera->x, cam_y = y + camera->y;
|
||||
|
||||
// Water
|
||||
if (cam_y > 49 || cam_x > 49 || map->data[cam_y][cam_x] == 139)
|
||||
dsubimage(3 + x * 15, y * 15, &img_large_water, 15 * calccity->blinker, 0, 15 * (calccity->blinker + 1), 15, DIMAGE_NONE);
|
||||
|
@ -41,9 +50,9 @@ void display_large_map(struct calccity *calccity, struct camera *camera, struct
|
|||
{
|
||||
unsigned tile_id = map->data[cam_y][cam_x];
|
||||
unsigned int tile_x = 15 * (tile_id % 10);
|
||||
unsigned int tile_y = 15 * (tile_id / 10);
|
||||
|
||||
dsubimage(3 + x * 15, y * 15, &img_large_tileset, tile_x, tile_y, 15, 15, DIMAGE_NONE);
|
||||
unsigned int tile_y = 15 * (tile_id / 10);
|
||||
|
||||
dsubimage(3 + x * 15, y * 15, &img_large_tileset, tile_x, tile_y, 15, 15, DIMAGE_NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,6 +60,25 @@ void display_large_map(struct calccity *calccity, struct camera *camera, struct
|
|||
}
|
||||
|
||||
|
||||
void display_mini_map(struct camera *camera, struct map *map)
|
||||
{
|
||||
extern const bopti_image_t img_mini_tileset;
|
||||
|
||||
for (int y = 0; y < 7; y ++)
|
||||
{
|
||||
for (int x = 0; x < 15; x ++)
|
||||
{
|
||||
int cam_x = x + camera->x, cam_y = y + camera->y;
|
||||
|
||||
unsigned tile_id = map->data[cam_y][cam_x];
|
||||
unsigned int tile_x = 8 * (tile_id % 10);
|
||||
unsigned int tile_y = 8 * (tile_id / 10);
|
||||
|
||||
dsubimage(3 + x * 8, y * 8, &img_mini_tileset, tile_x, tile_y, 8, 8, DIMAGE_NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void display_around(struct calccity *calccity, struct camera *camera, const int disp_cursor)
|
||||
{
|
||||
extern const bopti_image_t img_fn_keys;
|
||||
|
|
|
@ -13,6 +13,9 @@ void display_main(struct calccity *calccity, struct camera *camera, struct map *
|
|||
// display_large_map : display the current state of the large map
|
||||
void display_large_map(struct calccity *calccity, struct camera *camera, struct map *map);
|
||||
|
||||
// display_mini_map : display the current state of the mini map
|
||||
void display_mini_map(struct camera *camera, struct map *map);
|
||||
|
||||
// display_around : display the screen frame and cursor
|
||||
void display_around(struct calccity *calccity, struct camera *camera, const int disp_cursor);
|
||||
|
||||
|
|
|
@ -233,13 +233,13 @@ void menu_5(struct calccity *calccity)
|
|||
|
||||
for (int i = 0; i < 8; i ++)
|
||||
{
|
||||
if (values[i + scroll] < 0)
|
||||
if (i + scroll == 0 || i + scroll == 9 || i + scroll == 14 || i + scroll == 21)
|
||||
{
|
||||
drect(5, 7 + i * 7, 127, 13 + i * 7, C_BLACK);
|
||||
dtext(12, 8 + i * 7, C_WHITE, names[i + scroll]);
|
||||
drect(5, 7 * i + 7, 127, 7 * i + 13, C_BLACK);
|
||||
dtext(12, 7 * i + 8, C_WHITE, names[i + scroll]);
|
||||
}
|
||||
else
|
||||
dprint(7, 8 + i * 7, C_BLACK, "%s %lu", names[i + scroll], values[i + scroll]);
|
||||
dprint(7, 7 * i + 8, C_BLACK, "%s %lu", names[i + scroll], values[i + scroll]);
|
||||
}
|
||||
|
||||
dupdate();
|
||||
|
|
Loading…
Reference in New Issue