|
-
Mar 13th, 2001, 07:34 AM
#1
Thread Starter
Addicted Member
Hiyas,
I've written a basic Isometric game... Here's the revelant source code so far...
Option Explicit
Dim MapXSize As Integer
Dim MapYSize As Integer
Dim MapZSize As Integer
Dim X As Integer
Dim Y As Integer
Dim Z As Integer
Dim XOffSet As Integer
Dim YOffSet As Integer
Dim ZOffSet As Integer
Dim Map() As Integer
Dim CityMap(500, 500) As Integer
Private Declare Function BitBlt Lib "gdi32" (ByVal HeyhDestDC 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 Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp Then
XOffSet = XOffSet - 1
ElseIf KeyCode = vbKeyDown Then
XOffSet = XOffSet + 1
ElseIf KeyCode = vbKeyLeft Then
YOffSet = YOffSet - 1
ElseIf KeyCode = vbKeyRight Then
YOffSet = YOffSet + 1
End If
BitBltMap
TacPic.Refresh
OffSetLabel.Caption = XOffSet & " - " & YOffSet
End Sub
Private Sub Form_Load()
Randomize
XOffSet = 0
YOffSet = 0
MapXSize = 10
MapYSize = 10
MapZSize = 1
ReDim Map(MapXSize, MapYSize, MapZSize) As Integer
For X = 1 To MapXSize
For Y = 1 To MapYSize
For Z = 1 To MapZSize
Map(X, Y, Z) = 1 + Fix(2 * Rnd)
Next Z
Next Y
Next X
BitBltMap
TacPic.Refresh
End Sub
Private Sub BitBltMap()
Dim TempX As Integer
Dim TempY As Integer
On Error Resume Next
TacPic.Cls
For Y = 1 To 22
For X = 0 To 16
TempX = ((XOffSet + Y) + (YOffSet + (X - (MapYSize \ 2))))
TempY = ((XOffSet + Y) - (YOffSet + (X - (MapYSize \ 2))))
If Not TempX < 1 And Not TempY < 1 And Not TempX > MapXSize And Not TempY > MapYSize Then
BitBlt TacPic.hDC, (X * 40) - 20, (Y * 20) - 20, 40, 19, TileSource.hDC, (Map(TempX, TempY, 1) - 1) * 40, 19, vbSrcAnd
BitBlt TacPic.hDC, (X * 40) - 20, (Y * 20) - 20, 40, 19, TileSource.hDC, (Map(TempX, TempY, 1) - 1) * 40, 0, vbSrcPaint
End If
Next X
For X = 1 To 16
TempX = ((XOffSet + Y) + (YOffSet + (X - (MapYSize \ 2))))
TempY = ((XOffSet + Y) - (YOffSet + (X - (MapYSize \ 2))))
If Not TempX - 1 < 1 And Not TempY < 1 And Not TempX - 1 > MapXSize And Not TempY > MapYSize Then
BitBlt TacPic.hDC, (X * 40) - 40, (Y * 20) - 30, 40, 19, TileSource.hDC, (Map(TempX - 1, TempY, 1) - 1) * 40, 19, vbSrcAnd
BitBlt TacPic.hDC, (X * 40) - 40, (Y * 20) - 30, 40, 19, TileSource.hDC, (Map(TempX - 1, TempY, 1) - 1) * 40, 0, vbSrcPaint
End If
Next X
Next Y
End Sub
It blits perfectly, but how do I find the x,y position of the mouse on the actual isometric map? (I'm probably not going to use z now) I've tried lots of formulas but I can't figure out how to 'reverse' my blitting formula.
Btw I tried to use the code vB codes but they didn't seem to work.
Anyone?
Thanks,
-Git
Last edited by git; Mar 13th, 2001 at 07:41 AM.
-
Mar 13th, 2001, 09:03 AM
#2
Good Ol' Platypus
Here it is for anyone who wants to help 
Sorry, git, but you can put the code tags around it to preserve formatting. I'll post in a sec.
Code:
Option Explicit
Dim MapXSize As Integer
Dim MapYSize As Integer
Dim MapZSize As Integer
Dim X As Integer
Dim Y As Integer
Dim Z As Integer
Dim XOffSet As Integer
Dim YOffSet As Integer
Dim ZOffSet As Integer
Dim Map() As Integer
Dim CityMap(500, 500) As Integer
Private Declare Function BitBlt Lib "gdi32" (ByVal HeyhDestDC 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 Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp Then
XOffSet = XOffSet - 1
ElseIf KeyCode = vbKeyDown Then
XOffSet = XOffSet + 1
ElseIf KeyCode = vbKeyLeft Then
YOffSet = YOffSet - 1
ElseIf KeyCode = vbKeyRight Then
YOffSet = YOffSet + 1
End If
BitBltMap
TacPic.Refresh
OffSetLabel.Caption = XOffSet & " - " & YOffSet
End Sub
Private Sub Form_Load()
Randomize
XOffSet = 0
YOffSet = 0
MapXSize = 10
MapYSize = 10
MapZSize = 1
ReDim Map(MapXSize, MapYSize, MapZSize) As Integer
For X = 1 To MapXSize
For Y = 1 To MapYSize
For Z = 1 To MapZSize
Map(X, Y, Z) = 1 + Fix(2 * Rnd)
Next Z
Next Y
Next X
BitBltMap
TacPic.Refresh
End Sub
Private Sub BitBltMap()
Dim TempX As Integer
Dim TempY As Integer
On Error Resume Next
TacPic.Cls
For Y = 1 To 22
For X = 0 To 16
TempX = ((XOffSet + Y) + (YOffSet + (X - (MapYSize \ 2))))
TempY = ((XOffSet + Y) - (YOffSet + (X - (MapYSize \ 2))))
If Not TempX < 1 And Not TempY < 1 And Not TempX > MapXSize And Not TempY > MapYSize Then
BitBlt TacPic.hDC, (X * 40) - 20, (Y * 20) - 20, 40, 19, TileSource.hDC, (Map(TempX, TempY, 1) - 1) * 40, 19, vbSrcAnd
BitBlt TacPic.hDC, (X * 40) - 20, (Y * 20) - 20, 40, 19, TileSource.hDC, (Map(TempX, TempY, 1) - 1) * 40, 0, vbSrcPaint
End If
Next X
For X = 1 To 16
TempX = ((XOffSet + Y) + (YOffSet + (X - (MapYSize \ 2))))
TempY = ((XOffSet + Y) - (YOffSet + (X - (MapYSize \ 2))))
If Not TempX - 1 < 1 And Not TempY < 1 And Not TempX - 1 > MapXSize And Not TempY > MapYSize Then
BitBlt TacPic.hDC, (X * 40) - 40, (Y * 20) - 30, 40, 19, TileSource.hDC, (Map(TempX - 1, TempY, 1) - 1) * 40, 19, vbSrcAnd
BitBlt TacPic.hDC, (X * 40) - 40, (Y * 20) - 30, 40, 19, TileSource.hDC, (Map(TempX - 1, TempY, 1) - 1) * 40, 0, vbSrcPaint
End If
Next X
Next Y
End Sub
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Mar 13th, 2001, 09:10 AM
#3
Good Ol' Platypus
Well ya got me. I don't know how to do so... I guess it would've helped had I written the code originally.... I'll take a few 'educated' guesses, though...
And also ERROR in the code, in the second two blits you use (y*20)-30 while in the first two you use (y*20)-20.
Okay... get the position of the mouse. (in pixels)
Then.... I don't know, to tell the truth...
I can't seem to get it... Sorry about that. Maybe rewriting your code is the best way. (sometimes that helps me) If you have a really problematic piece of code, rem it out and start fresh.
Sorry I couldnt be more of a help.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Mar 14th, 2001, 11:45 AM
#4
This is an easy one. All you have to do is get the current mouse pos(GetCursorPos API). Then, just add XOffset to CursorPos.X, and YOffset to CursorPos.Y. So:
Code:
Declare blah blah blah GetCursorPos blah ()
Private Type POINTAPI
blah as blah
blah as blah
End Type
'//Suggestion: Fill in those two lines with real code =)
Private Sub GetActualCursorPos(CursorPos as POINTAPI)
GetCursorPos(CursorPos)
CursorPos.X = CursorPos.X + XOffset
CursorPos.Y = CursorPos.Y + YOffest
End Sub
One thing, though. If those offset values are for an entire tile, then just multiply XOffset by TileSizeX and YOffset by TileSizeY.
Z.
-
Mar 14th, 2001, 07:32 PM
#5
Good Ol' Platypus
Well then Zaei, I guess I just wasnt thinking. Hmm... I wonder why I didn't get that? Maybe it was because I didn't understand the code. Ah well, good luck git, and good job Zaei!
I'm just an email away - Sastraxi
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Mar 14th, 2001, 11:11 PM
#6
Thread Starter
Addicted Member
Still not working - it's not as simple as adding the offsets to the mouse positions... =/
I've revised the BitBlt sub so it runs better and looks easier. can anyone help me now...?
Code:
Private Sub BitBltMap()
Dim TempX As Integer
Dim TempY As Integer
GameForm.Cls
For Y = 1 To 22
For X = 0 To 16
TempX = XOffSet + Y + YOffSet + X - (MapYSize / 2)
TempY = XOffSet + Y - YOffSet - X + (MapYSize / 2)
If Not TempX < 1 And Not TempY < 1 And Not TempX > MapXSize And Not TempY > MapYSize Then
BitBlt GameForm.hDC, (X * 40) - 20, (Y * 20) - 20, 40, 19, TileSource.hDC, (Map(TempX, TempY, 1) - 1) * 40, 19, vbSrcAnd
BitBlt GameForm.hDC, (X * 40) - 20, (Y * 20) - 20, 40, 19, TileSource.hDC, (Map(TempX, TempY, 1) - 1) * 40, 0, vbSrcPaint
End If
Next X
For X = 1 To 16
TempX = XOffSet + Y + YOffSet + X - (MapYSize / 2) - 1
TempY = XOffSet + Y - YOffSet - X + (MapYSize / 2)
If Not TempX < 1 And Not TempY < 1 And Not TempX > MapXSize And Not TempY > MapYSize Then
BitBlt GameForm.hDC, (X * 40) - 40, (Y * 20) - 30, 40, 19, TileSource.hDC, (Map(TempX, TempY, 1) - 1) * 40, 19, vbSrcAnd
BitBlt GameForm.hDC, (X * 40) - 40, (Y * 20) - 30, 40, 19, TileSource.hDC, (Map(TempX, TempY, 1) - 1) * 40, 0, vbSrcPaint
End If
Next X
Next Y
End Sub
Thanks =)
-Git
-
Mar 15th, 2001, 01:48 AM
#7
transcendental analytic
i hate looking at others tile blitting engines, because they usually don't make sense. I see though there are lots of performance improvements you could do.
well, i'm just going to put the general algoritm for pixel -flat isometrical coordinates, and let you have your specifics added yourself.
ax=px/tilew
ay=py/tileh
ix=ax+ay
iy=ax-ay
pixel offsets are added to px,py
tile offsets are added to ax,ay
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|