This one is a more recent version, and it uses @WickedX s createsound plugin to generate the sounds of the game. Thanks to himm I don't need to add wav files to make a noisy game hahah
SET DISPLAY MODE 1366,768,32 : MAXIMIZE WINDOW : SET WINDOW LAYOUT 0,0,0
autocam off : position camera 0,0,0,400 : point camera 0,0,0,0 : set camera fov 0,10
type shotdata
available as boolean
t as byte
u as float
v as float
X AS FLOAT
Y AS FLOAT
speed as float
amount as integer
angle as float
has_Spread as boolean
spread as integer
range as integer
n as integer
damage as integer
element as byte
endtype
type shipdata
cpu_control as integer
cpu_program as byte
cpu_wpn as byte
hp as integer
element as byte
color as dword
width as byte
height as byte
seed as double integer
guns as byte
program as string
speed as float
turn as float
strafe as float
change as integer
endtype
ships = 2
dim ship(ships) as shipdata
dim weapon(ships,5) as shotdata
sync on : sync rate 60
do
randomize timer()
color backdrop 0
if ship(1).hp <= 0 then setup_ship(1) : POSITION OBJECT 1,-50,0,0 : ZROTATE OBJECT 1,90 : move object up 1,.1 : set object collision to spheres 1
if ship(2).hp <= 0 then setup_ship(2) : POSITION OBJECT 2,50,0,0 : ZROTATE OBJECT 2,-90 : move object up 2,.1 : set object collision to spheres 2
FOR N = 1 TO 2 : reset(N) : NEXT //reset onboard cpu
repeat
FOR N = 1 TO 2
moveshots(n)
reposition(N)
computer(N)
NEXT
SET TEXT SIZE 100
CENTER TEXT 100,0,STR$(SHIP(1).HP)
CENTER TEXT SCREEN WIDTH()-100,0,STR$(SHIP(2).HP)
sync
until spacekey() = 1 or ship(1).hp <= 0 or ship(2).hp <= 0
if spacekey() = 1 : ship(1).hp = 0 : ship(2).hp = 0 : endif
DELALL()
LOOP
function crop(v#,f#,t#)
if v# > t# then v# = t#
if v# < f# then v# = f#
ENDFUNCTION v#
function makeship(n,w,h,c)
create bitmap n,w,h : if image exist(n) = 1 then delete image n
x = w-1 : y = rnd(h-2)+1
sz = w*h
cls 0
lock pixels
repeat
dot x,y,c
x = x+sin(angle)*1 : y = y+cos(angle)*1
x = crop(x,1,w-1) : y = crop(y,1,h-1)
angle = wrapvalue(angle+((rnd(1)-rnd(1))*90)) //d = rnd(1)+1 : if d = 1 then angle = wrapvalue(angle+90) : if d = 2 then angle = wrapvalue(angle-90)
dec sz
until sz = 0
unlock pixels
get image n,0,0,w,h,1 : delete bitmap n
if object exist(n) = 1 then delete object n
make object plane n,w*2,h : set object texture n,2,1 : texture object n,n : set object transparency n,1 : scale object texture n,2,1 : set object filter n,0 : set object light n,0
endfunction
FUNCTION MAKEBLOCK(N,width,height,W,H,T,C1,C2,C3)
maketexture(n,t,w,h,c1,c2,c3)
IF OBJECT EXIST(N) = 1 THEN DELETE OBJECT N
MAKE OBJECT BOX N,width,height,width
TEXTURE OBJECT N,N
SET OBJECT TEXTURE N,T,1
IF T < 2 : SW = RND(4)+1 : SH = RND(4)+1 : ENDIF
IF T = 2 : SW = 2^(RND(2)+1) : SH = 2^(RND(2)+1) : ENDIF
SCALE OBJECT TEXTURE N,SW,SH
IF T < 2 THEN F = RND(1)+1 ELSE F = 0
SET OBJECT FILTER N,F
ENDFUNCTION
function maketexture(n,t,w,h,c1,c2,c3)
create bitmap n,w,h
CLS C3
LOCK PIXELS
IF T < 2 : SX = 1 : SY = 1 : ELSE : SX = RND(1)+1 : SY = RND(1)+1 : ENDIF
s = rnd(1) : lc = rnd(5)+1
if s = 0
for x = 0 to w STEP SX
for y = 0 to h STEP SY
p = rnd(1)
if p = 0 then dot x,y,c1 else dot x,y,c2
next
NEXT
else
sz = rnd((w*h)*2)+int((w*h)/2)
x = rnd(w) : y = rnd(h)
repeat
d = rnd(5)
if d = 0 then x = wrap(x-1,0,w)
if d = 1 then x = wrap(x+1,0,w)
if d = 2 then y = wrap(y-1,0,h)
if d = 3 then y = wrap(y+1,0,h)
if d = 4 and rnd(lc) = 0 : x = rnd(w) : y = rnd(h) : endif
if d = 5 and rnd(lc) = 0 then c = wrap(c+1,0,1)
if c = 0 then cor = c1
if c = 1 then cor = c2
dot x,y,cor
dec sz,1
UNTIL sz = 0
endif
IF IMAGE EXIST(N) = 1 THEN DELETE IMAGE N
UNLOCK PIXELS
GET IMAGE N,0,0,W,H,1
DELETE BITMAP N
ENDFUNCTION
function drawshot(n,w,h,color)
create bitmap n,w+1,h+2
cls 0
sx = rnd(1)+1 : sy = rnd(1)+1
rv = rnd(1)+1
lock pixels
for x = 1 to w step sx
for y = 1 to h step sy
if rnd(rv) > 0 then dot x,y,color
next
Next
unlock pixels
if image exist(n) = 1 then delete image n
get image n,0,0,w+1,h+2,1
delete bitmap n
Endfunction
function makeshot(n,t,e)
color = C_element(e)
w = rnd(8)+3 : h = rnd(8)+3
drawshot(n,w,h,color)
if object exist(n) = 1 then delete object n
ow = rnd(17)+3
oh = rnd(17)+3
row = 2 + rnd(6)
col = 3 + rnd(7)
if t = 0 : make object plane n,ow,oh : texture object n,n : scale object texture n,2,1 : set object transparency n,1 : set object filter n,2 : set object light n,0 : set object texture n,2,1 : endif
if t = 1 : make object sphere n,ow,row,col : texture object n,n : scale object texture n,(1+rnd(2))^2,(1+rnd(2))^2 : set object transparency n,1 : set object filter n,2 : set object light n,0 : set object texture n,2,1 : set object cull n,0 : rotate object n,rnd(1)*90,rnd(1)*90,rnd(1)*90 : fix object pivot n : endif
if t = 2 : make object cone n,oh : texture object n,n : scale object texture n,(1+rnd(2))^2,(1+rnd(2))^2 : set object transparency n,1 : set object filter n,2 : set object light n,0 : set object texture n,2,1 : set object cull n,0 : xrotate object n,rnd(3)*90 : fix object pivot n : endif
if t = 3 : make object cylinder n,h : texture object n,n : scale object texture n,(1+rnd(2))^2,(1+rnd(2))^2 : set object transparency n,1 : set object filter n,2 : set object light n,0 : set object texture n,2,1 : set object cull n,0 : xrotate object n,rnd(3)*90 : fix object pivot n : endif
if t = 1 : wd = rnd(3)+1 * 50 : hd = rnd(3)+1 * 50 : scale LIMB n,0,rnd(199)+1,rnd(199)+1,rnd(199)+1,1 : endif
position object n,0,-1000000,0 : SET OBJECT COLLISION On N
set object collision to boxes n
HIDE OBJECT N
ENDFUNCTION
function pitty(x1,y1,x2,y2)
a2 = (x1 - x2)^2
b2 = (y1 - y2)^2
c# = sqrt(a2+b2)
ENDFUNCTION c#
function C_element(elm)
if elm = 0 then color = rgb(255,255,255)
if elm = 1 then color = rgb(255,255,0)
if elm = 2 then color = rgb(255,127,0)
if elm = 3 then color = rgb(255,0,0)
if elm = 4 then color = rgb(0,255,0)
if elm = 5 then color = rgb(0,255,255)
if elm = 6 then color = rgb(0,127,255)
if elm = 7 then color = rgb(0,0,255)
if elm = 8 then color = rgb(127,0,255)
if elm = 9 then color = rgb(0,0,50)
if elm = 10 then color = rgb(0,100,0)
if elm = 11 then color = rgb(200,200,0)
if elm = 12 then color = rgb(220,220,220)
if elm = 13 then color = rgb(5,5,5)
ENDFUNCTION color
function action(n,p)
speed# = ship(n).speed
turn# = ship(n).turn
strafe# = ship(n).strafe
if p = 1 then move object up n,speed#
if p = 2 then move object down n,speed#
if p = 3 then roll object left n,turn#
if p = 4 then roll object right n,turn#
if p = 5 then move object left n,strafe#
if p = 6 then move object right n,strafe#
if n = 1 then e = 2 else e = 1
// if object collision(n,e) = 1 : set object collision off n : set object collision off e : else : set object collision on n : set object collision on e : endif
ENDFUNCTION
function makeprogram(lenght)
program$ = ""
for p = 1 to lenght
repeat : stage = rnd(6) : until stage <> prevstate
program$ = program$ + str$(stage)
prevstate = stage
next
ENDFUNCTION program$
function setup_ship(n)
ship(n).element = rnd(13)
ship(n).color = rgb(rnd(254)+1,rnd(254)+1,rnd(254)+1)
ship(n).width = rnd(5)+5
ship(n).height= rnd(5)+7
sw = ship(n).width : sh = ship(n).height : hpbonus = rnd(sw*sh) : hpbase = (sw*sh)/1.5
ship(n).hp = hpbase + hpbonus
ship(n).seed = rnd(5000000000000000000)
ship(n).guns = rnd(4)+1
ship(n).program = makeprogram(rnd(8)+2)
ship(n).speed = (rnd(19)+1) * 0.1
ship(n).turn = (rnd(19)+1) * 0.5
ship(n).strafe = (rnd(19)+1) * 0.1
ship(n).change = rnd(1400)+100
makeship(n,ship(n).width,ship(n).height,ship(n).color)
randomize ship(n).seed
for g = 1 to ship(n).guns
gn = (n * 10)+g
weapon(n,g).available = 1
weapon(n,g).t = rnd(3)
if weapon(n,g).t > 0 : weapon(n,g).u = (100-rnd(200))*0.001 : weapon(n,g).v = (100-rnd(200))*0.001 : else : weapon(n,g).u = 0 : weapon(n,g).v = 0 : endif
weapon(n,g).speed = ((rnd(40)+10)*0.1)
weapon(n,g).amount = RND(9)+1
IF WEAPON(N,G).AMOUNT > 1 THEN weapon(n,g).angle = RND(359) ELSE WEAPON(N,G).ANGLE = 0
weapon(n,g).has_Spread = RND(1)
weapon(n,g).spread = RND(45)
weapon(n,g).range = rnd(135)+15
weapon(n,g).n = gn
weapon(n,g).damage = rnd(49)+1
weapon(n,g).element = rnd(13)
makeshot(WEAPON(N,G).N,t,WEAPON(N,G).ELEMENT)
makesound(weapon(n,g).n)
NEXT
ENDFUNCTION
function computer(n)
if timer() > ship(n).cpu_control
ship(n).cpu_program = wrap(ship(n).cpu_program+1,1,len(ship(n).program))
ship(n).cpu_control = timer() + ship(n).change
endif
p = val(mid$(ship(n).program,ship(n).cpu_program))
autoselectgun(n)
action(n,p)
IF N = 1 THEN E = 2 ELSE E = 1
DIST# = PITTY(OBJECT POSITION X(N),OBJECT POSITION Y(N),OBJECT POSITION X(E),OBJECT POSITION Y(E))
IF ship(n).cpu_wpn > 0
g = ship(n).cpu_wpn
if DIST# <= WEAPON(N,g).RANGE then SHOOT(N,g)
endif
ENDFUNCTION
function reset(n)
ship(n).cpu_program = 0
ENDFUNCTION
function reposition(n)
x = object position x(n)
y = object position y(n)
sx = object screen x(n)
sy = object screen y(n)
if sx < 0 xor sx > screen width() then x = x*(-1)
if sy < 0 xor sy > screen height() then y = y*(-1)
position object n,x,y,0
endfunction
function shoot(n,g)
obj = weapon(n,g).n * 1000
CHK = 0
FOR O = OBJ TO OBJ+9
IF OBJECT EXIST(O) = 1 THEN INC CHK,1
NEXT
IF CHK = 0
if sound exist(weapon(n,g).n) = 1 then play sound weapon(n,g).n
WEAPON(N,G).X = OBJECT POSITION X(N)
WEAPON(N,G).Y = OBJECT POSITION Y(N)
baseangle# = object angle z(n)
IF WEAPON(N,G).AMOUNT > 1 : HALFANGLE# = WEAPON(N,G).ANGLE/2 : ADDANGLE# = WEAPON(N,G).ANGLE / (WEAPON(N,G).AMOUNT-1) : ELSE : ADDANGLE# = 0 : ENDIF
CORRECTANGLE# = 0
AMT = 1
WHILE AMT <= WEAPON(N,G).AMOUNT
INSTANCE OBJECT OBJ,WEAPON(N,G).N
POSITION OBJECT OBJ,WEAPON(N,G).X,WEAPON(N,G).Y,0
IF WEAPON(N,G).HAS_SPREAD = 1
SPREAD# = RND(WEAPON(N,G).SPREAD) - RND(WEAPON(N,G).SPREAD)
else
SPREAD# = 0
ENDIF
ZROTATE OBJECT OBJ,WRAPVALUE(BASEANGLE# - HALFANGLE# + CORRECTANGLE# + SPREAD#)
INC CORRECTANGLE#,ADDANGLE#
INC OBJ,1 : INC AMT,1
ENDWHILE
endif
ENDFUNCTION
FUNCTION DELALL()
FOR O = 100 TO 999999
IF OBJECT EXIST(O) = 1 THEN DELETE OBJECT O
NEXT
ENDFUNCTION
FUNCTION EXPLODESHIP(N)
IF SHIP(N).HP < 0
SHIP(N).HP = 0
IF PARTICLES EXIST(N) = 1 THEN DELETE PARTICLES N
MAKE PARTICLES N,0,1000,SHIP(N).WIDTH+SHIP(N).HEIGHT
POSITION PARTICLES N,OBJECT POSITION X(N),OBJECT POSITION Y(N),0
ROTATE PARTICLES N,90,O,O
SET PARTICLE EMISSIONS N,512
SET PARTICLE SPEED N,0.01
SET PARTICLE VELOCITY N,0
SET PARTICLE FLOOR N,0
SET PARTICLE LIFE N,500
SET PARTICLE GRAVITY N,0
SYNC
HIDE OBJECT N
SET PARTICLE EMISSIONS N,0
DELETE PARTICLES N
ENDIF
ENDFUNCTION
function autoselectgun(n)
if n = 1 then e = 2 else e = 1
x1=object position x(n)
y1=object position y(n)
x2 = object position x(e)
y2 = object position y(e)
dist# = pitty(x1,y1,x2,y2)
ship(n).cpu_wpn = 0
for gun = 1 to ship(n).guns
ship(n).cpu_wpn = wrap(gun,1,ship(n).guns)
if dist# <= weapon(n,gun).range then ship(n).cpu_wpn = gun
next
ENDFUNCTION
function moveshots(n)
for g = 1 to ship(n).guns
scroll object texture weapon(n,g).n,weapon(n,g).u,weapon(n,g).v
FOR OBJ = (WEAPON(N,G).N*1000) TO (WEAPON(N,G).N*1000)+(WEAPON(N,G).AMOUNT-1)
IF OBJECT EXIST(OBJ) = 1
MOVE OBJECT UP OBJ,WEAPON(N,G).SPEED
DIST# = PITTY(OBJECT POSITION X(OBJ),OBJECT POSITION Y(OBJ),WEAPON(N,G).X,WEAPON(N,G).Y)
IF N = 1 THEN E = 2 ELSE E = 1
if object collision(obj,e) = 1 and object hit(obj,e) = 1 : delete object obj : dec ship(e).hp,weapon(n,g).damage : endif
IF DIST# > WEAPON(N,G).RANGE THEN DELETE OBJECT OBJ
ENDIF
NEXT
NEXT
ENDFUNCTION
function makesound(n)
if memblock exist(1) = 1 then delete memblock 1
make memblock 1,1
if sound exist(n) = 1 then delete sound n
frequency# = rnd(1800)+200
length# = rnd(500)+100
loudness# = rnd(7800)+200
bend# = (rnd(99) - rnd(99)) * 0.01
decay# = rnd(999) * 0.001
vibratospeed# = rnd(999) * 0.001
vibratodepth# = rnd(999) * 0.001
tremelospeed# = rnd(999) * 0.001
tremelodepth# = rnd(2500)+500
attack# = rnd(99)*0.01
create sound n,frequency#,length#,loudness#,bend#,decay#,vibratospeed#,vibratodepth#,tremelospeed#,tremelodepth#,attack#
ENDFUNCTION
[size=+2]Forever and one[/size]