Quantcast
Viewing all articles
Browse latest Browse all 27077

VS 2008 VS2008: Made a Video Game Experiment with Arrays, Need Help

I've asked some people around here about this, but I think it'd be faster and much more efficient to post this question here rather than bog down individual people with this.

I have constructed a small video game experiment that generates a random playspace for the user. The method of which I do this, as well as store data, is use several arrays, some 2D, others 3D. Lemme post the code for all to read before I continue...

Code:

Imports System.Drawing

Public Class Form1

    Dim Planet(14, 14) As Integer
    Dim Area(1124, 1124, 10) As Integer
    '==========FOR THE Z DIMENSION========================
    '0 is geographical feature (tree, nothing, water, etc.)
    '1 is region type (snow, grass, sand)
        '2 is if anything is on that feature (item, enemy, player, nothing, etc.)
    '=====================================================
    Dim ran As Integer
    Dim G As Graphics
    Dim BBG As Graphics
    Dim BB As Bitmap
    Dim r As Rectangle
       
    Private Sub DrawGraphics()
        For Y = 0 To 74
            For X = 0 To 74
                'FILL THE BACKBUFFER
                'DRAW TILES
                'SYMBOLS:
                '0 = LAND (as defined by Area(X,Y,1))
                '...0 = Snow
                '...1 = Grass
                '...2 = Sand
                '1 = Tree
                '2 = Rock
                '3 = Water
                '4 = Lava
                r = New Rectangle(X * 3, Y * 3, 3, 3)

                If Area(X, Y, 0) = 0 AndAlso Area(X, Y, 1) = 0 Then
                    G.FillRectangle(Brushes.GhostWhite, r)
                ElseIf Area(X, Y, 0) = 0 AndAlso Area(X, Y, 1) = 1 Then
                    G.FillRectangle(Brushes.LimeGreen, r)
                ElseIf Area(X, Y, 0) = 0 AndAlso Area(X, Y, 1) = 2 Then
                    G.FillRectangle(Brushes.PaleGoldenrod, r)
                ElseIf Area(X, Y, 0) = 1 Then
                    G.FillRectangle(Brushes.ForestGreen, r)
                ElseIf Area(X, Y, 0) = 2 Then
                    G.FillRectangle(Brushes.DimGray, r)
                ElseIf Area(X, Y, 0) = 3 Then
                    G.FillRectangle(Brushes.Aqua, r)
                ElseIf Area(X, Y, 0) = 4 Then
                    G.FillRectangle(Brushes.Crimson, r)
                Else
                    G.FillRectangle(Brushes.Black, r)
                End If
            Next
        Next
               
        ' COPY BACKBUFFER TO GRAPHICS OBJECT
        G = Graphics.FromImage(BB)

        ' DRAW BACKBUFFER TO SCREEN
        BBG = Me.CreateGraphics
        BBG.DrawImage(BB, 0, 0, Me.Width, Me.Height)

        ' FIX OVERDRAW
        G.Clear(Color.Black)
               
    End Sub
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.Show()
        Me.Focus()

        G = Me.CreateGraphics
        BB = New Bitmap(1024, 768)
        ClearGame()
        RandomizePlanet()
        BigRun()
        DrawGraphics()

    End Sub
    Public Sub BigRun()
        'KEYS:
        '0 = LAND (as defined by Area(X,Y,1))
        '...0 = Snow
        '...1 = Grass
        '...2 = Sand
        '1 = Tree
        '2 = Rock
        '3 = Water
        '4 = Lava
        '=================
        Dim X1 As Integer
        Dim Y1 As Integer
        For Y = 0 To 14
            For X = 0 To 14
                X1 = X + 1
                Y1 = Y + 1
                If Planet(X, Y) = 0 Then
                    'Empty Ice Field Procedure
                    '-------------------
                    For Y2 = 0 To 74
                        For X2 = 0 To 74
                            ran = GetNext(1, 135)
                            If ran = 7 Then
                                Area((X2 * X1), (Y2 * Y1), 0) = 2
                            Else
                                Area((X2 * X1), (Y2 * Y1), 0) = 0
                            End If
                            ran = GetNext(1, 75)
                            If ran = 5 Then
                                Area((X2 * X1), (Y2 * Y1), 0) = 3
                            End If
                            Area((X2 * X1), (Y2 * Y1), 1) = 0
                        Next
                    Next
                    '-------------------
                End If
                If Planet(X, Y) = 1 Then
                    'Watery Ice Field Procedure
                    '-------------------
                    For Y2 = 0 To 74
                        For X2 = 0 To 74
                            ran = GetNext(1, 135)
                            If ran = 7 Then
                                Area((X2 * X1), (Y2 * Y1), 0) = 2
                            Else
                                Area((X2 * X1), (Y2 * Y1), 0) = 0
                            End If
                            ran = GetNext(1, 25)
                            If ran = 5 Then
                                Area((X2 * X1), (Y2 * Y1), 0) = 3
                            End If
                            Area((X2 * X1), (Y2 * Y1), 1) = 0
                        Next
                    Next
                    '-------------------
                End If
                If Planet(X, Y) = 2 Then
                    'Rocky Ice Field Procedure
                    '-------------------
                    For Y2 = 0 To 74
                        For X2 = 0 To 74
                            ran = GetNext(1, 35)
                            If ran = 7 Then
                                Area((X2 * X1), (Y2 * Y1), 0) = 2
                            Else
                                Area((X2 * X1), (Y2 * Y1), 0) = 0
                            End If
                            ran = GetNext(1, 75)
                            If ran = 5 Then
                                Area((X2 * X1), (Y2 * Y1), 0) = 3
                            End If
                            Area((X2 * X1), (Y2 * Y1), 1) = 0
                        Next
                    Next
                    '-------------------
                End If
                If Planet(X, Y) = 3 Then
                    'Dense Forest Procedure
                    '-------------------
                    For Y2 = 0 To 74
                        For X2 = 0 To 74
                            ran = GetNext(1, 70)
                            If ran = 7 Then
                                Area((X2 * X1), (Y2 * Y1), 0) = 2
                            Else
                                Area((X2 * X1), (Y2 * Y1), 0) = 0
                            End If
                            ran = GetNext(1, 7)
                            If ran = 5 Then
                                Area((X2 * X1), (Y2 * Y1), 0) = 1
                            End If
                            Area((X2 * X1), (Y2 * Y1), 1) = 1
                        Next
                    Next
                    '-------------------
                End If
                If Planet(X, Y) = 4 Then
                    'Small Grassland Clearing Procedure
                    '-------------------
                    For Y2 = 0 To 74
                        For X2 = 0 To 74
                            ran = GetNext(1, 115)
                            If ran = 7 Then
                                Area((X2 * X1), (Y2 * Y1), 0) = 2
                            Else
                                Area((X2 * X1), (Y2 * Y1), 0) = 0
                            End If
                            ran = GetNext(1, 30)
                            If ran = 5 Then
                                Area((X2 * X1), (Y2 * Y1), 0) = 1
                            End If
                            Area((X2 * X1), (Y2 * Y1), 1) = 1
                        Next
                    Next
                    '-------------------
                End If
                If Planet(X, Y) = 5 Then
                    'Barren Sands Procedure
                    '-------------------
                    For Y2 = 0 To 74
                        For X2 = 0 To 74
                            ran = GetNext(1, 115)
                            If ran = 7 Then
                                Area((X2 * X1), (Y2 * Y1), 0) = 2
                            Else
                                Area((X2 * X1), (Y2 * Y1), 0) = 0
                            End If
                            ran = GetNext(1, 75)
                            If ran = 5 Then
                                Area((X2 * X1), (Y2 * Y1), 0) = 4
                            End If
                            Area((X2 * X1), (Y2 * Y1), 1) = 2
                        Next
                    Next
                    '-------------------
                End If
                If Planet(X, Y) = 6 Then
                    'Magmic Sands Procedure
                    '-------------------
                    For Y2 = 0 To 74
                        For X2 = 0 To 74
                            ran = GetNext(1, 115)
                            If ran = 7 Then
                                Area((X2 * X1), (Y2 * Y1), 0) = 2
                            Else
                                Area((X2 * X1), (Y2 * Y1), 0) = 0
                            End If
                            ran = GetNext(1, 23)
                            If ran = 5 Then
                                Area((X2 * X1), (Y2 * Y1), 0) = 4
                            End If
                            Area((X2 * X1), (Y2 * Y1), 1) = 2
                        Next
                    Next
                    '-------------------
                End If

            Next
        Next
    End Sub
          Public Sub RandomizePlanet()

        For Y = 0 To 3
            For X = 0 To 14
                Planet(X, Y) = GetNext(0, 2)
            Next
        Next

        For Y = 4 To 9
            For X = 0 To 14
                Planet(X, Y) = GetNext(3, 4)
            Next
        Next

        For Y = 10 To 14
            For X = 0 To 14
                Planet(X, Y) = GetNext(5, 6)
            Next
        Next

        Dim HouseCount As Integer
        HouseCount = 0
        Do Until HouseCount = 3

            For Y = 0 To 14
                For X = 0 To 14
                    ran = GetNext(1, 180)
                    If ran = 10 Then
                        Planet(X, Y) = 7
                        HouseCount = HouseCount + 1
                    End If
                Next
            Next
        Loop
    End Sub
    Public Sub ClearGame()
        For X = 0 To 14
            For Y = 0 To 14
                Planet(X, Y) = 0
            Next
        Next

        For X = 0 To 1124
            For Y = 0 To 1124
                For Z = 0 To 10
                    Area(X, Y, Z) = 0
                Next
            Next
        Next
    End Sub
