Mario like jump in tile engine
Mario like jump in tile engine
Mario like jump in tile engine
Mario like jump in tile engine
Mario like jump in tile engine
Mario like jump in tile engine Mario like jump in tile engine Mario like jump in tile engine Mario like jump in tile engine Mario like jump in tile engine Mario like jump in tile engine Mario like jump in tile engine Mario like jump in tile engine
Mario like jump in tile engine Mario like jump in tile engine
Mario like jump in tile engine
Go Back  Xtreme Visual Basic Talk > > > Mario like jump in tile engine


Reply
 
Thread Tools Display Modes
  #1  
Old 01-24-2012, 06:28 PM
Mikeyb Mikeyb is offline
Newcomer
 
Join Date: Jan 2012
Posts: 1
Question Mario like jump in tile engine


I have a very basic tiling engine that was made from a YouTube tutorial for making an top down RPG style game and I am trying to adapt it to a platformer game. The code is fairly simple but not being a physics guy I’m looking for some help adding a Mario style jump to the program. I know there will most likely need to be some additional variables added to it such as gravity and velocity. That said I am not sure where to get started, below is the meet and potatoes so to speak of the program.
Code:
' VIEW PORT
    Dim ResWidth As Integer = 750
    Dim ResHeight As Integer = 550
    Dim TileSize As Integer = 32

    ' GRAPHICS VARIABLES
    Dim G As Graphics
    Dim BBG As Graphics
    Dim BB As Bitmap
    Dim bmpTile As Bitmap
    Dim sRect As Rectangle
    Dim dRect As Rectangle

    ' FPS COUNTER
    Dim tSec As Integer = TimeOfDay.Second
    Dim tTicks As Integer = 0
    Dim MaxTicks As Integer = 0

    ' MAP VARIABLES
    Dim Map(100, 100, 10) As Integer
    Dim MapX As Integer = 20
    Dim MapY As Integer = 20

    ' GAME RUNNING ?
    Dim IsRunning As Boolean = True

    ' MOUSE LOCATIONS
    Dim mouseX As Integer
    Dim mouseY As Integer
    Dim mMapX As Integer
    Dim mMapY As Integer

    Dim bmpToon As Bitmap
    Dim xPos As Integer = 0
    Dim yPos As Integer = 0
    Dim MoveSpeed As Integer = 8
    Dim MoveDir As Short = 0
    Dim LastDir As Short = 2

    Dim GuyX As Decimal = (MapX + 9) * TileSize
    Dim GuyY As Decimal = (MapY + 6) * TileSize

    ' PAINT BRUSH
    Dim PaintBrush As Integer = 0

    ' SHOW DIALOG
    Dim OpenDialog As Boolean = False
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Show()
        Me.Focus()

        ' INITIALIZE GRAPHICS OBJECTS
        G = Me.CreateGraphics
        BB = New Bitmap(ResWidth, ResHeight)
        bmpTile = New Bitmap(GFX.pbGFX.Image)
        bmpToon = New Bitmap(GFX.pbToon.Image)

        LoadMap()

        StartGameLoop()
    End Sub

    Private Sub StartGameLoop()
        Do While IsRunning = True
            Application.DoEvents()
            SetMoveDir()
            MoveToon(MoveDir)
            DrawGraphics()
            ' UPDATE TICK COUNTER
            TickCounter()
        Loop
    End Sub

    Private Sub SetMoveDir()
        If GetKeyState(Keys.W) = True Then MoveDir = 1
        If GetKeyState(Keys.S) = True Then MoveDir = 2
        If GetKeyState(Keys.A) = True Then MoveDir = 3
        If GetKeyState(Keys.D) = True Then MoveDir = 4

        If GetKeyState(Keys.T) = True Then OpenDialog = True
        If GetKeyState(Keys.T) = False Then OpenDialog = False

        If GetKeyState(Keys.W) = False And _
            GetKeyState(Keys.S) = False And _
            GetKeyState(Keys.A) = False And _
            GetKeyState(Keys.D) = False _
        Then
            MoveDir = 0
        End If

        If MoveDir <> 0 Then LastDir = MoveDir
    End Sub

    Private Sub MoveToon(ByVal dir As Short)
        Select Case dir
            Case 1
                If IsBlocked(0) = False Then
                    yPos += MoveSpeed
                    GuyY = (GuyY - MoveSpeed)

                    If yPos >= TileSize Then
                        yPos = 0
                        MapY -= 1
                    End If
                End If
            Case 2
                If IsBlocked(1) = False Then
                    yPos -= MoveSpeed
                    GuyY = (GuyY + MoveSpeed)

                    If yPos <= TileSize * -1 Then
                        yPos = 0
                        MapY += 1
                    End If
                End If
            Case 3
                If IsBlocked(2) = False Then
                    xPos += MoveSpeed
                    GuyX = (GuyX - MoveSpeed)

                    If xPos >= TileSize Then
                        xPos = 0
                        MapX -= 1
                    End If
                End If
            Case 4
                If IsBlocked(3) = False Then
                    xPos -= MoveSpeed
                    GuyX = (GuyX + MoveSpeed)

                    If xPos <= TileSize * -1 Then
                        xPos = 0
                        MapX += 1
                    End If
                End If
        End Select
    End Sub

    Private Sub DrawGraphics()
        'DRAW TILES
        For X = -1 To 19
            For Y = -1 To 14
                GetSourceRect(MapX + X, MapY + Y, TileSize, TileSize)

                dRect = New Rectangle((X * TileSize) + xPos, (Y * TileSize) + yPos, TileSize, TileSize)
                G.DrawImage(bmpTile, dRect, sRect, GraphicsUnit.Pixel)
            Next
        Next

        G.FillRectangle(Brushes.Wheat, 610, 0, 200, 500)

        G.FillRectangle(Brushes.Red, 21 * TileSize, 4 * TileSize, TileSize, TileSize)
        G.FillRectangle(Brushes.Blue, 21 * TileSize, 6 * TileSize, TileSize, TileSize)

        ' DRAW TOON
        GetToon(LastDir)
        bmpToon.MakeTransparent(Color.Fuchsia)
        G.DrawImage(bmpToon, 9 * TileSize, 6 * TileSize, sRect, GraphicsUnit.Pixel)

        ' DRAW DIALOG
        If OpenDialog = True Then
            DrawDialogBox()
        End If

        ' COPY BACKBUFFER TO GRAPHICS OBJECT
        G = Graphics.FromImage(BB)

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

        ' FIX OVERDRAW
        G.Clear(Color.Wheat)
    End Sub

    Private Sub GetToon(ByVal dir As Short)
        Select Case dir
            Case 1
                sRect = New Rectangle(32, 0, TileSize, TileSize)
            Case 2
                sRect = New Rectangle(0, 0, TileSize, TileSize)
            Case 3
                sRect = New Rectangle(0, 32, TileSize, TileSize)
            Case 4
                sRect = New Rectangle(32, 32, TileSize, TileSize)
        End Select
    End Sub

    Private Sub TickCounter()
        If tSec = TimeOfDay.Second And IsRunning = True Then
            tTicks = tTicks + 1
        Else
            MaxTicks = tTicks
            tTicks = 0
            tSec = TimeOfDay.Second
        End If
    End Sub

    
    Private Sub GetSourceRect(ByVal X As Integer, ByVal Y As Integer, ByVal w As Integer, ByVal h As Integer)
        Select Case Map(X, Y, 0)
            Case 0 'GRASS
                sRect = New Rectangle(32, 0, TileSize, TileSize)
                Map(X, Y, 1) = 0 'Passable
            Case 1 'Tree
                sRect = New Rectangle(32, 128, TileSize, TileSize)
                Map(X, Y, 1) = 0 'Passable
            Case 2 'Big Tree
                sRect = New Rectangle(0, 64, TileSize, TileSize)
                Map(X, Y, 1) = 0 'Passable
            Case 3 'Weird Mountain
                sRect = New Rectangle(96, 96, TileSize, TileSize)
                Map(X, Y, 1) = 1 'Blocked
            Case 4 'Mountain Center
                sRect = New Rectangle(160, 128, TileSize, TileSize)
                Map(X, Y, 1) = 1 'Blocked
            Case 5 'Flowers
                sRect = New Rectangle(64, 0, TileSize, TileSize)
                Map(X, Y, 1) = 0 'Passable
            Case 6 'Water
                sRect = New Rectangle(256, 32, TileSize, TileSize)
                Map(X, Y, 1) = 1 'Blocked
            Case 7 'Water Top
                sRect = New Rectangle(256, 0, TileSize, TileSize)
                Map(X, Y, 1) = 1 'Blocked
            Case 8 'Spire
                sRect = New Rectangle(96, 64, TileSize, TileSize)
                Map(X, Y, 1) = 1 'Blocked
        End Select
    End Sub

    Private Sub DrawDialogBox()
        Dim brshBG As Brush = New SolidBrush(Color.FromArgb(192, Color.Black))
        Dim bmpDialog As Bitmap = New Bitmap(GFX.pbDialog.Image)
        Dim fntChat As Font = New Font("Verdana", 12)

        sRect = New Rectangle(0, 0, 136, 146)
        dRect = New Rectangle(10, 10, 600, 90)

        bmpDialog.MakeTransparent(Color.Fuchsia)

        G.FillRectangle(brshBG, 25, 13, 600 - 50, 83)
        G.DrawImage(bmpDialog, dRect, sRect, GraphicsUnit.Pixel)
        G.DrawString("Rad Marvin: What a peculiar dream!", fntChat, Brushes.White, 40, 20)
    End Sub

    Private Function IsBlocked(ByVal dir As Short) As Boolean
        Select Case dir
            Case 0 ' NORTH
                If Map(GuyX / TileSize, Math.Ceiling(GuyY / TileSize) - 1, 1) = 1 Then
                    Return True
                End If
            Case 1 ' SOUTH
                If Map(GuyX / TileSize, Math.Floor(GuyY / TileSize) + 1, 1) = 1 Then
                    Return True
                End If
            Case 2 ' WEST
                If Map(Math.Ceiling(GuyX / TileSize) - 1, GuyY / TileSize, 1) = 1 Then
                    Return True
                End If
            Case 3 ' EAST
                If Map(Math.Floor(GuyX / TileSize) + 1, GuyY / TileSize, 1) = 1 Then
                    Return True
                End If
        End Select

        Return False
    End Function
Reply With Quote
  #2  
Old 01-26-2012, 06:21 PM
passel's Avatar
passelMario like jump in tile engine passel is offline
Sinecure Expert

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

I'm not a gamer but doesn't a "platform" game imply a side scroller type game where your character runs back and forth side to side and can jump up or climb up and down the screen on objects.
Since that code is all based on top down view, most of it needs to be thrown out. I guess, if I'm right about "platform", then there is too much that has to change to bother trying to add jumping logic to the existing code.
Perhaps searching for a tutorial on platform or side scroller games is your next 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
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
Mario like jump in tile engine
Mario like jump in tile engine
Mario like jump in tile engine Mario like jump in tile engine
Mario like jump in tile engine
Mario like jump in tile engine
Mario like jump in tile engine Mario like jump in tile engine Mario like jump in tile engine Mario like jump in tile engine Mario like jump in tile engine Mario like jump in tile engine Mario like jump in tile engine
Mario like jump in tile engine
Mario like jump in tile engine
 
Mario like jump in tile engine
Mario like jump in tile engine
 
-->