RPG Sprite problem...Help!!

Makkers
01-25-2002, 10:16 PM
Im trying to create an RPG based on the Rosebud Thriteen Code. Ive got the graphics improved and got the character on the map sprite properly working. Ive figured out how to do everything for the RPG now except for one hitch. On the battle screen, i use a map/tileset screen to create random ground each time the battle screen is called. On top of this i place the main character sprite(animated) and use the rosebuds code to load an enemy and place an enemy sprite(animated) on the map/tileset ground. The problem is that the enemy sprite appears wrong. about the a quater of the top half of the sprite appears correct and and the rest looks strange without all the colours. Im using the same code for the enemy sprite as the Main character sprite, but with different picture boxes. This is the first time ive used sprites as im a beginner and would love some help here :(

Here is the code:
---------------------------------------------------------------------------
Option Explicit

Dim Hit As Integer, EHit As Integer, Bar As Integer, E As Integer, BI As Integer, EBar As Integer
Private Type enemy
EName As String
Life As Integer
Speed As Integer
Strength As Integer
Def As Integer
XP As Integer
Money As Integer
End Type
Dim enemy As enemy

Dim charx As Integer
Dim chary As Integer
Dim enemyX As Integer
Dim enemyY As Integer

Const MAXROW = 20
Const MAXCOL = 70

Dim Map(MAXROW, MAXCOL) As Integer
Dim Row As Integer, Col As Integer 'current center coordinates

Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long

Private Sub Form_Load()
Dim r As Integer, c As Integer, mapID As Integer, tries As Integer
Dim maskclr As Long
Dim maskclr2 As Long

Randomize
Dim FileNum As Integer, I As Integer
LblName.Caption = T.PName
LblHP = T.Life & "/" & T.MLife
LblTP = T.Tech & "/" & T.MTech
FileNum = FreeFile
E = Random(1, 3)
Open App.Path & "\Enemy" & E & ".txt" For Input As FileNum
Input #FileNum, enemy.EName, enemy.Life, enemy.Strength, enemy.Def, enemy.XP, enemy.Money
picEnemy.Picture = LoadPicture(App.Path & "\Enemy" & E & ".bmp")
Close FileNum
LblE.Caption = enemy.EName
LblELife.Caption = enemy.Life

charx = 800
chary = 85

enemyX = 200
enemyY = 85

For r = 0 To MAXROW
For c = 0 To MAXCOL
For tries = 1 To 5
mapID = Int(Rnd() * 94) + 48
Select Case mapID
Case 94, 95
Case Else
Exit For
End Select
Next tries
Map(r, c) = mapID
Next c
Next r
Row = 6
Col = 15
picMap.Move 0, 260, 1050, 300



maskclr2 = GetPixel(picEnemy.hdc, 1, 1)
picMasks.Move 0, 0, picEnemy.Width, picEnemy.Height
For r = 0 To picEnemy.ScaleHeight - 1
For c = 0 To picEnemy.ScaleWidth - 1
If GetPixel(picEnemy.hdc, c, r) = maskclr2 Then
SetPixel picMask.hdc, c, r, 0&
SetPixel picEnemy.hdc, c, r, &HFFFFFFFF
Else
SetPixel picMask.hdc, c, r, &HFFFFFFFF
End If
Next c
Next r
picMask.Refresh
picEnemy.Refresh




maskclr = GetPixel(picChars.hdc, 1, 1)
picMasks.Move 0, 0, picChars.Width, picChars.Height
For r = 0 To picChars.ScaleHeight - 1
For c = 0 To picChars.ScaleWidth - 1
If GetPixel(picChars.hdc, c, r) = maskclr Then
SetPixel picMasks.hdc, c, r, 0&
SetPixel picChars.hdc, c, r, &HFFFFFFFF
Else
SetPixel picMasks.hdc, c, r, &HFFFFFFFF
End If
Next c
Next r
picMasks.Refresh
picChars.Refresh

End Sub

Private Sub DrawMap()


Dim r As Integer, c As Integer
Dim x1 As Integer, x2 As Integer, y1 As Integer, y2 As Integer, ndx As Integer

y1 = 0
For r = Row - 5 To Row + 5
x1 = 0
For c = Col - 5 To Col + 35
If (r < 0) Or (c < 0) Or (r > MAXROW) Or (c > MAXCOL) Then
BitBlt picMap.hdc, x1, y1, 32, 32, picTiles.hdc, 0, 0, vbBlackness
Else
ndx = Map(r, c)
x2 = (ndx Mod 8) * 32
y2 = (ndx \ 8) * 32
BitBlt picMap.hdc, x1, y1, 32, 32, picTiles.hdc, x2, y2, vbSrcCopy
End If
x1 = x1 + 32
Next c
y1 = y1 + 32
Next r
picMap.Refresh
End Sub

Private Sub Form_Paint()
DrawMap
MoveTimer.Enabled = True
End Sub

Private Sub MoveTimer_Timer()
Static flip As Boolean
Dim c As Integer
Dim em As Integer
If flip Then
c = 1 Mod 10 * 64
em = 1 Mod 10 * 64
Else
c = 1 Mod 10 * 64 + 100
em = 1 Mod 10 * 64 + 100
End If

DrawMap

BitBlt picMap.hdc, charx, chary, 100, 132, picMasks.hdc, c, 0, vbSrcPaint
BitBlt picMap.hdc, charx, chary, 100, 132, picChars.hdc, c, 0, vbSrcAnd

BitBlt picMap.hdc, enemyX, enemyY, 100, 132, picMask.hdc, em, 0, vbSrcPaint
BitBlt picMap.hdc, enemyX, enemyY, 100, 132, picEnemy.hdc, em, 0, vbSrcAnd

picMap.Refresh
flip = Not flip
End Sub

Private Sub testmove_Timer()
charx = (charx - 0)
End Sub

Private Sub TmrBar_Timer()
PicBar.Line (Bar, 0)-(Bar, 309), RGB(0, 0, 255)
Bar = Bar + 15
If Bar >= PicBar.Width Then
FraOptions.Visible = True
ImgOPoint.Visible = True
TmrBar.Enabled = False
End If
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case ImgOPoint.Visible
Case True
Select Case KeyCode
Case 38:
Select Case ImgOPoint.Top
Case 360: ImgOPoint.Top = 1850
Case 1080: ImgOPoint.Top = 360
Case 1850: ImgOPoint.Top = 1080
End Select
Case 40:
Select Case ImgOPoint.Top
Case 360: ImgOPoint.Top = 1080
Case 1080: ImgOPoint.Top = 1850
Case 1850: ImgOPoint.Top = 360
End Select
Case 13:
Select Case ImgOPoint.Top
Case 360:
Case 1080:
Case 1850:
ImgOPoint.Visible = False
ImgIPointer.Visible = True
LblTonic.Caption = "Tonic (" & Game.Tonics & ")"
LblEther.Caption = "Ether (" & Game.Ethers & ")"
LblFullCure.Caption = "Full Cure (" & Game.FCures & ")"
FraItem.Visible = True
End Select
Case False
Select Case KeyCode
Case 13:
Select Case ImgIPointer.Top
Case 360: Call Tonic
Case 1080: Call Ether
Case 1850: Call Cure
End Select
Case 40:
Select Case ImgIPointer.Top
Case 360: ImgIPointer.Top = 1080
Case 1080: ImgIPointer.Top = 1850
Case 1850: ImgIPointer.Top = 360
End Select
Case 38:
Select Case ImgIPointer.Top
Case 360: ImgIPointer.Top = 1850
Case 1080: ImgIPointer.Top = 360
Case 1850: ImgIPointer.Top = 1080
End Select
End Select
End Select
End Select
End Sub
-----------------------------------------

Thanx.

Kitaiko
01-25-2002, 10:56 PM
it could be that your picture box isnt big enough and it is causing some clipping problems, or something like that.

Makkers
01-26-2002, 02:01 AM
Nah its not that Kitaiko. i have tried that before. The pic holders for the enemy and main character are the same, same as the masks. ive checked it completely. Also if i put the enemy pics im using thru the char holder and mask, the enemy pic comes out fine so theres a prob in the coding. Im guessing that theres a buffer getting full??? As im totally new to sprites i cant be sure.
im guessing that the problem is in the BitBlt or getpixel or setpixel.
Any help would be appreciated...

I saw somewhere about a vbSrcErase or something, that can be used where u put vbSrcPaint for example. Should i be using this anyone?

Computer_Guy
01-26-2002, 10:33 PM
Well, first off, let me say I'm honored you would base your game off the way mine works. I've got it now so that the Main Character is masked when he is walking around on the World Map. You can easily take that tid bit of code and apply it to a battle
I wish you luck in your game, and hope to see a copy

By The way, post your game, and I'll take a look at it, I might know the problem

(You see, this game is based on a story that I've been writing for the past year, and though I can't fit all of the Characters into the game, I have the main character, and the name out, and since the person who downloaded this is in the UK, I'm so happy that This game is on Other Continents, too, I really am.)

Computer_Guy
01-26-2002, 10:34 PM
AND WHAT DO YOU MEAN GOT THE GRAPHICS IMPROVED??!!! THOSE ARE SOLID NINTENDO-QUALITY GRAPHICS!!! (LOL)

Makkers
01-27-2002, 01:06 AM
Heh well i got almost everything worked out except that enemy sprite glitch....(Spent a lot of time D/L ing other games and tutorials off planet source code so i think ill have it solved soon).

And Sure ill post it here when its done. The only thing thats been making me rack my brains lately is sound. Everywhere i find the same bits of code to do it and i cant get sound (WAV/MIDI) to work on my projects. Downloaded examples work in thier original projects but if i copy the code into a new project it wont work!!!

Perhaps ill figure it out from those games ive downloaded....

If im still stuck with this RPG...ill post the game code in a few days as u suggested.:)

Squirm
01-27-2002, 11:56 AM
Please please please use the tags when postin source code, especially large amounts of source code, it makes it much easier to read because it preserves the monospacing of VB and also the indenting. Without it, many people wont bother to read large blocks of code because they are too messy.

Just a tip :cool:

ChiefRedBull
01-27-2002, 01:25 PM
Whilst on code posting tips:

Use one the various code colorers available from people like VolteFace to make your text look all nice and pretty...... :)

Makkers
01-27-2002, 08:56 PM
Good News i figured out my problem!! Would u believe all it was, was that i put one entry of "picMasks" instead of "picMask".
This made the code try to use the same mask picturebox.

Doh silly me.

Now the only prob i have is sound. I copied all my RPG files into a project that i downloaded from the Net that had sound and i can use sound. But if i start a new project and try to use sound in my programs it wont play. Is there a component or reference or tickbox in an option im supposed to use, Anyone???

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum