whats wrong here

Blitz3D Forums/Blitz3D Beginners Area/whats wrong here

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

copied and pasted what u posted works ok for me, no matter i changed the resolution so i had all five aliens on screen, got an error on one

the error occurs when two bullets are on the screen

a work round whilst you figure it out is to use another field called 'visible' flagged as true/false.


Type Player
Field x
Field y
End Type

Type Enemy
Field x
Field y
Field vis ; added this
End Type

Type Bullet
Field x
Field y
End Type

SeedRnd MilliSecs()
Graphics 600,600
SetBuffer BackBuffer()

Global BulletTimer=MilliSecs()

create_player()
create_enemy()

While Not KeyHit(1)

update_player()
update_enemy()
update_bullet()
kills()

Flip
Cls
Wend
End

Function kills() ;NEEDS WORK... BAD REAL BAD
For e.enemy=Each enemy
For b.bullet=Each bullet
If RectsOverlap(e\x,e\y,10,10,b\x,b\y,10,10)
e\vis = False ; added this - removed delete
End If
Next
Next
End Function

Function create_player()
p.Player=New Player
p\x=300
p\y=350
End Function

Function update_player()
For p.Player=Each Player
Color 100,100,100
Rect p\x,p\y,20,20
If KeyDown(203) p\x=p\x-2
If KeyDown(205) p\x=p\x+2
If KeyHit(57) And MilliSecs()>BulletTime Then Create_Bullet(p\x,p\y)
Next
End Function

Function create_enemy()
For i=1 To 5
e.Enemy=New Enemy
e\x=Rnd(10,500)
e\y=Rnd(10,100)
e\vis = True ; added this
Next
End Function

Function update_enemy()
For e.Enemy=Each Enemy
Color 200,200,200
If e\vis = True ; added this
Rect e\x,e\y,10,10
EndIf; added this
Next
End Function

Function create_bullet(x,y)
b.Bullet=New Bullet
b\x=x+5
b\y=y-15
BulletTimer=MilliSecs()
End Function

Function update_bullet()
For b.Bullet=Each Bullet
Color 200,0,0
Rect b\x,b\y,10,10
b\y=b\y-3
If b\y<1 Then Delete b
Next
End Function