Project

General

Profile

Revision 143

fixed boundaries

View differences:

lab5.c
471 471
                        timer_int_handler();
472 472
                        if(no_interrupts == Nt*ticks_per_frame){
473 473

  
474
                            if(vx) draw_rectangle((vx > 0 ? x : x+sprite_get_w(sp)+vx),y                                   , abs(v)         , sprite_get_h(sp), 0);
475
                            if(vy) draw_rectangle(x                                   ,(vy > 0 ? y : y+sprite_get_h(sp)+vy),sprite_get_w(sp), abs(v)          , 0);
474
                            if(vx) {
475
                                uint16_t x_clear = (vx > 0 ? x : x+sprite_get_w(sp)+vx);
476
                                uint16_t y_clear = y;
477
                                uint16_t w = (x + abs(v) > get_XRes()) ? (get_XRes() - x) : (abs(v));
478
                                uint16_t h = (y + sprite_get_h(sp) > get_YRes()) ? (get_YRes() - y) : (sprite_get_h(sp));
476 479

  
480
                                if (x_clear < get_XRes() && y_clear < get_YRes()) {
481
                                    if (draw_rectangle(x_clear,y_clear,w,h, BLACK)) {
482
                                        if (vg_exit()) {
483
                                            printf("%s: vg_exit failed to exit to text mode.\n", __func__);
484
                                        }
485
                                        if (free_memory_map()) {
486
                                            printf("%s: lm_free failed\n", __func__);
487
                                        }
488
                                        return 1;
489
                                    }
490
                                }
491
                            }
492
                            if(vy) {
493
                                uint16_t x_clear = x;
494
                                uint16_t y_clear = (vy > 0 ? y : y+sprite_get_h(sp)+vy);
495
                                uint16_t w = (x + sprite_get_w(sp) > get_XRes()) ? (get_XRes() - x) : (sprite_get_w(sp));
496
                                uint16_t h = (y + abs(v) > get_YRes()) ? (get_YRes() - y) : (abs(v));
497

  
498
                                if (x_clear < get_XRes() && y_clear < get_YRes()) {
499
                                    if (draw_rectangle(x_clear,y_clear,w,h, BLACK)) {
500
                                        if (vg_exit()) {
501
                                            printf("%s: vg_exit failed to exit to text mode.\n", __func__);
502
                                        }
503
                                        if (free_memory_map()) {
504
                                            printf("%s: lm_free failed\n", __func__);
505
                                        }
506
                                        return 1;
507
                                    }
508
                                }
509
                            }
510

  
477 511
                            vx = (vx > 0 ? min(vx, xf-x) : max(vx, xf-x) );
478 512
                            vy = (vy > 0 ? min(vy, yf-y) : max(vy, yf-y) );
479 513
                            x += vx;
480 514
                            y += vy;
481 515
                            sprite_set_pos(sp,x,y);
482
                            //clear_screen();
483 516
                            sprite_draw(sp);
484 517

  
485 518
                            no_interrupts = 0;

Also available in: Unified diff