Rem Project: Jason Contest 1
Rem Created: 6/29/2007 4:27:30 PM
 
Rem ***** Main Source File *****
 
#constant B 0
#constant LW 0
#constant LF 0
#constant RW 0
#constant RF 0
REM #constant Multiplier 0.1
 
global Q
global total
global team
 
input "Choose difficulty (0 - easy; 1 - medium; 2 - hard): ",diff$
if diff$ = "1"
   total = 50
   team = 25
   enemyscore = 30
   teamscore = 25
else
   if diff$ = "2"
      total = 40
      team = 20
   enemyscore = 30
   teamscore = 20
   else
      total = 60
      team = 30
   enemyscore = 30
   teamscore = 30
   endif
endif
 
sync off
set camera range 0.1,120000
autocam off
cls
randomize timer()
dim firetime(total)
 
c as dword
for x = 0 to 3000
   bx = rnd(1024) : by = rnd(768)
   c = rgb(255-rnd(25),255-rnd(25),255-rnd(25))
   dot bx,by,c
   rem box bx-1,by-1,bx+1,by+1,c,c,c,c
next x
 
Q = 1
Space = Q
get image Q,0,0,1024,768,1
make object cube Q,50000
set object light Q,0
set object cull Q,0
texture object Q,Q
 
Q=Q+1 : cls
CspR = Q
ink rgb(255,0,0),rgb(255,0,0)
circle 10,10,5
ink rgb(255,255,255),rgb(255,255,255)
get image Q,0,0,20,20,1
sprite Q,0,0,Q
hide sprite Q
 
Q=Q+1 : cls
CspB = Q
ink rgb(0,0,255),rgb(0,0,255)
circle 10,10,5
ink rgb(255,255,255),rgb(255,255,255)
get image Q,0,0,20,20,1
sprite Q,0,0,Q
hide sprite Q
 
Q=Q+1 : cls
CspAimer = Q
ink rgb(255,170,0),rgb(255,170,0)
line 6,0,6,100
line 12,0,12,100
y = 0
for x = 1 to 5
   line 6-(x+1),y,6,y
   line 12+(x+1),y,12,y
   y = y + 11
next x
ink rgb(255,255,255),rgb(255,255,255)
get image Q,0,0,19,130,1
sprite Q,0,0,Q
offset sprite Q,9,150
hide sprite Q
 
Q=Q+1 : cls
 
type Player
   control as integer
   targeted as integer
   T as integer
   L as integer
   R as integer
   dx as float
   dy as float
   dz as float
endtype
player as Player
dim comp(total) as Player
 
REM make ships
player.control = 1+Q
for x = 1+Q to total+1+Q
   make object box x,2,1,8
   if x < team+1+Q
      color object x,rgb(0,0,150)
   else
      color object x,rgb(255,255,0)
   endif
   set object collision to boxes x
   rem make object box x*LW,2,0.5,1
   rem make object box x*LF,.5,.5,3
   rem make object box x*RW,2,0.5,1
   rem make object box x*RF,.5,.5,3
next x
 
for x = total+2+Q to total+20*total+2+Q
   make object box x,.3,.3,30
   set object diffuse x,rgb(255,0,0)
   set object ambience x,rgb(255,0,0)
   set object emissive x,rgb(255,0,0)
   hide object x
next x
 
dim bulletlife(20*total)
 
Rem position teams
Rem Blue Team
for x = 1+Q to team+Q
   position object x,rnd(500)-250,rnd(200)-100,rnd(50)-25
next x
 
for x = team+1+Q to total+1+Q
   position object x,rnd(500)-250,rnd(200)-100,rnd(50)-25+1500
   rotate object x,0,180,0
next x
 
rem move player.control back for a more action-oriented view
move object 1+Q,-300
 
 
hide mouse
sync on
sync rate 100
 
pturnspeed# = 5.0
rem turnspeed# = 0.01
turnspeed# = 0.001
s# = 0.4
Multiplier as float
 
do
text 0,0,str$(screen fps())
text 0,13,"Team: "+str$(teamscore)
text 0,26,"Enemy: "+str$(enemyscore)
REM Multiplier = (timer() - Last)*0.01
REM Last = timer()
Multiplier = 1.0
 
mmy# = mousemovey()*s#*Multiplier
if mmy# > pturnspeed#*Multiplier then mmy# = pturnspeed#*Multiplier
if mmy# < -pturnspeed#*Multiplier then mmy# = -pturnspeed#*Multiplier
mmx# = mousemovex()*s#*Multiplier
if mmx# > pturnspeed#*Multiplier then mmx# = pturnspeed#*Multiplier
if mmx# < -pturnspeed#*Multiplier then mmx# = -pturnspeed#*Multiplier
mmz# = mousemovez()*s#*0.1*Multiplier
if mmz# > pturnspeed#*Multiplier then mmz# = pturnspeed#*Multiplier
if mmz# < -pturnspeed#*Multiplier then mmz# = -pturnspeed#*Multiplier
x#=x#+mmy# : y#=y#+mmx# : z#=z#+mmz#
rem rotate object player.control,x#,y#,z#
rotate object player.control,0,0,0
rem turn object right player.control,y#
rem pitch object up player.control,x#
rem roll object left player.control,z#
rotate object player.control,x#,y#,0
rem roll object left player.control,z#
rem rotate limb player.control,1,0,0,z#
 
