beautyfarm - THE BEST DESIGN
DOWNLOAD MY MUSIK,participa la concursuri,soft-uri,cool stuff,NIKON CLUB,Baruri Trendy,ScreenSavers,Accesorii Cool,Masini sexy,Bannere,Games,Aparitii Cinematografice,Tribal Farm...etc distreaza-te!Totul pentru TINE.Cele mai tari subiecte.
Lista Forumurilor Pe Tematici
beautyfarm - THE BEST DESIGN | Inregistrare | Login

POZE BEAUTYFARM - THE BEST DESIGN

Nu sunteti logat.
Nou pe simpatie:
Profil andreeadede
Femeie
24 ani
Ilfov
cauta Barbat
24 - 39 ani
beautyfarm - THE BEST DESIGN / PASSWORD / Basics of making a game in VB  
Autor
Mesaj Pagini: 1
G-ride
Electrik Buzzz

Inregistrat: acum 16 ani
Postari: 35
.............

Code:

Private Declare Function GetAsyncKeyState Lib _
"user32" _
(ByVal vKey As Long) As Integer

after declaring GetasyncKeyState your free to start binding keypresses with actions. to do this, we want to create a timer, so drag a timer and set the interval to somewhere from 5-15 (milliseconds) what a timer do is executing its content every chosen amound of milliseconds. which is usefull. then the timer will check if a key is pressed every 10 milliseconds. >nice

To bind keys with actions we need to know the keycode of the specific key. Every key has a number which is its keycode.

a full list of all the key's numbers can be found here
This is the codes we need:

Code:

vbKeyLeft 37 LEFT ARROW key 
vbKeyUp 38 UP ARROW key 
vbKeyRight 39 RIGHT ARROW key 
vbKeyDown 40 DOWN ARROW key

So lets start binding. The keyboards left key has the number '37'. lets start with the left key. go to the timer and write this:

Code:

if GetAsyncKeyState(37) = true then
end if

this means that if key 37 (left) is held down it will execute commands below. >neat.

now. how do we move our image to the right?
easy!
the image has a left and a top position. by changing those positions we move the image. as so:

image.left = image.left - 10
to move it left ^

or

image.left = image.left + 10
to move it right ^

and pretty much the same with up and down, just using 'top' instead of 'left'.

so the code for the left key would be:

Code:

if GetAsyncKeyState(37) = true then
image.left = image.left - 10
end if

2: Collision detection:

We are gonna detect if objects are at the same position using the top and left positions, and the height and width of the image.

For this, its a good idea to make a square on the form that the image can move around inside, but not get out of. Now first lets do the left side, ill explain more after, dont worry.

we can either put this in a new timer or edit the older one.

If image.left <= square.left then image.left = square.left

say what?!?
what this means is that if the images left position is lesser or equals the the shapes left position (shapes left position is the same as the left side) then it sets the images position back to the same spot as the squares left side. so you cannot come any further.

now if say we want the image to go out of the opposite wall like in snake2 so it goes out of the screen and appears on the opposite side you can easily do that by saying 'then image.left = square.left + square.width - image.width. Now wtf does that mean?
square.left is the squares position on the form., now theres no option called right position se we need to add the left side up with the width, to get the right side's position on the form.

now then whats with the - image.width. well since we are calculating with the images left side it would appear on the wrong side of the right side on the square, we fix that by minus'ing the images width.
Note: i know this all may sound confusing.. little hard to explain.

now again this is pretty much the same with colliding with the top and bottom walls. remember the above part if your not very good at math, if you are good at logical thinking this shouldnt be no problem at all. anyway. ask if theres something.. also remember that you cannot use the '>' for all of the sides. on the opposite sides you need the '<' instead. but again. if your a logical thinker it shouldnt be a problem.

now. this is all fine but what if we need to detect collision with a smaller object than the image. say a little bullet or something like that.

Code:

If (image.Left + image.Width >= bullet.Left _
And image.Left <= bullet.Left + bullet.Width) _
And (image.Top + image.Height >= bullet.Top _
And image.Top <= bullet.Top + bullet.Height) Then
msgbox "collision"
end if



_______________________________________


pus acum 15 ani
   
Pagini: 1  

Mergi la