Startsidan  ▸  Texter  ▸  Teknikblogg

Anders Hesselbom

Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.

Collision detection

2011-04-01

A nice and quick way to create two filled sprites (sprite 1 and 2) is to enter the monitor and type:

F 0E00 0E3E FF
F 0E3F 0E7E FF

Of course you can fill both at once, but this the above code nicely declares the two memory areas I am using in this example. Now, let’s write a simple Basic program to fire the two sprites so that they collide now and then. This will make one sprite white and the other cyan, and fire the movements.

10 SPRITE 1, 1, 2, 0
20 MOVSPR 1, 100, 100
30 MOVSPR 1, 90#1
40 SPRITE 2, 1, 2, 0
50 MOVSPR 2, 100, 115
60 MOVSPR 2, 270#1

To detect collision between the two sprites, we can use the BUMP function. BUMP(1) returns a bit pattern telling us what sprites has collided, and BUMP(2) returns a bit pattern that tells us what sprites has collided with static graphics on screen. We would expect BUMP(1) to return 3 if sprite 1 and 2 is colliding, given that no other sprites are colliding as well, because the binary number 00000011 represents the decimal number 3. And indeed. Add these two lines to your program to see what BUMP(1) returns:

70 PRINT BUMP(1)
80 GOTO 70

To interrupt the program, press RunStop. If you are using the VICE emulator, that key might be mapped to the Escape key. BUMP(1) is actually just returning the bit pattern in the byte located at D01E, so BUMP(1) is equivalent to PEEK(53278).

Categories: Geeky

Tags: C128

Leave a Reply

Your email address will not be published. Required fields are marked *



En kopp kaffe!

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!

Bjud på en kopp kaffe!

Om...

Kontaktuppgifter, med mera, finns här.

Följ mig

Twitter Instagram
GitHub RSS

Public Service

Folkbildning om public service.

Hem   |   linktr.ee/hesselbom   |   winsoft.se   |   80tal.se   |   Filmtips