Results 1 to 9 of 9

Thread: Help me!!!!

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2001
    Posts
    4

    Unhappy Help me!!!!

    I have to make a clone of galaxian for a computer project and I'm having some trouble. I cannot get the ship to shoot. I've looked at some code form other programs, but I can't understand it very well. Can anyone help me? I want the program to show a moving object or line when the user hits the space bar, and when it hits the enemy, I want the computer to record it. Can anyone help me with the code?

    If you want more info, just ask. Thanks

  2. #2
    NOMADMAN
    Guest
    I wouldn't mind helping, but what do you have so far? Unless you just want me to make one.. you need to tell the forum what you got so far.

    You using DirectX? API (Bitblt)? or just the form and simple objects?

    If you are using the latter then you may have your code in the wrong objects keypress sub routine. Such that if another object has the focus when you press the space bar it runs that other objects keypress. I would suggest using bitblt, keeps the form as one of the only objects so your keypresses goto the form. Or use GetASyncKeyState

    VB Code:
    1. Declare Function BitBlt Lib "gdi32" Alias "BitBlt" _
    2. (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, _
    3. ByVal nWidth As Long, ByVal nHeight As Long, _
    4. ByVal hSrcDC As Long, ByVal xSrc As Long, _
    5. ByVal ySrc As Long, ByVal dwRop As Long) As Long
    6.  
    7. Declare Function GetAsyncKeyState Lib "user32" _
    8. Alias "GetAsyncKeyState" (ByVal vKey As Long) As Integer

    Another idea is to make a function that handles the shooting and then make every objects keypressed sub call that function, so you can't miss it.

    For all you hard core coders out there I know this may not be the best, actually, I know it isn't the best. DX is the best and the stagities aren't that hot either. But, they do work and a game as simple as Galaxian can still work for a school project using just form objects! I've done it before.

    NOMAD

  3. #3
    Zaei
    Guest
    Use BitBlt, or DirectX or PaintPicture as much as you want, but a game using VB objects is walking on a crutch. If the user decides to click on some object, your form loses focus, and the game stops. You can get around this, of course, but there is still the nasty flickering that comes with some objects. If you decide to go this route, be aware of the alternatives.

    Z.

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2001
    Posts
    4

    Exclamation Can anyone help me with this

    I'm using a normal form, not DX. Right now I can only get the ship to moveHere's my code so far (It's very small):


    Option Explicit

    Dim points As Double

    Private Sub Cmdnew_Click()
    Cmdnew.Visible = False
    lblpoints = 0
    lbllives.Caption = 2
    lblcallsign.Visible = True
    lblpointlabel.Visible = True
    lblpoints.Visible = True
    lblliveslabel.Visible = True
    lbllives.Visible = True
    imgship.Visible = True
    End Sub

    Private Sub Form_Load()
    Dim name As String
    name = InputBox("What is your callsign?")
    lblcallsign.Caption = "Callsign: " + name
    lblcallsign.Visible = False
    lblpointlabel.Visible = False
    lblpoints.Visible = False
    lblliveslabel.Visible = False
    lbllives.Visible = False
    imgship.Visible = False
    End Sub
    Private Sub imgship_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyDown Then
    If imgship.Top > 5000 Then
    imgship.Move imgship.Left, imgship.Top + 0
    Else
    imgship.Move imgship.Left, imgship.Top + 60
    End If
    End If
    If KeyCode = vbKeyUp Then
    If imgship.Top < 4000 Then
    imgship.Move imgship.Left, imgship.Top - 0
    Else
    imgship.Move imgship.Left, imgship.Top - 60
    End If
    End If
    If KeyCode = vbKeyLeft Then
    If imgship.Left < 0 Then
    imgship.Move imgship.Left - 0
    Else
    imgship.Move imgship.Left - 60
    End If
    End If
    If KeyCode = vbKeyRight Then
    If imgship.Left > 6500 Then
    imgship.Move imgship.Left + 0
    Else
    imgship.Move imgship.Left + 60
    End If
    End If
    End Sub

  5. #5
    NOMADMAN
    Guest
    Here is the new code for shooting (and a minor fix to the moving code):

    VB Code:
    1. Option Explicit
    2.  
    3. Dim BulletON(4) As Boolean
    4. Dim points As Double
    5. Dim i As Integer
    6.  
    7. Private Sub Cmdnew_Click()
    8. Cmdnew.Visible = False
    9. lblpoints = 0
    10. lbllives.Caption = 2
    11. lblcallsign.Visible = True
    12. lblpointlabel.Visible = True
    13. lblpoints.Visible = True
    14. lblliveslabel.Visible = True
    15. lbllives.Visible = True
    16. imgShip.Visible = True
    17. End Sub
    18.  
    19. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    20.  
    21.     Call GotKey(KeyCode)
    22.  
    23. End Sub
    24.  
    25. Private Sub Form_Load()
    26. Dim name As String
    27. name = InputBox("What is your callsign?")
    28. lblcallsign.Caption = "Callsign: " + name
    29. lblcallsign.Visible = False
    30. lblpointlabel.Visible = False
    31. lblpoints.Visible = False
    32. lblliveslabel.Visible = False
    33. lbllives.Visible = False
    34. imgship.Visible = False
    35. For i = 0 To 4
    36.     linBullet(i).Visible = False
    37. Next i
    38. End Sub
    39.  
    40. Public Function GotKey(KeyCode As Integer)
    41.  
    42. If KeyCode = vbKeyDown Then
    43. If imgShip.Top > 5000 Then
    44. imgShip.Move imgShip.Left, imgShip.Top + 0
    45. Else
    46. imgShip.Move imgShip.Left, imgShip.Top + 60
    47. End If
    48. End If
    49. If KeyCode = vbKeyUp Then
    50. If imgShip.Top < 4000 Then
    51. imgShip.Move imgShip.Left, imgShip.Top - 0
    52. Else
    53. imgShip.Move imgShip.Left, imgShip.Top - 60
    54. End If
    55. End If
    56. If KeyCode = vbKeyLeft Then
    57. If imgShip.Left < 0 Then
    58. imgShip.Move imgShip.Left - 0
    59. Else
    60. imgShip.Move imgShip.Left - 60
    61. End If
    62. End If
    63. If KeyCode = vbKeyRight Then
    64. If imgShip.Left > 6500 Then
    65. imgShip.Move imgShip.Left + 0
    66. Else
    67. imgShip.Move imgShip.Left + 60
    68. End If
    69. End If
    70.  
    71. '=======================
    72. '===I ADDED THIS CODE===
    73. '=======================
    74. Dim NextBullet As Integer
    75. NextBullet = -1
    76. For i = 0 To 4 'This sees which bullet is next ready
    77.     If BulletON(i) = False Then NextBullet = i
    78. Next i
    79.  
    80. If KeyCode = vbKeySpace And NextBullet <> -1 Then
    81.     BulletON(NextBullet) = True
    82.     linBullet(NextBullet).Visible = True
    83.     linBullet(NextBullet).X1 = imgShip.Left + (imgShip.Width / 2)
    84.     linBullet(NextBullet).X2 = imgShip.Left + (imgShip.Width / 2)
    85.     linBullet(NextBullet).Y1 = imgShip.Top + 250
    86.     linBullet(NextBullet).Y2 = linBullet(NextBullet).Y1 + 240
    87. End If
    88.  
    89. End Function
    90.  
    91. Public Function MoveBullet(bullet As Integer)
    92.    
    93.     For i = 0 To 4 '(4 is just the number of bullets
    94.                           'I chose you may even want a varible)
    95.         If BulletON(i) = True Then
    96.             linBullet(i).Y1 = linBullet(i).Y1 - 100 'again 100 is arbitrary
    97.             linBullet(i).Y2 = linBullet(i).Y1 + 240 ' 240 is just how long the line is
    98.             If linBullet(i).Y2 <= 0 Then BulletON(i) = False
    99.         End If
    100.     Next i
    101.  
    102. End Function
    103.  
    104. Private Sub imgship_KeyDown(KeyCode As Integer, Shift As Integer)
    105.  
    106.     Call GotKey(KeyCode)
    107.  
    108. End Sub
    109.  
    110. Private Sub Timer1_Timer()
    111.    
    112.     For i = 0 To 4
    113.         If BulletON(i) = True Then Call MoveBullet(i)
    114.     Next i
    115.  
    116. End Sub

    I hope this all makes scense. I'll try and explain though.
    I added a GotKey function this can be used by any object on the form. I then added a call to each or the objects KeyDown sub routines. This is what I was talking about in my first post, about objects taking the focus, this fixes that. Secondly, I added the ability to shoot. You get 5 shots and the shots recycle after they get turned "off". Notice the new array at the top of the form? This array tells if the bullet is going or not (on or off). You can add more bullets by adding more Line objects in the linBullet control array and changing the numbers... you know what a control array is? Its like an array for objects (very handy ) There is a movebullet function that will move a specific bullet one click forward (up) when you send the control array index number. I also added a timer (Timer1) this is set on 1 milli and calls the bulletmove function if bulleton(i) = true, so if the bullet is "on" then it gets moved. This routine will also turn the bullet "off" (false) when it goes off the top. You'd need to add code in a Enemy sub routine to make the bullet turn off when it hits an enemy, or else it will go right through them and keep on truckin' all the way to the top of the screen.

    I suggest getting real close to making functions and using timers. Functions simplify and timers regulate. A handy combo. Its also easier to plan and and correct you code like this.

    Need explaination on anything I'll be watching this thread, just ask!

    NOMAD

  6. #6
    Addicted Member Bazza81's Avatar
    Join Date
    Apr 2001
    Location
    Nottingham, UK
    Posts
    203

    Take a look

    Here, I made this space invaders game a while agao, take a look, i hope it helps
    Attached Files Attached Files
    Who needs rhetorical questions anyway?


    Bazza NET - The place you want to be!

  7. #7

    Thread Starter
    New Member
    Join Date
    Dec 2001
    Posts
    4
    Thank a lot everyone, your advice is really helping me.

  8. #8

    Thread Starter
    New Member
    Join Date
    Dec 2001
    Posts
    4
    Can anyone tell me what BitBlt is?

  9. #9
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Bitblt is a graphical API call that uses device contexts (DC, hDC properties). Read about it at my tutorial: http://vbden.tripod.com/articles/invmask.htm

    If you need any help, just reply.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width