FOOOOOOOOOUND IIIIIIIIIIIT!
You put one endif in the wrong place.
Here's the code, with the comment over the endif:
` player x
x=320
` player y
y=240
` enemy x
ex=320
` enemy y
ey=25
sync on
do
cls
` enemy
ink rgb(0,254,0),1
circle ex,ey,8
` gunx
gx=x+6
` guny
gy=y-8
` player
ink rgb(254,0,0),1
circle x,y,6
` player gun
line gx,y,gx,gy
` controls for player
if upkey()=1 then y=y-2
if downkey()=1 then y=y+2
if leftkey()=1 then x=x-2
if rightkey()=1 then x=x+2
if spacekey()=0
ink rgb(254,254,254),1
circle dx,dy,1
dx=dx
dy=dy-4
else
dx=gx
dy=gy
rem HERES THE PROBLEM--THIS ENDIF WAS IN THE WRONG PLACE!
`vvvvvvvvvvvvvvvvvvvvv
endif
`^^^^^^^^^^^^^^^^^^^^^^
` if bullets hit enemy
if dx < ex+8
if dx > ex-8
if dy-2 < ey+8
ey=0
ex=rnd(640)
endif
endif
endif
` end controls for player
sync
loop
The collision detection was only running when the space bar was held down, because the collision was nested (located) under the
if spacekey()=1
<<<<spacekey stuff>>>>>>
<<<<collision here>>>>>>
endif
instead of
if spacekey()=1
<<<spacekey stuff>>
endif
<<<<collision here>>>>>>
I am who I am