Murugan.com
Murugan Andezuthu Dharmaratnam

  |  HOME   |  BLOG   |  TWITTER   |  ARTICLES   |  8086  |  C++   |  VC++   |  ASP .NET   |  VB .NET   |  JAVA SCRIPT   |  MS SQL   |  MY   |  VIDEOS   |  DOWNLOADS   |  CONTACT ME   |  



8086 Game Programming Collusion Detection

Home   8086   8086 Game Programming Collusion Detection         


;---------------------------------------------------------------------
; CollusionDetectionProc: Wrote this for a simple car racing game
;   I/P :
;       
;   Description : Collusion Routine checks to see if two rectangles
;                 have collided . 
;---------------------------------------------------------------------

CollusionDetectionProc proc near
 mov CollusionFlag,0     ; Set that the objects have not Collided

; Compare the Object 2 Rectangle (Left Top Point ) With
; Object 1 Rectangle 
  mov ax,Object2Left
  cmp ax,Object1Left
  jle  Object2NoCollusionLT
  mov ax,Object2Top
  cmp ax,Object1Top
  jle  Object2NoCollusionLT
  mov ax,Object2Left
  cmp ax,Object1Right
  jge  Object2NoCollusionLT
  mov ax,Object2Top
  cmp ax,Object1Bottom
  jge  Object2NoCollusionLT
  mov CollusionFlag,1     ; Set that the objects have Collided
Object2NoCollusionLT:
;----------------
;Can Add A Jump Instuction Here Later For Speed 
;----------------
; Compare the Object 2 Rectangle (Right Top Point ) With
; Object 1 Rectangle
  mov ax,Object2Right
  cmp ax,Object1Left
  jle  Object2NoCollusionRT
  mov ax,Object2Top
  cmp ax,Object1Top
  jle  Object2NoCollusionRT
  mov ax,Object2Right
  cmp ax,Object1Right
  jge  Object2NoCollusionRT
  mov ax,Object2Top
  cmp ax,Object1Bottom
  jge  Object2NoCollusionRT
  mov CollusionFlag,1     ; Set that the objects have Collided
Object2NoCollusionRT:
;----------------
;Can Add A Jump Instuction Here Later For Speed 
;----------------
; Compare the Object 2 Rectangle (Left Bottom Point ) With
; Object 1 Rectangle
  mov ax,Object2Left
  cmp ax,Object1Left
  jle  Object2NoCollusionLB
  mov ax,Object2Bottom
  cmp ax,Object1Top
  jle  Object2NoCollusionLB
  mov ax,Object2Left
  cmp ax,Object1Right
  jge  Object2NoCollusionLB
  mov ax,Object2Bottom
  cmp ax,Object1Bottom
  jge  Object2NoCollusionLB
  mov CollusionFlag,1     ; Set that the objects have Collided
Object2NoCollusionLB:
;----------------
;Can Add A Jump Instuction Here Later For Speed 
;----------------
; Compare the Object 2 Rectangle (Right Bottom Point ) With
; Object 1 Rectangle
  mov ax,Object2Right
  cmp ax,Object1Left
  jle  Object2NoCollusionRB
  mov ax,Object2Bottom
  cmp ax,Object1Top
  jle  Object2NoCollusionRB
  mov ax,Object2Right
  cmp ax,Object1Right
  jge  Object2NoCollusionRB
  mov ax,Object2Bottom
  cmp ax,Object1Bottom
  jge  Object2NoCollusionRB
  mov CollusionFlag,1     ; Set that the objects have Collided
