From 9bf0e3c7fa3706b541d29c4770635365100951d5 Mon Sep 17 00:00:00 2001 From: kts Date: Mon, 7 Apr 2014 10:08:04 -0700 Subject: [PATCH] newTile no longer takes x, y, and z params. Default values are set to 0 and are changed/set upon addTileToMap call. --- engine/map.c | 37 +++++++++++++++++++++++++++++ engine/map.h | 2 +- engine/states/state_test.c | 29 +++++++++++++++------- engine/tile.c | 12 ++++++---- engine/tile.h | 2 +- modules/xibalba/CONF | 1 + modules/xibalba/sprites/CONF | 8 +++++++ modules/xibalba/sprites/shapes.png | Bin 0 -> 362 bytes modules/xibalba/xibalba.tsd | 11 +++++++++ 9 files changed, 87 insertions(+), 15 deletions(-) create mode 100644 modules/xibalba/sprites/shapes.png diff --git a/engine/map.c b/engine/map.c index 84dd532..fd4d221 100644 --- a/engine/map.c +++ b/engine/map.c @@ -133,3 +133,40 @@ int moveTile(struct Map *map, struct Tile *tile, float x, float y, float z) { tile->z = target_z; return 0; } + +int addTileToMap(struct Map *map, struct Tile *tile, float x, float y, float z) { + if (map == NULL) + return -1; + if (tile == NULL) + return -2; + int tile_x = (int)x; + int tile_y = (int)y; + int tile_z = (int)z; + // if out of bounds, add to nearest cell + if (tile_x >= map->width) { + tile_x = map->width-1; + } else if (tile_x < 0) { + tile_x = 0; + } + if (tile_y >= map->height) { + tile_y = map->height-1; + } else if (tile_y < 0) { + tile_y = 0; + } + if (tile_z >= map->depth) { + tile_z = map->depth-1; + } else if (tile_z < 0) { + tile_z = 0; + } + // set tile's x, y, and z params + tile->x = tile_x; + tile->y = tile_y; + tile->z = tile_z; + if (map->tiles[tile_x][tile_y][tile_z] == NULL) { + map->tiles[tile_x][tile_y][tile_z] = tile; + return 0; + } + // if existing, append to tile linked list there + appendTile(map->tiles[tile_x][tile_y][tile_z], tile); + return 0; +} diff --git a/engine/map.h b/engine/map.h index eeddfb5..39cd336 100644 --- a/engine/map.h +++ b/engine/map.h @@ -13,6 +13,6 @@ struct Map *newMap(int width, int height, int depth); int nullMap(struct Map *map); void freeMap(struct Map *map, int flags); - int moveTile(struct Map *map, struct Tile *tile, float x, float y, float z); +int addTileToMap(struct Map *map, struct Tile *tile, float x, float y, float z); #endif diff --git a/engine/states/state_test.c b/engine/states/state_test.c index 3a569ee..092852e 100644 --- a/engine/states/state_test.c +++ b/engine/states/state_test.c @@ -14,7 +14,7 @@ Called once when switching to this state. Used to load whatever data used during ================================ */ void initTestState() { - if ((test_map = newMap(32, 32, 2)) == NULL) { + if ((test_map = newMap(32, 32, 4)) == NULL) { printf("ERROR: failed to allocate map!\n"); stopRunning(); return; @@ -22,17 +22,29 @@ void initTestState() { int x,y,z; for (x=0;x < test_map->width;x++) { for (y=0;y < test_map->height;y++) { - test_map->tiles[x][y][0] = newTile(x, y, 0, getTileDataById(g_tile_data, 2, 0)); + addTileToMap(test_map, newTile(getTileDataById(g_tile_data, 2, 0)), x, y, 0); } } for (x=8;x < 9;x++) { for (y=0;y < test_map->height;y++) { - test_map->tiles[x][y][1] = newTile(x, y, 1, getTileDataById(g_tile_data, 3, 0)); + addTileToMap(test_map, newTile(getTileDataById(g_tile_data, 3, 0)), x, y, 1); } } - test_player_tile = newTile(2, 2, 1, getTileDataById(g_tile_data, 0, 0)); + int i = 0; + z = 0; + x = 0; + for (i=0;i < 3;i++) { + for (z = 0; z < 8;z++) { + //for(x = 12;x < 16;x++) { + //test_map->tiles[x][9][0]->next = newTile(getTileDataById(g_tile_data, 7, i)); + addTileToMap(test_map, newTile(getTileDataById(g_tile_data, 8, i)), x+i, 9, z); + //} + } + } + + test_player_tile = newTile(getTileDataById(g_tile_data, 0, 0)); test_map->tiles[2][2][1] = test_player_tile; key_press[0] = 0; @@ -72,22 +84,22 @@ void processTestState(int delta) { while(s_accumulator >= g_tick_time.n) { if (key_press[0] == 1) { test_player_tile->set = 4; - moveTile(test_map, test_player_tile, -0.1f, 0.0f, 0.0f); + moveTile(test_map, test_player_tile, -0.5f, 0.0f, 0.0f); //moveTile(test_map, test_player_tile, -1.0f, 0.0f, 0.0f); } if (key_press[1] == 1) { test_player_tile->set = 5; - moveTile(test_map, test_player_tile, 0.0f, 0.1f, 0.0f); + moveTile(test_map, test_player_tile, 0.0f, 0.5f, 0.0f); //moveTile(test_map, test_player_tile, 0.0f, 1.0f, 0.0f); } if (key_press[2] == 1) { test_player_tile->set = 6; - moveTile(test_map, test_player_tile, 0.1f, 0.0f, 0.0f); + moveTile(test_map, test_player_tile, 0.5f, 0.0f, 0.0f); //moveTile(test_map, test_player_tile, 1.0f, 0.0f, 0.0f); } if (key_press[3] == 1) { test_player_tile->set = 7; - moveTile(test_map, test_player_tile, 0.0f, -0.1f, 0.0f); + moveTile(test_map, test_player_tile, 0.0f, -0.5f, 0.0f); //moveTile(test_map, test_player_tile, 0.0f, -1.0f, 0.0f); } @@ -123,6 +135,7 @@ void renderTestState() { int id = tile->data->id; int pix_x = tile->x * g_module_spritesheets[tile->data->tid]->s_width; int pix_y = (tile->y * g_module_spritesheets[tile->data->tid]->s_height)/2; + pix_y -= (tile->z * (g_module_spritesheets[tile->data->tid]->s_height/4)); g_renderSprite(g_module_spritesheets[tile->data->tid], g_screen, id, pix_x, pix_y); tile = tile->next; diff --git a/engine/tile.c b/engine/tile.c index 1a52105..8c66d5f 100644 --- a/engine/tile.c +++ b/engine/tile.c @@ -1,12 +1,11 @@ #include #include "tile.h" -struct Tile *newTile(float x, float y, float z, struct TileData *data) { +struct Tile *newTile(struct TileData *data) { struct Tile *tile = malloc(sizeof(struct Tile)); - //printf("%fx%fx%f\n", x, y, z); - tile->x = x; - tile->y = y; - tile->z = z; + tile->x = 0.0f; + tile->y = 0.0f; + tile->z = 0.0f; tile->set = 0; tile->frame = 0; tile->data = duplicateTileData(data); @@ -23,7 +22,10 @@ void freeTile(struct Tile *tile) { free(tile); } +// TODO: return non-VOID and check for NULL tile_target and new_tile void appendTile(struct Tile *tile_target, struct Tile *new_tile) { + if (tile_target == NULL) + return; if (new_tile == tile_target) return; struct Tile *current_tile = tile_target; diff --git a/engine/tile.h b/engine/tile.h index 7f15b16..0741725 100644 --- a/engine/tile.h +++ b/engine/tile.h @@ -13,7 +13,7 @@ struct Tile { struct Tile *prev; }; -struct Tile *newTile(float x, float y, float z, struct TileData *data); +struct Tile *newTile(struct TileData *data); void freeTile(struct Tile *tile); void appendTile(struct Tile *tile_target, struct Tile *new_tile); diff --git a/modules/xibalba/CONF b/modules/xibalba/CONF index 9101f47..5d041b9 100644 --- a/modules/xibalba/CONF +++ b/modules/xibalba/CONF @@ -19,6 +19,7 @@ sprites { 5 items 6 materials 7 spells + 8 shapes } ; list of playable characters for character creation chars { diff --git a/modules/xibalba/sprites/CONF b/modules/xibalba/sprites/CONF index 53348fe..6578603 100644 --- a/modules/xibalba/sprites/CONF +++ b/modules/xibalba/sprites/CONF @@ -85,3 +85,11 @@ spells { set 1 frame 1 } + +shapes { + width 16 + height 32 + columns 4 + set 1 + frame 1 +} diff --git a/modules/xibalba/sprites/shapes.png b/modules/xibalba/sprites/shapes.png new file mode 100644 index 0000000000000000000000000000000000000000..47eaa98b52a08339bd94e1483d09d72420bc9484 GIT binary patch literal 362 zcmV-w0hRuVP)Zq}6b9fwRSwXhV+Ibu(2=zR2VmtE?jl=*0603&{mGEH6-kqUIR4StY z72E$w=t)L?^7DH#Ktx1DL_|bHL_|bH^iLwbK@-n#POB=KV_?=YGfu9;fMA z_YKqvhgV5O#OHaAVHlv4LYk)jd_KS2_t!X%YqzZS7FrAyk1GK6I^n(RD9aL6Rlzw2 z0EpvwRVSOK@mgybV~`}tZc`APfbIkMyxyb!iSx5E)%QJ=QULHQ-del*VB