EXPLODE!

Xtreme
03-21-2001, 11:31 AM
I am making a tile game like bomber man.

however i have run into a problem. When i place bombs on the screen i want them to have their own detonation counter that makes them explode when it = 100. therefore if i lay one bomb it will explode when its counter = 100 and when i place a second bomb its counter will be independant and start at 0 and count up to 100 and if i place a third it wil start at 0 and count up to 100.bomb1 will explode 1rst, bomb2 next, and bomb3 last.

This is the code i have:

counter = 0

For tiley = 0 To MaxTilesY
For tilex = 0 To MaxTilesX
Select Case Map(tiley, tilex)

Case Asc("3") '''a.k.a we are drawing the tiles on the screen and we have come
'''come across a laid bomb

counter = counter + 1

timer(counter) = timer(counter) + 1

if timer(counter) = 100 then
'''''i put code in here for the bomb to explode
timer(counter) = 0
end if

End Select
Next Tilex
Next Tiley


Can anyone see a problem with this code?


Thanks

BillSoo
03-21-2001, 12:21 PM
First, I believe that "timer" is a VB keyword so you should probably choose a different variable name.

Second, when a bomb explodes, I assume that you change the map tile. In that case, all bombs above the one that exploded will change their index and hence, their times.

For instance: you have 4 bombs ticking away with the following times:

Bomb 1 Bomb 2 Bomb 3 Bomb 4
25 99 87 55

The next second, bomb 2 goes to 100 and explodes and we get:

Bomb 1 Bomb 3 Bomb 4 ?
26 0 88 55

You need to tie your countdown times more closely to your bombs. The object oriented approach would be to make a bomb object but you could probably just use a UDT array.

Type bombtype
x as integer 'bomb coordinates
y as integer
countdown as integer 'countdown value
end type

dim Bombs() as bombtype

As each bomb is placed, you add it to the bomb array using redim preserve. Then you update the times each tick.

It does become a bit more complicated when a bomb explodes though. There are several ways to handle this:

1) copy the info from the *last* active bomb to the current bomb. This erases the current bomb that exploded but makes 2 copies of the last bomb. So you then redim preserve the array to one less than it was before to erase the last entry.

2) Leave the bomb with a time either left at 100 or set to some flag like -1. Then ignore it during your search routines.

3) Mark the bomb with a flag like -1 so it is ignored. Then, when adding a bomb, look for these empty pockets to use first before redimming the array.

Personally, I prefer method 1.

"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder

Xtreme
03-26-2001, 10:07 AM
I apologize for not responding sooner but i finally got the problem solved. I did use a type bomb and got it to work where:
map(Tiley, Tilex).timer = map(Tiley, Tilex).timer + 1

if map(Tiley, Tilex).timer = 100 then
explode
end if

therefore each sperate bomb tile on-screen is independant since there is a seperate .timer for each space in the 2 dimentional array.

Thanks again for your help.

EternalKnight
03-28-2001, 04:24 PM
I believe another way to do this would be to use a collection. Whenever a bomb explodes, simply remove it from the collection. One thing I do know about them is that they are not as efficient as arrays, tho. Just food for thought.

Whom shall I fear?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum