1 Replies - 224 Views - Last Post: 26 October 2014 - 11:02 PM Rate Topic: -----

#1 mgrimm21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 26-October 14

enemy going top left tile when moving

Posted 26 October 2014 - 10:44 PM

the enemy sometimes pops up in the top left of the screen. I define each 'block' as a 50x50'tile' so they get teleported to 0,50 50,50 0,0 etc. up to 400,400.
sometimes no matter where the enemy is be it 0,50 or 400,400, it always eventually gets 'teleported' to 0,0. I can't seem to find the mistake. I know my code is horrid, this is my first attempt at a huge project like this. I didn't expect it to highly succeed but this is really troubling me.

.dll file for handling half of the enemy movement
Imports System.Timers.Timer
Imports System.Drawing
Imports System.Windows
Imports System.Math
Imports System.Numerics
Imports Microsoft.VisualBasic.VBMath

Public Class Enemies
    Shared tmr As New Timers.Timer
    Shared currentX As Single
    Shared currentY As Single
    Shared newX As Single
    Shared newY As Single
    Shared ranX As Single
    Shared ranY As Single
    Shared Function move(playerposx As Single, playerposy As Single, treeposx As Single, treeposy As Single, currentenemypos As Point)
        currentX = currentenemypos.X
        currentY = currentenemypos.Y
        Dim xory As Integer
        Randomize()

        xory = Int(Rnd() * 2) + 1
        Dim leftorright As Integer
        Dim upordown As Integer
        If xory = 1 Then
            'x

            Randomize()
            leftorright = Int(Rnd() * 2) + 1
            If leftorright = 1 Then
                If currentenemypos.X >= 50 Then
                    'left
                    currentX -= 50
                    Dim cp As New Point(currentX, currentY)
                    Return cp
                End If
            End If
        ElseIf leftorright = 2 Then
            If currentenemypos.X <= 350 Then
                'right
                currentX += 50
                Dim dp As New Point(currentX, currentY)
                Return dp
            End If
        ElseIf xory = 2 Then
            'y

            Randomize()
            upordown = Int(Rnd() * 2) + 1
            If upordown = 1 Then
                If currentenemypos.Y <= 350 Then
                    'up
                    currentY += 50
                    Dim zp As New Point(currentX, currentY)
                    Return zp
                End If
            ElseIf upordown = 2 Then
                If currentenemypos.Y >= 50 Then
                    'down
                    currentY -= 50
                    Dim lp As New Point(currentX, currentY)
                    Return lp
                End If
                End If
            End If
    End Function


    Function checkforobstacle(direction As String, isclearup As Boolean, iscleardown As Boolean, isclearleft As Boolean, isclearright As Boolean)
        Dim canmove As Boolean = Nothing
        If direction = "left" And isclearleft = True Then
            canmove = True
        ElseIf direction = "right" And isclearright = True Then
            canmove = True
        ElseIf direction = "up" And isclearup = True Then
            canmove = True
        ElseIf direction = "down" And iscleardown = True Then
            canmove = True
        Else
            canmove = False
        End If
        Return canmove
    End Function
    Shared Function getstartingPos(playerposY As Single, playerposX As Single, canspawn As Boolean)
        Dim xcheck As Single
        Dim ycheck As Single
        If canspawn = True Then
            ycheck = ranpos("Y")
            xcheck = ranpos("X")
            If Not ycheck = playerposY Or xcheck = playerposX Then
                Dim pp As New Point(xcheck, ycheck)
                Return pp
            Else
                Dim newpoint As New Point(ranpos("X"), ranpos("Y"))
                Return newpoint
            End If
        Else
            Dim newpoint As New Point(ranpos("X"), ranpos("Y"))
            Return newpoint
        End If


    End Function

    Shared Function ranpos(xory As String)
        Dim pos As Single
        Try
            If xory = "X" Then
                Try
                    Randomize()
                    ranX = Int(Rnd() * 8) + 1
                    ranX *= 50
                    pos = ranX
                Catch ex As Exception

                End Try

            ElseIf xory = "Y" Then
                Try
                    Randomize()
                    ranY = Int(Rnd() * 8) + 1
                    ranY *= 50
                    pos = ranY
                Catch ex As Exception

                End Try

            Else
            End If
        Catch ex As Exception

        End Try
        Return pos
    End Function
End Class






