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

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




How to use the RECT collision in my directx7 game

 
Reply to this topicStart new topic

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

New D.I.C Head
*

Joined: 15 May, 2008
Posts: 33


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

LINQ D.I.C.
Group Icon

Joined: 29 May, 2008
Posts: 863



Thanked: 54 times
Dream Kudos: 2250
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

Be my fiduciary ♥
Group Icon

Joined: 11 Jul, 2007
Posts: 2,139



Thanked: 27 times
Dream Kudos: 400
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

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



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

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

New D.I.C Head
*

Joined: 15 May, 2008
Posts: 33


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

better than jam.
Group Icon

Joined: 6 Feb, 2008
Posts: 5,837



Thanked: 104 times
Dream Kudos: 2700
Expert In: slobbing.

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

New D.I.C Head
*

Joined: 15 May, 2008
Posts: 33


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: 1/9/09 02:48AM

Be Social

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

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month