void onInitialization() {
    //szintek letrehozasa
    //felso szint
    fieldElements[0][0] = Point2D(-1.0, 0.40);
    fieldElements[0][1] = Point2D(-0.6, 0.40);

    fieldElements[1][0] = Point2D(-0.2, 0.40);
    fieldElements[1][1] = Point2D(0.2, 0.40);

    fieldElements[2][0] = Point2D(0.6, 0.40);
    fieldElements[2][1] = Point2D(1.0, 0.40);

    //kozepso szint
    fieldElements[3][0] = Point2D(-1.0, -0.30);
    fieldElements[3][1] = Point2D(-0.6, -0.30);

    fieldElements[4][0] = Point2D(-0.2, -0.30);
    fieldElements[4][1] = Point2D(0.2, -0.30);

    fieldElements[5][0] = Point2D(0.6, -0.30);
    fieldElements[5][1] = Point2D(1.0, -0.30);

    //also szint vegig
    fieldElements[6][0] = Point2D(-1.0, -1.00);
    fieldElements[6][1] = Point2D(1.0, -1.0);

    Point2D nose(-0.00, 0.44);
    Color c;

    //zöld giliszta
    c.set(0.0, 1.0, 0.0);
    initWorm(greenWorm, nose, c);

    //piros giliszta
    nose.X() = -0.00;
    nose.Y() = -0.26;
    c.set(1.0, 0.0, 0.0);
    initWorm(redWorm, nose, c);
    redWorm.setDir();
}
Beispiel #2
0
void
initWorms(
    uint16_t number,
    uint16_t length,
    WORMS_T *worms,
    VC_IMAGE_TYPE_T imageType,
    DISPMANX_MODEINFO_T *info)
{
    initImage(&(worms->image), imageType, info->width, info->height, false);
    srand(time(NULL));

    worms->size = number;
    worms->worms = malloc(worms->size * sizeof(WORM_T));

    if (worms->worms == NULL)
    {
        fprintf(stderr, "worms: memory exhausted\n");
        exit(EXIT_FAILURE);
    }

    uint16_t i = 0;
    for (i = 0 ; i < worms->size ; i++)
    {
        WORM_T *worm = &(worms->worms[i]);
        initWorm(i, number, length, worm, &(worms->image));
    }

    //---------------------------------------------------------------------

    uint32_t vc_image_ptr;

    worms->frontResource =
        vc_dispmanx_resource_create(
            worms->image.type,
            worms->image.width  |(worms->image.pitch << 16),
            worms->image.height | (worms->image.alignedHeight << 16),
            &vc_image_ptr);
    assert(worms->frontResource != 0);

    worms->backResource =
        vc_dispmanx_resource_create(worms->image.type,
            worms->image.width | (worms->image.pitch << 16),
            worms->image.height | (worms->image.alignedHeight << 16),
            &vc_image_ptr);
    assert(worms->backResource != 0);

    //---------------------------------------------------------------------

    int result = 0;

    VC_RECT_T dst_rect;
    vc_dispmanx_rect_set(&dst_rect,
                         0,
                         0,
                         worms->image.width,
                         worms->image.height);

    result = vc_dispmanx_resource_write_data(worms->frontResource,
                                             worms->image.type,
                                             worms->image.pitch,
                                             worms->image.buffer,
                                             &dst_rect);
    assert(result == 0);
}