|
-
Mar 2nd, 2002, 06:25 PM
#1
Thread Starter
New Member
guys really, plz help :)
I can now bitblt, cept I am new to arrays and keyboard input. First of all, I REALY need to know how to use key input to do things efficiently, all of VBs defualt things SUCK. Isnt there a getsynckey api? Also, if I make a type for tiles, how would I assign each tile a value then be able to retrieve that value?
the type looks like this:
Code:
Type tiles as integer
x as integer
y as integer
tv as integer 'tile value..like lava, etc.
end type
how would I assign each tile a value and then recall it?
Code:
dim tile(maxtilesvar) as integer
I want it to basically say if it is the tile(0) then assign or view its tv, x, and y.
Also where is a good place to learn about text saving? DON'T FORGET HELP WITH KEY input is desired! THANKS GUYS
-
Mar 3rd, 2002, 05:27 AM
#2
Fanatic Member
About the keys:
To test which keys has been pressed, use the KeyDown event of your main form.
If you want to know more about it, just create a new VB project with an empty form. In the form's code you place:
VB Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Debug.Print "KeyCode: " & KeyCode & ", Shift: " & Shift
End Sub
In the immediate window, you'll see which keys has been pressed and which shift mask it has (shift = 1, ctrl = 2, alt = 4).
Look at the KeyCodeConstants and ShiftConstants in the object browser (press F2 in the VB IDE to access it).
About the tiles:
I would suggest you to name the user defined type 'tile', since one variable will hold information of only one tile. There's no need to store the X and Y in the tile, since it can be retrieved by the array index. If you are only interested in the type of a tile (the tv value), there's no need to use a user defined type, but this way you can store other information as well, like resistance. (It's a lot harder to move around in a swamp than on grass plains, for example.)
Dimension the tile array like this:
Code:
Dim Tiles(tileCountX - 1, tileCountY - 1) As Tile
Important note: Normally, the lowest index of an array is 0, so if you want an array of n elements, you should give it the dimension n-1 ! I admit this behaviour is indesirable, but you have to live with it.
To fill the tiles, you can do something like this:
VB Code:
For x = 0 to tileCountX - 1
For y = 0 to tileCountY - 1
Tiles(x, y).tv = value 'The source can be anything: another array, a text file, etc...
Next y
Next x
You can retrieve the tile value the same way: value = Tiles(x, y).tv
Another tip: install a copy of MSDN on your machine, if you haven't done so yet.
Good luck!
-
Mar 3rd, 2002, 09:53 AM
#3
Originally posted by riis
Important note: Normally, the lowest index of an array is 0, so if you want an array of n elements, you should give it the dimension n-1 ! I admit this behaviour is indesirable, but you have to live with it.
It is certainly strange behavior. C++ arrays are defined with the number of elements, then run from 0 to numElements - 1.
Z.
-
Mar 5th, 2002, 08:33 AM
#4
What if you use
Option Base 1
?
I think this sets the array base to be 1
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Mar 5th, 2002, 09:51 AM
#5
It does, but then you get used to using base one, and thats just strange =).
Z.
-
Mar 5th, 2002, 01:50 PM
#6
VB Code:
'in a module
Public Const DT_CENTER = &H1
Public Const DT_WORDBREAK = &H10
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Declare Function DrawTextEx Lib "user32" Alias "DrawTextExA" (ByVal hDC As Long, ByVal lpsz As String, ByVal n As Long, lpRect As RECT, ByVal un As Long, ByVal lpDrawTextParams As Any) As Long
Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Public Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Public Cnt As Long, sSave As String, sOld As String, Ret As String
Public Tel As Long
Public Function GetPressedKey() As String
For Cnt = 32 To 128
'Get the keystate of a specified key
If GetAsyncKeyState(Cnt) <> 0 Then
GetPressedKey = Chr$(Cnt)
Exit For
End If
Next Cnt
End Function
Public Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
Ret = GetPressedKey
If Ret <> sOld Then
sOld = Ret
sSave = sSave + sOld
End If
End Sub
'on your form
Private Sub Form_Load()
'KPD-Team 1999
'URL: [url]http://www.allapi.net/[/url]
Me.Caption = "Key Spy"
'Create an API-timer
SetTimer Me.hwnd, 0, 1, AddressOf TimerProc
End Sub
Private Sub Form_Paint()
Dim R As RECT
Dim mStr As String
mStr = "Start this project, go to another application, type something, switch back to this application "
mStr = mStr & "and unload the form. If you unload the form, a messagebox with all the typed keys "
mStr = mStr & "will be shown."
'Clear the form
Me.Cls
'API uses pixels
Me.ScaleMode = vbPixels
'Set the rectangle's values
SetRect R, 0, 0, Me.ScaleWidth, Me.ScaleHeight
'Draw the text on the form
DrawTextEx Me.hDC, mStr, Len(mStr), R, DT_WORDBREAK Or DT_CENTER, ByVal 0&
End Sub
Private Sub Form_Resize()
Form_Paint
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Kill our API-timer
KillTimer Me.hwnd, 0
'Show all the typed keys
MsgBox sSave
End Sub
-
Mar 5th, 2002, 04:20 PM
#7
Addicted Member
To understand recursion, one must first understand the concept of recursion.
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
|