Results 1 to 12 of 12

Thread: I cant get the laser to shoot!!!!!!!!!

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2001
    Location
    Heaven........ Whats that fire doing here?
    Posts
    39

    Unhappy I cant get the laser to shoot!!!!!!!!!

    Ok.... I am kinda new to vb (8 months just started programming games) and i have downloaded exampled of things like ships shooting lasers but I just cant seem to get it to work.... Ok this is what I want my game to do (I can do everything but the laser part)


    I want it so that I can move my guy topgod to be able to fire a laser line1 down........... but I can seem to make the laser follow the Topgod image...... I can get it to fly through the screen with this code


    private sub form_Keydown (keycode bla bla bla)
    if keycode = 32 then
    line1.visible = true
    timer1.enabled = true

    End sub



    private sub timer1_timer
    line1.top = line1.top - 100
    End sub




    now the - 100....... I dont really remember what I put but it made the laser go down....... I just need to make it so if the ImgGod is at the left part of the screen the laser will shoot from there, and not from just the middle of the screen..... i want the laser to be able to be shot from wherever my imggod is... (my imggod can only move left or right)




    Thank you soooooo much....................

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Well if you want the laser to come from your player's image, then just put its start co-ordinates there. Then have them incriment or decrement depending on the direction they're facing
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2001
    Location
    Heaven........ Whats that fire doing here?
    Posts
    39

    Question Im sorry but......

    Im sorry but I dont think I understand.... You mean

    imggod.left = line1.left
    imggod.top = line1.top





    or





    imggod.height = line1.height
    imggod.width = line1.width




    or what do you mean?

    and then once it does shoot, how do I get it to reappear so It can be shot again? Thanks soooo much......

  4. #4
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Okay lets say that the player's picture is imgGod, and the laser picture is imgLsr.
    To make the laser come from your player you'd start off like this :

    VB Code:
    1. With imgLsr
    2.         .Left = imgGod.Left
    3.         .Top = imgGod.Top
    4.     End With

    So the laser is now at the player. Then you would find out what direction the player is facing. If its simply just a left/right shooter, then just left/right, or if there are more angles involved, then trigonometry could be required.
    Lets assume that the player is facing straight up, so then to fire a laser straight up would mean you have to enable a timer, or something thats going to keep updating the position of the laser and do something like this :

    (assuming PicDisplay is where you're showing all this, and ScaleMode = 3)
    VB Code:
    1. If (imgLsr.Top < PicDisplay.ScaleHeight) Then
    2.     imgLsr.Top = imgLsr.Top - speedOfLaser
    3. End If

    That will make it go up..
    If you wanna see an example of this goto my website (www.coolground.com/plenderj), and grab Craft, which can be found if you scroll all the way to the right. That is a game in which you can shoot lasers.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2001
    Location
    Heaven........ Whats that fire doing here?
    Posts
    39

    What is the picdisplay

    Hey, sorry for being stupid but im learning...... What is the pic desplay/display....... whatever you said..... is it the pic ........ or just what is it....???????????? thanks

  6. #6
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Its wherever you're displaying all this stuff. If you're displaying everything just on a form, then change it to the form name.... or if you're displaying everything in a picturebox, then change it to the name of the picturebox
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2001
    Location
    Heaven........ Whats that fire doing here?
    Posts
    39

    Talking Hey Thanks sooo Much! It worked

    ok..... now I have another question..... Sorry if im annoying but I could not find any of this stuff in any vb book...... but I have looked at intersectRect before and I just dont get what Im supposed to do...... I need to make it so if the laser goes up and hits my image called imglord then I want imglord to explode (all I need is the collision part..... I know how to make the images visible and not visible)

    Thanks

  8. #8

    Thread Starter
    Member
    Join Date
    Nov 2001
    Location
    Heaven........ Whats that fire doing here?
    Posts
    39

    Question Hey what about collision.............???

    I need to make it so if the laser goes up and hits my image called imglord then I want imglord to explode (all I need is the collision part..... I know how to make the images visible and not visible)

    Im sorry but I do not get intersectrect..... so if someone could please explain everything that I need and everything about it (Explain in detail) then Im sure it would do this message board as well as me a lot of good...... I have looked at other other collision forums and posts adn I just can figure it out.... I have looked at all the totorials(CANT SPELL) in the world and Im stumped

    Thanks much.........

  9. #9
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Oregon
    Posts
    962
    Code:
    If (imgLaser.left + imgLaser.width  >= imgTarget.left) and _
       (imgLaser.left <= imgTarget.left + imgTarget.left) and _
       (imgLaser.top + imgLaser.height >= imgTarget.top) and _
       (imgLaser.top <= imgTarget.top + imgTarget.height) then
    COLLISION DETECTED CODE
    end if
    The above code should do square collision dection. imgLaser is the projectile being fired (from what I read the laser), and imgTarget is the object being fired at (fromn what I read imgLord).
    Last edited by Gaming_World; Nov 11th, 2001 at 02:05 AM.
    Involved in: Sentience

  10. #10
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Oregon
    Posts
    962
    The code I posted in my last post may not work if LaserSpeed >= imgTarget.height, as the laser could jump though the imgTarget.

    It also wouldn't matter what part of the laser hits what part of the target, it should still detect it.
    Involved in: Sentience

  11. #11

    Thread Starter
    Member
    Join Date
    Nov 2001
    Location
    Heaven........ Whats that fire doing here?
    Posts
    39

    Talking Thanks..... Finally one that works... :)

    Thank you so much...... and its an if statement..... I knew you could do that but I heard it was time consuming and made your program run really slow..... But Im happy Ok but there is one problem..... Everytime I shoot within 3 positions over (Whenever the laser passer by imgtarget by ------------ or within that(only to the right not to the left)) then it does the msgbox "collision" thing that I wanted it to do, but it does it to the right of the object as well, not just on the object



    Thanks Much.....

  12. #12

    Thread Starter
    Member
    Join Date
    Nov 2001
    Location
    Heaven........ Whats that fire doing here?
    Posts
    39

    Talking Thank you

    Thank you guys soo much for all the help..... finally I can now learn from looking at the code.... Thanks

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