Revision 137
corrected problem in 5th function
lab5.c | ||
---|---|---|
385 | 385 |
return 1; |
386 | 386 |
} |
387 | 387 |
/// |
388 |
uint16_t Dx = xf-xi;
|
|
389 |
uint16_t Dy = yf-yi;
|
|
390 |
if(xi != xf) Dy = 0;
|
|
391 |
else Dx = 0;
|
|
392 |
uint16_t v = (speed <= 0 ? 1 : speed); |
|
388 |
int16_t v = (speed <= 0 ? 1 : speed);
|
|
389 |
int16_t vx = 0, vy = 0;
|
|
390 |
if(xi != xf) vx = v;
|
|
391 |
else vy = v;
|
|
392 |
|
|
393 | 393 |
uint16_t Nt = (speed < 0 ? -speed : 1); |
394 | 394 |
uint32_t ticks_per_frame = frequency/(uint32_t)fr_rate; |
395 | 395 |
|
... | ... | |
417 | 417 |
if(no_interrupts == 0){ |
418 | 418 |
i = (i+1)%Nt; |
419 | 419 |
if(i == 0){ |
420 |
if(vx) draw_rectangle(min(x-v,x),y , abs(v) , sprite_get_h(sp), 0); |
|
421 |
if(vy) draw_rectangle(x ,min(y-v,y),sprite_get_w(sp), abs(v) , 0); |
|
420 | 422 |
sprite_set_pos(sp,x,y); |
421 | 423 |
sprite_draw(sp); |
422 |
if(Dx) draw_rectangle(min(x,x+v),y , abs(v) , sprite_get_h(sp), 0); |
|
423 |
if(Dy) draw_rectangle(x ,min(y,y+v),sprite_get_w(sp), abs(v) , 0); |
|
424 |
if(Dx) x += v; |
|
425 |
if(Dy) y += v; |
|
426 |
if(Dx && (x-xi)*(x-xf) >= 0){ x = xf; Dx = 0; } |
|
427 |
if(Dy && (y-yi)*(y-yf) >= 0){ y = yf; Dy = 0; } |
|
424 |
vx = (vx > 0 ? min(vx, xf-x) : max(vx, xf-x) ); |
|
425 |
vy = (vy > 0 ? min(vy, yf-y) : max(vy, yf-y) ); |
|
426 |
x += vx; |
|
427 |
y += vy; |
|
428 | 428 |
} |
429 | 429 |
} |
430 | 430 |
timer_int_handler(); |
... | ... | |
437 | 437 |
} else { /* received standart message, not a notification */ |
438 | 438 |
/* no standart message expected: do nothing */ |
439 | 439 |
} |
440 |
if(good == 0) continue; |
|
441 | 440 |
} |
442 | 441 |
|
443 | 442 |
if (unsubscribe_interrupt(&kbc_id)) { |
... | ... | |
448 | 447 |
return 1; |
449 | 448 |
}; |
450 | 449 |
|
450 |
if (unsubscribe_interrupt(&timer_id)) return 1; |
|
451 |
|
|
451 | 452 |
if (vg_exit()) { |
452 | 453 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
453 | 454 |
if (free_memory_map()) printf("%s: lm_free failed\n", __func__); |
Also available in: Unified diff