Author Topic: Collision Detection  (Read 1805 times)

0 Members and 1 Guest are viewing this topic.

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.796
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1033
  • Likes Given: 1747
Collision Detection
« on: 11:48, 14 January 14 »
I've rigged up this little example of a moving ship which moves through my ship (not going anywhere) and as it does the test comes into play to register on the Left Side as the moving ship travels through it, once it's completed the reverse is carried out which triggers the test for the lower side of the ship passing through the lower corner, however what's unusual with that test is a line below the actual moving ship is deleting my drawn ship and yet the character matrix for that pattern in the Amstrad Manual suggests the short 3 pixel stem at the bottom of that pattern matrix is the bottom of it yet TAG is deleting the line below it.

Code: [Select]
10 MODE 1:INK 1,26
20 GOSUB 2000
30 x=400:y=178:dir=2
40 LOCATE 20,1:PRINT "Intruder Base:"
50 LOCATE 1,1:PRINT "Intruder Top:"
60 WHILE 1
70 oldx=x:oldy=y
80 TAG:MOVE x,y:PRINT CHR$(226);:TAGOFF
90 x=x-2
100 LOCATE 35,1:PRINT TEST(x-6,y-14)
110 LOCATE 15,1:PRINT TEST(x-2,y)
120 IF x=250 THEN GOSUB 1000
130 IF y=200 AND dir=2 THEN y=212:dir=-2:GOSUB 2000
140 IF y=190 AND dir=-2 THEN y=178:dir=2:GOSUB 2000
150 WEND
1000 TAG
1010 MOVE oldx,oldy
1020 PRINT CHR$(32);
1030 TAGOFF
1040 x=400
1050 oldy=y
1060 y=y+dir
1070 RETURN
2000 PLOT 320,198,1
2010 DRAWR 10,-10
2020 DRAWR -10,-10
2030 DRAWR 0,20
2040 RETURN
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline Bruce Abbott

  • CPC664
  • ***
  • Posts: 53
  • Country: nz
  • Liked: 84
  • Likes Given: 0
Re: Collision Detection
« Reply #1 on: 10:14, 18 January 14 »
Congratulations, you found an error in the manual!

CHR$(226) is supposed to be the playing card 'Clubs' symbol. The manual shows a 5 pixel wide bar at the top, but this is wrong. The rest of the pattern should be moved up 1 line and the last line is blank (even though it is blank, it will still wipe out anything under it).
« Last Edit: 10:28, 18 January 14 by Bruce Abbott »

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.796
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1033
  • Likes Given: 1747
Re: Collision Detection
« Reply #2 on: 22:55, 18 January 14 »
Hmmm, so that explains why the bottom line was being deleted, just assumed the manual was correct and I had the right symbol.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.796
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1033
  • Likes Given: 1747
Re: Collision Detection
« Reply #3 on: 08:14, 19 January 14 »
Two more programs I've added carry out a 3 Point Collision Test using the Point Junctions of the Moving image to detect where it passes through the other image seems to produce a fairly accurate way of detecting where collision has occurred.

Initially I made 3PCOLSON.BAS which produces a flickery moving ship which works well, however I've made 3PCLSN2.BAS to simulate something with less flicker if anyone were interested, in that example I've removed the WAIT FRAME FLYBACK which seems to work well without.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.796
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1033
  • Likes Given: 1747
Re: Collision Detection
« Reply #4 on: 10:29, 08 August 17 »
I made another example relating to Collision Detection which I'm popping in here. This routine has some similarities to the last example I posted in the Silly Programming Ideas Thread (Attack of the Moving Shapes), though on this occasion I'm moving 3 Objects, a white border is drawn and 100 or so White Squares are randomly drawn onscreen. Initially if the Objects are drawn over the White Squares they'll move on til they find an open area and bounce off the Squares, the moving objects have their own set directions pretty much like a nasty from Roland in Time or Monty on the Run.



