
07-15-2012, 07:45 PM
|
|
Newcomer
|
|
Join Date: Jul 2012
Location: London, ON, Canada
Posts: 21
|
|
|
Well I tried it out and reviewed the code. Looks pretty good! So lets begin:
Add a range element to each tower, ie a number of squares it can attack as well as which units it can attack. Let's take the missile tower. A range of 4 squares? Instead of a circular range we can do a square one.
Dim tR as integer
Dim loopCOUNT as long ' THis is for the do while loop later
'tR is towerRANGE
loopCOUNT = 0
When you create a tower, depending on the type, set the range
Under your enemyMOV timer, add the code that checks if it is within range:
'Sorry if my variables are incorrect but you probably will understand
'Tower range left for missile would be -4 squares so -4 * your square width
For i = 0 to yourTOWERS
If enemyX >= towerRANGELEFT and enemyY <= towerRANGEUP and enemyX <= towerRANGERIGHT and enemyY >= towerRANGEDOWN then
'Checks range on all 4 sides
shootENEMY() ' A sub ill show later
end if
next
Private Sub shootENEMY()
'If the bullet details are coded then we can do this:
'In here use a threaded loop
Do While enemySHOT = false
'I only list the Y but the X is the same
If loopCount = 250 ' Every 1/4 of a second the lopp runs
If enemyY < towerY then
bulletY = (bulletY = bulletY - ((enemyY - bulletY) / 10))
elseif enemyX > towerX then
bulletY = (bulletY = bulletY + ((enemyY - bulletY) / 10))
end if
If bulletX > enemyX and bulletX < (enemyX + enemyWIDTH) and bulletY > enemyY and bulletY < (enemyY + enemyHEIGHT) then 'When a bullet hits the enemy
enemyHEALTH = enemyHEALTH - towerDAMAGE 'Takes damaga
If enemyHEALTH <= 0 then enemyDEAD = true
enemySHOT = true
loopcount = 0
Exit Do
end if
loopCOUNT = 0
else
loopCOUNT = loopCOUNT + 1
end if
DoEvents
Loop
End Sub
As for multiple enemies, use an array to store enemies and their health!
Dim eX(0 to total enemies) as integer 'X position
Dim eY(0 to total enemies) as integer 'Y position
Dim eH(0 to total enemies) as integer 'Health
Also try to use less For loops and control everything under one main game loop.
BTW Sorry for the sloppy code I was very tired when I wrote this because I just got back from work
|
|