Author Topic: Collision Detection  (Read 14869 times)

0 Members and 1 Guest are viewing this topic.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Collision Detection
« Reply #15 on: June 24, 2018, 12:50:46 am »
GDK?
Logic is the beginning of wisdom.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Collision Detection
« Reply #16 on: June 24, 2018, 04:41:11 am »
Thank you, I'm glad to look at it. I'm not an undergraduate, so I first had to find out what you mean by the triangular / circle method. I found this in a bachelor's thesis on this subject, so again i know more.

Hi Johhno56, GDK is Unseen MachineĀ“s library downloadable here: https://www.qb64.org/forum/index.php?topic=284.0;topicseen

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Collision Detection
« Reply #17 on: June 24, 2018, 06:14:48 am »
A little beyond the thema - function for detecting collisions between point and ellipse:

Code: QB64: [Select]
  1. 'elipse collision detection for point
  2. LET CenterX = 160: LET CenterY = 100: LET A = 40: LET B = 20
  3.  
  4. FOR F = 0 TO _PI(2) STEP .01
  5.     PSET (CenterX + SIN(F) * A, CenterY + COS(F) * B)
  6.  
  7.     LOCATE 1, 1: PRINT Ellipse(_MOUSEX, _MOUSEY, CenterX, CenterY, A, B)
  8.  
  9.  
  10. FUNCTION Ellipse (X&, Y&, CX&, CY&, A&, B&)
  11.     XY## = (((X& - CX&) ^ 2) / A& ^ 2) + (((Y& - CY&) ^ 2) / B& ^ 2)
  12.     IF XY## <= 1.1 THEN Ellipse = 1 ELSE Ellipse = 0
  13.  
  14.  

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Collision Detection
« Reply #18 on: June 24, 2018, 06:23:31 am »
IMHO
GDK, maybe is it Game Development Kit ?  Like that other library of Terry Ritchie.
They have different structures and GDK has maintenance, about Terry Ritchie's Library it seems discontinued....
I have a previous old version of these library on my Pc (TOSHIBA)
Quote
'\\ UnseenGDK Core v1.4 - Updated March 3rd 2015
'// Created By John Onyon a.k.a Unseen Machine
'// Optimistation by CodeGuy
'// ScanKeys% function by Cypherium
'// Image rotation function by Galleon
'// Rotated rectangle collisions by Richard Notley

from Unseen was coming also VQB02 in the same package...
(IMHO  Visual QB??? but there is nothing like mouseBuilding Interface or Structure of a program...)
a library to build application windowing and manage input from mouse and keyboard
and a demo .... MacDock.BAS

Quote
'// VQB v.02 - By John Onyon a.k.a Unseen Machine
'// VQB_01 programs are NOT comaptible with this version.
.... I don't know if this project is still in being or discontinued.... but of his child must talk at first the father if he will!

Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Collision Detection
« Reply #19 on: June 24, 2018, 09:50:42 am »
Quote
GDK, maybe is it Game Development Kit ? 

Dang! That's a great theory even if it were incorrect.

No, it's too good to be wrong? :D
« Last Edit: June 24, 2018, 09:52:00 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Collision Detection
« Reply #20 on: June 24, 2018, 10:26:24 am »
The flaw of this theory is this:

Why name it with _Dev for .bm file?

but in fact in the last posting he had removed _Dev from the library file name. In fact, I had to fix my copy of his code to match the first .bm I downloaded.
« Last Edit: June 24, 2018, 10:29:06 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Collision Detection
« Reply #21 on: June 24, 2018, 10:32:03 am »
I suppose these are developments from having your skull on fire!

BTW, VQB does sound like another excellent name of something!
« Last Edit: June 24, 2018, 10:33:11 am by bplus »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Collision Detection
« Reply #22 on: June 24, 2018, 04:07:14 pm »
Hi Petr
fine your sample but so much static....
so I have added a little movement in it

see here
 
