Pokemon VB6 Game
Pokemon VB6 Game
Pokemon VB6 Game
Pokemon VB6 Game
Pokemon VB6 Game
Pokemon VB6 Game Pokemon VB6 Game Pokemon VB6 Game Pokemon VB6 Game Pokemon VB6 Game Pokemon VB6 Game Pokemon VB6 Game Pokemon VB6 Game
Pokemon VB6 Game Pokemon VB6 Game
Pokemon VB6 Game
Go Back  Xtreme Visual Basic Talk > > > Pokemon VB6 Game


Reply
 
Thread Tools Display Modes
  #1  
Old 05-29-2009, 05:17 PM
chroncile chroncile is offline
Newcomer
 
Join Date: May 2009
Posts: 3
Default Pokemon VB6 Game


I have to do this project for my programming class at school and I would like help on how to move the character around. I'm going to use an image or a picturebox for the maps and an image or picturebox for the character.

I don't know how to make the character move so could anyone explain it to me step by step in a noobified version.

Thanks
Reply With Quote
  #2  
Old 05-29-2009, 06:08 PM
Flamespewer Flamespewer is offline
Freshman
 
Join Date: Sep 2008
Posts: 35
Default

so there are two easy ways to do this, first

Way 1: Moving the controls

this way is as simple as just changing the Top and Left properties of a control.

just put the map on your form and the character on it too, and then just use the Form_keydown() event to move your guy.

Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case vbKeyLeft
            man.Left = man.Left - 1
        Case vbKeyRight
            man.Left = man.Left + 1
        Case vbKeyUp
            man.Top = man.Top - 1
        Case vbKeyDown
            man.Top = man.Top + 1
    End Select
End Sub
you need to incorporate some collision detection etc.

Way 2: Bitblt

this is a little more complex but gets rid of flickering and is an easy way to do transparency. put the map, the character, and its mask in a picture box like this.
Sprite-
http://i189.photobucket.com/albums/z.../Pokemon-1.gif
Mask-
http://i189.photobucket.com/albums/z...pewer/Mask.gif
Background-
http://i189.photobucket.com/albums/z...background.gif
make sure to set the the form and the picture boxes Autoredraw property to true and scalemode to 3-Pixel or this wont work

next make a module and put in this code
Code:
Public Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
this declares the bitblt function so you can use it throughout your project.

Code:
Dim ashX As Integer
Dim ashY As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case vbKeyLeft
            ashX = ashX - 1 'moves guy left
            Draw_map 'call the Draw_map function
        Case vbKeyRight
            ashX = ashX + 1 'moves guy right
            Draw_map 'call the Draw_map function
        Case vbKeyUp
            ashY = ashY - 1 'moves guy up
            Draw_map 'call the Draw_map function
        Case vbKeyDown
            ashY = ashY + 1 'moves guy down
            Draw_map 'call the Draw_map function
    End Select
End Sub

Private Sub Form_Load()
    ashx=0
    ashy=0
    Draw_map
End Sub

Private Sub Draw_map()
    Form1.Refresh 'refresh the form
    BitBlt Form1.hDC, 0, 0, Picback.Width, Picback.Height, Picback.hDC, 0, 0, vbSrcCopy 'bitblt background onto form
    BitBlt Form1.hDC, ashX, ashY, Picmask.Width, Picmask.Height, Picmask.hDC, 0, 0, vbSrcAnd 'bitblt mask onto form
    BitBlt Form1.hDC, ashX, ashY, Picsprite.Width, Picsprite.Height, Picsprite.hDC, 0, 0, vbSrcPaint 'bitblt sprite onto form
End Sub
in the beginning we declare ashx and ashy to hold the characters x and y positions.
on Form_load we bitblt the background, the sprite and the mask onto the form.
although it looks complex bitblt is rather simple.

Bitblt-says we want to use the bitblt api

Form1.hDC-this part is the the destination of the image, in this case the form but it can be a picturebox too. .hdc must be added.

ashX, ashY,-this is where, on the destination, we want to put the desired image. we use this part to move the character(by changing the x and y)

Picsprite.Width, Picsprite.Height,Picsprite.hDC- this is the size of the image you want to blt, followed by the source of the image with .hdc.

0, 0-this is the x and y point you want to start bitblting from the source. just leave these at 0,0 to get the whole image.by changing these you can make a scrolling background.

vbSrcPaint & vbSrcCopy & vbSrcAnd-finally is the type of bitblt we want to do.

vbSrcPaint-paints the image on top of things, used for transparency
vbSrcCopy-Copies an image exactly onto the form
vbsrcAnd- use this on the mask to get rid of the black on the sprite

we use the Form_keydown() again but this time we just add or subtract 1(can be any number) to move the x and y coordinates around.

finally, we make a Draw_Map function which is used to re-bitblt onto the form

