|
-
Apr 18th, 2001, 04:36 PM
#1
Thread Starter
New Member
In my game you shoot bad guys with lasers. I want to see if there is a easy way of testing if the laser hit the target or not. Is there some kind of:
If line1 is touching shape1 then
sort of thing???
If you can tell me if there is please tell me. If there isent one can you please tell me the best way to do this? This game will be mutiplayer it will be the next number one game!
-
Apr 18th, 2001, 04:46 PM
#2
PowerPoster
Woah! The story in yet game is incredible!!! Better than any DeusEx or whatever!
Erm - enough of laughing
Try this:
Code:
Dim Laser As RECT
Dim Shape As RECT
If Laser.x + Laser.w > Shape.x Then
If Laser.y + Laser.h > Shape.y Then
If Laser.x < Shape.x + Shape.w Then
If Laser.y < Shape.y + Shape.h Then
'Code for hit here!
EndIf
EndIf
EndIf
EndIf
-
Apr 18th, 2001, 04:46 PM
#3
transcendental analytic
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.
-
Apr 18th, 2001, 04:47 PM
#4
-
Apr 18th, 2001, 05:02 PM
#5
transcendental analytic
yeah maybe, but i guess it depends, if the laser line is long enough i would treat it as a line
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.
-
Apr 18th, 2001, 07:13 PM
#6
Thread Starter
New Member
Hey Fox,...
what does this do :
Dim Laser As RECT <--------here
Dim Shape As RECT <--------here
If Laser.x + Laser.w > Shape.x Then
If Laser.y + Laser.h > Shape.y Then
If Laser.x < Shape.x + Shape.w Then
If Laser.y < Shape.y + Shape.h Then
'Code for hit here!
EndIf
EndIf
EndIf
EndIf
My lasar is line1 and my shape is shape1,.. explian the vareibles to me please!
-
Apr 18th, 2001, 08:06 PM
#7
Frenzied Member
A RECT type has the x & y coordinates of the top-left corner of a rectangle, and either the coords of the bottom-left corner or the height and width of the rectangle. It's just a structure to store a rectangle in.
Anyway, like Kedaman said, what kind of shape is it? A circle?
Harry.
"From one thing, know ten thousand things."
-
Apr 18th, 2001, 08:44 PM
#8
Thread Starter
New Member
its a square!
Its a sqare... But my laser is line1 and my shape is shape1 ,.... what does darclaring those vars do??
-
Apr 18th, 2001, 08:48 PM
#9
Thread Starter
New Member
More trouble
When i try to run that code the VB program highlights " Laser As RECT" from Dim Laser As RECT and says "Compile error: User-defined type not defined"
whats does that mean?
-
Apr 18th, 2001, 10:22 PM
#10
Good Ol' Platypus
It means you must declare the Type, as it is an extended member of the normal VB types:
Code:
Type RECT
Left as Integer
Top as Integer
Right as Integer
Bottom as Integer
End Type
Then make sure the scalemode is 3 - Pixels (vbPixels)
Then you would put .X1 in left, .Y1 in top, .X2 in right, .Y2 in bottom (for the line).
For the shape you would put .Top in Top, .Left in Left, .Left + .Scalewidth in Right, and .Top + .Scaleheight in Bottom. Then you can check the collision.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Apr 19th, 2001, 12:03 AM
#11
PowerPoster
Since I didn't really use the original RECT type you should either include this instead:
Code:
Type RECT
x As Integer 'x-pos
y As Integer 'y-pos
w As Integer 'width
h As Integer 'height
End Type
...or replace x by left, y by top and so on in my code.
It does not depend wheter your laser is just a line or a rectangle, use this code will work in both cases (better said: if you decide to switch to a rectangular (bitmap) laser, the code will still work perfectly)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|