Hey all!
Was feeling bored and couldn't think what to make so I made this! Use the mouse to move the player and left click to shoot. Aim with W,A,S+D.
rem Set screen resolution
set display mode 800,600,32
rem Hide loading
sync on
sync rate 60
sync
text 0,0,"LOADING"
sync
rem Enable backdrop
backdrop on
color backdrop 0
rem Start up Cloggy's dll
d3d_init
rem Make a font
d3d_font 1,"Courier",30,1,0,0
rem Set up types
type XYFloat
X as float
Y as float
endtype
type Blob
Exist as boolean
Position as XYFloat
Velocity as float
Angle as float
Size as integer
endtype
type Player
Position as XYFloat
Velocity as float
Angle as float
GunAngle as float
Score as integer
endtype
type Bullet
Life as integer
Position as XYFloat
Velocity as float
Angle as float
endtype
rem Declare variables
global dim Blob(100) as Blob
global Player as Player
global dim Bullet(40) as Bullet
rem Initial values
Player.Position.X=400.0
Player.Position.Y=300.0
rem Local variables
SpawnTime as integer
BulletTime as integer
mx as float
my as float
click as integer
oldclick as integer
rem Make vector for distance checks
v=make vector2(1)
rem Lock frame rate
sync on
sync rate 60
rem Start the main loop
do
rem Spawn blobs
inc SpawnTime,1
if SpawnTime=30
SpawnTime=0
eb=-2
b=0
while eb=-2
if Blob(b).Exist=0
eb=b
else
inc b,1
if b=50
eb=-1
endif
endif
endwhile
if eb>-1
x=4+rnd(792)
y=4+rnd(592)
Blob(eb).Exist=1
Blob(eb).Position.X=x
Blob(eb).Position.Y=y
Blob(eb).Velocity=1+rnd(2)
Blob(eb).Angle=rnd(360)
Blob(eb).Size=4
endif
endif
rem Control blobs
for b=0 to 99
if Blob(b).Exist=1
Blob(b).Position.X=Blob(b).Position.X+(sin(Blob(b).Angle)*Blob(b).Velocity)
Blob(b).Position.Y=Blob(b).Position.Y+(cos(Blob(b).Angle)*Blob(b).Velocity)
if Blob(b).Position.X<Blob(b).Size
Blob(b).Position.X=Blob(b).Size
Blob(b).Angle=360.0-Blob(b).Angle
endif
if Blob(b).Position.X>(800-Blob(b).Size)
Blob(b).Position.X=(800-Blob(b).Size)
Blob(b).Angle=360.0-Blob(b).Angle
endif
if Blob(b).Position.Y<Blob(b).Size
Blob(b).Position.Y=Blob(b).Size
Blob(b).Angle=180.0-Blob(b).Angle
endif
if Blob(b).Position.Y>(600-Blob(b).Size)
Blob(b).Position.Y=(600-Blob(b).Size)
Blob(b).Angle=180.0-Blob(b).Angle
endif
for i=0 to 99
if i<>b
if Blob(i).Exist=1
xdif#=abs(Blob(i).Position.X-Blob(b).Position.X)
if xdif#<(Blob(i).Size+Blob(b).Size)
ydif#=abs(Blob(i).Position.Y-Blob(b).Position.Y)
if xdif#<(Blob(i).Size+Blob(b).Size)
set vector2 1,xdif#,ydif#
d#=length vector2(1)
if d#<(Blob(i).Size+Blob(b).Size)
Blob(i).Exist=0
x#=((Blob(i).Position.X*Blob(i).Size)+(Blob(b).Position.X*Blob(b).Size))/(Blob(i).Size+Blob(b).Size)
y#=((Blob(i).Position.Y*Blob(i).Size)+(Blob(b).Position.Y*Blob(b).Size))/(Blob(i).Size+Blob(b).Size)
Blob(b).Position.X=x#
Blob(b).Position.Y=y#
if Blob(b).Size>Blob(i).Size
a#=Blob(b).Angle
v#=Blob(b).Velocity
else
a#=Blob(i).Angle
v#=Blob(i).Velocity
endif
Blob(b).Angle=a#
Blob(b).Velocity=v#
inc Blob(b).Size,Blob(i).Size
endif
endif
endif
endif
endif
next i
for i=0 to 39
if Bullet(i).Life>0
xdif#=abs(Bullet(i).Position.X-Blob(b).Position.X)
if xdif#<(2.0+Blob(b).Size)
ydif#=abs(Bullet(i).Position.Y-Blob(b).Position.Y)
if xdif#<(2.0+Blob(b).Size)
set vector2 1,xdif#,ydif#
d#=length vector2(1)
if d#<(2.0+Blob(b).Size)
Player.Score=Player.Score+5
Bullet(i).Life=0
s=(Blob(b).Size-1)/4
for o=1 to s
eb=-2
tb=0
while eb=-2
if Blob(tb).Exist=0
eb=tb
else
inc tb,1
if tb=100
eb=-1
endif
endif
endwhile
if eb>-1
x=Blob(b).Position.X
y=Blob(b).Position.Y
Blob(eb).Exist=1
Blob(eb).Velocity=1+rnd(2)
Blob(eb).Angle=o*(360/s)
Blob(eb).Position.X=x+(sin(Blob(eb).Angle)*Blob(eb).Velocity*o*4.0)
Blob(eb).Position.Y=y+(cos(Blob(eb).Angle)*Blob(eb).Velocity*o*4.0)
Blob(eb).Size=4
endif
next o
if Blob(b).Size>4
Blob(b).Size=4
else
Blob(b).Exist=0
Player.Score=Player.Score+10
endif
endif
endif
endif
endif
next i
xdif#=abs(Player.Position.X-Blob(b).Position.X)
if xdif#<(8.0+Blob(b).Size)
ydif#=abs(Player.Position.Y-Blob(b).Position.Y)
if xdif#<(8.0+Blob(b).Size)
set vector2 1,xdif#,ydif#
d#=length vector2(1)
if d#<(8.0+Blob(b).Size)
while scancode()=0
rem Draw blobs
d3d_color 255,0,0,255
for b=0 to 99
if Blob(b).Exist=1
d3d_circle Blob(b).Position.X,Blob(b).Position.Y,Blob(b).Size,0
endif
next b
rem Draw bullets
for b=0 to 39
if Bullet(b).Life>0
d3d_color 0,255,0,Bullet(b).Life
d3d_circle Bullet(b).Position.X,Bullet(b).Position.Y,2,0
endif
next b
rem Show score
d3d_color 255,255,255,92
d3d_box 200,0,600,26
d3d_color 255,255,255,255
d3d_line 200,0,600,0
d3d_line 200,0,200,26
d3d_line 200,26,600,26
d3d_line 600,0,600,26
d3d_starttext
d3d_text 1,400,0,1,"SCORE: "+str$(Player.Score)
d3d_text 1,400,100,1,"GAME OVER"
d3d_text 1,400,200,1,"(press any key)"
d3d_endtext
rem Update the screen
sync
endwhile
for b=0 to 99
Blob(b).Exist=0
next b
for b=0 to 39
Bullet(b).Life=0
next b
Player.Position.X=400.0
Player.Position.Y=300.0
Player.Score=0
Player.Velocity=0.0
endif
endif
endif
endif
next b
rem Control player
mx=mousemovex()
my=mousemovey()
set vector2 1,mx,my
Player.Velocity=length vector2(1)*0.5
Player.Angle=atanfull(mx,my)
Player.Position.X=Player.Position.X+(sin(Player.Angle)*Player.Velocity)
Player.Position.Y=Player.Position.Y+(cos(Player.Angle)*Player.Velocity)
if Player.Position.X<8
Player.Position.X=8
endif
if Player.Position.X>792
Player.Position.X=792
endif
if Player.Position.Y<8
Player.Position.Y=8
endif
if Player.Position.Y>592
Player.Position.Y=592
endif
rem Aim gun
W=keystate(17)
A=keystate(30)
S=keystate(31)
D=keystate(32)
if W=1
if S=0
if A=0
if D=0
Player.GunAngle=curveangle(180.0,Player.GunAngle,5)
else
Player.GunAngle=curveangle(135.0,Player.GunAngle,5)
endif
else
if D=0
Player.GunAngle=curveangle(225.0,Player.GunAngle,5)
endif
endif
endif
else
if S=1
if A=0
if D=0
Player.GunAngle=curveangle(0.0,Player.GunAngle,5)
else
Player.GunAngle=curveangle(45.0,Player.GunAngle,5)
endif
else
if D=0
Player.GunAngle=curveangle(315.0,Player.GunAngle,5)
endif
endif
else
if A=1
if D=0
Player.GunAngle=curveangle(270.0,Player.GunAngle,5)
endif
else
if D=1
Player.GunAngle=curveangle(90.0,Player.GunAngle,5)
endif
endif
endif
endif
rem Shoot
if BulletTime>0
dec BulletTime,1
endif
click=mouseclick()
if click=1
if BulletTime=0
BulletTime=7
eb=-2
b=0
while eb=-2
if Bullet(b).Life=0
eb=b
else
inc b,1
if b=40
eb=-1
endif
endif
endwhile
if eb>-1
x=4+rnd(792)
y=4+rnd(592)
Bullet(eb).Life=256
Bullet(eb).Position.X=Player.Position.X
Bullet(eb).Position.Y=Player.Position.Y
Bullet(eb).Velocity=3
Bullet(eb).Angle=Player.GunAngle
endif
endif
endif
rem Control bullets
for b=0 to 39
if Bullet(b).Life>0
dec Bullet(b).Life,4
Bullet(b).Position.X=Bullet(b).Position.X+(sin(Bullet(b).Angle)*Bullet(b).Velocity)
Bullet(b).Position.Y=Bullet(b).Position.Y+(cos(Bullet(b).Angle)*Bullet(b).Velocity)
if Bullet(b).Position.X<2 or Bullet(b).Position.X>798 or Bullet(b).Position.Y<2 or Bullet(b).Position.Y>598
Bullet(b).Life=0
endif
endif
next b
rem Draw blobs
d3d_color 255,0,0,255
for b=0 to 99
if Blob(b).Exist=1
d3d_circle Blob(b).Position.X,Blob(b).Position.Y,Blob(b).Size,0
endif
next b
rem Draw bullets
for b=0 to 39
if Bullet(b).Life>0
d3d_color 0,255,0,Bullet(b).Life
d3d_circle Bullet(b).Position.X,Bullet(b).Position.Y,2,0
endif
next b
rem Draw player
d3d_color 255,255,255,255
d3d_circle Player.Position.X,Player.Position.Y,8,0
sx=Player.Position.X+(sin(Player.GunAngle+90)*2.0)
sy=Player.Position.Y+(cos(Player.GunAngle+90)*2.0)
x=sx+(sin(Player.GunAngle)*12.0)
y=sy+(cos(Player.GunAngle)*12.0)
d3d_line x,y,sx,sy
sx=Player.Position.X+(sin(Player.GunAngle-90)*2.0)
sy=Player.Position.Y+(cos(Player.GunAngle-90)*2.0)
x=sx+(sin(Player.GunAngle)*12.0)
y=sy+(cos(Player.GunAngle)*12.0)
d3d_line x,y,sx,sy
rem Show score
d3d_color 255,255,255,92
d3d_box 200,0,600,26
d3d_color 255,255,255,255
d3d_line 200,0,600,0
d3d_line 200,0,200,26
d3d_line 200,26,600,26
d3d_line 600,0,600,26
d3d_starttext
d3d_text 1,400,0,1,"SCORE: "+str$(Player.Score)
d3d_endtext
rem Update the screen
sync
rem End the loop
loop
Have fun!
T3H_C0D3R3R