Subversion Repositories Kolibri OS

Rev

Rev 109 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 109 Rev 9241
Line 5... Line 5...
5
;     SMALL
5
;     SMALL
6
;       CODE
6
;       CODE
7
;         GaMe
7
;         GaMe
8
;           Libary
8
;           Libary
9
;
9
;
-
 
10
;   Ver 0.05
-
 
11
;
-
 
12
 
-
 
13
; game_collision_2d - get collision of two 2d rectangles
10
;   Ver 0.03 By Pavlushin Evgeni (RUSSIA)
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
{
11
;   www.waptap@mail.ru
19
    movt eax,xy1
-
 
20
    movt ebx,wh1
-
 
21
    movt ecx,xy2
-
 
22
    movt edx,wh2
-
 
23
    call game_collision_proc
Line -... Line 24...
-
 
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
12
 
32
game_collision_proc:
-
 
33
   ; y h test
-
 
34
   call _1dbounce
13
;InfoList
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 ;
14
;0.01 correct
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
15
;0.02 control ~14.05.2004
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
Line -... Line 64...
-
 
64
exit:
-
 
65
 
Line 16... Line 66...
16
;0.03 all macros optimized by halyavin, add at ~07.06.2004
66
end if
17
 
67
}
18
 
68
 
19
;         corectiryemoe,corectnoe,step
69
;  approxto
20
macro correct arg1,arg2,arg3
70
macro approxto value,target_value,step
21
{
71
{
22
local plus,minus,equal
72
local plus,minus,equal
23
    mov eax,arg2
73
    mov eax,target_value
24
    cmp arg1,eax
74
    cmp value,eax
25
    je  equal
75
    je  equal
26
    mov eax,arg3   
76
    mov eax,step
27
    ja  minus
77
    ja  minus
28
plus:
78
plus:
29
    add arg1,eax   
79
    add value,eax
30
    jmp equal
80
    jmp equal
31
minus:
81
minus:
Line 32... Line 82...
32
    sub arg1,eax  
82
    sub value,eax
33
equal:
83
equal:
34
}
84
}
35
 
85
 
36
macro control min,max,arg
86
macro clamp min,max,arg
37
{
87
{