Multiple Walls (VB 2010 Express)
Multiple Walls (VB 2010 Express)
Multiple Walls (VB 2010 Express)
Multiple Walls (VB 2010 Express)
Multiple Walls (VB 2010 Express)
Multiple Walls (VB 2010 Express) Multiple Walls (VB 2010 Express) Multiple Walls (VB 2010 Express) Multiple Walls (VB 2010 Express) Multiple Walls (VB 2010 Express) Multiple Walls (VB 2010 Express) Multiple Walls (VB 2010 Express) Multiple Walls (VB 2010 Express)
Multiple Walls (VB 2010 Express) Multiple Walls (VB 2010 Express)
Multiple Walls (VB 2010 Express)
Go Back  Xtreme Visual Basic Talk > > > Multiple Walls (VB 2010 Express)


Reply
 
Thread Tools Display Modes
  #1  
Old 07-03-2011, 05:48 PM
Chubzdoomer Chubzdoomer is offline
Newcomer
 
Join Date: Jul 2011
Posts: 1
Question Multiple Walls (VB 2010 Express)


Howdy, folks! I am rather new to Visual Basic and currently creating a tiny, one-screen RPG to put my skills to the test. A problem I'm encountering is being able to lay down as many walls as I need to in order to form rooms, hallways, and so forth. I'm using Visual Basic 2010 Express and laying out my room with the "design view." I can easily plop down two or three walls, but any more than that and my code is going to become incredibly cluttered.

For reference, CLICK HERE to have a look at my game inside the VB 2010 environment.

The green circle near the center is the player. You move him by clicking the directional arrows, and he moves 32 pixels at a time as though he's stuck on a grid. The black squares to the left and right of him are the walls I'm referring to. I've named them "Wall1" and "Wall2," respectively. All three are composed of 32x32 PictureBox controls. In my code for the directional arrow clicks, I use IF statements to determine whether the player can move in that direction according to his positions in relation to the position of "Wall1" or "Wall2." As you can imagine, as I start throwing in more walls using this method, I'll have an incredibly large set of IF statements just to handle basic collisions!

For reference, here's the code I'm using for the directional arrow clicks:
Code:
    'PLAYER INPUT AND COLLISION DETECTION/EVENTS'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'MOVE LEFT
    Private Sub Btn_MoveLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_MoveLeft.Click
        'Left border
        If Not xpos = 2 Then
            'Walls
            If Not xpos - 32 = Wall1.Left Or ypos < Wall1.Top Or ypos > Wall1.Top Then
                If Not xpos - 32 = Wall2.Left Or ypos < Wall2.Top Or ypos > Wall2.Top Then
                    xpos -= 32
                    Player.Left = xpos
                    My.Computer.Audio.Play("walk.wav")
                    checkFloor()
                End If
            End If
        End If
    End Sub

    'MOVE RIGHT
    Private Sub Btn_MoveRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_MoveRight.Click
        'Right border
        If Not xpos = 738 Then
            'Walls
            If Not xpos + 32 = Wall1.Left Or ypos < Wall1.Top Or ypos > Wall1.Top Then
                If Not xpos + 32 = Wall2.Left Or ypos < Wall2.Top Or ypos > Wall2.Top Then
                    xpos += 32
                    Player.Left = xpos
                    My.Computer.Audio.Play("walk.wav")
                    checkFloor()
                End If
            End If
        End If
    End Sub

    'MOVE UP
    Private Sub Btn_MoveUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_MoveUp.Click
        'Top border
        If Not ypos = -1 Then
            'Walls
            If Not ypos - 32 = Wall1.Top Or Not xpos = Wall1.Left Then
                If Not ypos - 32 = Wall2.Top Or Not xpos = Wall2.Left Then
                    ypos -= 32
                    Player.Top = ypos
                    My.Computer.Audio.Play("walk.wav")
                    checkFloor()
                End If
            End If
        End If
    End Sub

    'MOVE DOWN
    Private Sub Btn_MoveDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_MoveDown.Click
        'Bottom border
        If Not ypos = 319 Then
            'Walls
            If Not ypos + 32 = Wall1.Top Or Not xpos = Wall1.Left Then
                If Not ypos + 32 = Wall2.Top Or Not xpos = Wall2.Left Then
                    ypos += 32
                    Player.Top = ypos
                    My.Computer.Audio.Play("walk.wav")
                    checkFloor()
                End If
            End If
        End If
    End Sub
