Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Game Programming > [VB6] - Tower Defense


Reply
 
Thread Tools Display Modes
  #1  
Old 12-20-2011, 05:46 PM
Aitherix Aitherix is offline
Newcomer
 
Join Date: Sep 2011
Location: Brampton, Ontario
Posts: 1
Default [VB6] - Tower Defense


Hello, I'm working on a project in which I am designing a Tower Defense style game where you build towers along a track and so far, I have managed to get some basic things operating, i'm still kind of new at this. Just wondering how I can get the Towers to "shoot" the enemy and setting a range. I don't know if I could do it in the way I programmed it.

I'm also trying to figure out how to send multiple enemies at a time rather than 1 coming at a time. For placing towers, I used an image array and 'for next' statements in building and selling towers. Feel free to add any suggestions and comments in improving the game. Some help would be great!

This is what I have at the moment..
Attached Files
File Type: zip TowerDefense.zip (19.7 KB, 63 views)
Reply With Quote
  #2  
Old 07-15-2012, 07:45 PM
RevertiveDeath RevertiveDeath is offline
Newcomer
 
Join Date: Jul 2012
Location: London, ON, Canada
Posts: 21
Default

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
Reply With Quote
Reply

Tags
coding, game, programming, projectile, vb6


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->