RPG Problem Please Help
RPG Problem Please Help
RPG Problem Please Help
RPG Problem Please Help
RPG Problem Please Help
RPG Problem Please Help RPG Problem Please Help RPG Problem Please Help RPG Problem Please Help RPG Problem Please Help RPG Problem Please Help RPG Problem Please Help RPG Problem Please Help
RPG Problem Please Help RPG Problem Please Help
RPG Problem Please Help
Go Back  Xtreme Visual Basic Talk > > > RPG Problem Please Help


Reply
 
Thread Tools Display Modes
  #1  
Old 11-25-2004, 02:26 PM
Talus123 Talus123 is offline
Regular
 
Join Date: Sep 2004
Posts: 57
Default RPG Problem Please Help


Ok so I think all the code for this RPG game is correct except when I try to debug/run it there are two errors. It shows me exactly where they are I just do not know how to fix it. If anyone knows what to do please post a reply. I have attached my game to this post. Don't get too excited it is not a real RPG it is just a engine/template.

Edit by Iceplug: I had to remove 2 EXE(s) from your attachment
Attached Files
File Type: zip RPG Engine.zip (73.1 KB, 46 views)

Last edited by Iceplug; 11-26-2004 at 09:27 AM.
Reply With Quote
  #2  
Old 11-25-2004, 02:40 PM
theController theController is offline
Centurion
 
Join Date: May 2004
Posts: 120
Default

Quote:
Originally Posted by Talus123
Ok so I think all the code for this RPG game is correct except when I try to debug/run it there are two errors. It shows me exactly where they are I just do not know how to fix it. If anyone knows what to do please post a reply. I have attached my game to this post. Don't get too excited it is not a real RPG it is just a engine/template.

I see no error in gameplay, it was juts when i went to run it. I had to change

Code:
Public Class GameClass
    Public Shared alex As New clsSprite("alex")
    Public Shared map As New clsMap("lightworld.txt", "basis")
    'The form in which we will draw to.
    Public Shared GameForm As Form
Since it could not find a lightworld.map
Reply With Quote
  #3  
Old 11-25-2004, 02:42 PM
theController theController is offline
Centurion
 
Join Date: May 2004
Posts: 120
Default

Quote:
Originally Posted by Talus123
Ok so I think all the code for this RPG game is correct except when I try to debug/run it there are two errors. It shows me exactly where they are I just do not know how to fix it. If anyone knows what to do please post a reply. I have attached my game to this post. Don't get too excited it is not a real RPG it is just a engine/template.

I see no error in gameplay, it was juts when i went to run it. I had to change

Code:
Public Class GameClass
    Public Shared alex As New clsSprite("alex")
    Public Shared map As New clsMap("lightworld.txt", "basis")
    'The form in which we will draw to.
    Public Shared GameForm As Form
Since it could not find a lightworld.map
Reply With Quote
  #4  
Old 11-25-2004, 08:21 PM
Talus123 Talus123 is offline
Regular
 
Join Date: Sep 2004
Posts: 57
Default

Wow thank you so much. I hate stupid mistakes like that. Anyway I was wondering how is the best way to make it so the sprite cannot walk through the rocks. If you know how to do this please post your help. Thanks
Reply With Quote
  #5  
Old 11-26-2004, 09:00 AM
Talus123 Talus123 is offline
Regular
 
Join Date: Sep 2004
Posts: 57
Default

Also after I figure out how to create collisions between certain tiles, I wanted to know your opinion. Is this code good to use to build upon? I want to take this as sort of a template and then just build on it creating new lvls and story.
Reply With Quote
  #6  
Old 11-26-2004, 09:43 AM
theController theController is offline
Centurion
 
Join Date: May 2004
Posts: 120
Default

Quote:
Originally Posted by Talus123
Also after I figure out how to create collisions between certain tiles, I wanted to know your opinion. Is this code good to use to build upon? I want to take this as sort of a template and then just build on it creating new lvls and story.
Well I still dont know how to do the tile movement and map scrolling like you have done. But, for collision I previously used,