gamescreen form
Imports Inventory.inventorydata
Imports AI.Enemies
Public Class GameScreen
    Dim treex As Integer = 0
    Dim treey As Integer = 0
    Dim xpos As Single = 0
    Dim ypos As Single = 0
    Private imgman As New ImageManager
    Dim treebroke As Boolean = False
    Dim spawnnewenemy As Boolean = False
    Dim enemyspawn As New Point
    Dim isenemyspawned As Boolean = False
    Dim enemynewpos As New Point
    Private Sub GameScreen_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
        If treebroke = False And spawnnewenemy = False And isenemyspawned = False Then
            DrawDirt(e, 0, 0)
            DrawDirt(e, 50, 0)
            DrawDirt(e, 100, 0)
            DrawDirt(e, 150, 0)
            DrawDirt(e, 200, 0)
            DrawDirt(e, 250, 0)
            DrawDirt(e, 300, 0)
            DrawDirt(e, 350, 0)
            DrawDirt(e, 400, 0)
            DrawDirt(e, 0, 50)
            DrawDirt(e, 0, 100)
            DrawDirt(e, 0, 150)
            DrawDirt(e, 0, 200)
            DrawDirt(e, 0, 250)
            DrawDirt(e, 0, 300)
            DrawDirt(e, 0, 350)
            DrawDirt(e, 0, 400)
            DrawDirt(e, 50, 400)
            DrawDirt(e, 100, 400)
            DrawDirt(e, 150, 400)
            DrawDirt(e, 200, 400)
            DrawDirt(e, 250, 400)
            DrawDirt(e, 300, 400)
            DrawDirt(e, 350, 400)
            DrawDirt(e, 400, 400)
            DrawDirt(e, 400, 100)
            DrawDirt(e, 400, 150)
            DrawDirt(e, 400, 200)
            DrawDirt(e, 400, 250)
            DrawDirt(e, 400, 300)
            DrawDirt(e, 400, 350)

            DrawDirt(e, 400, 50)
            DrawGrass(e, 50, 50)
            DrawGrass(e, 100, 50)
            DrawGrass(e, 150, 50)
            DrawGrass(e, 200, 50)
            DrawGrass(e, 250, 50)
            DrawGrass(e, 300, 50)
            DrawGrass(e, 350, 50)
            DrawGrass(e, 50, 100)
            DrawGrass(e, 100, 100)
            DrawGrass(e, 150, 100)
            DrawGrass(e, 200, 100)
            DrawGrass(e, 250, 100)
            DrawGrass(e, 300, 100)
            DrawGrass(e, 350, 100)

            DrawGrass(e, 50, 150)
            DrawGrass(e, 50, 200)
            DrawGrass(e, 50, 250)
            DrawGrass(e, 50, 300)
            DrawGrass(e, 50, 350)
            DrawGrass(e, 100, 150)
            DrawGrass(e, 100, 200)
            DrawGrass(e, 100, 250)
            DrawGrass(e, 100, 300)
            DrawGrass(e, 100, 350)

            DrawGrass(e, 150, 150)
            DrawGrass(e, 150, 200)
            DrawGrass(e, 150, 250)
            DrawGrass(e, 150, 300)
            DrawGrass(e, 150, 350)

            DrawGrass(e, 200, 150)
            DrawGrass(e, 200, 200)
            DrawGrass(e, 200, 250)
            DrawGrass(e, 200, 300)
            DrawGrass(e, 200, 350)

            DrawGrass(e, 250, 150)
            DrawGrass(e, 250, 200)
            DrawGrass(e, 250, 250)
            DrawGrass(e, 250, 300)
            DrawGrass(e, 250, 350)

            DrawGrass(e, 300, 150)
            DrawGrass(e, 300, 200)
            DrawGrass(e, 300, 250)
            DrawGrass(e, 300, 300)
            DrawGrass(e, 300, 350)

            DrawGrass(e, 350, 150)
            DrawGrass(e, 350, 200)
            DrawGrass(e, 350, 250)
            DrawGrass(e, 350, 300)
            DrawGrass(e, 350, 350)
            drawplayer(e, xpos, ypos)
            If treex = 0 And treey = 0 Then
                wheretodrawtree()
                drawtree(e, treex, treey)
            Else
                drawtree(e, treex, treey)
            End If
            Me.Label3.Text = xpos
            Me.Label4.Text = ypos
            'imgman.DrawImage(Me, "Tree", New Point(0, 100), New Point(50, 50))
        ElseIf treebroke = True And spawnnewenemy = False And isenemyspawned = False Then
            DrawDirt(e, 0, 0)
            DrawDirt(e, 50, 0)
            DrawDirt(e, 100, 0)
            DrawDirt(e, 150, 0)
            DrawDirt(e, 200, 0)
            DrawDirt(e, 250, 0)
            DrawDirt(e, 300, 0)
            DrawDirt(e, 350, 0)
            DrawDirt(e, 400, 0)
            DrawDirt(e, 0, 50)
            DrawDirt(e, 0, 100)
            DrawDirt(e, 0, 150)
            DrawDirt(e, 0, 200)
            DrawDirt(e, 0, 250)
            DrawDirt(e, 0, 300)
            DrawDirt(e, 0, 350)
            DrawDirt(e, 0, 400)
            DrawDirt(e, 50, 400)
            DrawDirt(e, 100, 400)
            DrawDirt(e, 150, 400)
            DrawDirt(e, 200, 400)
            DrawDirt(e, 250, 400)
            DrawDirt(e, 300, 400)
            DrawDirt(e, 350, 400)
            DrawDirt(e, 400, 400)
            DrawDirt(e, 400, 100)
            DrawDirt(e, 400, 150)
            DrawDirt(e, 400, 200)
            DrawDirt(e, 400, 250)
            DrawDirt(e, 400, 300)
            DrawDirt(e, 400, 350)

            DrawDirt(e, 400, 50)
            DrawGrass(e, 50, 50)
            DrawGrass(e, 100, 50)
            DrawGrass(e, 150, 50)
            DrawGrass(e, 200, 50)
            DrawGrass(e, 250, 50)
            DrawGrass(e, 300, 50)
            DrawGrass(e, 350, 50)
            DrawGrass(e, 50, 100)
            DrawGrass(e, 100, 100)
            DrawGrass(e, 150, 100)
            DrawGrass(e, 200, 100)
            DrawGrass(e, 250, 100)
            DrawGrass(e, 300, 100)
            DrawGrass(e, 350, 100)

            DrawGrass(e, 50, 150)
            DrawGrass(e, 50, 200)
            DrawGrass(e, 50, 250)
            DrawGrass(e, 50, 300)
            DrawGrass(e, 50, 350)
            DrawGrass(e, 100, 150)
            DrawGrass(e, 100, 200)
            DrawGrass(e, 100, 250)
            DrawGrass(e, 100, 300)
            DrawGrass(e, 100, 350)

            DrawGrass(e, 150, 150)
            DrawGrass(e, 150, 200)
            DrawGrass(e, 150, 250)
            DrawGrass(e, 150, 300)
            DrawGrass(e, 150, 350)

            DrawGrass(e, 200, 150)
            DrawGrass(e, 200, 200)
            DrawGrass(e, 200, 250)
            DrawGrass(e, 200, 300)
            DrawGrass(e, 200, 350)

            DrawGrass(e, 250, 150)
            DrawGrass(e, 250, 200)
            DrawGrass(e, 250, 250)
            DrawGrass(e, 250, 300)
            DrawGrass(e, 250, 350)

            DrawGrass(e, 300, 150)
            DrawGrass(e, 300, 200)
            DrawGrass(e, 300, 250)
            DrawGrass(e, 300, 300)
            DrawGrass(e, 300, 350)

            DrawGrass(e, 350, 150)
            DrawGrass(e, 350, 200)
            DrawGrass(e, 350, 250)
            DrawGrass(e, 350, 300)
            DrawGrass(e, 350, 350)
            drawplayer(e, xpos, ypos)
            treex = Nothing
            treey = Nothing
            Me.Label3.Text = xpos
            Me.Label4.Text = ypos









        ElseIf treebroke = False And spawnnewenemy = False And isenemyspawned = True Then
            DrawDirt(e, 0, 0)
            DrawDirt(e, 50, 0)
            DrawDirt(e, 100, 0)
            DrawDirt(e, 150, 0)
            DrawDirt(e, 200, 0)
            DrawDirt(e, 250, 0)
            DrawDirt(e, 300, 0)
            DrawDirt(e, 350, 0)
            DrawDirt(e, 400, 0)
            DrawDirt(e, 0, 50)
            DrawDirt(e, 0, 100)
            DrawDirt(e, 0, 150)
            DrawDirt(e, 0, 200)
            DrawDirt(e, 0, 250)
            DrawDirt(e, 0, 300)
            DrawDirt(e, 0, 350)
            DrawDirt(e, 0, 400)
            DrawDirt(e, 50, 400)
            DrawDirt(e, 100, 400)
            DrawDirt(e, 150, 400)
            DrawDirt(e, 200, 400)
            DrawDirt(e, 250, 400)
            DrawDirt(e, 300, 400)
            DrawDirt(e, 350, 400)
            DrawDirt(e, 400, 400)
            DrawDirt(e, 400, 100)
            DrawDirt(e, 400, 150)
            DrawDirt(e, 400, 200)
            DrawDirt(e, 400, 250)
            DrawDirt(e, 400, 300)
            DrawDirt(e, 400, 350)

            DrawDirt(e, 400, 50)
            DrawGrass(e, 50, 50)
            DrawGrass(e, 100, 50)
            DrawGrass(e, 150, 50)
            DrawGrass(e, 200, 50)
            DrawGrass(e, 250, 50)
            DrawGrass(e, 300, 50)
            DrawGrass(e, 350, 50)
            DrawGrass(e, 50, 100)
            DrawGrass(e, 100, 100)
            DrawGrass(e, 150, 100)
            DrawGrass(e, 200, 100)
            DrawGrass(e, 250, 100)
            DrawGrass(e, 300, 100)
            DrawGrass(e, 350, 100)

            DrawGrass(e, 50, 150)
            DrawGrass(e, 50, 200)
            DrawGrass(e, 50, 250)
            DrawGrass(e, 50, 300)
            DrawGrass(e, 50, 350)
            DrawGrass(e, 100, 150)
            DrawGrass(e, 100, 200)
            DrawGrass(e, 100, 250)
            DrawGrass(e, 100, 300)
            DrawGrass(e, 100, 350)

            DrawGrass(e, 150, 150)
            DrawGrass(e, 150, 200)
            DrawGrass(e, 150, 250)
            DrawGrass(e, 150, 300)
            DrawGrass(e, 150, 350)

            DrawGrass(e, 200, 150)
            DrawGrass(e, 200, 200)
            DrawGrass(e, 200, 250)
            DrawGrass(e, 200, 300)
            DrawGrass(e, 200, 350)

            DrawGrass(e, 250, 150)
            DrawGrass(e, 250, 200)
            DrawGrass(e, 250, 250)
            DrawGrass(e, 250, 300)
            DrawGrass(e, 250, 350)

            DrawGrass(e, 300, 150)
            DrawGrass(e, 300, 200)
            DrawGrass(e, 300, 250)
            DrawGrass(e, 300, 300)
            DrawGrass(e, 300, 350)

            DrawGrass(e, 350, 150)
            DrawGrass(e, 350, 200)
            DrawGrass(e, 350, 250)
            DrawGrass(e, 350, 300)
            DrawGrass(e, 350, 350)
            drawplayer(e, xpos, ypos)
            drawenemy(e, enemynewpos.X, enemynewpos.Y)
            If treex = 0 And treey = 0 Then
                wheretodrawtree()
                drawtree(e, treex, treey)
            Else
                drawtree(e, treex, treey)
            End If
            Me.Label3.Text = xpos
            Me.Label4.Text = ypos
            'imgman.DrawImage(Me, "Tree", New Point(0, 100), New Point(50, 50))
        ElseIf treebroke = True And spawnnewenemy = False And isenemyspawned = True Then
            DrawDirt(e, 0, 0)
            DrawDirt(e, 50, 0)
            DrawDirt(e, 100, 0)
            DrawDirt(e, 150, 0)
            DrawDirt(e, 200, 0)
            DrawDirt(e, 250, 0)
            DrawDirt(e, 300, 0)
            DrawDirt(e, 350, 0)
            DrawDirt(e, 400, 0)
            DrawDirt(e, 0, 50)
            DrawDirt(e, 0, 100)
            DrawDirt(e, 0, 150)
            DrawDirt(e, 0, 200)
            DrawDirt(e, 0, 250)
            DrawDirt(e, 0, 300)
            DrawDirt(e, 0, 350)
            DrawDirt(e, 0, 400)
            DrawDirt(e, 50, 400)
            DrawDirt(e, 100, 400)
            DrawDirt(e, 150, 400)
            DrawDirt(e, 200, 400)
            DrawDirt(e, 250, 400)
            DrawDirt(e, 300, 400)
            DrawDirt(e, 350, 400)
            DrawDirt(e, 400, 400)
            DrawDirt(e, 400, 100)
            DrawDirt(e, 400, 150)
            DrawDirt(e, 400, 200)
            DrawDirt(e, 400, 250)
            DrawDirt(e, 400, 300)
            DrawDirt(e, 400, 350)

            DrawDirt(e, 400, 50)
            DrawGrass(e, 50, 50)
            DrawGrass(e, 100, 50)
            DrawGrass(e, 150, 50)
            DrawGrass(e, 200, 50)
            DrawGrass(e, 250, 50)
            DrawGrass(e, 300, 50)
            DrawGrass(e, 350, 50)
            DrawGrass(e, 50, 100)
            DrawGrass(e, 100, 100)
            DrawGrass(e, 150, 100)
            DrawGrass(e, 200, 100)
            DrawGrass(e, 250, 100)
            DrawGrass(e, 300, 100)
            DrawGrass(e, 350, 100)

            DrawGrass(e, 50, 150)
            DrawGrass(e, 50, 200)
            DrawGrass(e, 50, 250)
            DrawGrass(e, 50, 300)
            DrawGrass(e, 50, 350)
            DrawGrass(e, 100, 150)
            DrawGrass(e, 100, 200)
            DrawGrass(e, 100, 250)
            DrawGrass(e, 100, 300)
            DrawGrass(e, 100, 350)

            DrawGrass(e, 150, 150)
            DrawGrass(e, 150, 200)
            DrawGrass(e, 150, 250)
            DrawGrass(e, 150, 300)
            DrawGrass(e, 150, 350)

            DrawGrass(e, 200, 150)
            DrawGrass(e, 200, 200)
            DrawGrass(e, 200, 250)
            DrawGrass(e, 200, 300)
            DrawGrass(e, 200, 350)

            DrawGrass(e, 250, 150)
            DrawGrass(e, 250, 200)
            DrawGrass(e, 250, 250)
            DrawGrass(e, 250, 300)
            DrawGrass(e, 250, 350)

            DrawGrass(e, 300, 150)
            DrawGrass(e, 300, 200)
            DrawGrass(e, 300, 250)
            DrawGrass(e, 300, 300)
            DrawGrass(e, 300, 350)

            DrawGrass(e, 350, 150)
            DrawGrass(e, 350, 200)
            DrawGrass(e, 350, 250)
            DrawGrass(e, 350, 300)
            DrawGrass(e, 350, 350)
            drawplayer(e, xpos, ypos)
            drawenemy(e, enemynewpos.X, enemynewpos.Y)
            treex = Nothing
            treey = Nothing
            Me.Label3.Text = xpos
            Me.Label4.Text = ypos








        ElseIf treebroke = False And spawnnewenemy = True And isenemyspawned = False Then
            DrawDirt(e, 0, 0)
            DrawDirt(e, 50, 0)
            DrawDirt(e, 100, 0)
            DrawDirt(e, 150, 0)
            DrawDirt(e, 200, 0)
            DrawDirt(e, 250, 0)
            DrawDirt(e, 300, 0)
            DrawDirt(e, 350, 0)
            DrawDirt(e, 400, 0)
            DrawDirt(e, 0, 50)
            DrawDirt(e, 0, 100)
            DrawDirt(e, 0, 150)
            DrawDirt(e, 0, 200)
            DrawDirt(e, 0, 250)
            DrawDirt(e, 0, 300)
            DrawDirt(e, 0, 350)
            DrawDirt(e, 0, 400)
            DrawDirt(e, 50, 400)
            DrawDirt(e, 100, 400)
            DrawDirt(e, 150, 400)
            DrawDirt(e, 200, 400)
            DrawDirt(e, 250, 400)
            DrawDirt(e, 300, 400)
            DrawDirt(e, 350, 400)
            DrawDirt(e, 400, 400)
            DrawDirt(e, 400, 100)
            DrawDirt(e, 400, 150)
            DrawDirt(e, 400, 200)
            DrawDirt(e, 400, 250)
            DrawDirt(e, 400, 300)
            DrawDirt(e, 400, 350)

            DrawDirt(e, 400, 50)
            DrawGrass(e, 50, 50)
            DrawGrass(e, 100, 50)
            DrawGrass(e, 150, 50)
            DrawGrass(e, 200, 50)
            DrawGrass(e, 250, 50)
            DrawGrass(e, 300, 50)
            DrawGrass(e, 350, 50)
            DrawGrass(e, 50, 100)
            DrawGrass(e, 100, 100)
            DrawGrass(e, 150, 100)
            DrawGrass(e, 200, 100)
            DrawGrass(e, 250, 100)
            DrawGrass(e, 300, 100)
            DrawGrass(e, 350, 100)

            DrawGrass(e, 50, 150)
            DrawGrass(e, 50, 200)
            DrawGrass(e, 50, 250)
            DrawGrass(e, 50, 300)
            DrawGrass(e, 50, 350)
            DrawGrass(e, 100, 150)
            DrawGrass(e, 100, 200)
            DrawGrass(e, 100, 250)
            DrawGrass(e, 100, 300)
            DrawGrass(e, 100, 350)

            DrawGrass(e, 150, 150)
            DrawGrass(e, 150, 200)
            DrawGrass(e, 150, 250)
            DrawGrass(e, 150, 300)
            DrawGrass(e, 150, 350)

            DrawGrass(e, 200, 150)
            DrawGrass(e, 200, 200)
            DrawGrass(e, 200, 250)
            DrawGrass(e, 200, 300)
            DrawGrass(e, 200, 350)

            DrawGrass(e, 250, 150)
            DrawGrass(e, 250, 200)
            DrawGrass(e, 250, 250)
            DrawGrass(e, 250, 300)
            DrawGrass(e, 250, 350)

            DrawGrass(e, 300, 150)
            DrawGrass(e, 300, 200)
            DrawGrass(e, 300, 250)
            DrawGrass(e, 300, 300)
            DrawGrass(e, 300, 350)

            DrawGrass(e, 350, 150)
            DrawGrass(e, 350, 200)
            DrawGrass(e, 350, 250)
            DrawGrass(e, 350, 300)
            DrawGrass(e, 350, 350)
            drawplayer(e, xpos, ypos)
            drawenemy(e, enemyspawn.X, enemyspawn.Y)
            isenemyspawned = True
            If treex = 0 And treey = 0 Then
                wheretodrawtree()
                drawtree(e, treex, treey)
            Else
                drawtree(e, treex, treey)
            End If
            Me.Label3.Text = xpos
            Me.Label4.Text = ypos
            'imgman.DrawImage(Me, "Tree", New Point(0, 100), New Point(50, 50))
        ElseIf treebroke = True And spawnnewenemy = True And isenemyspawned = False Then
            DrawDirt(e, 0, 0)
            DrawDirt(e, 50, 0)
            DrawDirt(e, 100, 0)
            DrawDirt(e, 150, 0)
            DrawDirt(e, 200, 0)
            DrawDirt(e, 250, 0)
            DrawDirt(e, 300, 0)
            DrawDirt(e, 350, 0)
            DrawDirt(e, 400, 0)
            DrawDirt(e, 0, 50)
            DrawDirt(e, 0, 100)
            DrawDirt(e, 0, 150)
            DrawDirt(e, 0, 200)
            DrawDirt(e, 0, 250)
            DrawDirt(e, 0, 300)
            DrawDirt(e, 0, 350)
            DrawDirt(e, 0, 400)
            DrawDirt(e, 50, 400)
            DrawDirt(e, 100, 400)
            DrawDirt(e, 150, 400)
            DrawDirt(e, 200, 400)
            DrawDirt(e, 250, 400)
            DrawDirt(e, 300, 400)
            DrawDirt(e, 350, 400)
            DrawDirt(e, 400, 400)
            DrawDirt(e, 400, 100)
            DrawDirt(e, 400, 150)
            DrawDirt(e, 400, 200)
            DrawDirt(e, 400, 250)
            DrawDirt(e, 400, 300)
            DrawDirt(e, 400, 350)

            DrawDirt(e, 400, 50)
            DrawGrass(e, 50, 50)
            DrawGrass(e, 100, 50)
            DrawGrass(e, 150, 50)
            DrawGrass(e, 200, 50)
            DrawGrass(e, 250, 50)
            DrawGrass(e, 300, 50)
            DrawGrass(e, 350, 50)
            DrawGrass(e, 50, 100)
            DrawGrass(e, 100, 100)
            DrawGrass(e, 150, 100)
            DrawGrass(e, 200, 100)
            DrawGrass(e, 250, 100)
            DrawGrass(e, 300, 100)
            DrawGrass(e, 350, 100)

            DrawGrass(e, 50, 150)
            DrawGrass(e, 50, 200)
            DrawGrass(e, 50, 250)
            DrawGrass(e, 50, 300)
            DrawGrass(e, 50, 350)
            DrawGrass(e, 100, 150)
            DrawGrass(e, 100, 200)
            DrawGrass(e, 100, 250)
            DrawGrass(e, 100, 300)
            DrawGrass(e, 100, 350)

            DrawGrass(e, 150, 150)
            DrawGrass(e, 150, 200)
            DrawGrass(e, 150, 250)
            DrawGrass(e, 150, 300)
            DrawGrass(e, 150, 350)

            DrawGrass(e, 200, 150)
            DrawGrass(e, 200, 200)
            DrawGrass(e, 200, 250)
            DrawGrass(e, 200, 300)
            DrawGrass(e, 200, 350)

            DrawGrass(e, 250, 150)
            DrawGrass(e, 250, 200)
            DrawGrass(e, 250, 250)
            DrawGrass(e, 250, 300)
            DrawGrass(e, 250, 350)

            DrawGrass(e, 300, 150)
            DrawGrass(e, 300, 200)
            DrawGrass(e, 300, 250)
            DrawGrass(e, 300, 300)
            DrawGrass(e, 300, 350)

            DrawGrass(e, 350, 150)
            DrawGrass(e, 350, 200)
            DrawGrass(e, 350, 250)
            DrawGrass(e, 350, 300)
            DrawGrass(e, 350, 350)
            drawplayer(e, xpos, ypos)
            drawenemy(e, enemyspawn.X, enemyspawn.Y)
            isenemyspawned = True
            treex = Nothing
            treey = Nothing
            Me.Label3.Text = xpos
            Me.Label4.Text = ypos
        End If
        spawnnewenemy = False
    End Sub
    Private Sub DrawGrass(ByVal e As PaintEventArgs, ByVal x As Single, ByVal y As Single)
        Dim newImage As Image = Image.FromFile("C:\GrimmInc\ITS\Assets\Graphics\grass.jpeg")
        Dim width As Single = 50.0F
        Dim height As Single = 50.0F

        e.Graphics.DrawImage(newImage, x, y, width, height)
    End Sub
    Private Sub DrawDirt(ByVal e As PaintEventArgs, ByVal x As Single, ByVal y As Single)
        Dim newImage As Image = Image.FromFile("C:\GrimmInc\ITS\Assets\Graphics\dirt.jpeg")
        Dim width As Single = 50.0F
        Dim height As Single = 50.0F

        e.Graphics.DrawImage(newImage, x, y, width, height)
    End Sub
    Private Sub drawplayer(ByVal e As PaintEventArgs, ByVal x As Single, ByVal y As Single)
        Dim newImage As Image = Image.FromFile("C:\GrimmInc\ITS\Assets\Graphics\char1.jpeg")
        Dim width As Single = 50.0F
        Dim height As Single = 50.0F

        e.Graphics.DrawImage(newImage, x, y, width, height)
    End Sub

    Private Sub drawenemy(ByVal e As PaintEventArgs, ByVal x As Single, ByVal y As Single)
        Dim width As Single = 50.0F
        Dim height As Single = 50.0F
        Dim newEnemy As Image = Image.FromFile("C:\GrimmInc\ITS\Assets\Graphics\char1.jpeg")
        e.Graphics.DrawImage(newEnemy, x, y, width, height)
    End Sub
    Friend Sub wheretodrawtree()
        Randomize()
        treex = Int(Rnd() * 8) + 1
        treex *= 50
        Randomize()
        treey = Int(Rnd() * 8) + 1
        treey *= 50
        Me.Label1.Text = treex
        Me.Label2.Text = treey
    End Sub
    Private Sub drawtree(ByVal e As PaintEventArgs, ByVal x As Single, ByVal y As Single)
        Dim newImage As Image = Image.FromFile("C:\GrimmInc\ITS\Assets\Graphics\Tree.jpeg")
        Dim width As Single = 50.0F
        Dim height As Single = 50.0F

        e.Graphics.DrawImage(newImage, x, y, width, height)
    End Sub
    Private Sub GameScreen_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        Dim bHandled As Boolean = False
        Select Case e.KeyCode
            Case Keys.Right
                If xpos <= 350 Then
                    If treex = xpos + 50 And treey = ypos Then

                    ElseIf enemyspawn.X = xpos + 50 And enemyspawn.Y = ypos Then

                    Else
                        xpos += 50
                        e.Handled = True
                        Me.Refresh()
                    End If
                End If
            Case Keys.Left
                If treex = xpos - 50 And treey = ypos Then

                ElseIf enemyspawn.X = xpos - 50 And enemyspawn.Y = ypos Then

                Else
                    If xpos >= 50 Then
                        xpos -= 50
                        e.Handled = True
                        Me.Refresh()
                    Else
                    End If
                End If
            Case Keys.Up
                If treey = ypos - 50 And treex = xpos Then

                ElseIf enemyspawn.Y = ypos - 50 And enemyspawn.X = xpos Then

                Else
                    If ypos >= 50 Then
                        ypos -= 50
                        e.Handled = True
                        Me.Refresh()
                    End If
                End If
            Case Keys.Down
                If treey = ypos + 50 And treex = xpos Then

                ElseIf enemyspawn.Y = ypos + 50 And enemyspawn.X = xpos Then

                Else
                    If ypos <= 350 Then
                        ypos += 50
                        e.Handled = True
                        Me.Refresh()
                    End If
                End If



            Case Keys.D
                If xpos <= 350 Then
                    If treex = xpos + 50 And treey = ypos Then

                    Else
                        xpos += 50
                        e.Handled = True
                        Me.Refresh()
                    End If
                End If
            Case Keys.A
                If treex = xpos - 50 And treey = ypos Then

                Else
                    If xpos >= 50 Then
                        xpos -= 50
                        e.Handled = True
                        Me.Refresh()
                    Else
                    End If
                End If
            Case Keys.W
                If treey = ypos - 50 And treex = xpos Then
                Else
                    If ypos >= 50 Then
                        ypos -= 50
                        e.Handled = True
                        Me.Refresh()
                    End If
                End If
            Case Keys.S
                If treey = ypos + 50 And treex = xpos Then
                Else
                    If ypos <= 350 Then
                        ypos += 50
                        e.Handled = True
                        Me.Refresh()
                    End If
                End If

            Case Keys.B
                If ypos = treey + 50 And xpos = treex + 50 Then
                    treebroke = True
                    Me.Refresh()
                    InventoryManager.Additem("wood", getamountofwood(), Form1.ListBox2)
                ElseIf ypos = treey + 50 And xpos = treex - 50 Then
                    treebroke = True
                    Me.Refresh()
                    InventoryManager.Additem("wood", getamountofwood(), Form1.ListBox2)
                ElseIf ypos = treey - 50 And xpos = treex + 50 Then
                    treebroke = True
                    Me.Refresh()
                    InventoryManager.Additem("wood", getamountofwood(), Form1.ListBox2)
                ElseIf ypos = treey - 50 And xpos = treex - 50 Then
                    treebroke = True
                    Me.Refresh()
                    InventoryManager.Additem("wood", getamountofwood(), Form1.ListBox2)
                ElseIf ypos = treey And xpos = treex - 50 Then
                    treebroke = True
                    Me.Refresh()
                    InventoryManager.Additem("wood", getamountofwood(), Form1.ListBox2)
                ElseIf ypos = treey And xpos = treex + 50 Then
                    treebroke = True
                    Me.Refresh()
                    InventoryManager.Additem("wood", getamountofwood(), Form1.ListBox2)
                ElseIf ypos = treey - 50 And xpos = treex Then
                    treebroke = True
                    Me.Refresh()
                    InventoryManager.Additem("wood", getamountofwood(), Form1.ListBox2)
                ElseIf ypos = treey + 50 And xpos = treex Then
                    treebroke = True
                    Me.Refresh()
                    InventoryManager.Additem("wood", getamountofwood(), Form1.ListBox2)
                Else

                End If
            Case Keys.R
                wheretodrawtree()
                treebroke = False
                Me.Refresh()

            Case Keys.P
                spawnnewenemy = True
                enemyspawn = getstartingPos(ypos, xpos, True)
                Me.Refresh()
                Me.Timer1.Enabled = True
            Case Keys.M
                Try
                    enemyspawn = AI.Enemies.move(xpos, ypos, treex, treey, enemyspawn)
                    Me.Refresh()
                Catch ex As Exception

                End Try

        End Select
    End Sub

    Function getamountofwood()
        Randomize()
        Dim wooddropped As Integer = Int(Rnd() * 8) + 1
        Return wooddropped
    End Function

    Private Sub GameScreen_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.SetStyle(ControlStyles.UserPaint, True)
        Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
        Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
        'imgman.LoadImage("Tree", "C:\GrimmInc\ITS\Assets\Graphics\Tree.jpeg")
        Me.Hide()
        Me.Select()
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Try
            enemynewpos = AI.Enemies.move(xpos, ypos, treex, treey, enemyspawn)
            Me.Refresh()
        Catch ex As Exception

        End Try
    End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: enemy going top left tile when moving

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10803
  • View blog
  • Posts: 40,257
  • Joined: 27-December 08

Re: enemy going top left tile when moving

Posted 26 October 2014 - 11:02 PM

Let's not duplicate post.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1