position camera object position x(player.control),object position y(player.control),object position z(player.control)
rem rotate camera x#+15.0,y#,z#
rem roll camera right z#
rotate camera object angle x(player.control)+15.0,object angle y(player.control),0
move camera -75
position object Space,object position x(player.control),object position y(player.control),object position z(player.control)
 
paste sprite CspAimer,screen width()/2,screen height()/2
 
Rem Control AI:
for x = 1+Q to total+1+Q
 
if object visible(x) = 1
move object x,15*Multiplier
REM if x <> player.control then move object x,-1*Multiplier
 
if object in screen(x) = 1
   if x >= team+1+Q and x <= total+1+Q
      paste sprite CspR,object screen x(x)-10,object screen y(x)-10
   else
      paste sprite CspB,object screen x(x)-10,object screen y(x)-10
   endif
endif
 
coll = object collision(x,0)
if coll >= total+2+Q and coll <= total+20*total+2+Q
if object visible(coll) = 1
   hide object x
   hide object coll
   if x >= 1+Q and x < team+1+Q then teamscore = teamscore-1
   if x >= team+1+Q and x <= total+1+Q then enemyscore = enemyscore-1
   if teamscore = 0 or enemyscore = 0 then CalcVictory(teamscore,enemyscore)
endif
endif
 
if x <> player.control
   y = x-1-Q
   if comp(y).T = 0
      if x < team+1+Q then comp(y).T = rnd(total-team)+team+1+Q
      if x > team+Q then comp(y).T = rnd(team-1)+1+Q
      remstart
      if object visible(comp(y).T) = 1
         if comp(comp(y).T-1-Q).targeted = 0
            comp(comp(y).T-1-Q).targeted = y
         else
            comp(y).T = 0
         endif
      endif
      remend
   else
      ox# = object angle x(x) : oy# = object angle y(x) : oz# = object angle z(x)
      point object x,object position x(comp(y).T),object position y(comp(y).T),object position z(comp(y).T)
      dx# = ox#-object angle x(x) : dy# = oy#-object angle y(x) : dz# = oz#-object angle z(x)
      comp(y).dx = dx#/10.0 : if comp(y).dx > turnspeed#*Multiplier then comp(y).dx = turnspeed#*Multiplier : if comp(y).dx < -turnspeed#*Multiplier then comp(y).dx = -turnspeed#*Multiplier
      comp(y).dy = dy#/10.0 : if comp(y).dy > turnspeed#*Multiplier then comp(y).dy = turnspeed#*Multiplier : if comp(y).dy < -turnspeed#*Multiplier then comp(y).dy = -turnspeed#*Multiplier
      comp(y).dz = dz#/10.0 : if comp(y).dz > turnspeed#*Multiplier then comp(y).dz = turnspeed#*Multiplier : if comp(y).dz < -turnspeed#*Multiplier then comp(y).dz = -turnspeed#*Multiplier
      if dx# < 4.0 or dx# > -4.0
         if dy# < 4.0 or dy# > -4.0
            rem if dz# > 4.0 or dz# < -4.0
               obj = FreeLaser()
               firetime(y) = Fire(firetime(y),x,obj)
            rem endif
         endif
      endif
      if object visible(comp(y).T) = 0 then comp(y).T = 0
   endif
endif
endif
next x
 
if object visible(player.control) = 0 then player.control = rnd(team-1)+1+Q
 
obj = FreeLaser()
if mouseclick() = 1 then firetime(player.control-Q-1) = Fire(firetime(player.control-Q-1),player.control,obj)
 
for x = total+2+Q to total+20*total+2+Q
   if object visible(x) = 1
      bulletlife(x-total-1-Q) = bulletlife(x-total-1-Q)-1
      if bulletlife(x-total-1-Q) = 0 then hide object x
      move object x,30*Multiplier
      remstart
      rem coll = object collision(x,0)
      if coll >= 1+Q and coll <= total+1+Q
         hide object x
         hide object coll
      endif
      remend
   endif
next x
 
sync
loop
 
 
 
function FreeLaser()
   for x = total+2+Q to total+20*total+2+Q
      if object exist(x) = 1
         if object visible(x) = 0
            bulletlife(x-total-1-Q) = 50
            exitfunction x
         endif
      endif
   next x
endfunction x
 
function Fire(T,P,O)
if timer()-T > 300
   position object O,object position x(P),object position y(P),object position z(P)
   rotate object O,object angle x(P),object angle y(P),object angle z(P)
   rem move object O,7.6
   rem move object O,-5
   move object O,5+15
   show object O
   T = timer()
endif
endfunction T
 
 
function CalcVictory(t,e)
set text size 36
if e = 0 then center text screen width()/2,screen height()/2,"Victory!"
if t = 0 then center text screen width()/2,screen height()/2,"Failure!"
sync
wait 2000
end
endfunction