Skip to content

Commit

Permalink
Merge pull request #86 from algosup/change-the-strategy-for-ghost-col…
Browse files Browse the repository at this point in the history
…lision

Changed the strategy for ghost collision
  • Loading branch information
Malo-Archimbaud authored Dec 21, 2023
2 parents 46fa3aa + 0d58584 commit 7f5224d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 49 deletions.
102 changes: 54 additions & 48 deletions src/collider.asm
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ section .text
ret

PinkyContact:
mov bx, [strcPinky + posX]
mov ax, [strcPinky + posY]
mov dx, [strcPinky + isChased]
mov [afraid], dx

mov ax, [strcPinky + isChased]
mov [afraid], ax

mov cx, [strcPinky + posX]
mov dx, [strcPinky + posY]
call isThereContact
cmp byte [ghostCollision], 1
jne .noGhostCollision
call ClearPinky
Expand All @@ -42,11 +45,13 @@ section .text
ret
BlinkyContact:
mov bx, [strcBlinky + posX]
mov ax, [strcBlinky + posY]
mov dx, [strcBlinky + isChased]
mov [afraid], dx
mov ax, [strcBlinky + isChased]
mov [afraid], ax

mov cx, [strcBlinky + posX]
mov dx, [strcBlinky + posY]
call isThereContact

cmp byte [ghostCollision], 1
jne .noGhostCollision
call ClearBlinky
Expand All @@ -60,11 +65,13 @@ section .text
ret

InkyContact:
mov bx, [strcInky + posX]
mov ax, [strcInky + posY]
mov dx, [strcInky + isChased]
mov [afraid], dx
mov ax, [strcInky + isChased]
mov [afraid], ax

mov cx, [strcInky + posX]
mov dx, [strcInky + posY]
call isThereContact
cmp byte [ghostCollision], 1
jne .noGhostCollision
call ClearInky
Expand All @@ -78,11 +85,13 @@ section .text
ret
ClydeContact:
mov bx, [strcClyde + posX]
mov ax, [strcClyde + posY]
mov dx, [strcClyde + isChased]
mov [afraid], dx
mov ax, [strcClyde + isChased]
mov [afraid], ax

mov cx, [strcClyde + posX]
mov dx, [strcClyde + posY]
call isThereContact
cmp byte [ghostCollision], 1
jne .noGhostCollision
call ClearClyde
Expand All @@ -95,47 +104,25 @@ section .text
.noGhostCollision:
ret


isThereContact:
; read if a ghost touched pacman (or the reverse)

push ds ; pop at the end
mov ax, [strcPacMan + posX]
mov bx, [strcPacMan + posY]

;calculates the linear position of the ghost (result in ax)
mov cx, SCREEN_WIDTH
mul cx
add ax, bx

;stores the color of pacman into 'ah'
mov di, palette
inc di, ;(add 1 to di) cause '1' is the color of pacman according to the palette of colors for the spritesheet
xor bx, bx
mov bl, [ds:di]

;the destination is 'al'
call AbsoluteDifference
cmp ax, TILE_SIZE
jg .notTouched
;set the source 'ds:si'
push word [ScreenBufferSegment]
pop ds
mov si, ax
mov ax, bx
mov cx, dx
call AbsoluteDifference
cmp ax, TILE_SIZE
jg .notTouched
mov dx, SPRITE_SIZE
.eachLine:
mov cx, SPRITE_SIZE
.eachPixel:
lodsb
cmp al, bl
je .touched
dec cx
jnz .eachPixel
add si, SCREEN_WIDTH - SPRITE_SIZE
dec dx
jnz .eachLine
pop ds
jmp .notTouched

.touched:
pop ds
cmp byte [afraid], 0
je .normalContact
Expand Down Expand Up @@ -184,7 +171,26 @@ section .text
.notTouched:
ret

AbsoluteDifference:
; get the absolute difference between 2 numbers
; parameters :
; ax : number 1
; cx : number 2
; return : ax = absolute difference

sub ax, cx
; get the absolute value of this difference
mov cx, ax
sar cx, 15
xor ax, cx
shr cx, 15
add ax, cx

ret


isColliding:

; Set offset for the corner to check
Expand Down
2 changes: 1 addition & 1 deletion src/constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ endstruc
%define FRAMES_COUNTER_GHOSTS_ANIMATION 6
%define FRAMES_COUNTER_POWER_PELLET_ANIMATION 6

%define SPRITE_SPEED_PIXELS 2
%define SPRITE_SPEED_PIXELS 1

%define NUMBER_OF_PELLETS 260

Expand Down

0 comments on commit 7f5224d

Please sign in to comment.