Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Feature] Dynamic sprite sizes!
#1
Dynamic sprite sizes! Now 100% free!

Basically, this system is a more generic BltPlayer and DrawPlayerName subroutine fix, which calculates the size of the sprite by the width and height of the image file which is loaded. This will only work with a sprite system that houses each sprite in a seperate file, but in the default Mirage layout.

It's a very easy fix, and I'm really not sure how anyone could have trouble adding it.

General Change
Replace BltSprite with:

Code:
Private Sub BltSprite(ByVal Sprite As Long, ByVal x As Long, ByVal y As Long, rec As DxVBLib.RECT)
    If Sprite < 1 Or Sprite > NumSprites Then Exit Sub
    
    Call DD_BltFast(x, y, DDS_Sprite(Sprite).Surface, rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)
End Sub

Players
BltPlayer Subroutine:

Find;
Code:
Dim Sprite As Long

and replace with;
Code:
Dim Sprite As Long, spriteleft As Long

Find;
Code:
.Top = 0

and replace that entire block with;
Code:
'Pre-load graphic to get the width and height used in calculation
    Call DD_ReadySurface("sprites\" & Sprite, DDS_Sprite(Sprite))
    
    Select Case GetPlayerDir(Index)
        Case DIR_UP
            spriteleft = DIR_UP
        Case DIR_RIGHT
            spriteleft = DIR_RIGHT
        Case DIR_DOWN
            spriteleft = DIR_DOWN
        Case DIR_LEFT
            spriteleft = DIR_LEFT
    End Select
  
    With rec
        .Top = 0
        .Bottom = DDS_Sprite(Sprite).SurfDescription.lHeight
        .Left = (spriteleft * 3 + Anim) * (DDS_Sprite(Sprite).SurfDescription.lWidth / 12)
        .Right = .Left + (DDS_Sprite(Sprite).SurfDescription.lWidth / 12)
    End With

Find;
Code:
X = GetPlayerX(Index) * PIC_X + Player(Index).XOffset

and replace that entire block with;
Code:
' Calculate the X
    X = GetPlayerX(Index) * PIC_X + Player(Index).XOffset - ((DDS_Sprite(Sprite).SurfDescription.lWidth / 12 - 32) / 2)
    ' Is the player's height more than 32..?
    If (DDS_Sprite(Sprite).SurfDescription.lHeight) > 32 Then
        ' Create a 32 pixel offset for larger sprites
        Y = GetPlayerY(Index) * PIC_Y + Player(Index).YOffset - ((DDS_Sprite(Sprite).SurfDescription.lHeight) - 32)
    Else
        ' Proceed as normal
        Y = GetPlayerY(Index) * PIC_Y + Player(Index).YOffset
    End If

Find;
Code:
If Y < 0 Then

and replace that entire block with;
Code:
' Is player's Y less than 0..?
    If Y < 0 Then
        With rec
            .Top = .Top - Y
        End With
        Y = 0
    End If

    ' Is player's X less than 0..?
    If X < 0 Then
        With rec
            .Left = .Left + (X * -1)
        End With
        X = 0
    End If

    ' Is player's X more than max map values..?
    If X + (DDS_Sprite(Sprite).SurfDescription.lWidth / 12) > MAX_MAPX * 32 + 32 Then
        With rec
            .Right = .Right + (X - (MAX_MAPX * 32))
        End With
    End If

That finishes the BltPlayer stuff! Basically, the Spriteleft is just a system I made so the sprite layout doesn't have to be Up, Down, Left, Right. The X, Y and REC edits are just changing it so instead of assuming the sprite is 32x32, it reads the values from the sprite surface. The height is set to the height of the surface, and the width is set to the width of the surface divided by 12, which is the amount of different sprite frames are set in one surface. Very simple.

Now, we edit the name code.

DrawPlayerName Subroutine:

Find;
Code:
TextY = GetPlayerY(Index) * PIC_Y

and replace with;
Code:
TextY = GetPlayerY(Index) * PIC_Y + Player(Index).YOffset - (DDS_Sprite(GetPlayerSprite(Index)).SurfDescription.lHeight) + 16

Again, we're just using the height of the surface to calculate how high it should be, then removing 16 pixels, because we need to ;D

None Player Characters
BltNPC Subroutine:

Find;
Code:
Dim Sprite As Long

and replace with;
Code:
Dim Sprite As Long, spriteleft As Long

Find;
Code:
.Top = 0

and replace entire block with;
Code:
'Pre-load graphic to get the width and height used in calculation
    Call DD_ReadySurface("sprites\" & Sprite, DDS_Sprite(Sprite))
    
    Select Case MapNpc(MapNpcNum).Dir
        Case DIR_UP
            spriteleft = DIR_UP
        Case DIR_RIGHT
            spriteleft = DIR_RIGHT
        Case DIR_DOWN
            spriteleft = DIR_DOWN
        Case DIR_LEFT
            spriteleft = DIR_LEFT
    End Select
  
    With rec
        .Top = 0
        .Bottom = DDS_Sprite(Sprite).SurfDescription.lHeight
        .Left = (spriteleft * 3 + Anim) * (DDS_Sprite(Sprite).SurfDescription.lWidth / 12)
        .Right = .Left + (DDS_Sprite(Sprite).SurfDescription.lWidth / 12)
    End With

Find;
Code:
With MapNpc(MapNpcNum)

and replace entire block with;
Code:
With MapNpc(MapNpcNum)
        ' Calculate X
        x = .x * PIC_X + .XOffset - ((DDS_Sprite(Sprite).SurfDescription.lWidth / 12 - 32) / 2)
        ' Is sprite more than 32..?
        If ((DDS_Sprite(Sprite).SurfDescription.lHeight) - 32) > 0 Then
            ' Create a 32 pixel offset for larger sprites
            y = MapNpc(MapNpcNum).y * PIC_Y + MapNpc(MapNpcNum).YOffset - ((DDS_Sprite(Sprite).SurfDescription.lHeight) - 32)
        Else
            ' Proceed as normal
            y = MapNpc(MapNpcNum).y * PIC_Y + MapNpc(MapNpcNum).YOffset
        End If
    End With

Find;
Code:
If Y < 0 Then

and replace entire block with;
Code:
' Is player's Y less than 0..?
    If y < 0 Then
        With rec
            .Top = .Top - y
        End With
        y = 0
    End If

    ' Is player's X less than 0..?
    If x < 0 Then
        With rec
            .Left = .Left + (x * -1)
            '.Right = .Left + 48 - (x * -1)
        End With
        x = 0
    End If

    ' Is player's X more than max map values..?
    If x + (DDS_Sprite(Sprite).SurfDescription.lWidth / 12) > MAX_MAPX * 32 + 32 Then
        With rec
            .Right = .Right + (x - (MAX_MAPX * 32))
        End With
    End If

Same things happening as last time, just updated syntax for the MapNPC variables.

That's it! Enjoy your new dynamically driven system.

This feature only uses one subroutine for the rendering of the player, meaning you'll have clipping issues unless you use a Y-based sprite rendering system. You can find my quick tutorial on how to make this by following this link;
http://web.miragesource.com/forums/viewt...48&start=0

Can use this tutorial freely in your game/engine, as long as you don't claim it as your own. That means you, Frozengod!
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)