Qbasicnews.com

Full Version: Bomberman problem - explosions (in VB)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm using Visual Basic 6, with a user control someone made. Here is my dilemma:

Quote: Seph says:
do you know anyVB
←—[Alex :: Rachel :: GOD is my Saviour >> Rachel is my Blessing]—← says:
do i ever
←—[Alex :: Rachel :: GOD is my Saviour >> Rachel is my Blessing]—← says:
yup
Seph says:
ok well i have a dilemma
Seph says:
i want to do this in the best way possible
Seph says:
i have a bomberman game im making
Seph says:
and i have bombs and i have explosuions
Seph says:
BUT
Seph says:
the explosions, you see....
Seph says:
they are one square big
Seph says:
they dont outstretch like in the real gane
←—[Alex :: Rachel :: GOD is my Saviour >> Rachel is my Blessing]—← says:
so they don't animate?
Seph says:
yes it does animate
Seph says:
the explosions are animated gifs
Seph says:
im usnig an OCX for that
Seph says:
anyways
Seph says:
they are only one tile large, the explosions
Seph says:
but i want them to go outward like in the real game
Seph says:
is there a way i can simultaneously print the explosion's current frame around it?
Seph says:
like a copy funciton?
←—[Alex :: Rachel :: GOD is my Saviour >> Rachel is my Blessing]—← says:
hmmmmmm
←—[Alex :: Rachel :: GOD is my Saviour >> Rachel is my Blessing]—← says:
not sure
←—[Alex :: Rachel :: GOD is my Saviour >> Rachel is my Blessing]—← says:
never really used animations....
←—[Alex :: Rachel :: GOD is my Saviour >> Rachel is my Blessing]—← says:
or OCX for that matter
←—[Alex :: Rachel :: GOD is my Saviour >> Rachel is my Blessing]—← says:
i can poke around for a sec
Seph says:
im hoping there is a copy graphics function
←—[Alex :: Rachel :: GOD is my Saviour >> Rachel is my Blessing]—← says:
i don't have OCX.....
Seph says:
inside the control itself
←—[Alex :: Rachel :: GOD is my Saviour >> Rachel is my Blessing]—← says:
can't find it anyway
Seph says:
do you know what an OCX is?
←—[Alex :: Rachel :: GOD is my Saviour >> Rachel is my Blessing]—← says:
ya
Seph says:
ok
←—[Alex :: Rachel :: GOD is my Saviour >> Rachel is my Blessing]—← says:
graphics routine component
Seph says:
nope
Seph says:
it is not
←—[Alex :: Rachel :: GOD is my Saviour >> Rachel is my Blessing]—← says:
no?
Seph says:
it is a user defined control
←—[Alex :: Rachel :: GOD is my Saviour >> Rachel is my Blessing]—← says:
dam
←—[Alex :: Rachel :: GOD is my Saviour >> Rachel is my Blessing]—← says:

Seph says:
you can make an OCX if you wanted to
Seph says:
im using one that someone made for animated images
←—[Alex :: Rachel :: GOD is my Saviour >> Rachel is my Blessing]—← says:
ok
←—[Alex :: Rachel :: GOD is my Saviour >> Rachel is my Blessing]—← says:
can u send it here?
Seph says:
not right now brb
Don't use someone's else OCX that uses animated GIFs. Learn GDI or DX and control the frames for yourself.

Now, to be actually helpful: you need three different animations: one with this shape "+", another one with "-" and another one with "|". Then you have to build a simple function that attempts to draw a cross given its centre, with a certain extention. If any of the branches of the explosion hits a non-walkable tile, stop ("abort" that branch).

Once the explosion is calculated, you just have to draw the correct animation in each "explosion tile". "+" in the centre, "|" in each vertical "subexplosion tile", and "-" in each horizontal one.
fixed that problem. new one though:

keyhandler...

window's sucks for 2 players. i got it to be fine for one player but the 2 player one really sucks.
DirectInput

Code:
'dX Variables
Dim dx As New DirectX7
Dim di As DirectInput
Dim diDEV As DirectInputDevice
Dim diState As DIKEYBOARDSTATE

'Loop counter
Dim i As Integer

'Public array showing which keys are active
Public aKeys(211) As Boolean