Code:
        If PictureBox1.Visible = True And PictureBox2.Left < PictureBox1.Left + PictureBox1.Width And PictureBox1.Left < PictureBox2.Left + PictureBox2.Width Then
            If PictureBox1.Visible = True And PictureBox2.Top < PictureBox1.Top + PictureBox1.Height And PictureBox1.Top < PictureBox2.Top + PictureBox2.Height Then
                'collision!
                Collision = True
            End If
        End If
This is obviously between only two objects, but you can make a For Loop and have all objects indexed and then it would be If Char.Left < Object(i).Left + Object(i).Width.. etc.

When Collision (as a boolean) is true then I just made my character move back to its previous position.

But like i said i havent used tiles so Im not sure how useful this is. Try it
Reply With Quote
  #7  
Old 11-26-2004, 10:12 AM
Iceplug's Avatar
IceplugRPG Problem Please Help Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Quote:
Anyway I was wondering how is the best way to make it so the sprite cannot walk through the rocks.
The problem here is that you are using Bitmaps to represent the tiles instead of numeric values. Using Bitmaps is going to make player interaction much more burdensome than if you were using Integer.
Furthermore the tiles are all being loaded from file one by one, which is making the actual map creation process quite I/O intensive, which means that it'll take quite awhile to get a map loaded.
You should really rework the clsMap so that each tile is represented by a number instead of a picture (a picture is worth a thousand words, but you only need one to check what kind that it is ).
Having Alex and Map as shared methods of the gameclass is not a good idea, especially seeing as how you use Shared in the form case.
Now, assuming that you do have some way of determining what a tile is, your clsSprite would not be able to tell. Alex does not have a reference to any map object, so you cannot perform collision checks with Alex unless you make some crude comparison in the clsGame class. Instead, you should create a reference to the clsMap within clsSprite. Then, in your clsMap, create some function that will let you know if the player can walk on a tile if you give it the coordinates of the tile.
This function can be used from the clsSprite to determine if you will let the character move to this tile.
Quote:
Is this code good to use to build upon? I want to take this as sort of a template and then just build on it creating new lvls and story.
You should be able to build upon this code somehow, but it is quite difficult to follow from an OOP perspective.
Having a Game class is fine, albeit a bit redundant, IMO, but it is fine!
You declared a constant for the number of frames for the character (3), but you did not use it here:
If Frame = 3 Then Frame = 0
Remember that a constant is not just there for a reference, it's also there as a usable variable (quickly changeable as well).
'Holds all the images for the sprite
Public SpriteImage(NumberOfDirections - 1, NumberOfFrames - 1) As Bitmap

I doubt that you need to have an array of images to be public. These could be declared Private.
Code:
    Public Function ReturnDirection(ByVal CurrentDirection As Integer) As String
        If CurrentDirection = Dir.Up Then Return "up"
        If CurrentDirection = Dir.Down Then Return "down"
        If CurrentDirection = Dir.Left Then Return "left"
        If CurrentDirection = Dir.Right Then Return "right"
    End Function
I don't think I want to know why you need to return a string representation of the direction, so I won't ask.
Code:
    Public Shared alex As New clsSprite("alex")
    Public Shared map As New clsMap("lightworld.txt", "basis")
    'The form in which we will draw to.
    Public Shared GameForm As Form
Once again, I see no reason for these to be shared. Also, it doesn't seem that the Form needs to be Public either.
Also, you throw the number 30 around a lot, and it would seem more efficient for that 30 to be in a Const declaration.
Quote:
Originally Posted by theController
But, for collision I previously used
You can use PicBox.Bounds.IntersectsWith(PicBox2.Bounds) for rectangular collision detection.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #8  
Old 11-26-2004, 10:19 AM
Talus123 Talus123 is offline
Regular
 
Join Date: Sep 2004
Posts: 57
Default

Wow thx so much. I get what you mean. How is the easiest way to change the bmps to integers like how where/what would I change
Reply With Quote
  #9  
Old 11-26-2004, 10:51 AM
Iceplug's Avatar
IceplugRPG Problem Please Help Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Oh, I forgot to mention that.
With a map of integers, you would have the multidimensional array of integers:
Dim Tiles( ... , ... ) As Integer
and then, you would have the tileset.
Dim Tileset As Bitmap 'holds all of the tiles in one bmp.
and from the numbers that you assign to the map, you get the corresponding tile from the tileset.
Example, you'd get the tile from Number * 30 (30 is the tilewidth, I guess) from the Tileset.
If you have more than one row in the tileset, you'd do something like this to get the coordinate of the tile you want to draw.
X = (Number Mod rowsize) * 30
Y = (Number \ rowsize) * 30 'backslash for integer division.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #10  
Old 11-26-2004, 11:01 AM
Talus123 Talus123 is offline
Regular
 