End Class

Okay, so what happens is that when the game loads, the Planet(14,14) array generates a snowy region, grassy region, and a sandy region, as well as their specific types, like a dense grassland or a small clearing. This will fill up a 15x15 playspace, each value actually representing 75x75 tiles on a much larger array, the 1125x1125x10 array (the Z dimension serves to hold values for each individual array point). If I rig DrawGraphics to create a visual representation of Planet(14,14), it comes out perfect.

(Ignore the random Button... Heh...)
Attachment 93957

Now when I use BigRun, it's supposed to fill up certain Area array points in 75x75 increments according to the Planet array points. Like if Planet(1,0) = 2, then it fills up Area(0,0,0) all the way to Area(74,74,0) with the Watery Ice Field Procedure. In theory, it sounds swell to me. But I'm pretty certain I messed up along the way, because when I use the original code, DrawGraphics should give me what Area(0,0,0) all the way to Area(74,74,0) looks like... But for some reason, it looks like a horizontal hurricane came through and wrecked everything...

Attachment 93959

Does anyone know what I did? I'm almost certain it's something wrong with BigRun. Just look at it! It's a huge mess, but I'm not sure how to fix it. It's either that, or DrawGraphics obviously did something wrong.

Help is greatly appreciated :D

Also, I don't think working with Arrays to store values is a very safe (or at least efficient) thing to do. Does anyone know a more adequate substitute for this?
Attached Images
Image may be NSFW.
Clik here to view.
  Image may be NSFW.
Clik here to view.
 

Viewing all articles
Browse latest Browse all 27077

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>