Author Topic: Collision Detection in Axe?  (Read 5506 times)

0 Members and 1 Guest are viewing this topic.

Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Collision Detection in Axe?
« on: April 05, 2011, 09:22:00 pm »
Well, I was following DT's SHMUP guide(and enemy/array guide) and managed to put both together. But I can't figure it out how to make the colision detection(i.e. bullet killz)
Bullet data is in L4 and Enemy data L1.
Sig wipe!

Ashbad

  • Guest
Re: Collision Detection in Axe?
« Reply #1 on: April 05, 2011, 09:24:08 pm »
Well, I didnt look through his code on that, but one way to detect if the bullet hits the enemy is go through in a for loop and check each bullet's position, and if it's near enough to the enemy to kill it -- let's say its two pixels south and 1 pixel east of enemy 5, end that part of the loop and kill the enemy.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Collision Detection in Axe?
« Reply #2 on: April 05, 2011, 09:52:44 pm »
I really need to address that, don't I? x.x

Well, a short run-down: Say you have a bullet that's 2x2 and a character that's 6x8 (pretty reasonable dimensions). Now think about when you would call it a "collision":

████
██▒▒██████████
  ████████████
  ████████████
  ████████████
  ████████████
  ████████████
  ████████████
  ████████████

is a minimum collision on the top left corner. In this case, charX - bullX = 1, and charY - bullY = 1.

          ████
██████████▒▒██
████████████
████████████
████████████
████████████
████████████

is a minimum collision on the top right corner. In this case, charX - bullX = -5, and charY - bullY = 1.

████████████
████████████
████████████
████████████
████████████
██████████▒▒██
          ████

is a minimum collision on the bottom right corner. In this case, charX - bullX = -5, and charY - bullY = -7.

  ████████████
  ████████████
  ████████████
  ████████████
  ████████████
██▒▒██████████
████

is a minimum collision on the bottom left corner. In this case, charX - bullX = 1, and charY - bullY = -7.

You can see that there is a minimum collision whenever ((charX - bullX = 1) or (charX - bullX = -5)) and ((charY - bullY = 1) or (charY - bullY = -7)). But since that's only the extreme cases, anything between them is also a collision (obviously). So there would be a collision whenever (charX - bullX ≥ -5) and (charX - bullX ≤ 1) and (charY - bullY ≥ -7) and (charY - bullY ≤ 1).

