Thanks for the response,
The problem is now that it CANNOT detect collision between the two objects. It just passes right through. Here is the code as it is
Sync on
Sync rate 60
Hide mouse
Load image "media/stars.jpg",1
REM load sounds
gamestate = 0
REMStart
Object Number Index
1: PLayer
2-4: Shots
5-50: Enemies
100: Background
Gamestate index
0: Menu
1: Game
REMend
global shoot
global shot_speed
global bulletlife2
global score
global enemy_count
global enemy_shot
global enemy_bulletlife
global attack_delay_flag
attack_delay_flag = 0
yy=300
xx=10
shoot = 0
shot_speed = 15
bulletlife2 = 0
enemy_bulletlife = 0
Menu:
Show_Menu()
wait key
if inkey$() = "2"
end
endif
game()
end
function Show_Menu
cls
gamestate = 0
Set Cursor 100,100:print "Select Option"
Set Cursor 100,200:print "1 : Start Game"
Set Cursor 100,300:print "2 : Exit"
sync
endfunction
function game
gamestate = 1
cls
create_player()
create_enemies()
pitch camera down 90
do
if inkey$() = "["
end
endif
Draw_HUD()
get_input()
enemy_fire()
Move_Bullets()
Collision_Dection()
Camera()
if enemy_count = 0
goto menu
endif
loop
EndFunction
function create_player()
if object exist(1)
delete object 1
endif
if object exist(2)
delete object 2
endif
make object cube 1,10
color object 1,RGB(255,0,0)
make object cube 2,5
hide object 2
scale object 2,50,50,250
color object 2,RGB(0,255,0)
make object cube 3,5
hide object 3
scale object 3,50,50,250
color object 3,RGB(0,255,0)
make object cube 4,5
hide object 4
scale object 4,50,50,250
color object 4,RGB(0,255,0)
REM texture object 1,(player ship picture)
position object 1,100,0,-400
make object sphere 100,-2000
texture object 100,1
bulletlife2 = 0
bulletlife3 = 0
bulletlife4 = 0
shot_speed = 15
gamestate = 1
score = 0
endfunction
function create_enemies
for e = 8 to 50
make object cube e,10
position object e,xx,0,yy
xx= xx + 20
enemy_line_count = enemy_line_count + 1
if enemy_line_count = 15
yy=yy-75:xx=10
enemy_line_count = 0
endif
enemy_count = enemy_count + 1
color object e,RGB(0,255,0)
REM texture object e,(enemy ship picture)
next e
make object cube 51,5
hide object 51
scale object 51,50,50,250
color object 51,RGB(0,255,255)
rotate object 51,180,0,0
EndFunction
function fire
shoot = 1
position object 2,object position x(1),0,object position z(1):show object 2
endfunction
Function Move_Bullets
if shoot = 1
move object 2,shot_speed
bulletlife2 = bulletlife2 + 1
endif
if bulletlife2 = 60
shoot = 0
bulletlife2 = 0
hide object 2
endif
if enemy_shot = 1
move object 51,10
enemy_bulletlife = enemy_bulletlife + 1
endif
if enemy_bulletlife = 60
enemy_shot = 0
enemy_bulletlife = 0
attack_delay_flag = 0
hide object 2
endif
EndFunction
Function Create_Powerup
make object cube 8,10
color object 8,RGB(0,255,0)
EndFunction
Function Draw_HUD
set text font "Times New Roman"
set text to bold
set cursor 0,0:print "",screen fps()
set cursor 100,0:print "SCORE : ",score
set cursor 200,0:print "TRIES : ",tries
set cursor 300,0:Print "X : ",camera position x(0)
set cursor 350,0:Print "Y : ",camera position y(0)
set cursor 400,0:Print "Z : ",camera position z(0)
set cursor 500,0:Print "Shoot : ",shoot
set cursor 550,0:Print "Bulletlife : ",bulletlife2
set cursor 550,10:Print "Enemy Shot: ",enemy_shot
EndFunction
Function Camera
position camera 100,370,-120
point camera 100,0,90
Sync
EndFunction
Function get_input
rem If gamestate = 1
if leftkey() = 1
if object position x(1)>0 then move object left 1,3
endif
if rightkey() = 1
if object position x(1)<300 then move object right 1,3
endif
if spacekey() = 1 and shoot = 0
fire()
endif
rem endif
endfunction
Function Collision_Dection
for e = 8 to 50
if object exist(e)
if object collision (2,e)=1 and object visible (2)
delete object e
hide object 2
score=score+20
enemy_count = enemy_count -1
endif
endif
next e
endfunction
function enemy_fire
if enemy_shot = 0
if attack_delay_flag = 0
attacker = rnd(42) + 8
if not object exist(attacker)
break
endif
attack_delay = rnd(100)
attack_delay_flag = 1
enemy_shot = 1
position object 51,object position x(attacker),object position y(attacker),object position z(attacker)
show object 51
else
attack_delay = attack_delay - 1
endif
endif
endfunction
Comment out the lines relating to the stars image if you like, or change it (the background) with one of your own.
Thanks again