Results 1 to 2 of 2

Thread: Maybe you do need Math for programming?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Posts
    74

    Question Maybe you do need Math for programming?

    This might be a little different way of doing collision detection but hopefully someone can help me. I'm woking on a game that has elements like the old Sierra Adventure games where you can walk around objects on the screen by clicking where you want to go. Below is how I define obsticals (rectangles in pixels). It works great, but how would I modify it to determine if you've steped onto a obstical that is in the shape of a circle instead?


    Public Sub stopIfObstical()
    'note 90 is how many pixels tall the sprite is, needed since Sprite2Y is the top pixel adding 90 makes it the feet instead or bottom pixel of the sprite.

    '-----------Fountain----------------
    If Sprite2X > 420 And Sprite2X < 737 And (Sprite2Y + 90) >470 And (Sprite2Y + 90) < 590 Then

    'Stop moving onto the obstical and go back where you just were
    Sprite2X = lastX
    Sprite2Y = lastY
    stopMove = True
    End If
    '------------------------------

    '---Remember the last legal move-----
    lastX = Sprite2X
    lastY = Sprite2Y
    '------------------------------------
    End Sub
    All will fall before the might of the Black Sashi...

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    A circle is defined R^2=X^2+Y^2
    The internal is R^2<X^2+Y^2
    So your collision would be P<X*X+Y*Y where you'd want to prefer a constant on P or use R*R
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width