Tile Help

DKnight
01-07-2002, 05:23 PM
Hello everyone, I need some help. hehe. Well I have been learning tiles lately and I understand how they work and such, so I decided to make a sample program to test out what I had learned.

I attached the file so you can have a look at it and maybe see what I am doing wrong. It is suppose to draw the map, then check if any keys were pressed, check to see if the player can move there (note: player is not yet on the screen), and then redraw the map if he can move there 1 square at a time.

There is a few problems.
1. It moves over a few squares when i hiot an arrow key, not just one like I want it to.

2. If it moves out of bounds it gives me a subscript out of range, I believe this is because my player won't move just one square.

So if you could please have a look at my little program and tell me what it is I screwed up on. Thanks

-DKnight

Squirm
01-07-2002, 05:35 PM
Neat game. I fixed the bugs you were reporting. Add this to the top of the form below Option Explicit:

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Here is the new DrawMap sub:

Sub DrawMap()
boxy = 0
boxx = 0
Picture1.Cls
For i = (PlayerY - 3) To (PlayerY + 3)
For j = (PlayerX - 3) To (PlayerX + 3)

If (i < 0) Or (i > 19) Or (j < 0) Or (j > 19) Then
BitBlt Picture1.hDC, boxx * 64, boxy * 64, SpriteWidth, SpriteHeight, Picture2.hDC, 1 * SpriteWidth, 0, vbSrcCopy
ElseIf MapArray(i, j) = "0" Then
BitBlt Picture1.hDC, boxx * 64, boxy * 64, SpriteWidth, SpriteHeight, Picture2.hDC, 1 * SpriteWidth, 0, vbSrcCopy
ElseIf MapArray(i, j) = "1" Then
BitBlt Picture1.hDC, boxx * 64, boxy * 64, SpriteWidth, SpriteHeight, Picture2.hDC, 0 * SpriteWidth, 0, vbSrcCopy
ElseIf MapArray(i, j) = "2" Then
BitBlt Picture1.hDC, boxx * 64, boxy * 64, SpriteWidth, SpriteHeight, Picture2.hDC, 2 * SpriteWidth, 0, vbSrcCopy
End If
boxx = boxx + 1
Next j
boxx = 0
boxy = boxy + 1
Next i
End Sub

And here is the new RunMain sub:

Sub RunMain()
LoadMap
Do
If IsEscapePressed Then
Exit Do
End If
DrawMap
Updatekeys
Sleep 100
Me.Refresh
DoEvents
Loop
Unload Me
End Sub

and now it works, good work...... :) :D

DKnight
01-07-2002, 06:05 PM
Thank you very much kind sir! I asked my programming teacher today, and I think I embarassed her because she isn't the best at VB! Very cool, thnx a lot.

Alright, just to clarify so I won;t have to bother you again :)

1. You made it so it draws the Brown texture all around the map.

2. Made the program sleep for 100ms everytime it runs through the loop.

Am I right?

-DKnight

Squirm
01-07-2002, 06:14 PM
Yes

Basically, you had it counting from PlayerY-3 to PlayerY+3 and from PlayerX-3 to PlayerX+3.
Now, if PlayerX is 0, then PlayerX-3 is going to be -3.
There is no array element at -3, so the bit I changed checks to see if i or j are
less than 0 (or greater than 19) and then paints that bit brown as well.

The Sleep API merely is used to pause execution for X milliseconds, in this case 100, which is 1/10 of a second.

DKnight
01-07-2002, 09:40 PM
Sorry to bother you again, but I got it all working and then tried to change it so it would use Memory DC's instead of loading from picture boxes and ran into a problem. I added an attachment with all the changes.

I mean it works, but the tiles looks messed up and look limited to only a certain number of colours. Well please look and tell me if there is a way for me to fix that. Thanks

-DKnight

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum