Page 1 of 2 12 LastLast
Results 1 to 40 of 59

Thread: making things move

  1. #1

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    Question

    Im making a somewhat simple as I thought game that has ballons rise from the bottom of the screen at random locations. I can't figure out how to get images to move. Any help is appreciated
    Matt

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    put a balloon picture in a image control and then put this code in a commandbutton event or whatever...
    Code:
    Dim speed&
    image1.move rnd*scalewidth,scaleheight
    speed=30
    Do
       image1.move image1.left,image1.top-speed
       doevents
    Loop until image1.top<0
    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.

  3. #3

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    Thumbs up

    works great thanks
    Matt

  4. #4
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126

    Unhappy Controling the movement... I cant figure it out

    I can't figure out how to control a picture... like an RPG type game. How do I make it to where I can press an arrow button and make a character move around on a .bmp Background, or can i?

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Not too hard, here's just an example, if you want to have acceleration involved just put an extra couple of variables handling velocity.
    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        Select Case KeyCode
            Case vbKeyUp
                image1.Top = image1.Top - speed
            Case vbKeyDown
                image1.Top = image1.Top + speed
            Case vbKeyLeft
                image1.Left = image1.Left - speed
            Case vbKeyRight
                image1.Left = image1.Left + speed
    End Sub
    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.

  6. #6
    Guest
    If you use the GetAsyncKeyState API, you will be able to have more flexiblity. The standard KeyDown or KeyAscii will not allow you to press more than 1 key at a time, this will.

    Code for a module.
    Code:
    Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Code for a Timer. Set the Interval to 1.
    Code:
    Private Sub Timer1_Timer()
    
        If GetAsyncKeyState(vbKeyLeft) Then Image1.Move Image1.Left - 100
        If GetAsyncKeyState(vbKeyRight) Then Image1.Move Image1.Left + 100
        If GetAsyncKeyState(vbKeyUp) Then Image1.Move Image1.Left, Image1.Top - 100
        If GetAsyncKeyState(vbKeyDown) Then Image1.Move Image1.Left, Image1.Top + 100
    
    End Sub

  7. #7
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126

    Question Is that it?

    What else do I have to put on the form? I'm rather new at this, so I know next to nothing
    Thanks,
    Spie

  8. #8
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126

    Talking

    Never mind... I got it working
    But now I have another question... How do I make barriers... So my character wont keep walking when he gets to the end of the form, or picture? Lol, I full of questions
    -spie

  9. #9
    Guest
    In my example, you need a Timer and an ImageBox. You can use a PictureBox in place of the ImageBox, just make sure that you name it Image1.

  10. #10
    Guest
    Originally posted by Spie
    Never mind... I got it working
    But now I have another question... How do I make barriers... So my character wont keep walking when he gets to the end of the form, or picture? Lol, I full of questions
    -spie
    It depends. Are you making your character move at a fixed/relative size? (like Chip's Challenge) or is he moving Bit by Bit? (at no relative size)

    If it's at a relative size, before you move your character, check which position he is on your Map and if he's moving into a block, don't move him.

    If it's the Bit by Bit, you might have to research into collision detection.

  11. #11
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126

    uhh

    Uh, I'm testing this with link from Zelda: a Link to the Past. I am going to making my game similer to this one. I just need to know how to make "Invisible walls"... So the character can't leave the screen... I also need to know how to make him change direction with each key... For example, when I press the up key, the character points in that direction. When I press the right key, he points in that direction.

    One more question... If I'm not boring you to death. How do I make it look like he is running? Do I need an animation?

    As I said, I know almost nothing about this
    -Spie

  12. #12
    Guest
    Yes, animation is required if you want to make it look like he is running. Even a simple 2 frame animation would work.

    You can make him change direction by having 4 seperate images, each from the different directions and have it change when the Direction key is pressed.

    For example.

    Code:
    If GetAsyncKeyState(vbKeyLeft) Then
        'Change the picture so he is facing left, we assume
        'that imgCharLeft is a picture of the character facing left
        imgCharacter.Picture = imgCharLeft.Picture
        imgCharacter.Left = imgCharacter.Left - 100
    End If



  13. #13
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126

    Question

    Um... It makes the character turn left, but not move left.
    How do I make him go left? How do I make him go in the other directions?
    And how do make barriers?

  14. #14
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Sorry to disappoint you, but you can't continue like this, making this game will take ages, you will find Fox site a lot usefull, ask him and he will give you some advice.
    Fox McCloud's homepage
    http://foxmccloud.tsx.org/

    btw, Getasyncstate will allow you to press several keys at once and monitor them

    Also you could ask me an i'll give you some samples how to create a game structure by using classes

    Thrust me, I know games.
    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.

  15. #15
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126
    Lol, I only need to know how to move the character in different directions... Do you know how?

  16. #16
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126

    Unhappy I'm stumped

    I'm stumped. I spent three hours trying to figure out how to make the character change directions. I only managed to make him face left, instead of down. Then he would stay like that. Please help me with a couple things...
    1. Making him change directions when you press a key...
    2. Barriers... So he wont walk on water, or over cliffs.
    ... ...
    Oh, if you have a program that has a character that can move around the screen, please send me the code.
    Thanks alot,
    Spie

  17. #17
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Ok, I'll give you a hint: (Just found this thread again after 15 posts I thought it's time to have a look at it )

    Well, to check the keys you can use GetAsyncKeyState (or something), the standard KeyDown event from Forms or Directinput (which is one of the easiest DirectX packets ). The idea is, that you store the keys in an array and check them in a loop, so you get faster performance. I'll show you an example:

    Code:
    Dim KD() as Boolean 'Holds the keys
    
    Form_KeyDown
       KD( KeyCode ) = True
    End Sub
    
    Form_KeyUp
       KD( KeyCode ) = False
    End Sub
    
    Public Sub Main
       While Active
          If KD( vbKeyUp ) = True then
             'Move the Player up
          ElseIf KD( vbKeyRight ) = True then
             'Move the Player right
          ElseIf KD( vbKeyDown ) = True then
             'Move the Player down
          ElseIf KD( vbKeyLeft ) = True then
             'Move the Player left
          EndIf
    
          DoEvents
       Wend
    End Sub

    I hope you ge the idea... sorry but have to go to work now, I'll prolly come back later

  18. #18
    Guest
    Spie:
    The example I have you before should have worked. But maybe you did not have the correct controls on. Make 2 PictureBox's and called them imgCharacter and imgCharLeft. Then make a Timer and Set it's Interval to 1.

    Code for a module
    Code:
    Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Now put this Code into the Timer.
    Code:
    Private Sub Timer1_Timer()
    
        If GetAsyncKeyState(vbKeyLeft) Then
            'Change the picture so he is facing left, we assume
            'that imgCharLeft is a picture of the character facing left
            imgCharacter.Picture = imgCharLeft.Picture
            imgCharacter.Left = imgCharacter.Left - 100
        End If
    
    End Sub

    This is just a simple example using Controls for simplicity
    sake. when you are making a game, use you should consider using DirectDraw or BitBlt.

  19. #19
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126

    Question

    That works, but he keeps pointing left. Where should I put the other two pictures?

  20. #20
    Guest
    There should be 1 main picture for the character and 4 other pictures for the different directions. For the 4 that you are not using, set their Visible property to False.

  21. #21
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126

    Talking

    Thank you so much... I got him to change directions.
    Lol, you don't mind if I ask somemore questions, do you?

  22. #22
    Guest
    Not at all. That's what these forums are for.

  23. #23
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126

    Smile

    Ok, I didn't understand what you said about "invisible walls" Is there some kind of code that will stop the character from going past a certain point?




  24. #24
    Guest
    Well that depends on how you are making the game. Firstly, how do you have your Map stored? Is it in an Array? Secondly, are you making your character move at a fixed/relative size? (like Chip's Challenge) or is he moving Bit by Bit? (at no relative size)

  25. #25
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126

    Question

    What do you mean by map? Do you mean the screen he is walking on? If not... I need help with that (figures), lol.

    I have never played Chip's challenge... Have you played Zelda for the super nintendo (A Link to the Past)? That is the kind of game I am talking about. If you don't have it you can download an emulator for it... ZSNES is a good one.
    Thanks,
    Spie

  26. #26
    Guest
    Yes, the map is what you play on. For example, a simple Map could look something like this.

    9 = You
    2 = Item
    1 = Wall
    0 = Walkable

    0000000000
    0111110000
    0000000000
    0100200020
    0100000000
    0100009000
    0100000000
    0000000000
    0111100000
    0000100020

  27. #27
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126

    Smile

    Is that what I have to put? lol
    Where do I put it? and how do I make a new one?
    -Spie

  28. #28
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126

    Question Animations

    How do I get animations to play?

  29. #29
    Guest
    You can store that Map in a 2 Dimensional Array.

    To play simple animations, you can use a Timer. Make 3 PictureBox's. picMain, pic1 and pic2. Make the Picture in picMain and pic1 the same and load a different one into pic2.

    Put this code into a Timer and set its Interval to 200.
    Code:
    Private Sub Timer1_Timer()
    
        'If our Picture is the 1st frame then
        If picMain = pic1 Then
            picMain = pic2
            Exit Sub
        Else
            'If it's the 2nd Frame
            picMain = pic1
        End If
    
    End Sub

  30. #30
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126
    Is there any way to speed up the animation?

  31. #31
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126
    sorry for two posts, but I forgot to ask how to make a 2d array...

  32. #32
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    In your declarations (in a form not class or else use private instead of public)
    Public map() as byte
    Public Width as long, Height as long

    And in your initial code (ie sub form_load)

    Height=50:width=50
    Redim map(Width,Height)

    No you can't speed up that without having to use layers with device context, or better up DirectDraw
    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.

  33. #33
    Guest
    You can speed up animation by setting the Timer's Interval to a lower number. If you do not want to use the Timer for animation, use BitBlt or DirectDraw (The best one).

  34. #34
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126
    Ok, I have seen a .map file... Is that what I need?

  35. #35
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126
    Again, sorry for two posts, but is there some way to make the picture of the character less choppy? When I move sometimes the background turns to white for a second, then changes back to being transperent. Is it the animation?

  36. #36
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    Wow! this post is getting long! I haven't been able to get these things working that your talking about. Can you send me an example of what you guys are talking about? Im very interrested in maps and 2D arrays.
    [email protected]

  37. #37
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Steve, Go download the demo from Fox page

    Spie, You have to post some code, or probably the whole form, eventually send your project if you want to solve that kind of problems because anything can cause that.

    If you want to store your map you could have use of a .map file

    Open it in binary and to read with get and write with put

    How to save map:
    Code:
    ff=freefile
    Open yourfile for binary as ff
      put ff,,Width
      put ff,,Height
      put map
    close ff
    How to Load map:
    Code:
    ff=freefile
    Open yourfile for binary as ff
      get ff,,Width
      get ff,,Height
      redim map(width,height)
      get map
    close ff
    [/code]
    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.

  38. #38
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126
    How do I make a map? Where do I put the code?

  39. #39
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    This code will store your map array binary so you will have to use an hex editor if you want to edit it externally..

    Instead you could edit it in you game, that would be much easier.

    Your map will be created in memory as soon as the array is initialized, and it will be stored on your harddrive by using the save map code i gave you.

    Put it in a commandbutton, a menu or whereever you want. I would recommend you make procedures for them so that you can call them anywhere you want
    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.

  40. #40
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126
    How do I make an array?

Page 1 of 2 12 LastLast

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