Code: [Select]
100 MODE 0:CALL &BC02:INK 0,11:BORDER 11:INK 1,26:PEN 1
110 FOR y=1 TO 25
120   LOCATE 1,y
130   PRINT CHR$(143);
140   LOCATE 20,y
150   PRINT CHR$(143);
160 NEXT y
170 LOCATE 1,1
180 PRINT STRING$(20,CHR$(143));
190 LOCATE 1,25
200 PRINT STRING$(20,CHR$(143));
210 FOR b=1 TO 100
220   RANDOMIZE TIME:RANDOMIZE RND
230   x=(RND*17)+2
240   y=(RND*23)+2
250   LOCATE x,y
260   PRINT CHR$(143);
270 NEXT b
280 PRINT CHR$(23)+CHR$(1); ' XOR Mode
290 w=320:z=350:u=288:v=238:s=96:t=94
300 a=32 :b=16 :c=a              :d=a
310 c=5:x=w:y=z:GOSUB 1000:x=u:y=v:c=1:GOSUB 1000:x=s:y=t:c=2:GOSUB 1000
320 LOCATE 1,1
330 WHILE INKEY(18)<>0 ' Enter/Return to Exit
340   x=w:y=z:c=5:z=z+b:GOSUB 1000:x=w:y=z:GOSUB 1000
350   IF TEST(w,z+16)=1 THEN b=-16 ELSE IF TEST(w,z-16)=1 THEN b=16
360   x=u:y=v:c=1:u=u+a:GOSUB 1000:x=u:y=v:GOSUB 1000
370   IF TEST(u+32,v)=1 THEN a=-32 ELSE IF TEST(u-32,v)=1 THEN a=32
380   x=s:y=t:c=2:s=s+d:GOSUB 1000:x=s:y=t:GOSUB 1000
390   IF TEST(s+32,t)=1 THEN d=-32 ELSE IF TEST(s-32,t)=1 THEN d=32
400 WEND
410 WHILE INKEY$<>"":WEND:MODE 2:END 
1000 PLOT -2,-2,c:MOVE x,y
1010 TAG
1020 PRINT CHR$(225);
1030 TAGOFF
1040 RETURN




[attachimg=1]



* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.796
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1033
  • Likes Given: 1747
Re: Collision Detection
« Reply #5 on: 13:57, 27 May 19 »

This following example I'm adding to this thread deals in having a character which follows your character around the screen, I'm referring to it as "Zombie Style" since it clearly follows your character, this example comes from the Lawn Mower Simulator from AA52 Type-Ins, which plays the dreaded person you must avoid with your mower. At this level though, I have not added the screen data, so no array has been setup let along any checks. The main thing I have here from the Lawn Mower Simulator is the "in" variable in line 120, this works as a real number, the larger the number is divided by 10 the faster the Obstacle moves.

Code: [Select]
100 MODE 0:INK 0,11:INK 1,26:INK 2,3,6:INK 3,25
110 LOCATE 1,25:PEN 3:PRINT CHR$(248)
120 x=1:y=25:x1=1:y1=1:ox=x:oy=y:in=1/10
130 WHILE 1
140   IF INKEY(1)=0 AND x<20 THEN ox=x:oy=y:GOSUB 1000:x=x+1:GOSUB 1010
150   IF INKEY(8)=0 AND x>1 THEN ox=x:oy=y:GOSUB 1000:x=x-1:GOSUB 1010
160   IF INKEY(0)=0 AND y>1 THEN oy=y:ox=x:GOSUB 1000:y=y-1:GOSUB 1010
170   IF INKEY(2)=0 AND y<25 THEN oy=y:ox=x:GOSUB 1000:y=y+1:GOSUB 1010
180   IF x1<x THEN dix=in
190   IF x1>x THEN dix=-in
200   IF y1<y THEN diy=in
210   IF y1>y THEN diy=-in
220   x2=x1:y2=y1:x1=x1+dix:y1=y1+diy
230   IF x1<>x2 OR y1<>y2 THEN LOCATE x2,y2:PRINT" ";
240   LOCATE x1,y1:PEN 2:PRINT CHR$(225);
250   IF x=ROUND(x1) AND y=ROUND(y1) THEN LOCATE 8,10:PEN 1:PRINT"Rats!!":END
260 WEND
1000 LOCATE ox,oy:PRINT" ";:RETURN
1010 LOCATE x,y:PEN 3:PRINT CHR$(248);:RETURN
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3