I am currently trying to create a tower defense game where the tower shoots a bullet at a moving enemy when the enemy comes into range. The game is going to be like any other tower defense game with multiple enemies on the screen at a time. I am really struggling and have a few questions.
1) Is there a way to give an object a health bar that can be effected by collisions. Each Enemy will need its own health bar that is effected when that specific enemy is hit. This is the code I have to spawn enemies which i can adjust the amount of enemies with the repeat statement.
Code: Select all
global i
on makeWave1
repeat with i = 1 to 2
clone button "EnemyX"
set the name of the last button to ("Enemy" & i)
set the loc of the last button to (105),(205)
set the visible of the last button to true
move button ("Enemy" & i) to the points of the graphic "path" in 10 seconds without waiting
wait .5 seconds with messages
end repeat
end makeWave1
Code: Select all
local y
local i
on mousedown
shootBullet
end mousedown
command shootBullet
repeat with i = 1 to 2
clone button "Ball"
add 1 to y
set the name of the last button to ("Bullet" & y)
put the loc of button "FireTowerA" into button "Ball"
set visible of button ("Bullet" & y) to true
move button "Ball" to loc of button ("Enemy" & i) in 5 ticks
if intersect (button "ball", button ("Enemy" & i)) then
delete the button ("Bullet" & y)
subtract 5 from field "EnemyHealth"
if field "EnemyHealth" < 1 then
repeat with i = 1 to 2
delete button ("Enemy" & i)
end repeat
end if
end if
end repeat
end shootBullet
Code: Select all
global y
on mouseDown
add 1 to y
grab me
clone me
set the name of me to ("FireTower" & y)
set the loc of btn "FireTower" to (59),(650)
end mouseDown