Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
void place_caged(void)
{
    int x = 0;
    int y = 0;

    do
    {
        x = rand() % (CAGE_SIZE - 1);
        y = rand() % (ARENA_SIZE - 1);
    } while (0 != f_state.cage[x][y] || f_state.score >= 50);
    
    h3m_object_add(f_state.h3m, f_state.def_apple, CAGE_START + x, ARENA_START + y, 0, NULL);

    f_state.cage[x][y] = 1;
}
Ejemplo n.º 3
0
int _update_nodes(int x_inc, int y_inc)
{
    struct NODE *n = NULL;
    int i = 0;
    int od_index = 0;
    int x_new = f_state.head->x + x_inc;
    int y_new = f_state.head->y + y_inc;

    if (has_node(x_new, y_new) || x_new < ARENA_START + 1 || y_new < ARENA_START + 1
        || x_new >= ARENA_START + ARENA_SIZE || y_new >= ARENA_START + ARENA_SIZE)
    {
        return 1;
    }

    if (f_state.node_count >= f_state.size)
    {
        _new_head(f_state.tail, x_new, y_new);
        f_state.tail = f_state.tail->next;
        h3m_object_move(f_state.h3m, f_state.head->od_index, f_state.head->x, f_state.head->y, 0);
    }
    else
    {
        n = calloc(1, sizeof(*n));
        _new_head(n, x_new, y_new);

        ++f_state.node_count;

        h3m_object_add(f_state.h3m, "Serpent Fly", n->x, n->y, 0, &n->od_index);
    }

    if (has_apple(x_new, y_new))
    {
        place_apple();
        place_caged();
        ++f_state.score;
        ++f_state.size;
    }

    return 0;
}
Ejemplo n.º 4
0
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;
}