VB School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB Expert!

Join 307,125 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,078 people online right now. Registration is fast and FREE... Join Now!




How to use the RECT collision in my directx7 game

 

How to use the RECT collision in my directx7 game, Please help me source is provided

giuseppe105

15 Jul, 2008 - 06:57 PM
Post #1

D.I.C Head
**

Joined: 15 May, 2008
Posts: 143



Thanked: 1 times
My Contributions
Hello I have a directx7 tutorial that i'm using to make my game in the tutorial it told me how to create a grid and how to move a tile I have searched a great deal of time trying to figure out how to use the IntersectRECT. What I would like you to explain to me is how to make the tile that the player moves stop when it tries to move over a solid object and make it reusable so I keep code alot shorter.

This is the intersect rect im talking about:
CODE
Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Declare Function IntersectRect Lib "user32" Alias "IntersectRect" (lpDestRect As RECT, lpSrc1Rect As RECT, lpSrc2Rect As RECT) As Long

mblnCollision = IntersectRect(udtTempRect, mudtRect1, mudtRect2)


This is the code for the variable modual
CODE
'these variables are used for when you press a key
Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Global Const KEY_TOGGLED As Integer = &H1
Global Const KEY_DOWN As Integer = &H1000


And this is the game loop that moves the tile and displays the map
CODE
Dim xPos As Integer, yPos As Integer
Dim SpriteX As Integer, SpriteY As Integer
Public Sub GameLoop()

Running = True
                              'running becomes false only
  Do Until Running = False    'when you press the escape key, which
                              'the code is in the form keyup sub
    DoEvents
    
    'these are the events triggered when you press a key
    'they modify the x or y postion of where the sprite is located
    If (GetKeyState(vbKeyRight) And KEY_DOWN) Then
      SpriteX = SpriteX + 1
    End If
    If (GetKeyState(vbKeyLeft) And KEY_DOWN) Then
      SpriteX = SpriteX - 1
    End If
    If (GetKeyState(vbKeyUp) And KEY_DOWN) Then
      SpriteY = SpriteY - 1
    End If
    If (GetKeyState(vbKeyDown) And KEY_DOWN) Then
      SpriteY = SpriteY + 1
    End If

    For xPos = 1 To 20
        DrawXY Grass, xPos, 1, True
        For yPos = 1 To 15
            DrawXY Grass, xPos, yPos, True
        Next yPos
    Next xPos
    
    '         The Sprite
    '           |    multiplied by sprite width, on the x axis it will be shown
    '           |     |  multiplied by the sprite height, on the y axis it will be shown
    '           |     |   |    Whether you want it to be transparent
    '           |     |   |     |
    DrawXY Mushrooms, 12, 5, True
    
    For xPos = 6 To 12
        DrawXY GrassMid, xPos, 9, True
        For yPos = 9 To 14
            DrawXY GrassMid, xPos, yPos, True
        Next yPos
    Next xPos
    
    DrawAnyWhere Rock, SpriteX, SpriteY, True '16, 12
    
    'calls to the backbuffer
    RenderBackBuffer

  Loop
Leave

End Sub


IPB Image

This post has been edited by giuseppe105: 16 Jul, 2008 - 10:28 AM

User is offlineProfile CardPM
+Quote Post


AdamSpeight2008

RE: How To Use The RECT Collision In My Directx7 Game

17 Jul, 2008 - 09:59 AM
Post #2

The Bandido Coder
Group Icon

Joined: 29 May, 2008
Posts: 2,734



Thanked: 160 times
Dream Kudos: 3925
Expert In: vb.net, LINQ

My Contributions
Am I Being Ignored? icon_down.gif
Shh!! Did you hear something?
User is offlineProfile CardPM
+Quote Post

OliveOyl3471

RE: How To Use The RECT Collision In My Directx7 Game

18 Jul, 2008 - 09:08 AM
Post #3

Quick and Dirty
Group Icon

Joined: 11 Jul, 2007
Posts: 5,660



Thanked: 107 times
Dream Kudos: 775
Expert In: Basketball

My Contributions
I can't speak for anyone but me, but I'm not ignoring you. I just don't know the answer to your question.
Maybe someone will help you though if you wait a while.
icon_up.gif


edit--if you haven't figured it out already, you shouldn't post your question in more than one forum. Patience!

This post has been edited by OliveOyl3471: 18 Jul, 2008 - 09:10 AM
User is offlineProfile CardPM
+Quote Post

PsychoCoder

RE: How To Use The RECT Collision In My Directx7 Game

18 Jul, 2008 - 09:12 AM
Post #4

I Code, Therefore I am
Group Icon

Joined: 26 Jul, 2007
Posts: 14,934



Thanked: 517 times
Dream Kudos: 11575
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
Given your reply to the other post you have I stand by what I said there. You're getting the same error no matter what code you execute, it has to be something to do with whatever you did to your video card a while back. Since no error number is being returned, I don't believe this is a code issue, I believe it's a hardware issue
User is offlineProfile CardPM
+Quote Post

giuseppe105

RE: How To Use The RECT Collision In My Directx7 Game

18 Jul, 2008 - 01:05 PM
Post #5

D.I.C Head
**

Joined: 15 May, 2008
Posts: 143



Thanked: 1 times
My Contributions
arigt tnx for posting srr i got a little impacient and im new to forums for some reson i have full control over directx7 but directx 8 dosent work i found out how to use the collision thing but i dont know how to make it reuseable in my game so im gona stare at it till i go to bed in 5 hours...

i have no live by the way...
User is offlineProfile CardPM
+Quote Post

gabehabe

RE: How To Use The RECT Collision In My Directx7 Game

18 Jul, 2008 - 01:12 PM
Post #6

Sexy DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 8,864



Thanked: 177 times
Dream Kudos: 3275
Expert In: Lots of things.

My Contributions
Why is your player a rock?
User is offlineProfile CardPM
+Quote Post

giuseppe105

RE: How To Use The RECT Collision In My Directx7 Game

18 Jul, 2008 - 05:33 PM
Post #7

D.I.C Head
**

Joined: 15 May, 2008
Posts: 143



Thanked: 1 times
My Contributions
its a complicated game took me a while to get an extream rock and some other cool characters i think its gona be an epic game defenetly gona push the wii to the max.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 02:23PM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month