git
Mar 13th, 2001, 06:34 AM
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
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