CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Simple RPG

  1. #1
    Join Date
    Feb 2011
    Posts
    1

    Simple RPG

    I searched a lot of forums, but I can't really find the answer to my problem. Simply put, my problem is that my character won't move. Here's my code:

    Private Sub frmMain_Load()

    Randomize 'sets the randomizer

    r = Fix(Rnd * 100) Mod 10 'sets how many moves it will take to enter the battle subroutine

    lblLevel.Caption = Fix(Experience / 50) + 1 'displays the level

    End Sub

    Private Sub frmMain_KeyDown()

    If KeyCode = vbKeyEscape Then 'the game ends if the escape key is pressed

    Me.Hide

    Else

    Do Until r < 0 'loops the movement keys

    If KeyCode = vbKeyW Or KeyCode = vbKeyUp Then 'checks if W was pressed

    If imgElf.Top - 480 = img8.Top And imgElf.Left = img8.Left Then

    Boss = 1

    Me.Hide

    frmBattleSub.Show

    ElseIf imgElf.Top - 480 = img1.Top Or imgElf.Left = img1.Left Or imgElf.Top - 480 = img196.Top Or imgElf.Left = img196.Left Or imgElf.Top - 480 = Image6.Top And imgElf.Left = Image6.Left Or imgElf.Top - 480 = Image18.Top And imgElf.Left = Image18.Left Or imgElf.Top - 480 = Image25.Top And imgElf.Left = Image25.Left Or imgElf.Top - 480 = Image29.Top And imgElf.Left = Image29.Left Or imgElf.Top - 480 = Image39.Top And imgElf.Left = Image39.Left Or imgElf.Top - 480 = Image41.Top And imgElf.Left = Image41.Left Or imgElf.Top - 480 = Image51.Top And imgElf.Left = Image51.Left Or imgElf.Top - 480 = Image59.Top And imgElf.Left = Image59.Left Or imgElf.Top - 480 = Image65.Top And imgElf.Left = Image65.Left Or imgElf.Top - 480 = Image72.Top And imgElf.Left = Image72.Left Or imgElf.Top - 480 = Image74.Top And imgElf.Left = Image74.Left Or imgElf.Top - 480 = Image77.Top And imgElf.Left = Image77.Left Or imgElf.Top - 480 = Image83.Top And imgElf.Left = Image83.Left Then

    MsgBox "Can't move there!" 'tells the player if he can’t move to an area

    ElseIf imgElf.Top - 480 = Image85.Top And imgElf.Left = Image85.Left Or imgElf.Top - 480 = Image86.Top And imgElf.Left = Image86.Left Or imgElf.Top - 480 = Image96.Top And imgElf.Left = Image96.Left Or imgElf.Top - 480 = Image97.Top And imgElf.Left = Image97.Left Or imgElf.Top - 480 = Image99.Top And imgElf.Left = Image99.Left Or imgElf.Top - 480 = Image101.Top And imgElf.Left = Image101.Left Or imgElf.Top - 480 = Image104.Top And imgElf.Left = Image104.Left Or imgElf.Top - 480 = Image111.Top And imgElf.Left = Image111.Left Or imgElf.Top - 480 = Image114.Top And imgElf.Left = Image114.Left Or imgElf.Top - 480 = Image119.Top And imgElf.Left = Image119.Left Or imgElf.Top - 480 = Image126.Top And imgElf.Left = Image126.Left Or imgElf.Top - 480 = Image132.Top And imgElf.Left = Image132.Left Or imgElf.Top - 480 = Image133.Top And imgElf.Left = Image133.Left Or imgElf.Top - 480 = Image141.Top And imgElf.Left = Image141.Left Or imgElf.Top - 480 = Image145.Top And imgElf.Left = Image145.Left Then

    MsgBox "Can't move there!" 'tells the player if he can’t move to an area

    ElseIf imgElf.Top - 480 = Image153.Top And imgElf.Left = Image153.Left Or imgElf.Top - 480 = Image160.Top And imgElf.Left = Image160.Left Or imgElf.Top - 480 = Image171.Top And imgElf.Left = Image171.Left Or imgElf.Top - 480 = Image176.Top And imgElf.Left = Image176.Left Or imgElf.Top - 480 = Image186.Top And imgElf.Left = Image186.Left Or imgElf.Top - 480 = Image193.Top And imgElf.Left = Image193.Left Then

    MsgBox "Can't move there!" 'tells the player if he can’t move to an area

    Else

    imgElf.Top = imgElf.Top - 480

    r = r - 1 'counter for entering the battle subroutine

    End If

    ElseIf KeyCode = vbKeyS Or KeyCode = vbKeyDown Then

    If imgElf.Top + 480 = img1.Top Or imgElf.Left = img1.Left Or imgElf.Top + 480 = img196.Top Or imgElf.Left = img196.Left Or imgElf.Top + 480 = Image6.Top And imgElf.Left = Image6.Left Or imgElf.Top + 480 = Image18.Top And imgElf.Left = Image18.Left Or imgElf.Top + 480 = Image25.Top And imgElf.Left = Image25.Left Or imgElf.Top + 480 = Image29.Top And imgElf.Left = Image29.Left Or imgElf.Top + 480 = Image39.Top And imgElf.Left = Image39.Left Or imgElf.Top + 480 = Image41.Top And imgElf.Left = Image41.Left Or imgElf.Top + 480 = Image51.Top And imgElf.Left = Image51.Left Or imgElf.Top + 480 = Image59.Top And imgElf.Left = Image59.Left Or imgElf.Top + 480 = Image65.Top And imgElf.Left = Image65.Left Or imgElf.Top + 480 = Image72.Top And imgElf.Left = Image72.Left Or imgElf.Top + 480 = Image74.Top And imgElf.Left = Image74.Left Or imgElf.Top + 480 = Image77.Top And imgElf.Left = Image77.Left Or imgElf.Top + 480 = Image83.Top And imgElf.Left = Image83.Left Then

    MsgBox "Can't move there!" 'tells the player if he can’t move to an area

    ElseIf imgElf.Top + 480 = Image85.Top And imgElf.Left = Image85.Left Or imgElf.Top + 480 = Image86.Top And imgElf.Left = Image86.Left Or imgElf.Top + 480 = Image96.Top And imgElf.Left = Image96.Left Or imgElf.Top + 480 = Image97.Top And imgElf.Left = Image97.Left Or imgElf.Top + 480 = Image99.Top And imgElf.Left = Image99.Left Or imgElf.Top + 480 = Image101.Top And imgElf.Left = Image101.Left Or imgElf.Top + 480 = Image104.Top And imgElf.Left = Image104.Left Or imgElf.Top + 480 = Image111.Top And imgElf.Left = Image111.Left Or imgElf.Top + 480 = Image114.Top And imgElf.Left = Image114.Left Or imgElf.Top + 480 = Image119.Top And imgElf.Left = Image119.Left Or imgElf.Top + 480 = Image126.Top And imgElf.Left = Image126.Left Or imgElf.Top + 480 = Image132.Top And imgElf.Left = Image132.Left Or imgElf.Top + 480 = Image133.Top And imgElf.Left = Image133.Left Or imgElf.Top + 480 = Image141.Top And imgElf.Left = Image141.Left Or imgElf.Top + 480 = Image145.Top And imgElf.Left = Image145.Left Then

    MsgBox "Can't move there!" 'tells the player if he can’t move to an area

    ElseIf imgElf.Top + 480 = Image153.Top And imgElf.Left = Image153.Left Or imgElf.Top + 480 = Image160.Top And imgElf.Left = Image160.Left Or imgElf.Top + 480 = Image171.Top And imgElf.Left = Image171.Left Or imgElf.Top + 480 = Image176.Top And imgElf.Left = Image176.Left Or imgElf.Top + 480 = Image186.Top And imgElf.Left = Image186.Left Or imgElf.Top + 480 = Image193.Top And imgElf.Left = Image193.Left Then

    MsgBox "Can't move there!" 'tells the player if he can’t move to an area

    Else

    imgElf.Top = imgElf.Top + 480

    r = r - 1

    End If

    ElseIf KeyCode = vbKeyA Or KeyCode = vbKeyLeft Then

    If imgElf.Top = img1.Top Or imgElf.Left = img1.Left - 375 Or imgElf.Top = img196.Top Or imgElf.Left = img196.Left - 375 Or imgElf.Top = Image6.Top And imgElf.Left = Image6.Left - 375 Or imgElf.Top = Image18.Top And imgElf.Left = Image18.Left - 375 Or imgElf.Top = Image25.Top And imgElf.Left = Image25.Left - 375 Or imgElf.Top = Image29.Top And imgElf.Left = Image29.Left - 375 Or imgElf.Top = Image39.Top And imgElf.Left = Image39.Left - 375 Or imgElf.Top = Image41.Top And imgElf.Left = Image41.Left - 375 Or imgElf.Top = Image51.Top And imgElf.Left = Image51.Left - 375 Or imgElf.Top = Image59.Top And imgElf.Left = Image59.Left - 375 Or imgElf.Top = Image65.Top And imgElf.Left = Image65.Left - 375 Or imgElf.Top = Image72.Top And imgElf.Left = Image72.Left - 375 Or imgElf.Top = Image74.Top And imgElf.Left = Image74.Left - 375 Or imgElf.Top = Image77.Top And imgElf.Left = Image77.Left - 375 Or imgElf.Top = Image83.Top And imgElf.Left = Image83.Left Then

    MsgBox "Can't move there!" 'tells the player if he can’t move to an area

    ElseIf imgElf.Top = Image85.Top And imgElf.Left = Image85.Left - 375 Or imgElf.Top = Image86.Top And imgElf.Left = Image86.Left - 375 Or imgElf.Top = Image96.Top And imgElf.Left = Image96.Left - 375 Or imgElf.Top = Image97.Top And imgElf.Left = Image97.Left - 375 Or imgElf.Top = Image99.Top And imgElf.Left = Image99.Left - 375 Or imgElf.Top = Image101.Top And imgElf.Left = Image101.Left - 375 Or imgElf.Top = Image104.Top And imgElf.Left = Image104.Left - 375 Or imgElf.Top = Image111.Top And imgElf.Left = Image111.Left - 375 Or imgElf.Top = Image114.Top And imgElf.Left = Image114.Left - 375 Or imgElf.Top = Image119.Top And imgElf.Left = Image119.Left - 375 Or imgElf.Top = Image126.Top And imgElf.Left = Image126.Left - 375 Or imgElf.Top = Image132.Top And imgElf.Left = Image132.Left - 375 Or imgElf.Top = Image133.Top And imgElf.Left = Image133.Left - 375 Or imgElf.Top = Image141.Top And imgElf.Left = Image141.Left - 375 Or imgElf.Top = Image145.Top And imgElf.Left = Image145.Left Then

    MsgBox "Can't move there!" 'tells the player if he can’t move to an area

    ElseIf imgElf.Top = Image153.Top And imgElf.Left = Image153.Left - 375 Or imgElf.Top = Image160.Top And imgElf.Left = Image160.Left - 375 Or imgElf.Top = Image171.Top And imgElf.Left = Image171.Left - 375 Or imgElf.Top = Image176.Top And imgElf.Left = Image176.Left - 375 Or imgElf.Top = Image186.Top And imgElf.Left = Image186.Left - 375 Or imgElf.Top = Image193.Top And imgElf.Left = Image193.Left Then

    MsgBox "Can't move there!" 'tells the player if he can’t move to an area

    Else

    imgElf.Left = imgElf.Left - 375

    r = r - 1

    End If

    ElseIf KeyCode = vbKeyD Or KeyCode = vbKeyRight Then

    If imgElf.Top = img1.Top Or imgElf.Left = img1.Left + 375 Or imgElf.Top = img196.Top Or imgElf.Left = img196.Left + 375 Or imgElf.Top = Image6.Top And imgElf.Left = Image6.Left + 375 Or imgElf.Top = Image18.Top And imgElf.Left = Image18.Left + 375 Or imgElf.Top = Image25.Top And imgElf.Left = Image25.Left + 375 Or imgElf.Top = Image29.Top And imgElf.Left = Image29.Left + 375 Or imgElf.Top = Image39.Top And imgElf.Left = Image39.Left + 375 Or imgElf.Top = Image41.Top And imgElf.Left = Image41.Left + 375 Or imgElf.Top = Image51.Top And imgElf.Left = Image51.Left + 375 Or imgElf.Top = Image59.Top And imgElf.Left = Image59.Left + 375 Or imgElf.Top = Image65.Top And imgElf.Left = Image65.Left + 375 Or imgElf.Top = Image72.Top And imgElf.Left = Image72.Left + 375 Or imgElf.Top = Image74.Top And imgElf.Left = Image74.Left + 375 Or imgElf.Top = Image77.Top And imgElf.Left = Image77.Left + 375 Or imgElf.Top = Image83.Top And imgElf.Left = Image83.Left Then

    MsgBox "Can't move there!" 'tells the player if he can’t move to an area

    ElseIf imgElf.Top = Image85.Top And imgElf.Left = Image85.Left + 375 Or imgElf.Top = Image86.Top And imgElf.Left = Image86.Left + 375 Or imgElf.Top = Image96.Top And imgElf.Left = Image96.Left + 375 Or imgElf.Top = Image97.Top And imgElf.Left = Image97.Left + 375 Or imgElf.Top = Image99.Top And imgElf.Left = Image99.Left + 375 Or imgElf.Top = Image101.Top And imgElf.Left = Image101.Left + 375 Or imgElf.Top = Image104.Top And imgElf.Left = Image104.Left + 375 Or imgElf.Top = Image111.Top And imgElf.Left = Image111.Left + 375 Or imgElf.Top = Image114.Top And imgElf.Left = Image114.Left + 375 Or imgElf.Top = Image119.Top And imgElf.Left = Image119.Left + 375 Or imgElf.Top = Image126.Top And imgElf.Left = Image126.Left + 375 Or imgElf.Top = Image132.Top And imgElf.Left = Image132.Left + 375 Or imgElf.Top = Image133.Top And imgElf.Left = Image133.Left + 375 Or imgElf.Top = Image141.Top And imgElf.Left = Image141.Left + 375 Or imgElf.Top = Image145.Top And imgElf.Left = Image145.Left Then

    MsgBox "Can't move there!" 'tells the player if he can’t move to an area

    ElseIf imgElf.Top = Image153.Top And imgElf.Left = Image153.Left + 375 Or imgElf.Top = Image160.Top And imgElf.Left = Image160.Left + 375 Or imgElf.Top = Image171.Top And imgElf.Left = Image171.Left + 375 Or imgElf.Top = Image176.Top And imgElf.Left = Image176.Left + 375 Or imgElf.Top = Image186.Top And imgElf.Left = Image186.Left + 375 Or imgElf.Top = Image193.Top And imgElf.Left = Image193.Left Then

    MsgBox "Can't move there!" 'tells the player if he can’t move to an area

    Else

    imgElf.Left = imgElf.Left + 375

    r = r - 1

    End If

    Else

    MsgBox "Inavlid Key!"

    End If

    Loop

    End If

    If r < 0 Then 'the game enters the battle subroutine

    Me.Hide

    frmBattleSub.Show

    End If

    End Sub

    Private Sub img7_Click()

    End Sub


    If anybody can help, I would really appreciate it. Thank you.
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2010
    Posts
    1,133

    Re: Simple RPG

    Please use the [code][/code] tags, no one would bother reading such a lengthy piece of unformatted code. Now, I'm not a VB programmer, but I can give you some general tips. First, narrow down the problem, find the parts of your code that are relevant to the issue, try commenting out some stuff, debug it. Second, it's probably one of two things: either your code doesn't update the locations for some reason, or you're not refreshing your screen.
    Maybe there's a design flaw. Either way, you'll have to experiment a bit.

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Simple RPG

    That code is way to cluttered to read.
    Always use [code][/code] tags when posting code.

  4. #4
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Simple RPG

    I had a quick look and your problem is

    Code:
    Do Until r < 0
    
    -----
    
    Loop
    Your looping over and over until all all keypresses are done, and the page does not get a chance to refresh... Take the Loop out, and try it again....
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

Tags for this Thread

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

Featured