form1.refresh-refresh the form without this the bitblt wont work correctly
and then blit backonto the form, but we use the variables ashx, and ashy to move the character.

Result
- a character that moves smoothly without flickering
http://i189.photobucket.com/albums/z...wer/bitblt.jpg

Last edited by Flamespewer; 05-30-2009 at 07:36 AM.
Reply With Quote
  #3  
Old 05-29-2009, 08:08 PM
chroncile chroncile is offline
Newcomer
 
Join Date: May 2009
Posts: 3
Default

Thanks for the reply, flame.

Could you please give me the vb project that you just did so I could clarify a few things.

Also, some of the pokemon maps are too big to actually fit on one form so I would like to use the scrolling effect. Do both of these methods cover that?
Reply With Quote
  #4  
Old 05-29-2009, 08:33 PM
Flamespewer Flamespewer is offline
Freshman
 
Join Date: Sep 2008
Posts: 35
Default

no, only bitblt can use scrolling
here is the project containing both an example of moving a character and also scrolling the screen.

to scroll the basic thing you need to remember is you don't move the character you move the background.


Code:
Dim scrollX As Integer
Dim scrollY As Integer
Const SPEED = 5
Private Sub Form_Load()
    scrollX = 0
    scrollY = 0
    Draw_map
End Sub

Private Sub Draw_map()
    BitBlt Picscreen.hDC, 0, 0, Picback.Width, Picback.Height, Picback.hDC, scrollX, scrollY, vbSrcCopy
    BitBlt Picscreen.hDC, (Picscreen.Width - Picsprite.Width) * 0.5, (Picscreen.Height - Picsprite.Height) * 0.5, Picmask.Width, Picmask.Height, Picmask.hDC, 0, 0, vbSrcAnd 'bitblt mask onto picscreen(centered)
    BitBlt Picscreen.hDC, (Picscreen.Width - Picsprite.Width) * 0.5, (Picscreen.Height - Picsprite.Height) * 0.5, Picsprite.Width, Picsprite.Height, Picsprite.hDC, 0, 0, vbSrcPaint 'bitblt sprite onto picscreen(centered)
    Picscreen.Refresh  'refresh the form
End Sub
Private Sub Picscreen_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case vbKeyLeft
            If (scrollX) > 0 Then
                scrollX = scrollX - SPEED
                Draw_map 'call the Draw_map function
            End If
        Case vbKeyRight
            If scrollX + Picscreen.Width < Picback.Width Then
                scrollX = scrollX + SPEED
                Draw_map 'call the Draw_map function
            End If
        Case vbKeyUp
            If scrollY > 0 Then 
                scrollY = scrollY - SPEED
                Draw_map 'call the Draw_map function
            End If
        Case vbKeyDown
            If scrollY + Picscreen.Height < Picback.Height Then  
                scrollY = scrollY + SPEED
                Draw_map 'call the Draw_map function
            End If
    End Select
  
End Sub
if you use bitblt you can easily go into the negative(messes up the screen) by using some very basic if statements you can prevent it from going into the negative or going to far positive(past the actual map).
the bitblt function might look a little bit more complex, but thats just because i centered the character in the screen
Code:
(Picscreen.Width - Picsprite.Width) * 0.5, (Picscreen.Height - Picsprite.Height) * 0.5
you can get rid of that and set it to 0,0 if you want
i set a const SPEED so that you can easily change how fast or slow you want to scroll. i also incorporated both vertical and horizontal scrolling.
Attached Files
File Type: zip Bitblt.zip (69.8 KB, 63 views)

Last edited by Flamespewer; 05-30-2009 at 07:41 AM.
Reply With Quote
  #5  
Old 05-30-2009, 07:34 PM
chroncile chroncile is offline
Newcomer
 
Join Date: May 2009
Posts: 3
Default

Thank you very much for the reply

I have one question, how do I make the speed constant like in the original pokemon game. You know in the original firered pokemon game, it doesn't matter whether you hold down the move key or tap it, it will always go the same speed so how do I do that in visual basic because I plan to have character animations and if the person were to hold down the move key, the animation would look messed up.

Thanks
Reply With Quote
  #6  
Old 05-30-2009, 10:21 PM
Flamespewer Flamespewer is offline
Freshman
 
Join Date: Sep 2008
Posts: 35
Default

i declared const SPEED and you can change the speed there. the speed is always the same.

you should also look up game loops while your at it
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Pokemon VB6 Game
Pokemon VB6 Game
Pokemon VB6 Game Pokemon VB6 Game
Pokemon VB6 Game
Pokemon VB6 Game
Pokemon VB6 Game Pokemon VB6 Game Pokemon VB6 Game Pokemon VB6 Game Pokemon VB6 Game Pokemon VB6 Game Pokemon VB6 Game
Pokemon VB6 Game
Pokemon VB6 Game
 
Pokemon VB6 Game
Pokemon VB6 Game
 
-->