realbasic-games
[Top] [All Lists]

detecting tile collisions - Update

To: realbasic-games at lists dot realsoftware dot com
Subject: detecting tile collisions - Update
From: "Eric Richards" <erockus at juno dot com>
Date: Tue, 28 Dec 2004 04:21:33 GMT
Delivered-to: realbasic-games at lists dot realsoftware dot com
Hi -

I've been doing some work on this, trying to
clean up the code a bit.  I added TheCornerXY() and
TheCornerColRow methods - I hope this is what you
had in mind.

Now what I have right now works. The knight can walk around
and not go through objects and can go between objects !

Anyway do you see any problems with the following code?

The only problem I have is when I take in the RunSpeed
into the calc's the Knight can, on occasion, stop an extra
few pixels away from an object if he is running. 

Move()

  If keyboard.AsyncShiftKey then// shift aka run
    Knight.RunSpeed = 4
  else
    Knight.RunSpeed = 0
  end if

 '    A       B                       0          1
  'C +---------+ D                    +----------+
  '  |         |                      |          | 
  '  |         |                      |          |
  '  |         |                      |          |
  'G +---------+ H                    +----------+
  '   E       F                       2          3
 

  if Keyboard.AsyncKeyDown(&h7E)  then //UP
    Knight.myDirection = "up"
    Knight.frameIndex = ((Knight.FrameIndex+1) mod 3) + 3
    /////////////////  //////////////////
    TheCornerXY(Knight,0)
    TheCornerColRow
    ///////////////////////////////////
    if TileIDAtColRow(3,CornerCol,CornerRow) > 0  Then
      return
    end if
    /////////////////  //////////////////
    TheCornerXY(Knight,1)
    TheCornerColRow
   ///////////////////////////////////
    if TileIDAtColRow(3,CornerCol,CornerRow) > 0  Then
      return
    end if
    Knight.y = (Knight.y -6) - Knight.RunSpeed
    return
  END IF


 
End Sub

Sub TheCornerXY(Object as HeroClass, WhatCorner as integer)
   
   Select Case Object.MyDirection
   Case "up"
      if WhatCorner = 0 then
         CornerX = (Object.X +4)
         CornerY = (Object.Y-2) -Object.RunSpeed
      elseif WhatCorner = 1 then
         CornerX = (Object.X +32)-4
         CornerY = (Object.Y-2)- Object.RunSpeed 
      end if
   Case "down"
      if WhatCorner = 2 then
         CornerX = (Object.X)+4
         CornerY = (Object.Y+32)+2+Object.RunSpeed
      elseif whatCorner = 3 then
         CornerX = (Object.X+32)-4
         CornerY = (Object.Y+32)+2+Object.RunSpeed
      end if
   Case "right"
      if WhatCorner = 1 then
         CornerX = (Object.X+32)+2+Object.RunSpeed
         CornerY = (Object.Y)+4
      elseif whatCorner = 3 then
         CornerX = (Object.X+32)+2+Object.RunSpeed
         CornerY = (Object.Y+32)-4
      end if
   Case "left"
      if whatCorner = 0 then
         CornerX = (Object.X-2)-Object.RunSpeed
         CornerY = (Object.Y)+4
      elseif whatCorner = 2 then
         CornerX = (Object.X-2)-Object.RunSpeed
         CornerY = (Object.Y+32)-4
      end if
   end select
   
End Sub


Sub TheCornerColRow()
   CornerCol = (CornerX\32)
   CornerRow = (CornerY\32)
End Sub


________________________________________________________________
Juno Gift Certificates
Give the gift of Internet access this holiday season.
http://www.juno.com/give

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>
  • detecting tile collisions - Update, Eric Richards <=