Exemple #1
0
void	graphics::draw		(const entity_c &obj) {

	draw_at (obj,
			camera->zoom(),
			(obj.pos[0] - camera->pos[0]) * camera->zoom() + camera->size[0]/2,
			(-obj.pos[1] + camera->pos[1]) * camera->zoom() + camera->size[1]/2);
}
Exemple #2
0
void Map::draw(Torbit& target)
{
    const bool z = zoom;
    int less_x = 0;
    int less_y = 0; // how much is the screen larger than the map?
    if (!get_torus_x() && get_xl() * (z+1) < screen_xl)
     less_x = screen_xl - get_xl() * (z+1);
    if (!get_torus_y() && get_yl() * (z+1) < screen_yl)
     less_y = screen_yl - get_yl() * (z+1);

    for     (int x = less_x/2; x < screen_xl-less_x/2; x += get_xl()*(z+1)) {
        for (int y = less_y;   y < screen_yl;          y += get_yl()*(z+1)) {
            draw_at(target, x, y);
            if (less_y != 0) break;
        }
        if (less_x != 0) break;
    }

    // Draw the screen border
    const int c = useR->screen_border_colored
                ? color[COL_SCREEN_BORDER] : 0;
    if (less_x) {
        rectfill(target.get_al_bitmap(), 0, 0, less_x/2 - 1,
         screen_yl - 1, c);
        rectfill(target.get_al_bitmap(), screen_xl - less_x/2, 0,
         screen_xl - 1, screen_yl - 1, c);
    }
    if (less_y)
     rectfill(target.get_al_bitmap(), less_x/2, 0,
     screen_xl - less_x/2 - 1, less_y - 1, c);
}
Exemple #3
0
void GameCursor::draw() const {
    if (!show) {
        return;
    }

    Point where = sys.video->get_mouse();

    where = clamp(where);
    if (active()) {
        const Rect clip_rect = viewport();
        const RgbColor color = GetRGBTranslateColorShade(SKY_BLUE, MEDIUM);

        Point top_a = Point(where.h, clip_rect.top);
        Point top_b = Point(where.h, (where.v - kCursorBoundsSize));
        Point bottom_a = Point(where.h, (where.v + kCursorBoundsSize));
        Point bottom_b = Point(where.h, clip_rect.bottom - 1);
        Point left_a = Point(clip_rect.left, where.v);
        Point left_b = Point((where.h - kCursorBoundsSize), where.v);
        Point right_a = Point(std::max(viewport().left, where.h + kCursorBoundsSize), where.v);
        Point right_b = Point(clip_rect.right - 1, where.v);

        Rects rects;
        if (top_a.h >= viewport().left) {
            rects.fill({top_a.h, top_a.v, top_b.h + 1, top_b.v + 1}, color);
            rects.fill({bottom_a.h, bottom_a.v, bottom_b.h + 1, bottom_b.v + 1}, color);
        }
        rects.fill({right_a.h, right_a.v, right_b.h + 1, right_b.v + 1}, color);
        if (left_b.h >= viewport().left) {
            rects.fill({left_a.h, left_a.v, left_b.h + 1, left_b.v + 1}, color);
        }
    }

    if (where.h < viewport().left) {
        draw_at(where);
    }
}
static int check_collision( INSTANCE * proc1, GRAPH * bmp1, REGION * bbox3, INSTANCE * proc2 )
{
    REGION bbox1, bbox2 ;
    int x, y, w, h ;
    GRAPH * bmp2 ;

    bbox1 = *bbox3;

    bmp2 = instance_graph( proc2 ) ; if ( !bmp2 ) return 0 ;
    instance_get_bbox( proc2, bmp2, &bbox2 );

    region_union( &bbox1, &bbox2 ) ;
    if ( region_is_empty( &bbox1 ) ) return 0 ;

    // Solo si las regiones de ambos bbox se superponen

    w = bbox1.x2 - bbox1.x + 1 ;
    h = bbox1.y2 - bbox1.y + 1 ;
    bbox2.x = bbox2.y = 0 ;
    bbox2.x2 = w - 1 ;
    bbox2.y2 = h - 1 ;

    bmp1 = bitmap_new( 0, w, h, sys_pixel_format->depth ) ;
    if ( !bmp1 ) return 0;

    bmp2 = bitmap_new( 0, w, h, sys_pixel_format->depth ) ;
    if ( !bmp2 )
    {
        bitmap_destroy( bmp1 ) ;
        return 0;
    }

    memset( bmp1->data, 0, bmp1->pitch * h ) ;
    memset( bmp2->data, 0, bmp2->pitch * h ) ;

    x = LOCINT32( mod_grproc, proc1, COORDX ) ;
    y = LOCINT32( mod_grproc, proc1, COORDY ) ;
    RESOLXY( mod_grproc, proc1, x, y );

    x -= bbox1.x ;
    y -= bbox1.y ;
    draw_at( bmp1, x, y, &bbox2, proc1 ) ;

    x = LOCINT32( mod_grproc, proc2, COORDX ) ;
    y = LOCINT32( mod_grproc, proc2, COORDY ) ;
    RESOLXY( mod_grproc, proc2, x, y );

    x -= bbox1.x ;
    y -= bbox1.y ;
    draw_at( bmp2, x, y, &bbox2, proc2 ) ;

    if ( sys_pixel_format->depth == 32 )
    {
        uint32_t * ptr1 = ( uint32_t * ) bmp1->data ;
        uint32_t * ptr2 = ( uint32_t * ) bmp2->data ;

        uint8_t * _ptr1 = ( uint8_t * ) ptr1 ;
        uint8_t * _ptr2 = ( uint8_t * ) ptr2 ;

        for ( y = 0 ; y < h ; y++ )
        {
            for ( x = 0 ; x < w ; x++, ptr1++, ptr2++ )
            {
                if ( *ptr1 && *ptr2 )
                {
                    bitmap_destroy( bmp1 ) ;
                    bitmap_destroy( bmp2 ) ;
                    return 1;
                }
            }
            ptr1 = ( uint32_t * )( _ptr1 += bmp1->pitch );
            ptr2 = ( uint32_t * )( _ptr2 += bmp2->pitch );
        }
    }
    else
    {
        if ( sys_pixel_format->depth == 16 )
        {
            uint16_t * ptr1 = ( uint16_t * ) bmp1->data ;
            uint16_t * ptr2 = ( uint16_t * ) bmp2->data ;

            uint8_t * _ptr1 = ( uint8_t * ) ptr1 ;
            uint8_t * _ptr2 = ( uint8_t * ) ptr2 ;

            for ( y = 0 ; y < h ; y++ )
            {
                for ( x = 0 ; x < w ; x++, ptr1++, ptr2++ )
                {
                    if ( *ptr1 && *ptr2 )
                    {
                        bitmap_destroy( bmp1 ) ;
                        bitmap_destroy( bmp2 ) ;
                        return 1;
                    }
                }
                ptr1 = ( uint16_t * )( _ptr1 += bmp1->pitch );
                ptr2 = ( uint16_t * )( _ptr2 += bmp2->pitch );
            }
        }
        else
        {
            uint8_t * ptr1 = ( uint8_t * )bmp1->data ;
            uint8_t * ptr2 = ( uint8_t * )bmp2->data ;

            uint8_t * _ptr1 = ptr1 ;
            uint8_t * _ptr2 = ptr2 ;

            for ( y = 0 ; y < h ; y++ )
            {
                for ( x = 0 ; x < w ; x++, ptr1++, ptr2++ )
                {
                    if ( *ptr1 && *ptr2 )
                    {
                        bitmap_destroy( bmp1 ) ;
                        bitmap_destroy( bmp2 ) ;
                        return 1;
                    }
                }
                ptr1 = _ptr1 += bmp1->pitch;
                ptr2 = _ptr2 += bmp2->pitch;
            }
        }
    }

    bitmap_destroy( bmp1 ) ;
    bitmap_destroy( bmp2 ) ;
    return 0;
}
static int check_collision_with_mouse( INSTANCE * proc1, int colltype )
{
    REGION bbox1, bbox2 ;
    int x, y, mx, my ;
    static GRAPH * bmp = NULL;

    switch ( colltype )
    {
        case    COLLISION_BOX:
        case    COLLISION_CIRCLE:
                if ( !get_bbox( &bbox2, proc1 ) ) return 0 ;

        case    COLLISION_NORMAL:
                break;

        default:
                return 0;
    }

    mx = GLOINT32( mod_grproc, MOUSEX ) ;
    my = GLOINT32( mod_grproc, MOUSEY ) ;

    /* Checks the process's bounding box to optimize checking
       (only for screen-type objects) */

    if ( LOCDWORD( mod_grproc, proc1, CTYPE ) == C_SCREEN )
    {
        switch ( colltype )
        {
            case    COLLISION_NORMAL:
                    if ( !get_bbox( &bbox2, proc1 ) ) return 0 ;
                    if ( bbox2.x > mx || bbox2.x2 < mx || bbox2.y > my || bbox2.y2 < my ) return 0 ;
                    break;

            case    COLLISION_BOX:
                    if ( bbox2.x <= mx && bbox2.x2 >= mx && bbox2.y <= my && bbox2.y2 >= my ) return 1;
                    return 0;
                    break;

            case    COLLISION_CIRCLE:
                {
                    int cx1, cy1, dx1, dy1;

                    cx1 = bbox2.x + ( dx1 = ( bbox2.x2 - bbox2.x + 1 ) ) / 2 ;
                    cy1 = bbox2.y + ( dy1 = ( bbox2.y2 - bbox2.y + 1 ) ) / 2 ;

                    if ( get_distance( cx1, cy1, 0, mx, my, 0 ) < ( dx1 + dy1 ) / 4 ) return 1;
                    return 0;
                    break;
                }
        }
    }

    /* Creates a temporary bitmap (only once) */

    if ( colltype == COLLISION_NORMAL )
    {
        /* maybe must force this to 32 bits */
        if ( bmp && bmp->format->depth != sys_pixel_format->depth ) { bitmap_destroy( bmp ); bmp = NULL; }
        if ( !bmp ) bmp = bitmap_new( 0, 2, 1, sys_pixel_format->depth ) ;
        if ( !bmp ) return 0 ;

        memset( bmp->data, 0, bmp->pitch * bmp->height ) ;
    }

    /* Retrieves process information */

    bbox1.x = 0 ; bbox1.x2 = 1 ;
    bbox1.y = 0 ; bbox1.y2 = 0 ;

    x = LOCINT32( mod_grproc, proc1, COORDX ) ;
    y = LOCINT32( mod_grproc, proc1, COORDY ) ;

    RESOLXY( mod_grproc, proc1, x, y );

    /* Scroll-type process: check for each region */

    if ( LOCDWORD( mod_grproc, proc1, CTYPE ) == C_SCROLL )
    {
        SCROLL_EXTRA_DATA * data;
        scrolldata  * scroll;
        int i;

        if ( GLOEXISTS( mod_grproc, SCROLLS ) )
        {
            int cnumber = LOCDWORD( mod_grproc, proc1, CNUMBER );
            if ( !cnumber ) cnumber = 0xffffffff ;

            for ( i = 0 ; i < 10 ; i++ )
            {
                data = &(( SCROLL_EXTRA_DATA * ) & GLODWORD( mod_grproc, SCROLLS ) )[i] ;
                scroll = ( scrolldata * ) data->reserved[0];

                if ( scroll && scroll->active && ( cnumber & ( 1 << i ) ) )
                {
                    REGION * r = scroll->region;

                    switch ( colltype )
                    {
                        case    COLLISION_NORMAL:
                                if ( r->x > mx || r->x2 < mx || r->y > my || r->y2 < my ) continue;

                                draw_at( bmp, x + r->x - mx - scroll->posx0, y + r->y - my - scroll->posy0, &bbox1, proc1 );
                                switch ( sys_pixel_format->depth )
                                {
                                    case    8:
                                        if ( *( uint8_t * )bmp->data ) return 1;
                                        break;

                                    case    16:
                                        if ( *( uint16_t * )bmp->data ) return 1;
                                        break;

                                    case    32:
                                        if ( *( uint32_t * )bmp->data ) return 1;
                                        break;
                                }
                                break;

                        case    COLLISION_BOX:
                                if ( bbox2.x <= scroll->posx0 + r->x + mx && bbox2.x2 >= scroll->posx0 + r->x + mx &&
                                     bbox2.y <= scroll->posy0 + r->y + my && bbox2.y2 >= scroll->posy0 + r->y + my ) return 1;
                                break;

                        case    COLLISION_CIRCLE:
                            {
                                int cx1, cy1, dx1, dy1;

                                cx1 = bbox2.x + ( dx1 = ( bbox2.x2 - bbox2.x + 1 ) ) / 2 ;
                                cy1 = bbox2.y + ( dy1 = ( bbox2.y2 - bbox2.y + 1 ) ) / 2 ;

                                if ( get_distance( cx1, cy1, 0, r->x + mx + scroll->posx0, r->y + my + scroll->posy0, 0 ) < ( dx1 + dy1 ) / 4 ) return 1;
                                break;
                            }
                    }
                }
            }
        }

        return 0;
    }

    switch ( colltype )
    {
        case    COLLISION_NORMAL:
                /* Collision check (blits into temporary space and checks the resulting pixel) */
                draw_at( bmp, x - mx, y - my, &bbox1, proc1 ) ;

                switch ( sys_pixel_format->depth )
                {
                    case    8:
                        if ( *( uint8_t * )bmp->data ) return 1;
                        break;

                    case    16:
                        if ( *( uint16_t * )bmp->data ) return 1;
                        break;

                    case    32:
                        if ( *( uint32_t * )bmp->data ) return 1;
                        break;
                }
                break;

        case    COLLISION_BOX:
                if ( bbox2.x <= mx && bbox2.x2 >= mx &&
                     bbox2.y <= my && bbox2.y2 >= my ) return 1;
                break;

        case    COLLISION_CIRCLE:
            {
                int cx1, cy1, dx1, dy1;

                cx1 = bbox2.x + ( dx1 = ( bbox2.x2 - bbox2.x + 1 ) ) / 2 ;
                cy1 = bbox2.y + ( dy1 = ( bbox2.y2 - bbox2.y + 1 ) ) / 2 ;

                if ( get_distance( cx1, cy1, 0, mx, my, 0 ) < ( dx1 + dy1 ) / 4 ) return 1;
                break;
            }
    }

    return 0 ;
}
Exemple #6
0
void Cursor::draw() const {
    draw_at(sys.video->get_mouse());
}
void TILE :: display()
{
  draw_at(pX(),pY());
}