Jump to content
IGNORED

What's wrong with my collision detection?


Recommended Posts

I was trying to experiment with collision detection, and it does not seem to be working. Im trying to detect the colision of the sprite and the play field. I want the sprite to start going to the left when it hits the wall. here is my code.

 

	processor 6502
include "vcs.h"
org $F000


START
lda #0
tax
tay
RAMCLR
sta 0,x
inx
bne RAMCLR

lda #%11110000
sta HMP0

lda #%00000001
sta CTRLPF

lda #%00010000
sta COLUPF

STARTOFFRAME

lda #0 
sta VBLANK

lda #2 
sta VSYNC

sta WSYNC
sta WSYNC
sta WSYNC

lda #0
sta VSYNC

ldy #37
Verticalblank
dey
sta WSYNC
bne Verticalblank

lda #%11110000
sta COLUBK
lda #%00010000
sta PF0

ldy #91
topy

sta WSYNC
dey
bne topy


ldy #9
ldx #0
Picture

lda Sprite,X
sta GRP0

inx

dey
sta WSYNC
bne Picture

lda #0
sta GRP0


ldy #92
topx
sta WSYNC
dey
bne topx

lda #0
sta PF0

lda #%01000010
sta VSYNC

lda #0
sta COLUBK
sta PF1
sta $82
sta $83



ldy #29
Overscan
dey
sta WSYNC
bne Overscan

lda CXP0FB
cmp #%10000000
bne nocx

sta HMCLR
repeat 14
	nop
repend
lda #%00010000
sta HMP0
sta CXCLR

nocx
sta WSYNC
sta HMOVE

dec $81
lda $81
sta $80


jmp STARTOFFRAME







Sprite
.byte #%00011000
.byte #%00111100
.byte #%01111110
.byte #%01110000
.byte #%01100000
.byte #%01110000
.byte #%01111110
.byte #%00111100
.byte #%00011000






org $FFFA
.word START
.word START
.word START

Link to comment
Share on other sites

It's the way you're testing the value-- "cmp #%10000000". I would have thought that would work, but after watching it in the debugger, I see that "lda CXP0FB" results in $02 if there's no collision, or $82 if there *is* a collision (between player 0 and the playfield). So you can change it to any of the following:

 

   lda CXP0FB
  cmp #%10000010
  bne nocx

 

   lda CXP0FB
  AND #%10000000
  beq nocx

 

   lda CXP0FB
  bpl nocx

 

   bit CXP0FB; <-- this is best if you ask me, A is unchanged
  bpl nocx; and you can test bit 6 and 7 at the same time

It looks to me like the $02 is coming from the address being read-- $02-- presumably because "lda CXP0FB" is setting only bits 6 and 7, and leaving the other bits alone (?). If you change it to "lda CXP1FB" the results are $03, $43, $83, or $C3.

 

Michael

Edited by SeaGtGruff
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...