6 Replies - 3549 Views - Last Post: 18 July 2008 - 06:33 PM Rate Topic: -----

#1 giuseppe105  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 444
  • Joined: 15-May 08

How to use the RECT collision in my directx7 game

Post icon  Posted 15 July 2008 - 07:57 PM

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:
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
'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
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


Posted Image

This post has been edited by giuseppe105: 16 July 2008 - 11:28 AM


Is This A Good Question/Topic? 0
  • +

Replies To: How to use the RECT collision in my directx7 game

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: How to use the RECT collision in my directx7 game

Posted 17 July 2008 - 10:59 AM

Am I Being Ignored? :v:
Shh!! Did you hear something?
Was This Post Helpful? 0
  • +
  • -

#3 OliveOyl3471  Icon User is offline

  • Everybody's crazy but me!
  • member icon

Reputation: 134
  • View blog
  • Posts: 6,581
  • Joined: 11-July 07

Re: How to use the RECT collision in my directx7 game

Posted 18 July 2008 - 10:08 AM

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.
:^:


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 July 2008 - 10:10 AM

Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: How to use the RECT collision in my directx7 game

Posted 18 July 2008 - 10:12 AM

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
Was This Post Helpful? 0
  • +
  • -

#5 giuseppe105  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 444
  • Joined: 15-May 08

Re: How to use the RECT collision in my directx7 game

Posted 18 July 2008 - 02:05 PM

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...
Was This Post Helpful? 0
  • +
  • -

#6 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1385
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: How to use the RECT collision in my directx7 game

Posted 18 July 2008 - 02:12 PM

Why is your player a rock?
Was This Post Helpful? 0
  • +
  • -

#7 giuseppe105  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 444
  • Joined: 15-May 08

Re: How to use the RECT collision in my directx7 game

Posted 18 July 2008 - 06:33 PM

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1