The code I have at this time works fine, but I certainly don't want to add dozens and dozens of extra IF statements inside the ones I already have. That just doesn't seem right at all. Is there an easy way to create multiple objects that share the same collision detection? (Example: Place 12+ walls that all follow the exact procedures as Wall1 and Wall2.) I'm totally new to this stuff, so perhaps I'm just going about it all wrong to begin with.

Thank you very much for any help,
Chubzdoomer
Reply With Quote
  #2  
Old 07-06-2011, 10:09 AM
passel's Avatar
passelMultiple Walls (VB 2010 Express) passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

Since you place things by grid, and you move by grid, I wouldn't do collision detection by comparing an object against all the other objects in the game.
I would use a map, an array accessed in a two dimensional manner that contains data about what is in that grid position. That way, instead of checking all the objects, you just check the "cell" that you are planning on moving into, and if it is a valid place to move to, not a wall, tree, pond, etc... then move.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #3  
Old 07-08-2011, 06:34 AM
surfR2911 surfR2911 is offline
Contributor
 
Join Date: Oct 2009
Posts: 719
Default An approach to walls

I'm not an expert on VB.Net but I agree with passel.

The approach that will probably save you the most headaches down the road is to generate the walls at run time from some kind of saved data file.

Since you say you are new to visual basic, I would look around for some tutorials.

Just doing a quick google search I came up with this site and this game programming example.

There are also some free eBooks on .Net game programming if you look around..
Reply With Quote
  #4  
Old 08-10-2011, 05:24 PM
firstdaygaming firstdaygaming is offline
Newcomer
 
Join Date: Jun 2011
Posts: 7
Default

You need to make a layer system.

Each layer is represented by an Array layer 1 , layer 2 layer 3 .... etc

Each array should contain rectangle information i.e. the size of image.

There should be 3 basic layers for any 2d game.

1st the background. This layer should have little to no collision detection because it is simply there for looks.

2nd should be the Midlayer this would be the layer where you would put object that the character would normally collide with. Such as walls , tables , etc.

The 3rd Layer will be for the foreground. This layer generally contains things such as your main character / item.

Instead of checking against every rectangle in a scene. You will divide the scene up into layer and simply check for collisions against a specific layer.

You can further simplify this by using your characters position on a grid and doing collision detection only with sprites (the rectangles) with in a certain range.

You should also make a separate thread for checking collisions. One that is running constantly in the background at set intervals.

I have an 2d game drawing engine built entirely in GDI + I did for practice. I'd be glad to share some of the code with you. It's a little slow but of course GDI + wasn't designed for making games. You may want to look into Direct X if you want to design games.
Reply With Quote
  #5  
Old 08-10-2011, 06:33 PM
passel's Avatar
passelMultiple Walls (VB 2010 Express) passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

Welcome to the forum.
You shouldn't post in threads more than 30 days old.
The person who asked the question hasn't been back since the day he asked the question, so has not seen any of our responses in any case.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
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
Multiple Walls (VB 2010 Express)
Multiple Walls (VB 2010 Express)
Multiple Walls (VB 2010 Express) Multiple Walls (VB 2010 Express)
Multiple Walls (VB 2010 Express)
Multiple Walls (VB 2010 Express)
Multiple Walls (VB 2010 Express) Multiple Walls (VB 2010 Express) Multiple Walls (VB 2010 Express) Multiple Walls (VB 2010 Express) Multiple Walls (VB 2010 Express) Multiple Walls (VB 2010 Express) Multiple Walls (VB 2010 Express)
Multiple Walls (VB 2010 Express)
Multiple Walls (VB 2010 Express)
 
Multiple Walls (VB 2010 Express)
Multiple Walls (VB 2010 Express)
 
-->