| | Richard
Registered: Dec 2001 Posts: 621 |
Stopping a sprite when hitting background
How do I stop a sprite from hitting the background, and let the sprite move around the screen, avoiding contact. This is mainly because my games usually make the player die when it touches the background, which I think gets too repetitive. Reason: I don't know how to stop the player from walking when touching a wall - without the player freezing when you try to move it away from the wall.
The collision routine, which I usually use is (As on Lemon64):
BGRCOL LDA $D01F
LSR A
BCC NOBGCOL
DEC STATUS
LDA STATUS
CMP #$00
BNE NOBGCOL
JMP GAMEOVER
NOBGCOL RTS
Please help. |
|
... 10 posts hidden. Click here to view all posts.... |
| | ToD Account closed
Registered: Dec 2003 Posts: 10 |
Quote: Thanks for your additions Oswald!
Now its a really great collission routine :-)
edit: cannot get it to work correctly.... i´m lame :-)
i cant get it to work aswell , seems way out |
| | Richard
Registered: Dec 2001 Posts: 621 |
Same with me.... |
| | Kenho Account closed
Registered: Jan 2003 Posts: 26 |
Some minor changes:
xtmp .byte 0
ldx #3
sty xtmp ;
lda xtmp
clc
adc #4 ;(if x xpanded, #3 otherwize)
sta xtmp
_l1
lda ($70),y
cmp #32
bne _hit
iny
cpy xtmp
bne _l1
lda $70
clc
adc #$28 ;next row
sta $70
bcc _l2
inc $71
_l2
dey
dey
dey
dey ; if x expanded
dex
bne _l1
rts
_hit
inc $d020
rts
|
| | Oswald
Registered: Apr 2002 Posts: 5094 |
kenho: oh yeah, my code had some serious bugs, but this happens when one writes code from the top of his head, without any testing :) Sorry!
one thing: X expanded sprites are 6 chars wide, not 4 :)
one word to the part calculating the positon on the character screen:
its a very common way to calculate the onscreen position like that. But you can make it even faster. The table could be made so, that you dont need the sec sbc lsr lsr lsr before.. just ldy $d001 lda tablelo,y sta $70 lda tablehi,y sta $71, well depends how much speed you need :)
a bit of optimization follows, as I cannot stand not to brush up the code:)
ldx #3
sty selfmod+1
_l1
lda ($70),y
cmp #32
bne _hit
iny
lda ($70),y
cmp #32
bne _hit
iny
lda ($70),y
cmp #32
bne _hit
selfmod ldy #$00
lda $70
clc
adc #$28 ;next row
sta $70
bcc _l2
inc $71
_l2
dex
bne _l1
rts
_hit
inc $d020
rts
|
| | Kenho Account closed
Registered: Jan 2003 Posts: 26 |
Really nice Oswald :-) i couldnt stand that lousy variable solution i made either :-)
|
| | Oswald
Registered: Apr 2002 Posts: 5094 |
to optimize it even more :) :
instead of selfmod and the 9 bit adc:
tya
clc
adc #$28-2
tay
=)
(y will never overflow) |
| | Richard
Registered: Dec 2001 Posts: 621 |
I have been following a routine which Kenho had supplied, on how to make a sprite collide into the background. This routine seems to work quite nicely if the sprite hits 'the A' character.
Source wrote:
;The sprite collides into the background, therefore we have a sprite to background collision Smile
backcollision: lda sprtpos+1
sec
sbc #$32
lsr
lsr
lsr
tay
lda scrlo,y
sta $70
lda scrhi,y
sta $71
lda sprtpos+0
sec
sbc #$0c
lsr
lsr
tay
ldx #3
sty _selfmod+1
_l1: lda ($70),y
cmp #32
bne _hit
iny
lda ($70),y
cmp #32
bne _hit
iny
lda ($70),y
cmp #32
bne _hit
_selfmod: ldy #$00
lda $70
clc
adc #$28 ;next row
sta $70
bcc _l2
inc $71
_l2: dex
bne _l1
rts
_hit: inc $d027
rts
xtmp: dc.b 00
killerchars: dc.b $10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$1a,$1b,$1c,$1d,$1e,$1f
dc.b $20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30,$31,$32,$33,$34,$35
dc.b $36,$37,$38,$39,$3a,$3b,$3c,$3d,$3e,$3f,$40,$41,$42,$43,$44,$45
dc.b $46,$47,$48,$49,$4a,$4b,$4c,$4d,$4e,$4f,$50,$51,$52,$53,$54,$55
dc.b $56,$57,$58,$59,$5a,$5b,$5c,$5d,$5e,$5f,$60,$61,$62,$63,$64,$65
dc.b $66,$67,$68,$69,$6a,$6b,$6c,$6d,$6e,$6f,$70,$71,$72,$73,$74,$75
dc.b $76,$77,$78,$79,$7a,$7b,$7c,$7d,$7e,$7f,$80,$81,$82,$83,$84,$85
dc.b $86,$87,$88,$90,$8a,$8b,$8c,$8d,$8e,$8f,$90,$91,$92,$93,$94,$95
dc.b $96,$97,$98,$99,$9a,$9b,$9c,$9d,$9e,$9f,$a0,$a1,$a2,$a3,$a4,$a5
dc.b $a6,$a7,$a8,$a9,$aa,$ab,$ac,$ad,$ae,$af,$b0,$b1,$b2,$b3,$b4,$b5
dc.b $b6,$b7,$b8,$b9,$ba,$bb,$bc,$bd,$be,$bf,$c0,$c1,$c2,$c3,$c4,$c5
dc.b $c6,$c7,$c8,$c9,$ca,$cb,$cc,$cd,$ce,$cf,$d0,$d1,$d2,$d3,$d4,$d5
dc.b $d6,$d7,$d8,$d9,$da,$db,$dc,$dd,$de,$df,$e0,$e1,$e2,$e3,$e4,$e5
dc.b $e6,$e7,$e8,$e9,$ea,$eb,$ec,$ed,$ee,$ef,$f0,$f1,$f2,$f3,$f4,$f5
dc.b $f6,$f7,$f8,$f9,$fa,$fb,$fc,$fd,$fe,$ff,$ff,$ff,$ff,$ff,$ff,$ff
scrhi: dc.b $44,$44,$44,$44,$44,$44,$44,$45,$45,$45,$45,$45,$45,$46,$46,$46,$46,$46,$46,$46, $47,$47,$47,$47,$47,$47
scrlo: dc.b $00,$28,$50,$78,$a0,$c8,$f0,$18,$40,$68,$90,$b8,$e0,$08,$30,$58,$80,$a8,$d0,$f8, $20,$48,$70,$98,$c0,$e0
However I am still stuck regarding setting 'kill blocks' for my Real Speed We Need game project. I had to keep resetting the code from how it was, but I would like to import my kill tables into this particular routine, so that if a block is located according to the kill table, the sprite to background collision is detected.
|
| | Richard
Registered: Dec 2001 Posts: 621 |
(Continued from Kehno's example)
Hi again. Oh not again, it is the return of an old topic :P
I am having problems with the sprite/background collision routine.
I'm doing a game, but having problems with the player sprite/background collision.
What I am trying to do is make the sprite stop *by* the rocks (which are built as 2x2 chars). The sprite is full size as 1 filled square. When the player sprite moves from the left to the right hand side of the rock, this works nicely, however, when the player moves from the right, to the left of the rock, it somehow stops on the whole char. The routine looks something like this:
;Player sprite to background collision routines
BACKCOLLISION: LDA OBJPOS+$01
SEC
SBC #$32
LSR
LSR
LSR
TAY
LDA SCRLO,Y
STA $70
LDA SCRHI,Y
STA $71
LDA OBJPOS+$00
SEC
SBC #$0C
LSR
LSR
TAY
LDX #3
STY _SELFMOD+1
_L1: INY
LDA ($70),Y
CMP #65
BEQ _HIT
LDA ($70),Y
CMP #65 ;Player touches the food,
BEQ _HIT; if touched the food is off screen
CMP #66;
BEQ _HIT;
CMP #67;
BEQ _HIT;
CMP #68;
BEQ _HIT;
INY
LDA ($70),Y
CMP #65
BEQ _HIT
CMP #67
BEQ _HIT
CMP #66
BEQ _HIT
CMP #68
BEQ _HIT
CMP #$56 ;Player touches the switch char
BEQ _SWITCH ;if touched, the switch will turn
CMP #$57 ;all the water into food
BEQ _SWITCH
CMP #$58
BEQ _SWITCH
CMP #$59
BEQ _SWITCH
CMP #$4A ;Player touches the water chars
BEQ _WATER ;if the player touches the water
CMP #$4B ;he will drown
BEQ _WATER
CMP #$4C
BEQ _WATER
CMP #$4D
BEQ _WATER
CMP #$4E
BEQ _WATER
CMP #$52 ;Player touches the rock chars
BEQ _ROCK ;if touched, then the player
CMP #$53 ;will stop according to the
BEQ _ROCK ;direction he moves
CMP #$54
BEQ _ROCK
CMP #$55
BEQ _ROCK
INY
JMP _SELFMOD
;LDA ($70),Y
;CMP #16
;BPL _HIT
_SELFMOD:
MODE2: LDY #$00
LDA $70
CLC
ADC #$28 ;NEXT ROW
STA $70
BCC _L2
INC $71
_L2: DEX
BNE _L1
RTS
_WATER: JSR PLAYER_DROWN ;Because player touched water, he drowns
RTS
_HIT: LDA #73
STA ($70),Y
JSR SCORE
JSR ADDFOOD
;CMP #$00
;BEQ LEVELDONE
NO: RTS
_SWITCH JSR WATER_TO_FOOD ;Turn water into food
RTS
_ROCK JSR STOP_AT_ROCK ;Stop player moving
RTS
STOP_AT_ROCK LDA DIRFACE
CMP #$01
BEQ STOPATUP
CMP #$02
BEQ STOPATDOWN
CMP #$03
BEQ STOPATLEFT
CMP #$04
BEQ STOPATRIGHT
RTS
Please can you help me solve this problem, why the sprite stops right in the middle of the rock, when it is supposed to stop right next to it (when moving left)? |
Previous - 1 | 2 - Next | |