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.
PlayersBltPlayer 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:
Select Case GetPlayerDir(Index)
Case DIR_UP
spriteleft = 0
Case DIR_RIGHT
spriteleft = 3
Case DIR_DOWN
spriteleft = 1
Case DIR_LEFT
spriteleft = 2
End Select
With rec
.Top = 0
.Bottom = DDSD_Sprite(Sprite).SurfDescription.lHeight
.Left = (spriteleft * 3 + Anim) * (DDSD_Sprite(Sprite).SurfDescription.lWidth / 12)
.Right = .Left + (DDSD_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 - ((DDSD_Sprite(Sprite).lWidth / 12 - 32) / 2)
' Is the player's height more than 32..?
If ((DDSD_Sprite(Sprite).lHeight) - 32) > 0 Then
' Create a 32 pixel offset for larger sprites
Y = GetPlayerY(Index) * PIC_Y + Player(Index).YOffset - ((DDSD_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)
'.Right = .Left + 48 - (x * -1)
End With
X = 0
End If
' Is player's X more than max map values..?
If X + (DDSD_Sprite(Sprite).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 - (DDSD_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 CharactersBltNPC 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:
Select Case MapNpc(MapNpcNum).Dir
Case DIR_UP
spriteleft = 0
Case DIR_RIGHT
spriteleft = 3
Case DIR_DOWN
spriteleft = 1
Case DIR_LEFT
spriteleft = 2
End Select
With rec
.Top = 0
.Bottom = DDSD_Sprite(Sprite).SurfDescription.lHeight
.Left = (spriteleft * 3 + Anim) * (DDSD_Sprite(Sprite).SurfDescription.lWidth / 12)
.Right = .Left + (DDSD_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 - ((DDSD_Sprite(Sprite).SurfDescription.lWidth / 12 - 32) / 2)
' Is sprite more than 32..?
If ((DDSD_Sprite(Sprite).SurfDescription.lHeight) - 32) > 0 Then
' Create a 32 pixel offset for larger sprites
Y = MapNpc(MapNpcNum).Y * PIC_Y + MapNpc(MapNpcNum).YOffset - ((DDSD_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 + (DDSD_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/viewtopic.php?f=124&t=5048&start=0Can use this tutorial freely in your game/engine, as long as you don't claim it as your own. That means you, Frozengod!
That should work with the new version of MS4. For those of you who can't see what I changed:
Find any instance of DDS_Sprite(Sprite).lWidth and DDS_Sprite(Sprite).lHeight and change them to:
Good luck. Tested it for Doomy, worked, but in the source he sent me, the sprites weren't animated.