Code: QB64: [Select]
  1. 'elipse collision detection for point
  2. SCREEN 13 'w320xh200 I don't remember well dimensions of old legacy screen mode :-)
  3. LET CenterX = 80: LET CenterY = 100: LET A = 40: LET B = 20
  4. LET MoveX = 1: LET MoveY = 1
  5.  
  6. ' output engine (Not mine) :-)
  7.     FOR F = 0 TO _PI(2) STEP .01
  8.         PSET (CenterX + SIN(F) * A, CenterY + COS(F) * B)
  9.     NEXT F
  10.  
  11. ' refreshing after an elapsed time  
  12.     _DELAY 0.02
  13.     CLS
  14. ' logic engine to let stay ellipse in the screen
  15.     IF (CenterX - A <= 0) THEN
  16.         MoveX = 1
  17.     ELSE
  18.         IF (CenterX + A >= 320) THEN MoveX = -1
  19.     END IF
  20.  
  21.     IF (CenterY - B <= 0) THEN
  22.         MoveY = 1
  23.     ELSE
  24.         IF (CenterY + B >= 200) THEN MoveY = -1
  25.     END IF
  26. ' logic engine calculating new position of ellipse
  27.     CenterX = CenterX + MoveX 'centerx++/centerx--
  28.     CenterY = CenterY + MoveY 'centery++/ centery--
  29.  
  30.     LOCATE 1, 1: PRINT Ellipse(_MOUSEX, _MOUSEY, CenterX, CenterY, A, B)
  31.  
  32.  
  33. FUNCTION Ellipse (X&, Y&, CX&, CY&, A&, B&)
  34.     XY## = (((X& - CX&) ^ 2) / A& ^ 2) + (((Y& - CY&) ^ 2) / B& ^ 2)
  35.     IF XY## <= 1.1 THEN Ellipse = 1 ELSE Ellipse = 0
  36.  

@Bplus
hey boy but  are you talking about my brain or my skull? :-(( For now weather is hot but not such so hot!

Quote
I suppose these are developments from having your skull on fire!

a skull can be a head without a brain into it.... just a zombie head :-)
I cannot imagine what can be thought in a head on fire... and moreover in a skull on fire....
like this https://tse3.mm.bing.net/th?id=OIP.tONt-rsCjWByGGeqc9QaiQHaHa&pid=15.1&P=0&w=300&h=300
or this one http://www.desktopanimated.com/img/Preview/FireSkull3.jpg
or just this last http://3.bp.blogspot.com/_6GGcln-fE78/TCXYCwNk2NI/AAAAAAAAAWk/mwmCK9izrG0/s1600/Fire+Skull.jpg

Ok I have found the just SkullOnFire... it is attached
Programming isn't difficult, only it's  consuming time and coffee

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Collision Detection
« Reply #23 on: June 24, 2018, 04:36:02 pm »
Hi TempoDiBasic, thank you. Now it's nicer. I've been looking at your source, and I have never seen the skull picture now, so I say, what it would be. BPlus had some sort of muse :-D mood today, as I read on the forum. He gave his passage full of muse. And my muse is sleeping today: -D

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Collision Detection
« Reply #24 on: June 24, 2018, 06:37:39 pm »
For burning skull, I was talking about unseen machine's latest avatar!

We were talking about the naming of his GDK system and I was wondering why he named his .BM file unseenGDK_Dev.bm which translates to unseen Game Develoment Kit _ Development.bm the word "development" looked a bit redundant.

Offline Unseen Machine

  • Forum Regular
  • Posts: 158
  • Make the game not the engine!
    • View Profile
Re: Collision Detection
« Reply #25 on: June 24, 2018, 06:48:41 pm »
_DEV is cause it is the Development version, being edited, its so i dont get confused!

VQB is now moving into v.4, ill be putting it out soon.

Unseen

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Collision Detection
« Reply #26 on: June 24, 2018, 07:04:57 pm »
;-))  I see, very logical, now.

Very curious about VQB!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Collision Detection
« Reply #27 on: June 27, 2018, 05:39:22 pm »
This is only the final part of the program, which I will release as long as I finish:

WARNING FOR BPLUS! FULLSCREEN IS USED :-D
Code: QB64: [Select]
  1. 'IF o theraphy :-D (how, for hell write correct conditions?)
  2.  
  3. object0: '0 are empty places, 1 are points
  4. DATA 0,0,0,0,0
  5. DATA 0,1,1,1,1
  6. DATA 0,0,0,0,1
  7. DATA 1,1,1,1,1
  8. DATA 1,0,0,0,0
  9.  
  10. DIM O(4, 4)
  11. 'load object data to array for this example. This values return next program i send here soon as possible.
  12. FOR ObjectLoad = 0 TO 24
  13.     READ value
  14.     O(x, y) = value
  15.     x = x + 1: IF x > 4 THEN x = 0: y = y + 1
  16.  
  17. SCREEN _NEWIMAGE(320, 240, 256): _FULLSCREEN
  18. 'show what is in array
  19. FOR y = 0 TO 4
  20.     FOR x = 0 TO 4
  21.         IF O(x, y) = 1 THEN PSET (160 + x, 100 + y), 14
  22. NEXT x, y
  23.  
  24. 'now own collision detection form. If Object 1 is in quad Object 2 or above, then:
  25. 'example - first row: first row is 5 x empty pixel. Let say, object 2 is comming to this area to third pixel:
  26.  
  27. 'original: 0,0,0,0,0    new: 0,0,1,0,0 - beacause in this row for Object1 are zeros, is none collision.
  28.  
  29. 'If object1 go next 1 pixel down, second row for Object1 is: 0,1,1,1,1 - and now is comming to third position where but is 1. Also is object collision.
  30.  
  31. 'so this programmable:
  32. Object1X = 160
  33. Object1Y = 100
  34.         Object2X = _MOUSEX
  35.         Object2Y = _MOUSEY
  36.     WEND
  37.     CLS
  38.     FOR y = 0 TO 4
  39.         FOR x = 0 TO 4
  40.             IF O(x, y) = 1 THEN
  41.  
  42.                 PSET (Object1X + x, Object1Y + y), 14
  43.                 PSET (Object2X + x, Object2Y + y), 15
  44.             END IF
  45.     NEXT x, y
  46.  
  47.  
  48.     coll = 0
  49.     'first standard QUAD condition and THEN detail comparation:  (both objects are 5 x 5 pixels)
  50.     IF Object2X >= Object1X - 5 AND Object2X <= Object1X + 5 THEN
  51.         TTT = TIMER
  52.         IF Object2Y >= Object1Y - 5 AND Object2Y <= Object1Y + 5 THEN
  53.             LOCATE 1, 1: PRINT "In collision area "
  54.             FOR TY = Object1Y TO Object1Y + 4
  55.                 FOR TX = Object1X TO Object1X + 4
  56.  
  57.                     FOR tTY = Object2Y TO Object2Y + 4
  58.                         FOR tTX = Object2X TO Object2X + 4
  59.                             IF O(TX - Object1X, TY - Object1Y) = 1 AND O(tTX - Object2X, tTY - Object2Y) = 1 AND TX = tTX AND TY = tTY THEN coll = 1: GOTO E ELSE coll = 0
  60.                             'Of course, for a higher program speed, it's better to use a step higher than 1 for the shape of the object. Let's assume that your character is 60 pixels high,
  61.                             ' moving in one step by 10 pixels. Then, the enemy moves with a 10-pixel pitch, so only every ten of the pixel per circuit character is needed.
  62.             NEXT tTX, tTY, TX, TY
  63.         END IF
  64.         LOCATE 3, 1: PRINT TIMER - TTT
  65.     END IF
  66.     E:
  67.     IF coll THEN LOCATE 2, 1: PRINT "Is collision " ELSE LOCATE 2, 1: PRINT "Not collision"
  68.     _DISPLAY
  69.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Collision Detection
« Reply #28 on: June 27, 2018, 05:55:54 pm »
Thanks for warning, I am now armed with Alt+F4 and ready for no escape. ;)

This seems like allot of work and works!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Collision Detection
« Reply #29 on: June 27, 2018, 06:11:22 pm »
Divide and rule. The digital monster was stubborn, so I had to divide it. :-D