Join Date: Sep 2004
Posts: 57
Default

Ok I think I understand. Where would I put this code in and once I have the map made from integers how do I create the collision.
Reply With Quote
  #11  
Old 11-26-2004, 11:12 AM
Iceplug's Avatar
IceplugRPG Problem Please Help Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Quote:
Where would I put this code in
Wherever you are drawing the map. That, ironically, is contained within the form's Paint event.
So, to draw the image, you'd have
fx = x calc above
fy = y calc above.
.DrawImage(the tileset, 30 * x, 30 * y, New Rectangle(fx, fy, 30, 30), GraphicsUnit.Pixel)
Quote:
once I have the map made from integers how do I create the collision
Again, you'd have a function in your clsMap that determines from two coordinates if this tile can be walked on by the user. This would likely be checking the tile value against existing unwalkable tile values (in an array using .IndexOf() or perhaps it's hardcoded version, the Select Case with lots of commas, or even worse, a Select Case with lots of cases) If you need me to elaborate, let me know where.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #12  
Old 11-26-2004, 11:25 AM
Talus123 Talus123 is offline
Regular
 
Join Date: Sep 2004
Posts: 57
Default

Ok so I have tryed doing what you said but every time it seems my code gains errors so I know I am doing something wrong. Could you elaborate on what I need to change from my original code?
Reply With Quote
  #13  
Old 11-26-2004, 11:30 AM
Iceplug's Avatar
IceplugRPG Problem Please Help Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

What did you change and what errors did you get?
I don't know exactly what you are referring to... getting the maps to have integers or displaying the map by use of the integers and the tileset.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #14  
Old 11-26-2004, 11:40 AM
Talus123 Talus123 is offline
Regular
 
Join Date: Sep 2004
Posts: 57
Default

Both I think. I am not sure what I am did so I didnt save and I opened to the exact one I have on the website. Ok so now can you take me through this process step by step?
Reply With Quote
  #15  
Old 11-26-2004, 12:04 PM
Iceplug's Avatar
IceplugRPG Problem Please Help Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Quote:
Ok so now can you take me through this process step by step?
Oh goodness.
Well, first of all, it shouldn't take that much effort to load the integers into the array.
However, I'll explain that as well.
When you read the line from file, you should use Integer.Parse() to convert strings into Integers.

So, in the for loop, you'd put the index into the array like this:
Tiles(CurrentColumn, CurrentRow) = Integer.Parse(Line(CurrentColumn))
Tiles, a 2D array of integers, should be fine with you setting one of its members to an integer.

So, now you should have an array of integers representing the map. Do you have this?
You have to show me what you have done so that I can see where you are.

Have you set up the tileset so that all of the tiles are in one bitmap?
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #16  
Old 11-26-2004, 12:11 PM
Talus123 Talus123 is offline
Regular
 
Join Date: Sep 2004
Posts: 57
Default

