Subversion Repositories Kolibri OS

Rev

Rev 109 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. lang equ ru
  2.  
  3. ;
  4. ;   Assembler
  5. ;     SMALL
  6. ;       CODE
  7. ;         GaMe
  8. ;           Libary
  9. ;
  10. ;   Ver 0.05
  11. ;
  12.  
  13. ; game_collision_2d - get collision of two 2d rectangles
  14. ; result of collision test placed in CF.
  15. ; if CF = 1, objects is collided
  16. _1dbounce_count=0;
  17. macro game_collision_2d xy1,wh1,xy2,wh2  ;img1_off,x1,y1,img2_off,x2,y2 ;,otv
  18. {
  19.     movt eax,xy1
  20.     movt ebx,wh1
  21.     movt ecx,xy2
  22.     movt edx,wh2
  23.     call game_collision_proc
  24.  
  25. if ~ defined game_collision_used
  26. game_collision_used equ 1
  27.    jmp exit
  28.    ; eax = x1*65536+y1
  29.    ; ebx = w1*65536+h1
  30.    ; ecx = x2*65536+y2
  31.    ; edx = w2*65536+h2
  32. game_collision_proc:
  33.    ; y h test
  34.    call _1dbounce
  35.    jnc @f
  36.    ; x w test
  37.    shr eax,16 ;eax,y1 ;
  38.    shr ebx,16 ;mov ebx,[img1_off+4] ;h1
  39.    shr ecx,16 ;mov ecx,y2 ;
  40.    shr edx,16 ;mov edx,[img2_off+4] ;h2
  41.    call _1dbounce
  42. @@:
  43.    ret
  44. ; ax - x1, bx - w1, cx - x2, dx - w2
  45. ; or
  46. ; ax - y1, bx - h1, cx - y2, dx - h2
  47. ; if collision ecx is incremented
  48. _1dbounce:
  49.    cmp cx,ax   ; if x2 < x1 jmp anot
  50.    jb  anot
  51.    add ax,bx
  52.    cmp ax,cx   ; if x1+xs <= x2 not coll
  53.    jbe not_coll
  54. coll:
  55.    stc           ; CF = 1
  56.    ret
  57. anot:
  58.    add cx,dx
  59.    cmp cx,ax   ; x2 + xs2 > x1
  60.    ja  coll
  61. not_coll:
  62.    clc           ; CF = 0
  63.    ret
  64. exit:
  65.  
  66. end if
  67. }
  68.  
  69. ;  approxto
  70. macro approxto value,target_value,step
  71. {
  72. local plus,minus,equal
  73.     mov eax,target_value
  74.     cmp value,eax
  75.     je  equal
  76.     mov eax,step
  77.     ja  minus
  78. plus:
  79.     add value,eax
  80.     jmp equal
  81. minus:
  82.     sub value,eax
  83. equal:
  84. }
  85.  
  86. macro clamp min,max,arg
  87. {
  88. local gr,low,norm
  89.     mov eax,max
  90.     cmp arg,eax
  91.     jg  gr
  92.     mov eax,min
  93.     cmp arg,eax
  94.     jnl norm
  95. gr:
  96. low:
  97.     mov arg,eax
  98. norm:
  99. }
  100.