Object2NoCollusionRB:
;----------------
;Can Add A Jump Instuction Here Later For Speed 
;----------------
;----------------
;Second Rectangle Collusion Detection 
;----------------
; Compare the Object 1 Rectangle (Left Top Point ) With
; Object 2 Rectangle
  mov ax,Object1Left
  cmp ax,Object2Left
  jle  Object1NoCollusionLT
  mov ax,Object1Top
  cmp ax,Object2Top
  jle  Object1NoCollusionLT
  mov ax,Object1Left
  cmp ax,Object2Right
  jge  Object1NoCollusionLT
  mov ax,Object1Top
  cmp ax,Object2Bottom
  jge  Object1NoCollusionLT
  mov CollusionFlag,1     ; Set that the objects have Collided
Object1NoCollusionLT:
;----------------
;Can Add A Jump Instuction Here Later For Speed 
;----------------
; Compare the Object 1 Rectangle (Right Top Point ) With
; Object 2 Rectangle
  mov ax,Object1Right
  cmp ax,Object2Left
  jle  Object1NoCollusionRT
  mov ax,Object1Top
  cmp ax,Object2Top
  jle  Object1NoCollusionRT
  mov ax,Object1Right
  cmp ax,Object2Right
  jge  Object1NoCollusionRT
  mov ax,Object1Top
  cmp ax,Object2Bottom
  jge  Object1NoCollusionRT
  mov CollusionFlag,1     ; Set that the objects have Collided
Object1NoCollusionRT:
;----------------
;Can Add A Jump Instuction Here Later For Speed 
;----------------
; Compare the Object 1 Rectangle (Left Bottom Point ) With
; Object 2 Rectangle
  mov ax,Object1Left
  cmp ax,Object2Left
  jle  Object1NoCollusionLB
  mov ax,Object1Bottom
  cmp ax,Object2Top
  jle  Object1NoCollusionLB
  mov ax,Object1Left
  cmp ax,Object2Right
  jge  Object1NoCollusionLB
  mov ax,Object1Bottom
  cmp ax,Object2Bottom
  jge  Object1NoCollusionLB
  mov CollusionFlag,1     ; Set that the objects have Collided
Object1NoCollusionLB:
;----------------
;Can Add A Jump Instuction Here Later For Speed 
;----------------
; Compare the Object 1 Rectangle (Right Bottom Point ) With
; Object 2 Rectangle
  mov ax,Object1Right
  cmp ax,Object2Left
  jle  Object1NoCollusionRB
  mov ax,Object1Bottom
  cmp ax,Object2Top
  jle  Object1NoCollusionRB
  mov ax,Object1Right
  cmp ax,Object2Right
  jge  Object1NoCollusionRB
  mov ax,Object1Bottom
  cmp ax,Object2Bottom
  jge  Object1NoCollusionRB
  mov CollusionFlag,1     ; Set that the objects have Collided
Object1NoCollusionRB:
;----------------
;Can Add A Jump Instuction Here Later For Speed 
;----------------
   ret
CollusionFlag   db 0
Object1Left     dw 0
Object1Top      dw 0
Object1Right    dw 0
Object1Bottom   dw 0
Object2Left     dw 0
Object2Top      dw 0
Object2Right    dw 0
Object2Bottom   dw 0
endp

hextoasc proc near                 ;AX input , si point result storage addres
        push ax bx cx dx si di bp es
        mov cx,00h
        mov bx,0ah
        hexloop1:
                mov dx,0
                div bx
                add dl,'0'
                push dx
                inc cx
                cmp ax,0ah
                jge hexloop1
                add al,'0'
                mov [si],al
        hexloop2:
                pop ax
                inc si
                mov [si],al
                loop hexloop2
                inc si
                mov al,'$'
                mov [si],al
                pop es bp di si dx cx bx ax
                ret
endp

Compile using: tasm filename.asm
link: tlink /t filename





  |  HOME   |  BLOG   |  TWITTER   |  ARTICLES   |  8086  |  C++   |  VC++   |  ASP .NET   |  VB .NET   |  JAVA SCRIPT   |  MS SQL   |  MY   |  VIDEOS   |  DOWNLOADS   |  CONTACT ME   |  

Copyright 2009 @ Murugan Andezuthu Dharmaratnam