Author Topic: Collision detection (without "pxl-test(" )  (Read 4832 times)

0 Members and 1 Guest are viewing this topic.

Offline GreenFreak

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 191
  • Rating: +16/-1
    • View Profile
Collision detection (without "pxl-test(" )
« on: June 05, 2011, 11:47:34 am »
Hi!

First: I'm sorry for my bad english  :P

I tried to write a collision detection in Axe for 2 of my programs.
But I made a mistake in my code.
This is a test program for my collision detection:

Code: [Select]
.PXLTEST BYEBYE
DiagnosticOff
[FFFFFFFFFFFFFFFFüPic1
0->X+1->D
Zeros(10)->{L1}
44->{L1+0}
54->{L1+1}
.For(X,1,3)
.rand^88->{X*2+L1}
.rand^56>{X*2+1+L1}
.Pt-On({X*2+L1},{X*2+1+L1},Pic1
.End
.StorePic
Repeat getKey(15)
Pt-On({L1+2},{L1+3},Pic1
Line(0,63,95,63)
.RecallPic
Pt-On({L1+0},{L1+1},Pic1)

DispGraphClrDraw

If getKey(2)
{L1+0}--
ElseIf getKey(3)
{L1+0}++
End

If D
{L1+1}--
D--
End

!If D
If {L1+0}>{L1+2}
If {L1+0}<8+{L1+2}
If {L1+1}=8+{L1+3}
20->D
End
End
End
{L1+1}++
End

If {L1+1}=54
20->D
End

End

The problem seems to be at the
Code: [Select]
!If D
If {L1+0}>{L1+2}
If {L1+0}<8+{L1+2}
If {L1+1}=8+{L1+3}
20->D
End
End
End
{L1+1}++
End

Can you please help me to find the problem?  :(
If you don't know where my problem is, you should run this program.
I need this for all of my 3 first Axe games.

Thanks a lot  :D
« Last Edit: June 05, 2011, 11:48:50 am by GreenFreak »

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 (without "pxl-test(" )
« Reply #1 on: June 05, 2011, 12:41:20 pm »
Hi and welcome, GreenFreak! Haven't looked too closely at your code, but I see the lines
Code: (Axe) [Select]
If {L1+0}<8+{L1+2}
If {L1+1}=8+{L1+3}
Remember that Axe has a strictly left-to-right order of operations, so those lines would actually be interpreted as
Code: (Axe) [Select]
If ({L1+0}<8)+{L1+2}
If ({L1+1}=8)+{L1+3}
I'm guessing there's a fair chance that's your problem right there, but again, haven't looked at the rest of your code yet (don't have time, sorry). Hope this helps :)




Offline GreenFreak

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 191
  • Rating: +16/-1
    • View Profile
Re: Collision detection (without "pxl-test(" )
« Reply #2 on: June 05, 2011, 03:05:32 pm »
Thanks, Deep Thought!
I've worked on it, but it won't work :(
There must be another mistake...
My currently code:
Code: [Select]
.PXLTEST
DiagnosticOff
[FFFFFFFFFFFFFFFF]->Pic1
0->X->D
44->{0+L1}
53->{1+L1}
66->{2+L1}
50->{3+L1}

Repeat getKey(15)
Pt-On({2+L1},{3+L1},Pic1
Line(0,63,95,63)
Pt-On({0+L1},{1+L1},Pic1)

DispGraphClrDraw

If getKey(2)
{0+L1}--
ElseIf getKey(3)
{0+L1}++
End

!If D
If ({2+L1})<({0+L1})
If (8+{2+L1})>({0+L1})
If (8+{3+L1})=({1+L1})
40->D
End
End
End
End

!If D
{1+L1}++
If {1+L1}=56
20->D
End
End
If D
{1+L1}--
D--
End

End

« Last Edit: June 05, 2011, 03:08:21 pm by GreenFreak »

Offline GreenFreak

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 191
  • Rating: +16/-1
    • View Profile
Re: Collision detection (without "pxl-test(" )
« Reply #3 on: June 07, 2011, 10:03:58 am »
No idea? :(
I need this check in all of my 3 Axe-games :(

Offline Compynerd255

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +53/-4
  • Betafreak Games
    • View Profile
    • Betafreak Games
Re: Collision detection (without "pxl-test(" )
« Reply #4 on: June 07, 2011, 10:38:57 am »
For the sake of testing, instead of using {1+L1} and {2+L1} and stuff, I would recommend using temporary variables that no one else will use (such as r1-r6 which are normally used for subroutine arguments, but can be considered fair game).
The Slime: On Hold, preparing to add dynamic tiles

Axe Eitrix: DONE

Betafreak Games: Fun filled games for XBox and PC. Check it out at http://www.betafreak.com



Offline GreenFreak

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 191
  • Rating: +16/-1
    • View Profile
Re: Collision detection (without "pxl-test(" )
« Reply #5 on: June 08, 2011, 01:49:10 pm »
Thanks for your answer!  ;)

How would you write this? ???
Isn't it possible with {X+L1} to do this?  :-\
Because I'll use this for many different sprites and their positions (in my DoodleJump game.. BTW: I need a name for it ;))

Thanks for your help :)

Offline Compynerd255

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +53/-4
  • Betafreak Games
    • View Profile
    • Betafreak Games
Re: Collision detection (without "pxl-test(" )
« Reply #6 on: June 09, 2011, 11:13:08 am »
Usually, whenever you write a routine that can be used in multiple programs, you code it in such a way that it can be used as easily as possible, without restricting where people can store things. In Axe, you write a subroutine and have it accept arguments, like so:
Code: [Select]
sub(SUB, EXP1, EXP2, ... , EXP6
In this code, EXP1-EXP6 are loaded in the variables r1-r6 (the Polar variables), respectively. Then the subroutine is called. You can use this to pass up to 6 values into a subroutine.

I also looked at your collision code, and I see serious flaws in the logic. Below is a piece of code that should function the same as the second chunk in your code (the collision between the two sprites).
Code: (In the program) [Select]
If sub(COL, {0+L1}, {1+L1}, Pic1, {2+L1}, {3+L1}, Pic1
40→D
End
Code: (Bottom of program, past main Return) [Select]
Lbl COL
If abs(r1-r4)<8 and (abs(r2-r5)<8)
.So that we can use the same For loop no matter how the sprites are positioned, we will flip the arguments if Sprite1 is higher up than Sprite2
If r5<r2:Exch(r1º, r4º, 6):End
.Count up the sprite rows
For(X1T, 0, 7
.Now, we will take the first potentially colliding row of the first sprite and bit shift it so it is in correct space with the second sprite. We will bitwise AND that result with the second sprite. If the two sprites share a pixel at that location, the If statement will become true.
If {r5-r2+X1T+r6}*e^(r4-r1) and {X1T+r3}
.Pixel Collision Occured
1:Return
End
End
0:Return
The actual per pixel test logic might not be accurate... Please correct me.

Thank you for bringing this up, BTW. I might use this myself in my next project.
« Last Edit: June 09, 2011, 11:29:40 am by Compynerd255 »
The Slime: On Hold, preparing to add dynamic tiles

Axe Eitrix: DONE

Betafreak Games: Fun filled games for XBox and PC. Check it out at http://www.betafreak.com



Offline GreenFreak

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 191
  • Rating: +16/-1
    • View Profile
Re: Collision detection (without "pxl-test(" )
« Reply #7 on: July 03, 2011, 11:31:31 am »
I'm sorry, but it's too diffcult to understand for me...
But I found the solution that I have searched for in your code:
Code: [Select]
If sub(COL, {0+L1}, {1+L1}, Pic1, {2+L1}, {3+L1}, Pic1
40→D
End

Lbl COL
If abs(r1-r4)<8 and (abs(r2-r5)<8)

Thanks ;)

Offline Compynerd255

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +53/-4
  • Betafreak Games
    • View Profile
    • Betafreak Games
Re: Collision detection (without "pxl-test(" )
« Reply #8 on: July 04, 2011, 04:17:28 pm »
I was just trying to do something fancy with bitshifting and stuff so that irregularly shaped sprites don't collide if their pixel maps don't touch. But the first line just checks the squares, and that's usually fine for most purposes.
« Last Edit: July 11, 2011, 05:07:39 pm by Compynerd255 »
The Slime: On Hold, preparing to add dynamic tiles

Axe Eitrix: DONE

Betafreak Games: Fun filled games for XBox and PC. Check it out at http://www.betafreak.com



Offline GreenFreak

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 191
  • Rating: +16/-1
    • View Profile
Re: Collision detection (without "pxl-test(" )
« Reply #9 on: July 08, 2011, 03:19:21 pm »
But you don't mind, if I didn't use your code in my code?
« Last Edit: July 08, 2011, 03:20:07 pm by GreenFreak »

Offline Compynerd255

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +53/-4
  • Betafreak Games
    • View Profile
    • Betafreak Games
Re: Collision detection (without "pxl-test(" )
« Reply #10 on: July 11, 2011, 05:07:16 pm »
But you don't mind, if I didn't use your code in my code?
No, not at all. Unless the owner says otherwise (and I don't), any code samples posted on the Internet can be used by anyone who finds them useful. To say that you can't use posted code is to taunt you sadistically. :)
The Slime: On Hold, preparing to add dynamic tiles

Axe Eitrix: DONE

Betafreak Games: Fun filled games for XBox and PC. Check it out at http://www.betafreak.com