Enemy Shooting Time

BlitzPlus Forums/BlitzPlus Programming/Enemy Shooting Time

nyybaseball(Posted 2014) [#1]
How would i make the enemy shoot at random times? Its in the function testai(). Heres the program:

Graphics 1000,600

SetBuffer BackBuffer()

AutoMidHandle True

SeedRnd MilliSecs()

Global leftplayer = LoadImage("LeftStickMan.bmp")

Global rightplayer = LoadImage("RightStickMan.bmp")

Global bullet = LoadImage("Bullet.bmp")

ScaleImage leftplayer, .7, .7

ScaleImage rightplayer, .7, .7

font=LoadFont("Arial",15)

SetFont font
x = 0
Type bullet
Field x,y
Field from
End Type

Type user
Field x,y
End Type

Global player.user = New user
player\x = 950
player\y = 490

Type yoface
Field x,y
End Type

Global comp.yoface = New yoface
comp\x = 50
comp\y = 490

While Not KeyDown(1)

Cls

testinput()
testai()
updtaebullet()
DrawImage rightplayer, player\x, player\y
DrawImage leftplayer, comp\x, comp\y
Text 10,10,+MilliSecs()

Flip

Wend

End

Function testinput()

If KeyDown(200) Then
player\y = player\y - 5
EndIf
If KeyDown(208) Then
player\y =player\y + 5

EndIf

If KeyHit(57) Then
bullets.bullet = New bullet
bullets\x = player\x
bullets\y = player\y
bullets\from = 0
EndIf
End Function

Function testai()

If comp\y > player\y Then
comp\y = comp\y - 1
EndIf
If comp\y < player\y Then
comp\y = comp\y + 1
EndIf
If MilliSecs() >= MilliSecs() + 5000
ebullet.bullet = New bullet
ebullet\x = comp\x
ebullet\y = comp\y
ebullet\from = 1
EndIf
End Function

Function updtaebullet()

For bullets.bullet = Each bullet
If bullets\from = 0 Then
bullets\x = bullets\x - 10
Else
bullets\x = bullets\x + 5
EndIf
DrawImage bullet, bullets\x, bullets\y
Next

End Function