Click to See Complete Forum and Search --> : making things move
MPrestonf12
Jun 30th, 2000, 01:25 PM
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
kedaman
Jun 30th, 2000, 02:03 PM
put a balloon picture in a image control and then put this code in a commandbutton event or whatever...
Dim speed&
image1.move rnd*scalewidth,scaleheight
speed=30
Do
image1.move image1.left,image1.top-speed
doevents
Loop until image1.top<0
MPrestonf12
Jun 30th, 2000, 06:06 PM
works great thanks
Spie
Jul 2nd, 2000, 12:26 AM
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?
kedaman
Jul 2nd, 2000, 04:04 AM
Not too hard, here's just an example, if you want to have acceleration involved just put an extra couple of variables handling velocity.
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
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.
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Code for a Timer. Set the Interval to 1.
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
Spie
Jul 2nd, 2000, 01:14 PM
What else do I have to put on the form? I'm rather new at this, so I know next to nothing :)
Thanks,
Spie
Spie
Jul 2nd, 2000, 01:32 PM
Never mind... I got it working :D
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
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.
Originally posted by Spie
Never mind... I got it working :D
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.
Spie
Jul 2nd, 2000, 01:56 PM
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 :D
-Spie
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.
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
Spie
Jul 2nd, 2000, 07:13 PM
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?
kedaman
Jul 2nd, 2000, 09:20 PM
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.
Spie
Jul 2nd, 2000, 09:31 PM
Lol, I only need to know how to move the character in different directions... Do you know how? :)
Spie
Jul 2nd, 2000, 10:26 PM
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
Fox
Jul 3rd, 2000, 12:07 AM
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:
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 ;)
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
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Now put this Code into the Timer.
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.
Spie
Jul 3rd, 2000, 11:40 AM
That works, but he keeps pointing left. Where should I put the other two pictures?
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.
Spie
Jul 3rd, 2000, 12:26 PM
Thank you so much... I got him to change directions. :)
Lol, you don't mind if I ask somemore questions, do you?
Not at all. That's what these forums are for.
Spie
Jul 3rd, 2000, 01:18 PM
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?
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)
Spie
Jul 3rd, 2000, 02:14 PM
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
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
Spie
Jul 3rd, 2000, 03:30 PM
Is that what I have to put? lol :D
Where do I put it? and how do I make a new one?
-Spie
Spie
Jul 4th, 2000, 02:12 PM
How do I get animations to play?
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.
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
Spie
Jul 4th, 2000, 04:49 PM
Is there any way to speed up the animation?
Spie
Jul 4th, 2000, 04:55 PM
sorry for two posts, but I forgot to ask how to make a 2d array... :)
kedaman
Jul 4th, 2000, 04:59 PM
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
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).
Spie
Jul 4th, 2000, 06:37 PM
Ok, I have seen a .map file... Is that what I need?
Spie
Jul 4th, 2000, 07:49 PM
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?
SteveCRM
Jul 4th, 2000, 08:31 PM
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.
SteveCRM@altavista.com
kedaman
Jul 4th, 2000, 09:16 PM
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:
ff=freefile
Open yourfile for binary as ff
put ff,,Width
put ff,,Height
put map
close ff
How to Load map:
ff=freefile
Open yourfile for binary as ff
get ff,,Width
get ff,,Height
redim map(width,height)
get map
close ff
[/code]
Spie
Jul 4th, 2000, 10:02 PM
How do I make a map? Where do I put the code?
kedaman
Jul 5th, 2000, 01:17 AM
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
Spie
Jul 5th, 2000, 02:16 AM
How do I make an array?
Fox
Jul 5th, 2000, 02:24 AM
A 1D-array:
Dim A(10) as Integer
A 2D-array:
Dim A(10, 20) as Integer
...
Fox
Jul 5th, 2000, 02:26 AM
Oh, I forgot:
Array with any dimension and size:
Dim A() as Long
ReDim A(10, 20)
ReDim A(34, 23, 54)
ReDim A(12000)
...whatever you like ;)
Spie
Jul 5th, 2000, 02:30 AM
Stupid me... confused again :( I don't understand where I put the code.
You should put it in a Module. This will create a 10x10 Map.
Public Map(10, 10) As Integer
Spie
Jul 5th, 2000, 01:10 PM
Ohh... Do I put the code for the map the the module too? :)
You mean the code to read the Map? Yes, you can put that in a module and just call it when your Form loads.
Spie
Jul 5th, 2000, 03:59 PM
I meant the code for the map:
>9 = You
>2 = Item
>1 = Wall
>0 = Walkable
>
>0000000000
>0111 1100 00
>0000000000
>0100 200020
>0100 000000
>0100 009000
>0100 000000
>0000000000
>011 1100 000
>000 0100 020
Is this a map?
The Map will be stored in the 2-dimensional Array, and yes, the Array should be stored in the Module.
Spie
Jul 5th, 2000, 04:52 PM
The numbers in the map turn red when I put them in the modual :(
You do not put the number's directly into the module. You put the Array into the Module. The Number's go in a *.txt or *.map file and when you load the file, you store each each numbers in the Array.
Spie
Jul 5th, 2000, 05:53 PM
What code do I out the the modual? The
Public Map(10, 10) As Integer
works, but how do I load my map? I tryed this:
ff=freefile
Open yourfile for binary as ff
get ff,,Width
get ff,,Height
redim map(width,height)
get map
close ff
But it doesnt work :(
Fox
Jul 5th, 2000, 11:58 PM
Did you save a map before trying to load?
Open FileName for binary as FileNumber
Put FileNumber,, Width
Put FileNumber,, Height
Put Map
Close FileNumber
Spie
Jul 6th, 2000, 12:02 AM
I saved my map as a .txt file...
kedaman
Jul 6th, 2000, 01:36 AM
That's not a text file so don't name it .TXT, it's a binary dump and you have to use a hex editor to edit it.
Also I suggest you make an internal editor in your game so that you can design your maps there, that's if you don't have or want to use an hexaeditor.
Spie
Jul 6th, 2000, 02:54 AM
How do I make an editor in my game? :)
Say you have a 10x10 Map. Draw a Grid in your Map editor which is 10x10. In terms of numbers, all our squares are 0's because they are empty.
Now when you select a Tile (a wall for example) and click on your Map, change that specifc square on the map to a 1 to represent the wall. Then when you select a "Death Spot" Tile, change the number to a 2.
Then you just save your Array when you are done your Map.
kedaman
Jul 6th, 2000, 08:57 AM
You should declare a palette variable that you can select a palette for drawing your map, then by clicking on the map you change the array:
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (X - scrollX) / tileW < Width And (Y - scrollY) / tileH < Height Then
map((X - scrollX) / tileW, (Y - scrollY) / tileH) = Palette
End If
End Sub
If you don't need scrolling in your map just remove the scroll variables, you should set the tileW and TileH as the dimensions of your tiles in your game
Spie
Jul 6th, 2000, 01:41 PM
It didnt do anything. What am I suposed to look for?
kedaman
Jul 7th, 2000, 06:55 AM
You should declare a palette variable
Private palette as integer
To which you assign values the way you want, by clicking on a terrain palette or pressing keys (0-9) or anything. You can even set palette=5 in immediate window and it will change
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.