Project

General

Profile

Revision 134

corrected dragging and flickering. now one or + pixels do not match

View differences:

lab5.c
12 12
#include "kbc.h"
13 13
#include "kbc_macros.h"
14 14
#include "timer.h"
15
#include "utils.h"
15 16

  
16 17
// Any header files included below this line should have been created by you
17 18

  
......
411 412
                case HARDWARE: /* hardware interrupt notification */
412 413
                    if (msg.m_notify.interrupts & timer_irq) { /* subscribed interrupt */
413 414
                        timer_int_handler();
415
                        if(no_interrupts == dt){
416
                            no_interrupts = 0;
417
                            i = (i+1)%Nt;
418
                            if(i == 0 && (dx || dy)){
419
                                if(dx) draw_rectangle(min(x,x+dframe),y              , abs(dframe)    , sprite_get_h(sp), 0);
420
                                if(dy) draw_rectangle(x              ,min(y,y+dframe),sprite_get_w(sp), abs(dframe)     , 0);
421
                                if(dx) x += dframe;
422
                                if(dy) y += dframe;
423
                                if(dx && (x-xi)*(x-xf) >= 0){
424
                                    x = xf;
425
                                    dx = 0;
426
                                }
427
                                if(dy && (y-yi)*(y-yf) >= 0){
428
                                    y = yf;
429
                                    dy = 0;
430
                                }
431
                                sprite_set_pos(sp,x,y);
432
                                sprite_draw(sp);
433
                            }
434
                        }
414 435
                    }
415 436
                    if (msg.m_notify.interrupts & kbc_irq) { /* subscribed interrupt */
416 437
                        kbc_ih();
......
424 445
            /* no standart message expected: do nothing */
425 446
        }
426 447
        if(good == 0) continue;
427
        if(no_interrupts == dt){
428
            no_interrupts = 0;
429
            i = (i+1)%Nt;
430
            if(i == 0){
431
                if(dx) x += dframe;
432
                if(dy) y += dframe;
433
                if((dx < 0 && x <= xf)||
434
                   (dx > 0 && x >= xf)){
435
                    x = xf;
436
                    good = 0;
437
                }
438
                if((dy < 0 && y <= yf)||
439
                   (dy > 0 && y >= yf)){
440
                    y = yf;
441
                    good = 0;
442
                }
443
                sprite_set_pos(sp,x,y);
444
                sprite_draw(sp);
445
            }
446
        }
447 448
    }
448 449

  
449 450
    if (unsubscribe_interrupt(&kbc_id)) {

Also available in: Unified diff