I have been programming a quick little game in my spare time. For some reason it just randomly crashes with "Circle Man.exe has encountered a problem and needs to close. We are sorry for the inconvenience." I don't know why this is happenning. For some reason it does this after I start shooting at the enemies.
This is all of my code and I attached the media.
REM Project: Circle Man
REM
REM ***** Main Source File *****
REM
Set Display Mode 1024,768,32
sync on:sync rate 60
hide mouse
randomize timer()
`======================================================
`********************IMAGE NUMBERS********************
Global CirclemanImage as integer = 1
Global bulletImage as integer = 2
Global CrosshairImage as Integer = 3
Global Background1 as integer = 4
Global RedTriangle as integer = 5
Global GreenTriangle as integer = 6
Global YellowTriangle as integer = 7
`======================================================
`********************SPRITE NUMBERS********************
Global CirclemanSprite as integer = 1
Global Crosshairsprite as integer = 2
`======================================================
`*******************BULLET VARIABLES*******************
Global shoottime as integer = 50
Global shoot as integer = 0
Global TotalBullets as integer = 0
type Bullet
Global Num as dword
Global X as float
Global Y as float
Global An as float
endtype
Global bulletnum as integer = 5
dim Bullet(Bulletnum) as Bullet
Global distanceX# as float = 0.0
Global distanceY# as float = 0.0
Global speed# as float = 0.0
Global CrosshairX as integer = 0
Global CrosshairY as integer = 0
Global PosX# as float = 0.0
Global PosY# as float = 0.0
Global PlayerHealth as integer = 100
`======================================================
`*******************ENEMY VARIABLES********************
Global EnemySpawnTime as integer = 0
Global TotalEnemies as integer = 0
type Enemy
Global Num as dword
Global X as float
Global Y as float
Global An as float
Global Life as float
endtype
Global Enemynum as integer = 20
dim Enemy(Enemynum) as Enemy
`======================================================
`=========================MAIN=========================
`======================================================
Load_Background()
Load_Player()
Load_Enemies()
do
cls
paste image Background1,0,0
Control_Player()
Control_Enemies()
Bullet_Collision()
Player_Enemy_Collision()
HUD()
sync
loop
Function Load_Background()
Load image "Media/Images/Background1.bmp", Background1
Endfunction
Function Load_Player()
Load image "Media/Images/Circle man.bmp", CirclemanImage
Load image "Media/Images/Shoot.bmp", BulletImage
Load Image "Media/Images/Crosshairs.bmp", CrosshairImage
Endfunction
Function Load_Enemies()
Load image "Media/Images/TriangleRed.bmp",RedTriangle
Load image "Media/Images/TriangleGreen.bmp",GreenTriangle
Load image "Media/Images/TriangleYellow.bmp",YellowTriangle
Endfunction
Function Control_Player()
if keystate(17)=1 then PosY# = PosY# - 3.0
if keystate(31)=1 then PosY# = PosY# + 3.0
if keystate(30)=1 then PosX# = PosX# - 3.0
if keystate(32)=1 then PosX# = PosX# + 3.0
sprite Circlemansprite, PosX#, PosY#, CirclemanImage
set sprite Circlemansprite, 1, 1
aim()
Shoot()
endfunction
Function Aim()
CrosshairX = MouseX()+(image width(CrosshairImage)/2)
CrosshairY = MouseY()+(image height(CrosshairImage)/2)
Sprite Crosshairsprite, CrosshairX, CrosshairY, CrosshairImage
endfunction
Function Shoot()
if mouseclick()=1 and shoottime=0 and TotalBullets<5
BulletNum=1
While Bullet(bulletnum).num>0
inc BulletNum
Endwhile
spritenum=1
While Sprite Exist(spritenum)
inc spritenum
ENDWHILE
Bullet(bulletnum).num=spritenum
aimX#=mouseX()
aimy#=mouseY()
Bullet(bulletnum).X=sprite X(CirclemanSprite)
Bullet(bulletnum).Y=sprite Y(CirclemanSprite)
Bullet(bulletnum).an=-Atanfull((PosX#-AimX#),(PosY#-AimY#))
sprite Bullet(bulletnum).num, Bullet(bulletnum).X+(Sprite width(Circlemansprite)/2), Bullet(bulletnum).Y+(Sprite height(Circlemansprite)/2), BulletImage
rotate sprite Bullet(bulletnum).num,Bullet(bulletnum).an
shoottime=50
endif
If Shoottime>0 then Dec Shoottime
TotalBullets=0
For B = 1 to 5
If Bullet(B).num>0
If Sprite Exist(Bullet(B).num)=1 then Inc TotalBullets
endif
Next B
For B = 1 to 5
If Bullet(B).num>0
if sprite exist(Bullet(B).num)=1
move sprite Bullet(B).num,5
if sprite x(Bullet(B).num)<0 or sprite x(Bullet(B).num)>screen width() or sprite y(Bullet(B).num)<0 or sprite y(Bullet(B).num)>screen height()
delete sprite Bullet(B).num
Bullet(B).num=0
endif
endif
endif
Next B
endfunction
Function Control_Enemies()
Spawn_Enemies()
For E=1 to 20
If Enemy(E).num>0
If Sprite Exist(Enemy(E).num)=1
Rotate Sprite Enemy(E).num,Enemy(E).an
move sprite Enemy(E).num,3
If Enemy(E).life>0
Dec Enemy(E).Life
else
Delete Sprite Enemy(E).num
Enemy(E).num=0
endif
endif
endif
Next E
ENDFUNCTION
Function Spawn_Enemies()
If EnemySpawnTime=0 and TotalEnemies<20
E=1
While Enemy(E).num>0
inc E
Endwhile
spritenum=1
While Sprite Exist(spritenum)
inc spritenum
ENDWHILE
Enemy(E).num=spritenum
SpawnSpot=rnd(3)+1
If SpawnSpot=1
Enemy(E).X=Screen Width()+41
Enemy(E).Y=rnd(768)
endif
If SpawnSpot=2
Enemy(E).X=Rnd(1024)
Enemy(E).Y=Screen Height()-41
endif
If SpawnSpot=3
Enemy(E).X=-41
Enemy(E).Y=rnd(768)
endif
If SpawnSpot=4
Enemy(E).X=Rnd(1024)
Enemy(E).Y=-41
endif
Color=rnd(2)+1
if Color=1 then Sprite Enemy(E).num,Enemy(E).X,Enemy(E).Y,RedTriangle
if Color=2 then Sprite Enemy(E).num,Enemy(E).X,Enemy(E).Y,GreenTriangle
if Color=3 then Sprite Enemy(E).num,Enemy(E).X,Enemy(E).Y,YellowTriangle
Set Sprite Enemy(E).num,1,1
Enemy(E).Life=500
Enemy(E).an=-Atanfull((Enemy(E).X-rnd(1024)),(Enemy(E).Y-rnd(768)))
Rotate Sprite Enemy(E).num,Enemy(E).an
EnemySpawnTime=75
ENDIF
TotalEnemies=0
For E = 1 to 5
If Enemy(E).num>0
If Sprite Exist(Enemy(E).num)=1 then Inc TotalEnemies
endif
Next E
If EnemySpawnTime>0 then dec EnemySpawnTime
ENDFUNCTION
Function Bullet_Collision()
For B = 1 to 5
For E=1 to 20
If Bullet(B).num>0 and Enemy(E).num>0
If sprite exist(Bullet(B).num)=1 and Sprite Exist(Enemy(E).num)=1
If Sprite Hit(Bullet(B).num,Enemy(E).num)>0
Delete Sprite Bullet(B).num
Bullet(B).num=0
While Enemy(E).Life>0
dec Enemy(E).Life
ENDWHILE
endif
endif
endif
Next E
Next B
ENDFUNCTION
Function Player_Enemy_Collision()
For E=1 to 20
If Enemy(E).num>0
If Sprite Exist(Enemy(E).num)=1
If Sprite Hit(Enemy(E).num,CircleManSprite)=1
Dec PlayerHealth,5
endif
endif
endif
Next E
ENDFUNCTION
Function HUD()
Text 0,0,"Health: "+Str$(PlayerHealth)
ENDFUNCTION
If it hasn't exploded yet, I haven't touched it.