Of course, that's only for a bullet that's 2x2 and a character that's 6x8. But you can just use the same logic to find the values for colliding objects of any size.
« Last Edit: April 05, 2011, 09:54:27 pm by Deep Thought »




Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Re: Collision Detection in Axe?
« Reply #3 on: April 05, 2011, 10:04:51 pm »
is the picture distorted, or is it supposed to look that way?
Sig wipe!

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Collision Detection in Axe?
« Reply #4 on: April 05, 2011, 10:12:50 pm »
Hmm? It's supposed to look like this:





Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Re: Collision Detection in Axe?
« Reply #5 on: April 05, 2011, 10:13:40 pm »
oh now I got the scenario. Okee. Thanks.
Sig wipe!

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Collision Detection in Axe?
« Reply #6 on: April 05, 2011, 10:17:37 pm »
Hmm, what browser were you using that made the diagram look bad?




Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Collision Detection in Axe?
« Reply #7 on: April 05, 2011, 11:51:03 pm »
In the case of Axe (and also ASM), it can be a good idea to use a single unsigned comparison to check if a value is in a certain range. For example, if you are trying to check M<=X<=N, you can change that inequality to 0<=X-M<=N-M. Using an unsigned comparison, that is just X-M<=N-M. This works out quite nicely for constant N and M.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Re: Collision Detection in Axe?
« Reply #8 on: April 06, 2011, 08:25:44 pm »
Well, I still couldn't figure out where to put collision detection D:
So imma post mah code here hoping someone can help me...
I deleted mah cd try because it didnt work XP
Spoiler For ASHMUP:
Code: (ASHMUP) [Select]
:.MSLUGSKY
:prgmASHMUPD
:prgmASHMUPI
:Repeat getKey(15)
:C+1→C
:prgmASHMUPK
:prgmASHMUPM
:ClrDraw
:prgmASHMUPB
:
:If F
:rand^3→G
:End
:
:If rand<4096
:sub(PE,88,rand^8*8,rand^2+1,0
:End
:
:If B
:For(I,1,B
:Pt-On({I*4+L4-2→J},G-1+{J+1},8*D+Pic0)
:End
:End
:
:If L
:For(I,1,L
:If {{I*4+L1-4→J}-{J+2}→{J}}≤0
:Goto RM
:End
:If {{J+1}+{J+3}→{J+1}}≥64
:Lbl RM
:sub(RE,I-1→I
:End
:End
:End
:Pt-Change(X,Y,GDB0
:sub(DA
:DispGraph
:sub(DA
:End
:prgmASHMUPR
Spoiler For ASHMUPB:
Code: [Select]
:..BG
:Pt-Change(‾3*C+96,5,Pic1
:Pt-Change(‾3*C+96+8,5,Pic1+8
:Pt-Change(‾3*C+130,15,Pic1
:Pt-Change(‾3*C+130+8,15,Pic1+8
:Pt-Change(‾3*C+180,38,Pic1
:Pt-Change(‾3*C+180+8,38,Pic1+8
:Pt-Change(‾3*C+70,35,Pic1
:Pt-Change(‾3*C+70+8,35,Pic1+8
:Pt-Change(‾3*C+5,42,Pic1
:Pt-Change(‾3*C+5+8,42,Pic1+8
:
Spoiler For ASHMUPD:
Code: [Select]
:..DATA
:[000004181FFC8000→GDB0
:[00003C0000000000→Pic0
:[0000FF0000000000
:[00FFA1FF00000000
:[FFFFFFFFFFFFFFFF
:[0036498080493600→Pic1
:[006C920101926C00
:[0070ADE39D7E0000→Pic3
:[F82070AFCE7050F8
Spoiler For ASHMUPI:
Code: [Select]
:..INIT
:44→X
:40→Y
:0→B→D→G→L
:15→E
:3→H
Spoiler For ASHMUPK:
Code: [Select]
:..KEYS
:If getKey(1) and (Y≠56
:Y+2→Y
:End
:If getKey(2) and (X≠0
:X-2→X
:End
:If getKey(3) and (X≠88
:X+2→X
:End
:If getKey(4) and (Y≠0
:Y-2→Y
:End
:If getKey(54)
:!If C^E
:sub(ASB,D+1,H,X+1,Y+2)
:End
:End
:If getKey(34)
:15→E
:0→D
:0→F
:3→H
:End
:If getKey(26)
:6→E
:1→D
:1→F
:4→H
:End
:If getKey(18)
:25→E
:2→D
:0→F
:4→H
:End
:If getKey(35)
:1→E
:3→D
:0→F
:8→H
:End
Spoiler For ASHMUPM:
Code: [Select]
:..MOVEMENT
:If B
:For(I,1,B
:If {{I*4+L4-2→J}+{J-1}→{J}}>127
:sub(RSB,I-1→I)
:End
:End
:End
Spoiler For ASHMUPR:
Code: [Select]
:..ROUTINES
:Lbl ASB
:If B<80
:r4→{r3→{r2→{r1→{B+1→B*4+L4-4}+1}+1}+1}
:End
:Return
:Lbl RSB
:conj(r1*4+L4+4,-4,B-1→B-r1*4+1)
:Return
:Lbl DA
:If L
:For(I,1,L
:Pt-Change({I*4+L1-4→J},{J+1},Pic3
:End
:End
:Return
:Lbl PE
:If L<176
:r4→{r3→{r2→{r1→{L+1→L*4+L1-4}+1}+1}+1}
:End
:Return
:Lbl RE
:conj(r1*4+L1+4,-4,L-1→L-r1*4+1)
:Return
Maybe Screenie too jic.
Sig wipe!

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: Collision Detection in Axe?
« Reply #9 on: April 07, 2011, 06:47:02 am »
>.>
<.<
Code tags in spoilers
>.>
<.<
x.x
looking cool, though.
I'm not a nerd but I pretend:

Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Re: Collision Detection in Axe?
« Reply #10 on: April 07, 2011, 07:09:17 am »
I did that to save space XD
Sig wipe!