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
Printable View
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
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
works great thanks
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?
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
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 for a Timer. Set the Interval to 1.Code:Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
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
What else do I have to put on the form? I'm rather new at this, so I know next to nothing :)
Thanks,
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
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.
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)Quote:
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
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.
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.
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
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?
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.
Lol, I only need to know how to move the character in different directions... Do you know how? :)
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
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 ;)
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
Now put this Code into the Timer.Code:Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
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.
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.
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.
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)
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
Is that what I have to put? lol :D
Where do I put it? and how do I make a new one?
-Spie
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.
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
Is there any way to speed up the animation?
sorry for two posts, but I forgot to ask how to make a 2d array... :)
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).
Ok, I have seen a .map file... Is that what I need?
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?
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]
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:
How to Load map:Code:ff=freefile
Open yourfile for binary as ff
put ff,,Width
put ff,,Height
put map
close ff
[/code]Code:ff=freefile
Open yourfile for binary as ff
get ff,,Width
get ff,,Height
redim map(width,height)
get map
close ff
How do I make a map? Where do I put the code?
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
How do I make an array?