[VB.NET] I'm looking for some ideas or concepts to solve a few game design issues-VBForums
Results 1 to 2 of 2

Thread: I'm looking for some ideas or concepts to solve a few game design issues

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    1

    I'm looking for some ideas or concepts to solve a few game design issues

    I'm looking for a simple way to hold terrain data. So if I have a tile set that is for example 10 x 10 tiles, then there are 100 positions. A 2 dimensional array is very simple for a single value, but I need more than that. I was thinking of a class object that fills a container. Maybe someone can give a simple example of how I could implement this. What kind of member variables should I have and so on. If you have an example, feel free to use any idea. I have not thought out the game yet, except that it would be a simple tile based rpg type level. So I'm looking more at how to implement in code, rather than anything else. My VB .NET skills are good and this is kind of a first project. I have decent C/C++ skills, but I only mention that since I said this is a first project (I'm not new to programming). As a last remark, however, complex algorithms might do me in, so don't throw a computer science book at me.

  2. #2
    The DirectXpert Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,075

    Re: I'm looking for some ideas or concepts to solve a few game design issues

    I have a great example in my Bosskillers Game in my sig, but its been implemented in VB6 and uses DirectX8, yet it shouldn't be too hard to do in vb.net. The code is so superb, that you can make the worlds as big as you want and it'll never slow down. Like 100000x100000 tiles are possible. The secret is that the 2 for loops executed in rendering only renders what you see. It's equivilant to a rectangular shape magnifine glass over a gigantic size map. I have done something similar in vb.net without directx as an experiment and surprisingly it worked. The data structure you'll need is just a structure. No class necessary. Although I do recommend you use DirectX if you plan on doing an RPG. I can help you learn it in VB.Net using DirectX9. If you need the example I was talking about, heres sourcecode of a tile engine.

    vb.net Code:
    1. Option Explicit On
    2.  
    3. Public Class frmMain
    4.  
    5.     Inherits System.Windows.Forms.Form
    6.  
    7.     Private Structure RECT
    8.         Dim Left As Integer
    9.         Dim Right As Integer
    10.         Dim Top As Integer
    11.         Dim Bottom As Integer
    12.     End Structure
    13.  
    14.     Private Structure Vector
    15.         Dim X As Single
    16.         Dim Y As Single
    17.     End Structure
    18.  
    19.     Private Structure Map_Type
    20.         <VBFixedString(50)> Dim Name As String
    21.         Dim Initial_Position As Vector 'Used for if you click to move the map with the mouse youll use a new set of map position coordinates.
    22.         Dim Position As Vector 'The map position on screen which is typically negative as it goes more right.
    23.         Dim Tile(,) As Integer 'The tile image number used in Tile(X,Y) 'ex. Tile(0,0) = 0 "grass" Tile(2,5) = 1 "Rock"
    24.         Dim Width As Integer 'Width of map in tiles
    25.         Dim Height As Integer 'Height of map in tiles
    26.         <VBFixedString(256)> Dim Texture_List() As String 'File path of textures
    27.         Dim Number_of_Textures As Integer
    28.         Dim Screen_Tile_Width As Integer 'Number of tiles possible to display on screen horizontally
    29.         Dim Screen_Tile_Height As Integer 'Number of tiles possible to display on screen vrtically
    30.     End Structure
    31.  
    32.     Private Const TILE_WIDTH As Integer = 50
    33.     Private Const TILE_HEIGHT As Integer = 50
    34.  
    35.     Dim Map As New Map_Type()
    36.     Dim Running As Boolean
    37.     Dim Backbuffer As Bitmap
    38.     Dim G As Graphics
    39.  
    40.     Private Sub Setup_Map()
    41.  
    42.         Map.Width = 64
    43.         Map.Height = 64
    44.         Map.Screen_Tile_Width = 32
    45.         Map.Screen_Tile_Height = 16
    46.         Map.Number_of_Textures = 2
    47.  
    48.         Map.Tile = New Integer(Map.Width, Map.Height) {}
    49.         Map.Texture_List = New String(Map.Number_of_Textures) {}
    50.         Map.Texture_List(0) = Application.StartupPath() & "\Graphics\grass.bmp"
    51.         Map.Texture_List(1) = Application.StartupPath() & "\Graphics\rock.bmp"
    52.  
    53.         'Normally its loaded from file but you can manually put where the images go here
    54.         Dim X As Integer, Y As Integer
    55.  
    56.         For Y = 0 To Map.Height
    57.             For X = 0 To Map.Width
    58.                 Map.Tile(X, Y) = 0
    59.             Next X
    60.         Next Y
    61.  
    62.  
    63.     End Sub
    64.  
    65.     Private Sub Draw_Map()
    66.  
    67.         Dim imageFile As Image
    68.         Dim g As Graphics
    69.         Dim newGraphics As Graphics
    70.         Dim Coordinates As Vector 'Tile Coordinates of the position on map such as 5,10 or 24, 8
    71.         Dim X1 As Integer, Y1 As Integer, X2 As Integer, Y2 As Integer
    72.         Dim X As Integer, Y As Integer
    73.         Dim R As RECT
    74.  
    75.         R.Left = 0
    76.         R.Top = 0
    77.         R.Right = Me.Width
    78.         R.Bottom = Me.Height
    79.  
    80.         Coordinates.X = Int(-(Map.Position.X) / TILE_WIDTH)
    81.         Coordinates.Y = Int(-(Map.Position.Y) / TILE_HEIGHT) 'converts your position into tile coordinates
    82.  
    83.         'This here allows the world to be as gigantic as you want with zero slow down like 5000x5000 for example. Only draws what is on screen.
    84.  
    85.         X1 = Coordinates.X
    86.         Y1 = Coordinates.Y
    87.         X2 = Coordinates.X + Map.Screen_Tile_Width
    88.         Y2 = Coordinates.Y + Map.Screen_Tile_Height
    89.  
    90.         If X2 <= 0 Then X2 = 0
    91.         If Y2 <= 0 Then Y2 = 0
    92.         If Y2 >= Map.Height - 1 Then Y2 = Map.Height - 1
    93.         If X2 >= Map.Width - 1 Then X2 = Map.Width - 1
    94.         If X1 <= 0 Then X1 = 0
    95.         If Y1 <= 0 Then Y1 = 0
    96.         If X1 >= X2 Then X1 = X2
    97.         If Y1 >= Y2 Then Y1 = Y2
    98.  
    99.         For Y = Y1 To Y2
    100.             For X = X1 To X2
    101.                 If Running = True Then
    102.                     If Not ((Map.Position.X + ((TILE_WIDTH * X) + TILE_WIDTH) < R.Left) Or (Map.Position.X + ((TILE_WIDTH * X)) > R.Right) Or (Map.Position.Y + ((TILE_HEIGHT * Y) + TILE_HEIGHT) < R.Top) Or (Map.Position.Y + ((TILE_HEIGHT * Y)) > R.Bottom)) Then
    103.                         imageFile = Image.FromFile(Map.Texture_List(Map.Tile(X, Y)))
    104.                         g = Me.CreateGraphics()
    105.                         newGraphics = Graphics.FromImage(imageFile)
    106.                         g.DrawImage(imageFile, New RectangleF(Map.Position.X + (TILE_WIDTH * X), Map.Position.Y + (TILE_HEIGHT * Y), TILE_WIDTH + 3, TILE_HEIGHT + 3))
    107.                         newGraphics.Dispose()
    108.                         g.Dispose()
    109.                     End If
    110.                 End If
    111.             Next X
    112.         Next Y
    113.  
    114.     End Sub
    115.  
    116.     Private Sub frmMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
    117.  
    118.         If e.KeyCode = Keys.Left Then Map.Position.X += 10
    119.         If e.KeyCode = Keys.Right Then Map.Position.X -= 10
    120.         If e.KeyCode = Keys.Up Then Map.Position.Y += 10
    121.         If e.KeyCode = Keys.Down Then Map.Position.Y -= 10
    122.  
    123.     End Sub
    124.  
    125.     Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    126.  
    127.         Me.Show()
    128.         Me.DoubleBuffered = True
    129.         Setup_Map()
    130.         Running = True
    131.         Backbuffer = New Bitmap(Width, Height, Me.CreateGraphics())
    132.         G = Graphics.FromImage(Backbuffer)
    133.  
    134.     End Sub
    135.  
    136.     Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
    137.         Running = False
    138.         Application.Exit()
    139.     End Sub
    140.  
    141.     Private Sub frmMain_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    142.         e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
    143.         e.Graphics.PixelOffsetMode = Drawing2D.PixelOffsetMode.None
    144.         Do While Running = True
    145.             e.Graphics.Clear(Color.Black)
    146.             Draw_Map()
    147.             System.Windows.Forms.Application.DoEvents()
    148.         Loop
    149.     End Sub
    150. End Class

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.