Page 1 of 4 123 ... LastLast
Results 1 to 15 of 53

Thread: Need help with Visual Basic

  1. #1

    Need help with Visual Basic

    I need help getting images that i call up to move.. anyone help me with that?



    Hey im working on my final project in Computer science in school and im trying to make a flash, where you can but different unit types(Marines, Zerglings, Dragoons, etc from SC) by hitting buttons and then moving them into range of the enemy(Siege tanks from SC) and attacking the enemy with waves until they are destroyed. I just started but i was wondering if anyone had any pointers, for example, im at a loss at how i can set up each Picture or (unit) to move and how to select them To move them.. help?
    Last edited by SemperFidelisZ3; April 1st, 2008 at 09:10 PM. Reason: no posts

  2. #2
    bump?

  3. #3
    1,627
    posts
    hugeExplosions = true;
    Are you using VB.NET? You might want to consider using a graphics library - you don't want to be using windows forms..

    Depends what language you are using though
    MS Paint FTW!


  4. #4
    Nope we are just using Microsoft Visual Basic 6.0 Vb98

    But i cant set an image to the keys and make it move when i hit a button.. im trying to code it so that it moves right when i click D and up with W and all of that but at the moment this is all i have and it isnt working haha....



    Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    KeyUp = W
    End Sub

    Private Sub Form_Load()

    Image1.Top = 500
    Image1.Left = 500

    If W = True Then
    Image1.Top = Image1.Top - 30
    End If
    End Sub

    I know im doing something wrong but as a first year programmer i dont know what so any tips and pointers would be loved.. i cant find any tutorials anywhere on t3h web


  5. #5
    Wow I haven't seen vb6 code for a long while, nostalgia feeling.

    Code:
    Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
      If KeyCode = 87 Then 'Keycode for W=87
        Image1.Top = Image1.Top - 30
      ElseIf KeyCode = 83 Then 'Keycode for S=83
        Image1.Top = Image1.Top + 30
      End If
    End Sub
    I think you can figure out right and left.

    Keycodes:
    http://www.gh-gold.co.uk/keycodes.php

    Why are you guys learning with such an outdated software when Visual Studio is free? I really insist you mention something to your teacher. Your teacher will argue its just so you can learn the logic, but a rebuttal would simply be your not learning how to use the actual gui that MS uses now a days.

    (I haven't used VB6 sense I was very little, but I remember the basics if you still have any more questions)
    Last edited by Templarian; April 2nd, 2008 at 03:18 PM.

    Join #kirupa | Click the under my Username | CL | Jeff

  6. #6
    Thank you ill try that out right now!

    and we are just in basic to learn how to work the basics and we have more advanced courses (and our school is kinda stupid with technology)

  7. #7
    Quote Originally Posted by Templarian View Post
    Wow I haven't seen vb6 code for a long while, nostalgia feeling.

    Code:
    Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
      If KeyCode = 87 Then 'Keycode for W=87
        Image1.Top = Image1.Top - 30
      ElseIf KeyCode = 83 Then 'Keycode for S=83
        Image1.Top = Image1.Top + 30
      End If
    End Sub
    I think you can figure out right and left.

    Keycodes:
    http://www.gh-gold.co.uk/keycodes.php

    Why are you guys learning with such an outdated software when Visual Studio is free? I really insist you mention something to your teacher. Your teacher will argue its just so you can learn the logic, but a rebuttal would simply be your not learning how to use the actual gui that MS uses now a days.

    (I haven't used VB6 sense I was very little, but I remember the basics if you still have any more questions)

    Thank you well right now i am starting to work on bringing up all the images.. i got the movement down but in the process i had to erase how i selected units.. i had it set so that if you hit a command button it would bring an image into a set box but i dont know how to deselect the command button and select the image to move it, also if i have the command buttons i cannot select an image.. any ideas?

  8. #8
    Why not a drag select. If I remember there are like box controls.

    READ THIS:
    http://www.codeguru.com/vb/controls/...cle.php/c3499/
    control.remove() i believe removes a control.

    Now that you understand how to create controls dynamically and remove them.

    Basically when you click down create a box control at the mouse postion x and y. Then use the mouse move to drag out the box. and then use a mouseup to then find the starting x,y and ending x,y.

    MOUSE EVENTS:
    http://www.garybeene.com/vb/tut-mice.htm

    Because you can make arrays of controls in vb6 (was removed for the better from vb.net) you can create all your units at once on the screen and loop through them quite easily.


    Create a box off the main view area called Mr. "boxy" these will be your units that you want to select. I used a button you might want to do this onload.

    Code:
    Private Sub Command1_Click()
    For i = 1 To 10
      Load Boxy(i)
      boxy(i).Visible = True
      If i = 1 Then
        boxy(i).top = 10
        boxy(i).left = 10
      Else
        boxy(i).Top = boxy(i-1).Top + boxy(i-1).Height + 2 
      End If
    Next i
    End Sub
    (I believe you can use the unload to remove dynamicly created indexes of control arrays).

    With an array of units you can actually loop through them to move them to see if they are in the selection range of your cursor.

    Global these in a module.
    Code:
    global start_selection_x = 0
    global start_selection_y = 0
    global end_selection_x = 0
    global end_selection_y = 0
    global selected() as Integer
    Mouse Event Code where mousedown will set the start_selection_x/y and the mouseup will end it.

    The mouse move will be used to draw a selection box so the user can see graphically what hes selecting.

    MouseDown
    Code:
    Sub Form_MouseDown (Button As Integer, Shift As Integer, X as Single, Y As Single)
    start_selection_x = x
    start_selection_y = y
    'Create a Visual Selection Box Dynamically here at x,y
    End Sub
    MouseMove
    Code:
    Sub Form_MouseMove (Button As Integer, Shift As Integer, X as Single, Y As Single)
    'Resize the visual selection box.
    End Sub
    MouseUp
    Code:
    Sub Form_MouseUp (Button As Integer, Shift As Integer, X as Single, Y As Single)
    Dim j as Integer = 0
    'Clears out selected array.
    Erase selected
    end_selection_x = x
    end_selection_y = y
    'For loop through boxes to see which top and left are in the area.
    For i = 1 To 10
      if boxy(i).top > start_selection_y and boxy(i).left > start_selection_x and boxy(i).top < y and boxy(i).left < x Then
        selected(j) = i
        j += 1;
      end if
    Next i
     End Sub
    Downside that you have to fix is you can only select from top left to bottom right (simple logic can fix that I'll let you do this if you choose).

    With the selected in an array you can now use this on your key events(if you can understand it, it basically moves all the selected objects for the w key):
    Code:
    Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
      If KeyCode = 87 Then 'Keycode for W=87
         For i = 0 To UBound(selected())
          boxy(selected(i)).Top = boxy(selected(i)).Top - 30
        Next i
      End If
    End Sub
    Thats all I'm gonna type today it should help some... also remember that I haven't used vb6 in a very long time and I typed it all in the browser.

    You may also when adding them change their color its probably something like "boxy.color".
    Last edited by Templarian; April 2nd, 2008 at 10:17 PM.

    Join #kirupa | Click the under my Username | CL | Jeff

  9. #9
    Alright Much appreciation mate, If theres anyway i can repay you for this just let me know and i will do it ASAP :-D......


    Im Happy i got it so i can create my images with Booleans and Move them WooHoo!!




    Just fixed a major bug in my program :-) fixed a spelling error haha

  10. #10
    Hey can someone give me a hint on how to make images collide and take "Damage?"

  11. #11
    To help, can you give a screenshot with arrows on how you battles take place?

    (just to let you know these ways I'm telling you to code this thing is absolutely horrible and cpu intensive and would never be used for a real game).

    Join #kirupa | Click the under my Username | CL | Jeff

  12. #12
    Quote Originally Posted by Templarian View Post
    (just to let you know these ways I'm telling you to code this thing is absolutely horrible and cpu intensive and would never be used for a real game).

    It doesnt have to be a real game we are just doing these for our final games in flash and i simply need help on some of the aspects we have yet to learn

  13. #13


    Its very Simple at the moment

  14. #14

  15. #15
    The easiest way would be to loop through the control array of selected units with the units that you can attack (tanks). I assume tanks are a control array also?

    If you using the code I gave you to select your units they will be in the array selected.

    Hydry = Hydraliscs
    Tanky = Siege Tanks

    This will go at the bottom of your keyUp input:
    Code:
    'Change the []'s with the keycodes for A S D
    If KeyCode = 87 and KeyCode = [] and KeyCode = [] and KeyCode = [] Then
    Dim i
    Dim j
    'Oh yea create an attack button.
    attackbutton.visible = false
    For i = 0 To UBound(selected())
      For j = 0 To UBound(tanky())
       'I think I typed this right... basic hit detect.
        if tanky(j).top > hydry(selected(i)).top and tanky(j).top < hydry(selected(i)).top + hydry(selected(i)).height and tanky(j).left > hydry(selected(i)).left and tanky(j).left < hydry(selected(i)).left + hydry(selected(i)).width Then
          'Make Button visible so we can click it.
          attackbutton.visible = true
        end if
      Next j
    Next i
    end if
    global a few more vars
    Code:
    global hydrahealth() as integer
    global hydradmg as integer = 10
    global tankhealth() as integer
    global tankdmg as integer = 10
    When you create the tanks also add to the array tankhealth() and set its value to 100. This way all the tanks have unique health.

    AttackButton Simular to detecting if they overlap to show the button;
    Code:
    Dim i
    Dim j
    For i = 0 To UBound(selected())
      For j = 0 To UBound(tanky())
       'I think I typed this right... basic hit detect.
        if tanky(j).top > hydry(selected(i)).top and tanky(j).top < hydry(selected(i)).top + hydry(selected(i)).height and tanky(j).left > hydry(selected(i)).left and tanky(j).left < hydry(selected(i)).left + hydry(selected(i)).width Then
          'Now we know whos overlapping who.
          hydrahealth(selected(i)) -= tankdmg
          tankhealth(j) -= hydradmg
          if hydrahealth(selected(i)) <= 0 Then
            hydry(selected(i)).remove()
            'This will error now because but I don't remember how to remove a index value from an array. hydry(selected(i)) Will be undefined next time around I believe.
          end if
          if tankhealth(j) <= 0 Then
            tanky(j).remove()
    'This will error now because but I don't remember how to remove a index value from an array. hydry(selected(i)) Will be undefined next time around I believe.
          end if
        end if
      Next j
    Next i
    Sorry man that got so confusing. I just hope you can use it.
    Last edited by Templarian; April 4th, 2008 at 10:57 AM.

    Join #kirupa | Click the under my Username | CL | Jeff

Page 1 of 4 123 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012