'Keycode constants
Global Const DIK_ESCAPE = 1
Global Const DIK_1 = 2
Global Const DIK_2 = 3
Global Const DIK_3 = 4
Global Const DIK_4 = 5
Global Const DIK_5 = 6
Global Const DIK_6 = 7
Global Const DIK_7 = 8
Global Const DIK_8 = 9
Global Const DIK_9 = 10
Global Const DIK_0 = 11
Global Const DIK_MINUS = 12
Global Const DIK_EQUALS = 13
Global Const DIK_BACKSPACE = 14
Global Const DIK_TAB = 15
Global Const DIK_Q = 16
Global Const DIK_W = 17
Global Const DIK_E = 18
Global Const DIK_R = 19
Global Const DIK_T = 20
Global Const DIK_Y = 21
Global Const DIK_U = 22
Global Const DIK_I = 23
Global Const DIK_O = 24
Global Const DIK_P = 25
Global Const DIK_LBRACKET = 26
Global Const DIK_RBRACKET = 27
Global Const DIK_RETURN = 28
Global Const DIK_LCONTROL = 29
Global Const DIK_A = 30
Global Const DIK_S = 31
Global Const DIK_D = 32
Global Const DIK_F = 33
Global Const DIK_G = 34
Global Const DIK_H = 35
Global Const DIK_J = 36
Global Const DIK_K = 37
Global Const DIK_L = 38
Global Const DIK_SEMICOLON = 39
Global Const DIK_APOSTROPHE = 40
Global Const DIK_GRAVE = 41
Global Const DIK_LSHIFT = 42
Global Const DIK_BACKSLASH = 43
Global Const DIK_Z = 44
Global Const DIK_X = 45
Global Const DIK_C = 46
Global Const DIK_V = 47
Global Const DIK_B = 48
Global Const DIK_N = 49
Global Const DIK_M = 50
Global Const DIK_COMMA = 51
Global Const DIK_PERIOD = 52
Global Const DIK_SLASH = 53
Global Const DIK_RSHIFT = 54
Global Const DIK_MULTIPLY = 55
Global Const DIK_LALT = 56
Global Const DIK_SPACE = 57
Global Const DIK_CAPSLOCK = 58
Global Const DIK_F1 = 59
Global Const DIK_F2 = 60
Global Const DIK_F3 = 61
Global Const DIK_F4 = 62
Global Const DIK_F5 = 63
Global Const DIK_F6 = 64
Global Const DIK_F7 = 65
Global Const DIK_F8 = 66
Global Const DIK_F9 = 67
Global Const DIK_F10 = 68
Global Const DIK_NUMLOCK = 69
Global Const DIK_SCROLL = 70
Global Const DIK_NUMPAD7 = 71
Global Const DIK_NUMPAD8 = 72
Global Const DIK_NUMPAD9 = 73
Global Const DIK_SUBTRACT = 74
Global Const DIK_NUMPAD4 = 75
Global Const DIK_NUMPAD5 = 76
Global Const DIK_NUMPAD6 = 77
Global Const DIK_ADD = 78
Global Const DIK_NUMPAD1 = 79
Global Const DIK_NUMPAD2 = 80
Global Const DIK_NUMPAD3 = 81
Global Const DIK_NUMPAD0 = 82
Global Const DIK_DECIMAL = 83
Global Const DIK_F11 = 87
Global Const DIK_F12 = 88
Global Const DIK_NUMPADENTER = 156
Global Const DIK_RCONTROL = 157
Global Const DIK_DIVIDE = 181
Global Const DIK_RALT = 184
Global Const DIK_HOME = 199
Global Const DIK_UP = 200
Global Const DIK_PAGEUP = 201
Global Const DIK_LEFT = 203
Global Const DIK_RIGHT = 205
Global Const DIK_END = 207
Global Const DIK_DOWN = 208
Global Const DIK_PAGEDOWN = 209
Global Const DIK_INSERT = 210
Global Const DIK_DELETE = 211

Public Sub Init()

    'Create the direct input object
    Set di = dx.DirectInputCreate()
        
    'Aquire the keyboard as the device
    Set diDEV = di.CreateDevice("GUID_SysKeyboard")
    
    'Get input nonexclusively, only when in foreground mode
    diDEV.SetCommonDataFormat DIFORMAT_KEYBOARD
    diDEV.SetCooperativeLevel BSCWindow.hWnd, DISCL_BACKGROUND Or DISCL_NONEXCLUSIVE
    diDEV.Acquire
    
End Sub

Public Sub CheckKeys()
    
    'Get the current state of the keyboard
    diDEV.GetDeviceStateKeyboard diState
    
    'Scan through all the keys to check which are depressed
    For i = 1 To 211
        If diState.Key(i) <> 0 Then
            aKeys(i) = True             'If the key is pressed, set the appropriate array index to true
        Else
            aKeys(i) = False            'If the key is not pressed, set the appropriate array index to false
        End If
    Next
    
End Sub

Public Sub Shutdown()
    
    'Unaquire the keyboard when we quit
    diDEV.Unacquire
    
End Sub

Save this as "DINPUT.BAS" and add it to your project. Enable DirectX in the references. When you need to read the keyboard, just call

Code:
Dinput.CheckKeys

And now just check the "aKeys" array using the constants...

Code:
If Dinput.aKeys(DIK_LEFT) Then
   MsgBox "Left!"
End If

And don't forget to call Init at the beginning of your program and Shutdown at the end!!