Code:
Public Sub ReadMap(ByVal MapName As String, ByVal tileset As String)
        'Read a certain map file
        SR = New System.IO.StreamReader("maps\" & MapName)
        Dim ln As String
        'This will store the width/height of the map, seperated by commas.
        ln = SR.ReadLine()
        'This will store the width and the height individually
        Dim str() As String
        'Split ln from it's commas
        str = ln.Split(",")
        'Store the width and the height
        Width = str(0) - 1
        Height = str(1) - 1
        'Now that we know the height and the width:
        'Redim Tiles according to height and the width of the map
        ReDim Tiles(Width, Height)
        'Stores the current row/column being read
        Dim CurrentRow As Integer
        Dim CurrentColumn As Integer
        Dim Line() As String
        For CurrentRow = 0 To Height
            'Read each Line 
            ln = SR.ReadLine()
            Line = ln.Split(",")
            For CurrentColumn = 0 To Width
                'Read each character (Go across the file)
                Tiles(CurrentColumn, CurrentRow) = New Bitmap("tiles\" & tileset & "\" & Line(CurrentColumn) & ".jpg")
                Tiles(CurrentColumn, CurrentRow) = Integer.Parse(Line(CurrentColumn))
            Next
        Next
    End Sub
End Class
like that?

Also the I do not have the tileset set up yet I dont understand how to do this.
Reply With Quote
  #17  
Old 11-26-2004, 12:23 PM
Iceplug's Avatar
IceplugRPG Problem Please Help Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Tiles() is an array of integers
You do not need the top line (which is creating a new bitmap, and we do not want to do that.
Code:
               Tiles(CurrentColumn, CurrentRow) = New Bitmap("tiles\" & tileset & "\" & Line(CurrentColumn) & ".jpg")
                Tiles(CurrentColumn, CurrentRow) = Integer.Parse(Line(CurrentColumn))
Did you set up that tileset?

For drawing the map, you will extract the number for the active tile (in your Paint event)
Const rowsize As Integer = ??? 'I'm guessing that it'll be about 32 if you add some more tiles.
Thistile = Tiles(X, Y)
fX = (Thistile Mod rowsize) * 30
fY = (Thistile \ rowsize) * 30

And then, you draw the map like this:
e.Graphics.DrawImage(tileset, 30 * x, 30 * y, New Rectangle(fX, fY, 30, 30), GraphicsUnit.Pixel)
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #18  
Old 11-26-2004, 02:18 PM
Talus123 Talus123 is offline
Regular
 
Join Date: Sep 2004
Posts: 57
Default

Ok I think I got it except what is throwing me off is how to set up the tileset.

Yes, that is right. I have fit everything in except the tileset I do not understand that part.

Edit by Iceplug: I had to remove the same 2 EXE(s) from this attachment
Attached Files
File Type: zip Game Engine.zip (73.7 KB, 7 views)

Last edited by Iceplug; 11-26-2004 at 05:32 PM.
Reply With Quote
  #19  
Old 11-26-2004, 05:47 PM
Iceplug's Avatar
IceplugRPG Problem Please Help Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

You have an error here:
Thistile = Tiles(x, y)
Tiles is not declared. Surely you declared Tiles in the clsMap object, right?
That's where you should get it from.

You seem to be using a lot of Shared values, which are confusing me, but let's see if I can follow:
The Tiles can be found at: clsMap.Tiles(), since .Tiles is declared as a Shared array. You should also declare it as a Public Shared array, so that you can access it from other classes.

As for the tiles, you need to put them in one bitmap. You can do this by opening paint and just slapping the pictures into paint (make the first tile empty... that corresponds to 0, so the grass tile will be off from the left a little bit).
You can also do this by loading all of your tiles into an array (although, I'm not too crazy about this approach, it does *seem* easier).

Dim Tilepics() As Bitmap
Tilepics = New Bitmap(3) {}
'load pictures into the tilepics array.
'Element 0 is blank to correspond with the fact that
'you are not using 0s in your map.

And from there you just use the numbers that are in the tiles array to index the elements that are in the bitmap array Tilepics.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #20  
Old 11-26-2004, 08:21 PM
Talus123 Talus123 is offline
Regular
 
Join Date: Sep 2004
Posts: 57
Default

Ok so am I almost there. The tiles problem didnt get fixed when I added the Public Shared. I posted the most recent file up. Please take a look at it I am not sure what to do. Thanks for all the help so far though.

Edit by Iceplug: Remove your EXE files before you ZIP. I had to remove the same 2 EXE(s) again.
Attached Files
File Type: zip RPG Engine.zip (80.2 KB, 12 views)

Last edited by Iceplug; 11-27-2004 at 07:36 AM.
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
RPG Problem Please Help
RPG Problem Please Help
RPG Problem Please Help RPG Problem Please Help
RPG Problem Please Help
RPG Problem Please Help
RPG Problem Please Help RPG Problem Please Help RPG Problem Please Help RPG Problem Please Help RPG Problem Please Help RPG Problem Please Help RPG Problem Please Help
RPG Problem Please Help
RPG Problem Please Help
 
RPG Problem Please Help
RPG Problem Please Help
 
-->