int main(void) { h3mlib_ctx_t h3m = NULL; int od_index = 0; h3m_init_min(&h3m, H3M_FORMAT_ROE, H3M_SIZE_SMALL); h3m_object_add(h3m, "Castle", 5, 5, 0, &od_index); h3m_object_set_owner(h3m, od_index, 0); h3m_player_enable(h3m, 0); h3m_name_set(h3m, "h3msnake2"); if (0 != h3m_code_set_dll(h3m, "..\\..\\..\\..\\OUTPUT\\Release\\h3complete_snakeloader.dll")) { h3m_exit(&h3m); return 1; } h3m_desc_set(h3m, DESC_PREFIX_COMPLETE DESC); h3m_code_set_target(h3m, H3M_CODE_TARGET_COMPLETE); h3m_write(h3m, "h3msnake2_h3complete.h3m"); h3m_desc_set(h3m, DESC_PREFIX_HDMOD DESC); h3m_code_set_target(h3m, H3M_CODE_TARGET_HDMOD); h3m_write(h3m, "h3msnake2_hdmod.h3m"); h3m_exit(&h3m); return 0; }
enum H3MSNAKE_STATE h3msnake_update_state(enum H3MSNAKE_INPUT input) { enum H3MSNAKE_STATE state = H3MSNAKE_STATE_ALIVE; int x_inc = 0; int y_inc = 0; switch (input) { case H3MSNAKE_INPUT_START: ExitProcess(1); case H3MSNAKE_INPUT_LEFT: f_state.direction = DIR_LEFT; break; case H3MSNAKE_INPUT_DOWN: f_state.direction = DIR_DOWN; break; case H3MSNAKE_INPUT_UP: f_state.direction = DIR_UP; break; case H3MSNAKE_INPUT_RIGHT: f_state.direction = DIR_RIGHT; break; default: break; } //char dbg[256] = { 0 }; //sprintf(dbg, "input: %d\n", input); //OutputDebugStringA(dbg); switch (f_state.direction) { case DIR_RIGHT: x_inc = 1; break; case DIR_UP: y_inc = -1; break; case DIR_LEFT: x_inc = -1; break; case DIR_DOWN: y_inc = 1; break; default: *((int *)(0xFBADC0DE)) = 0xDEADDEAD; } if (0 != _update_nodes(x_inc, y_inc)) { int oa_index = 0; const char *def_gameover = "ava0128.def"; // Pandoras const char *def_score = f_state.def_apple; char score[12]; int terrain = f_state.terrain; h3m_exit(&f_state.h3m); f_state.h3m = NULL; h3m_init_min(&f_state.h3m, H3M_FORMAT_ROE, 36); h3m_add_oa_by_def(f_state.h3m, def_gameover, &oa_index); h3m_alg_od_text(f_state.h3m, def_gameover, oa_index, 7, 1 + 6, 0, "GAME"); h3m_alg_od_text(f_state.h3m, def_gameover, oa_index, 7, 1 + 6 + 6, 0, "OVER"); snprintf(score, sizeof(score)-1, "%d", f_state.score); h3m_add_oa_by_name(f_state.h3m, f_state.def_apple, &oa_index); h3m_alg_od_text(f_state.h3m, f_state.def_apple, oa_index, 7, 1, 0, score); //h3m_object_add(f_state.h3m, "Angel", 5, 5, 0, NULL); uint8_t terrain_types[36 * 36]; uint8_t river_types[36 * 36]; uint8_t road_types[36 * 36]; uint8_t impassable[36][36]; memset(terrain_types, terrain, sizeof(terrain_types)); memset(river_types, 0, sizeof(river_types)); memset(road_types, 0, sizeof(road_types)); memset(impassable, 1, sizeof(impassable)); h3m_generate_tiles(f_state.h3m, 36, 0, (uint8_t *)terrain_types, (uint8_t *)road_types, (uint8_t *)river_types); for (int i = 0; i < 36; ++i) { for (int j = 6; j < 30; ++j) impassable[i][j] = 0; } h3m_impassable_fill(f_state.h3m, (uint8_t *)impassable, 36); state = H3MSNAKE_STATE_DEAD; } h3m_write(f_state.h3m, f_state.filename); return state; }
int h3msnake_init(const char *filename) { struct NODE *nodes[START_SIZE]; int od_index = 0; memset(&f_state, 0, sizeof(f_state)); h3m_init_min(&f_state.h3m, H3M_FORMAT_ROE, 36); h3m_write(f_state.h3m, filename); srand((unsigned int)time(NULL)); f_state.filename = _strdup(filename); g_map_filename = f_state.filename; f_state.direction = DIR_RIGHT; for (int i = 0; i < START_SIZE; ++i) { h3m_object_add(f_state.h3m, "Serpent Fly", START_POS + i, START_POS, 0, &od_index); nodes[i] = calloc(1, sizeof(*(nodes[i]))); nodes[i]->od_index = od_index; nodes[i]->x = START_POS + i; nodes[i]->y = START_POS; } f_state.head = nodes[START_SIZE - 1]; f_state.tail = nodes[0]; for (int i = 0; i < START_SIZE - 1; ++i) { nodes[i]->next = nodes[i + 1]; nodes[i]->prev = (0 != -i) ? nodes[i - 1] : NULL; } nodes[0]->prev = f_state.head; nodes[START_SIZE - 1]->next = f_state.tail; f_state.size = START_SIZE; f_state.node_count = START_SIZE; //f_state.tail->prev = f_state.head; uint8_t terrain_types[36 * 36]; uint8_t river_types[36 * 36]; uint8_t road_types[36 * 36]; uint8_t impassable[36][36]; f_state.terrain = (rand() + 1) % 8; memset(terrain_types, f_state.terrain, sizeof(terrain_types)); memset(river_types, 0, sizeof(river_types)); memset(road_types, 0, sizeof(road_types)); memset(impassable, 1, sizeof(impassable)); #if 1 h3m_generate_tiles(f_state.h3m, 36, 0, (uint8_t *)terrain_types, (uint8_t *)road_types, (uint8_t *)river_types); const char *defs_apple[] = { "Skeleton", "Gold Golem", "Pikeman", "Gremlin", "Gnoll", "Goblin", "Troglodyte", "Imp" }; const char *defs_wall[] = { "Skeleton Warrior", "Diamond Golem", "Halberdier", "Master Gremlin", "Gnoll Marauder", "Hobgoblin", "Infernal Troglodyte", "Familiar" }; for (int i = ARENA_START; i < ARENA_START+ARENA_SIZE; ++i) { h3m_object_add(f_state.h3m, defs_wall[f_state.terrain], i, ARENA_START + ARENA_SIZE, 0, NULL); h3m_object_add(f_state.h3m, defs_wall[f_state.terrain], ARENA_START + ARENA_SIZE, i, 0, NULL); h3m_object_add(f_state.h3m, defs_wall[f_state.terrain], i, ARENA_START, 0, NULL); h3m_object_add(f_state.h3m, defs_wall[f_state.terrain], ARENA_START, i, 0, NULL); for (int j = ARENA_START; j < ARENA_START + ARENA_SIZE + 1; ++j) impassable[i][j] = 0; for (int j = CAGE_START; j < CAGE_START + CAGE_SIZE; ++j) impassable[i][j] = 0; } h3m_impassable_fill(f_state.h3m, (uint8_t *)impassable, 36); h3m_object_add(f_state.h3m, defs_wall[f_state.terrain], ARENA_START + ARENA_SIZE, ARENA_START, 0, NULL); h3m_object_add(f_state.h3m, defs_wall[f_state.terrain], ARENA_START, ARENA_START + ARENA_SIZE, 0, NULL); h3m_object_add(f_state.h3m, defs_wall[f_state.terrain], ARENA_START, ARENA_START, 0, NULL); h3m_object_add(f_state.h3m, defs_wall[f_state.terrain], ARENA_START + ARENA_SIZE, ARENA_START + ARENA_SIZE, 0, NULL); #endif f_state.def_apple = defs_apple[f_state.terrain]; h3m_object_add(f_state.h3m, f_state.def_apple, 15, 0, 0, &f_state.apple.od_index); place_apple(); return 0; }