Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user tubesockor ! (Registered 2024-05-12) You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Stopping a sprite when hitting background
2004-07-27 08:49
Richard

Registered: Dec 2001
Posts: 619
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.
 
... 8 posts hidden. Click here to view all posts....
 
2004-07-29 15:57
Richard

Registered: Dec 2001
Posts: 619
Quote: Just to add a question to rich about my code. where on the sprite does it hit the char?



The top of the sprite hits the bottom of the charset and this is a sort of collision.
2004-07-29 16:51
Kenho
Account closed

Registered: Jan 2003
Posts: 26
Thanks for your additions Oswald!

Now its a really great collission routine :-)

edit: cannot get it to work correctly.... i´m lame :-)

2004-07-29 18:21
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
2004-07-29 18:25
Richard

Registered: Dec 2001
Posts: 619
Same with me....
2004-07-29 19:28
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
2004-07-30 08:05
Oswald

Registered: Apr 2002
Posts: 5025
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
2004-07-30 11:23
Kenho
Account closed

Registered: Jan 2003
Posts: 26
Really nice Oswald :-) i couldnt stand that lousy variable solution i made either :-)

2004-07-30 12:02
Oswald

Registered: Apr 2002
Posts: 5025
to optimize it even more :) :

instead of selfmod and the 9 bit adc:

tya
clc
adc #$28-2
tay

=)

(y will never overflow)
2005-02-19 13:07
Richard

Registered: Dec 2001
Posts: 619
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.

2007-07-17 18:04
Richard

Registered: Dec 2001
Posts: 619
(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
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
KAL_123
E$G/hOKUtO fOrcE
El Jefe/Slackers
Guests online: 124
Top Demos
1 13:37  (9.8)
2 Next Level  (9.8)
3 Mojo  (9.7)
4 Coma Light 13  (9.7)
5 Edge of Disgrace  (9.6)
6 Comaland 100%  (9.6)
7 No Bounds  (9.6)
8 Uncensored  (9.6)
9 Wonderland XIV  (9.6)
10 Multiverse 100%  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Layers  (9.6)
5 Copper Booze  (9.5)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Rainbow Connection  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Booze Design  (9.3)
3 Nostalgia  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Original Suppliers
1 Black Beard  (9.7)
2 Derbyshire Ram  (9.5)
3 hedning  (9.2)
4 Baracuda  (9.1)
5 Jazzcat  (8.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.267 sec.