@All working with the Enemy
We need to be in sync when keeping track of the enemy. We will be using the array below with those values so everyone must change your current values and usage accordingly.
REM Foe(number,0) = Face Type , Ranges from 1 to 10
REM Foe(number,1) = X
REM Foe(number,2) = Y
REM Foe(number,3) = Destination X
REM Foe(number,4) = Destination Y
REM Foe(number,5) = Current WayPoint , Default=0
REM Foe(number,6) = Traveled , Default=0
REM Foe(number,7) = Targeted , Default=0
dim Foe(50,7)
@Irojo
When a Foe move you must add it's speed onto the Traveled element. I need that to know which is further down the road and prioritize shooting.
[edit]
Tower AI Updates. Left Click to set the Tower and Right Click to set the Fort.
REM --------------------------------------------------------------
REM Tower AI
REM --------------------------------------------------------------
sync on
sync rate 80
REM Tower(number,0) = Type
REM Tower(number,1) = X
REM Tower(number,2) = Y
REM Tower(number,3) = Shooting
REM Tower(number,4) = Shot Speed
REM Tower(number,5) = Shot Range
REM Tower(number,6) = ReLoad Time
REM Tower(number,7) = Ready to shoot
REM Tower(number,8) = Targeting
dim Tower(50,8)
REM TowerStats(number,0) = ShotSpeed
REM TowerStats(number,0) = ShotRange
REM TowerStats(number,0) = ShotReload
dim TowerStats(5,2)
REM Default stats for the Tower1
TowerStats(1,0) = 5
TowerStats(1,1) = 100
TowerStats(1,2) = 80
REM Default stats for the Tower2
TowerStats(2,0) = 1
TowerStats(2,1) = 50
TowerStats(2,2) = 120
REM Setting up the First Test Tower
Type = 2
ShotSpeed = TowerStats(Type,0)
ShotRange = TowerStats(Type,1)
ShotReload = TowerStats(Type,2)
number = 0
Tower(number,0) = Type
Tower(number,1) = 320
Tower(number,2) = 240
Tower(number,3) = 0
Tower(number,4) = ShotSpeed
Tower(number,5) = ShotRange
Tower(number,6) = ShotReload
Tower(number,7) = 0
Tower(number,8) = 0
REM Foe(number,0) = Face Type , Ranges from 1 to 10
REM Foe(number,1) = X
REM Foe(number,2) = Y
REM Foe(number,3) = Destination X
REM Foe(number,4) = Destination Y
REM Foe(number,5) = Current WayPoint
REM Foe(number,6) = Traveled , Default=0
REM Foe(number,7) = Targeted , Default=0
dim Foe(50,7)
dim c(10)
c(1) = rgb(0,255,0)
c(2) = rgb(255,255,0)
c(3) = rgb(155,155,0)
c(4) = rgb(255,0,0)
c(5) = rgb(255,0,255)
c(6) = rgb(0,0,255)
c(7) = rgb(80,80,80)
c(8) = rgb(215,215,215)
c(9) = rgb(215,215,255)
c(10) = rgb(255,215,255)
count = 1000
REM --------------------------------------------------------------
REM Main Loop
REM --------------------------------------------------------------
do
gosub Spawn
gosub Foe
gosub TowerAI
gosub TestKey
sync : cls 0
loop
REM ******************************
REM This is Temporary as Jamesb is
REM Assigned to take this task.
REM ******************************
Spawn:
if Count < 1000 then Count = Count + 1
if Count > 80
Count = 0
for loops = 0 to 50
if Foe(loops,0) = 0
Foe(loops,0) = rnd(9)+1
Foe(loops,1) = 0
Foe(loops,2) = 280
Foe(loops,3) = 0
Foe(loops,4) = 0
Foe(loops,5) = 0
Foe(loops,6) = 0
Foe(loops,7) = 0
Loops = 50
endif
next loops
endif
return
REM ******************************
REM This is Temporary as Irojo is
REM Assigned to take this task.
REM ******************************
Foe:
for loops = 0 to 50
if Foe(loops,0) > 0
Foe(loops,1) = Foe(loops,1) + 1
Foe(loops,6) = Foe(loops,6) + 1
x = Foe(loops,1)
y = Foe(loops,2)
ink c(Foe(loops,0)),0
box x-13,y-13,x+13,y+13
set cursor x,y
ink rgb(255,255,255),0
print Foe(loops,0)
REM If this Enemy goes off screen then reset this Enemy.
if x > 640 then Foe(loops,0) = 0
endif
next loops
return
TestKey:
mx = mousex()
my = mousey()
mc = mouseclick()
if mc > 0
if keyM = 0
for loops = 0 to 50
if Tower(loops,0) = 0
Type = mc
ShotSpeed = TowerStats(Type,0)
ShotRange = TowerStats(Type,1)
ShotReload = TowerStats(Type,2)
Tower(loops,0) = Type
Tower(loops,1) = mx
Tower(loops,2) = my
Tower(loops,3) = 0
Tower(loops,4) = ShotSpeed
Tower(loops,5) = ShotRange
Tower(loops,6) = ShotReload
Tower(loops,7) = 0
Tower(loops,8) = 0
loops = 50
endif
next loops
endif
KeyM = 1
else
keyM = 0
endif
return
REM --------------------------------------------------------------
REM TowerAI
REM --------------------------------------------------------------
TowerAI:
REM Loop for as many possible towers, 0-50 is maximun amout of towers.
for loops = 0 to 50
REM If Tower exists otherwise the value should be zero.
check = Tower(loops,0)
if check > 0
if check = 1 then gosub Tower1
if check = 2 then gosub Tower2
endif
next loops
return
REM --------------------------------------------------------------
REM Tower1
REM --------------------------------------------------------------
Tower1:
REM Draw Tower (Orange)
ink rgb(225,200,0),0
x = Tower(loops,1)
y = Tower(loops,2)
box x-5,y-15,x+5,y+15
mode = 1
gosub InRangeCheck
gosub ShootSingle
return
REM --------------------------------------------------------------
REM Tower2
REM --------------------------------------------------------------
Tower2:
REM Draw Tower (Blue)
ink rgb(50,100,225),0
x = Tower(loops,1)
y = Tower(loops,2)
box x-5,y-15,x+5,y+15
box x-15,y-5,x+15,y+5
mode = 0
gosub InRangeCheck
gosub Shoot8Ways
return
REM --------------------------------------------------------------
REM InRangeCheck
REM --------------------------------------------------------------
InRangeCheck:
REM Cool down time reseting.
if Tower(loops,7) > 0 then Tower(loops,7) = Tower(loops,7) - 1
if Tower(loops,7) = 0
Tower(loops,8) = -1
Tower(loops,3) = 0
et = 0
REM Loop 50 times
for lp = 0 to 50
REM Check Type, 0 means it's dead.
if Foe(lp,0) > 0
REM Input for use X,Y,Traveled
ix = Foe(lp,1)
iy = Foe(lp,2)
it = Foe(lp,6)
distance = abs(sqrt( (x-ix)^2 + (y-iy)^2 ))
if distance < Tower(loops,5)
if it > et and Foe(lp,7) < Foe(lp,0)
et = it
Tower(loops,8) = lp
Tower(loops,7) = Tower(loops,6)
if mode = 0 then lp = 50
endif
endif
endif
next lp
REM Flag the Target element only if it's tower1
if Tower(loops,8) > -1 and mode = 1
Foe(Tower(loops,8),7) = Foe(Tower(loops,8),7) + 1
endif
endif
return
REM --------------------------------------------------------------
REM ShootSingle
REM --------------------------------------------------------------
ShootSingle:
if Tower(loops,8) > -1
if Foe(Tower(loops,8),0) > 0
ex = Foe(Tower(loops,8),1)
ey = Foe(Tower(loops,8),2)
b = atanfull(x-ex,y-ey)
REM Get the distance of the Tower and Mouse
distance = abs(sqrt( (x-ex)^2 + (y-ey)^2 ))
REM If the mouse is within shooting range.
if distance < Tower(loops,5)
x1 = x-sin(b)*Tower(loops,3)
y1 = y-cos(b)*Tower(loops,3)
x2 = x-sin(b)*(Tower(loops,3)+5)
y2 = y-cos(b)*(Tower(loops,3)+5)
REM Update the shooting value
Tower(loops,3) = Tower(loops,3) + Tower(loops,4)
REM When the shooting value exceeds the shooting range
REM then reset the shooting value to zero.
if Tower(loops,3) > Tower(loops,5) then Tower(loops,3) = 0
REM Get the current position of the Arrow/Shot
position = abs(sqrt( (x-x1)^2 + (y-y1)^2 ))
REM Draw the Arrow
ink rgb(255,255,255),0
line x1,y1,x2,y2
REM Kill the Targeted enemy
if position > distance
REM Clear Type
Foe(Tower(loops,8),0) = Foe(Tower(loops,8),0) - 1
REM Clear Targeted on Foe
Foe(Tower(loops,8),7) = Foe(Tower(loops,8),7) - 1
REM Out of bounce (negative) check making it zero
if Foe(Tower(loops,8),0) < 0 then Foe(Tower(loops,8),0) = 0
REM Clear Targeted on Tower
Tower(loops,8) = -1
endif
else
Foe(Tower(loops,8),7) = Foe(Tower(loops,8),7) - 1
endif
endif
endif
return
REM --------------------------------------------------------------
REM Shoot8Ways
REM --------------------------------------------------------------
Shoot8Ways:
if Tower(loops,8) > -1
REM Draw 8 arrows
for lp = 45 to 360 step 45
ex = x + sin(lp)*Tower(loops,5)
ey = y + cos(lp)*Tower(loops,5)
b = atanfull(x-ex,y-ey)
x1 = x-sin(b)*Tower(loops,3)
y1 = y-cos(b)*Tower(loops,3)
x2 = x-sin(b)*(Tower(loops,3)+4)
y2 = y-cos(b)*(Tower(loops,3)+4)
REM Update the shooting value
Tower(loops,3) = Tower(loops,3) + Tower(loops,4)
REM When the shooting value exceeds the shooting range
REM then reset the shooting value to zero.
if Tower(loops,3) > Tower(loops,5)
Tower(loops,3) = 0
Tower(loops,8) = -1
endif
REM Draw the Arrow
ink rgb(255,255,255),0
line x1,y1,x2,y2
REM Checking the Foe getting hit.
for lp2 = 0 to 50
if Foe(lp2,0) > 0
ix = Foe(lp2,1)
iy = Foe(lp2,2)
if CheckArea(x2,y2,ix,iy,13) = 1
Foe(lp2,0) = Foe(lp2,0) - 1
if Foe(lp2,0) < 0 then Foe(lp2,0) = 0
endif
endif
next lp2
next lp
endif
return
REM --------------------------------------------------------------
REM CheckArea Function
REM --------------------------------------------------------------
Function CheckArea(px,py,x,y,size)
retval = 0
if px > x-size & px < x+size & py > y-size & py < y+size then retval = 1
EndFunction retval
@BN2
Since I made the images shall I write the loading process for them as well?