|
-
Aug 10th, 2002, 09:52 AM
#1
Thread Starter
Lively Member
Make my player face the mouse?
Hi all, need a little help here I'm making a game (well, attempting to) and I've got a problem with aiming. It's a 2D shooter and I want to use the mouse, but that means I need to rotate (or simulate rotation of) my player character. So how would I make my player face in the direction of the mouse cursor? (The player rotation is not the problem, I'll just load loads of pictures of the player into a resource file).
I fear it's gonna include alot of maths, angles and other complicated stuff which I will struggle to understand 
Thanks in advance.
Walter
Anticipation of death is worse than death itself
-
Aug 10th, 2002, 10:58 AM
#2
Frenzied Member
I have some example code for a 2D shooter which uses the mouse, but its in C++ though....let me know if want it.
-
Aug 10th, 2002, 11:09 AM
#3
Thread Starter
Lively Member
That'd be great thanks. I suppose I could try and use it as an example to code it in VB but I don't have much experience in C++. (I'll give it my best shot anyway). Could you email it to me at [email protected] please. Thanks again! 
Walter
Anticipation of death is worse than death itself
-
Aug 10th, 2002, 11:18 AM
#4
Thread Starter
Lively Member
Anyone know how to do this in VB??
Anticipation of death is worse than death itself
-
Aug 10th, 2002, 06:19 PM
#5
Frenzied Member
There's a game called "Craft", I think it was made by Plenderj (yes he's in this forum), it's exactly what you're looking for
-
Aug 11th, 2002, 08:15 AM
#6
Thread Starter
Lively Member
Cool, thanks alot I'll check it out. Has he uploaded it in a post or am I gonna have to email him for it (and if so could I have his email address please?). Thanks again. 
Walter
Anticipation of death is worse than death itself
-
Aug 11th, 2002, 11:15 AM
#7
Frenzied Member
Just use the forum's Search button to look for one of his posts, and then send him a PM or check his user profile for his e-mail address
-
Aug 11th, 2002, 11:36 AM
#8
Thread Starter
Lively Member
Thankyou. Couldn't find it in a post so I've emailed him (at the only address I could find). Thanks again Jotaf 
Walter
Anticipation of death is worse than death itself
-
Aug 13th, 2002, 02:54 AM
#9
Retired VBF Adm1nistrator
Hmmmmmm ego massage.
Aaaaanyway.
The later versions of Craft, rotate the ship by using the cursor keys.
But I have a version of it thats about two years old or more that still rotates that way.
The rotation code is still in the application, as you can see below.
The code, I'm afraid to say, isn't too clean, as this is a very early version.
You can download the entire app from here :
http://www.coolground.com/plenderj/c...unt_bitblt.zip
But do remember, this is a very old version, so the code isn't the greatest.
VB Code:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If (doloop = False) And (var_status = 1) Then
doloop = True
RunGameLoop
End If
''' For i = ccl.LBound To ccl.ubound
''' If ccl(i).FillColor = &HFF0000 Then ccl(i).FillColor = &H80FFFF
''' Next i
''' For i = ccl_stn.LBound To ccl_stn.ubound
''' If ccl_stn(i).FillColor = &HFF0000 Then ccl_stn(i).FillColor = &H40C0&
''' Next i
If (var_status <> 0) Then
var_speed = Sqr(((mewidth / 2) - x) ^ 2 + ((meheight / 2) - y) ^ 2)
lblspeed = var_speed
var_temp_x = x
var_temp_y = y
var_cords_x = (mewidth / 2) - x
var_cords_y = (meheight / 2) - y
If (var_cords_y <> 0) Then
var_angle = (Atn((var_cords_x * -1) / var_cords_y) * var_pi)
Else: var_cords_y = 0.001
End If
If (var_angle < 0) Then var_angle = var_angle * -1
If (var_angle = 0) And (var_cords_x = 0) And (var_cords_y < 0) Then var_angle = 180
If (var_cords_x < 0) Then
If (var_cords_y > 0) Then
var_angle = var_angle
ElseIf (var_cords_y < 0) Then
var_angle = 90 - var_angle
var_angle = var_angle + 90
End If
ElseIf (var_cords_x > 0) Then
If (var_cords_y > 0) Then
var_angle = 270 - var_angle
var_angle = var_angle + 90
ElseIf (var_cords_y < 0) Then
var_angle = var_angle + 180
End If
End If
var_angle = (Int(Int(var_angle) / 10) * 10)
var_dist_x = Sin(var_pi2 * var_angle) * var_speed
If ((Cos(var_pi2 * var_angle) * var_speed) = 0) Then var_dist_y = var_speed Else var_dist_y = Cos(var_pi2 * var_angle) * var_speed
End If
lblstuff.Caption = ""
End Sub
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Aug 13th, 2002, 02:58 AM
#10
Retired VBF Adm1nistrator
Oh yes and the ship is then drawn by this awful piece of code
VB Code:
If (var_angle = 0) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_0, 0, 0, vbSrcInvert
End If
If (var_angle = 10) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_10, 0, 0, vbSrcInvert
End If
If (var_angle = 20) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_20, 0, 0, vbSrcInvert
End If
If (var_angle = 30) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_30, 0, 0, vbSrcInvert
End If
If (var_angle = 40) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_40, 0, 0, vbSrcInvert
End If
If (var_angle = 50) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_50, 0, 0, vbSrcInvert
End If
If (var_angle = 60) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_60, 0, 0, vbSrcInvert
End If
If (var_angle = 70) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_70, 0, 0, vbSrcInvert
End If
If (var_angle = 80) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_80, 0, 0, vbSrcInvert
End If
If (var_angle = 90) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_90, 0, 0, vbSrcInvert
End If
If (var_angle = 100) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_100, 0, 0, vbSrcInvert
End If
If (var_angle = 110) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_110, 0, 0, vbSrcInvert
End If
If (var_angle = 120) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_120, 0, 0, vbSrcInvert
End If
If (var_angle = 130) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_130, 0, 0, vbSrcInvert
End If
If (var_angle = 140) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_140, 0, 0, vbSrcInvert
End If
If (var_angle = 150) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_150, 0, 0, vbSrcInvert
End If
If (var_angle = 160) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_160, 0, 0, vbSrcInvert
End If
If (var_angle = 170) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_170, 0, 0, vbSrcInvert
End If
If (var_angle = 180) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_180, 0, 0, vbSrcInvert
End If
If (var_angle = 190) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_190, 0, 0, vbSrcInvert
End If
If (var_angle = 200) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_200, 0, 0, vbSrcInvert
End If
If (var_angle = 210) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_210, 0, 0, vbSrcInvert
End If
If (var_angle = 220) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_220, 0, 0, vbSrcInvert
End If
If (var_angle = 230) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_230, 0, 0, vbSrcInvert
End If
If (var_angle = 240) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_240, 0, 0, vbSrcInvert
End If
If (var_angle = 250) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_250, 0, 0, vbSrcInvert
End If
If (var_angle = 260) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_260, 0, 0, vbSrcInvert
End If
If (var_angle = 270) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_270, 0, 0, vbSrcInvert
End If
If (var_angle = 280) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_280, 0, 0, vbSrcInvert
End If
If (var_angle = 290) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_290, 0, 0, vbSrcInvert
End If
If (var_angle = 300) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_300, 0, 0, vbSrcInvert
End If
If (var_angle = 310) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_310, 0, 0, vbSrcInvert
End If
If (var_angle = 320) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_320, 0, 0, vbSrcInvert
End If
If (var_angle = 330) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_330, 0, 0, vbSrcInvert
End If
If (var_angle = 340) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_340, 0, 0, vbSrcInvert
End If
If (var_angle = 350) Then
BitBlt Me.hdc, 450, 300, 81, 81, dc_ship_350, 0, 0, vbSrcInvert
End If
dc_ship_[0-350]: these are a collection of numbers with the device context of the ship at each angle.
It was then later replaced with an array
VB Code:
Public dc_ship(0 To 35) As Long
And the device contexts in that array were generated as follows :
VB Code:
dc_ship(0) = GenerateDC(App.Path & "\images\ship_0.bmp")
For i = 1 To 35
dc_ship(i) = GenerateDC(App.Path & "\images\ship_" & i & "0.bmp")
Next i
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Aug 13th, 2002, 11:09 AM
#11
Thread Starter
Lively Member
That's wonderful! I'll go threw all the code and see what I can make out of it all. Thanks again everyone
Walter
Anticipation of death is worse than death itself
-
Aug 13th, 2002, 11:13 AM
#12
Retired VBF Adm1nistrator
let us know how you get on.
if you have any problems just post back here
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Aug 17th, 2002, 08:13 AM
#13
Thread Starter
Lively Member
Ok, think I've managed to do it! Now all I need to do is test it out...someone know where I can get some "royalty free" game characters?? I'm absolutely hopeless at drawing on computers!
Walter
Anticipation of death is worse than death itself
-
Aug 17th, 2002, 11:42 PM
#14
PowerPoster
Try looking at the games section of www.vbexplorer.com
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
|