; PROJECT : BulletViewer
; AUTHOR : Aaron Matherly
; CREATED : 6/20/2008
; EDITED : 7/29/2008
; ---------------------------------------------------------------------
SetFPS 70
; --------------------------------------------------------------------]
;Variables
; ---------------------------------------------------------------------]
; ---------------------------------------------------------------------]
Type weapon
name$
id
bulsize
bulshape
bes#
besacc#
damage#
bullets
rof
reload
rldTime
clipSize
spread#
swarm#
weight#
phit
ghit
life
lifeacc
fragID
force#
trans
EndType
Dim wep As weapon List
Type bullet
xspeed#
yspeed#
xpos#
ypos#
lived
life
obj
angle#
stuck
bulsize
bulshape
damage
swarm#
weight#
phit
ghit
fragID
force#
trans
EndType
Dim bul As bullet List
Type player
health#
wepID
xspeed#
yspeed#
xpos#
ypos#
clip
rof
angle#
dir
c_up$
c_down$
c_left$
c_right$
c_fire$
c_jump$
EndType
Dim plr As player List
Dim fi As Integer
Dim file As String
Dim cl As String
Dim commands$(1)
; ---------------------------------------------------------------------]
; ---------------------------------------------------------------------]
; ---------------------------------------------------------------------]
;Graphics -------------------------------------------------------------]
; ---------------------------------------------------------------------]
; ---------------------------------------------------------------------]
; ---------------------------------------------------------------------]
; ---------------------------------------------------------------------]
;Loading --------------------------------------------------------------]
; ---------------------------------------------------------------------]
fi = GetFreeFile()
file$ = CurrentDir$()+"weapons.txt"
If Not FileExist(file$) Then End
ReadFile file$,fi
Do
cl$ = Lower$(Trim$(Read(fi)," "))
words = SplitToArray(cl$,"=,",commands$(),1)
If commands$(1) = "endfile" Then ExitDo
If commands$(1) = "new"
wep = New weapon
Do
cl$ = Lower$(Trim$(Read(fi)," "))
words = SplitToArray(cl$,"=,",commands$(),1)
temp$ = commands$(1)
Print commands$(1) + " = " + commands$(2)
Select temp$
Case "name"
wep.name$ = commands$(2)
Case "id"
wep.id = Val(commands$(2))
Case "bulsize"
wep.bulsize = Val(commands$(2))
Case "bulshape"
wep.bulshape = Val(commands$(2))
Case "bes"
wep.bes# = Val#(commands$(2))
Case "besacc"
wep.besacc# = Val#(commands$(2))
Case "damage"
wep.damage# = Val#(commands$(2))
Case "bullets"
wep.bullets = Val(commands$(2))
Case "rof"
wep.rof = Val(commands$(2))
Case "reload"
wep.reload = Val(commands$(2))
Case "rldtime"
wep.rldtime = Val(commands$(2))
Case "clipsize"
wep.clipsize = Val(commands$(2))
Case "spread"
wep.spread# = Val#(commands$(2))
Case "swarm"
wep.swarm# = Val#(commands$(2))
Case "weight"
wep.weight# = Val#(commands$(2))
Case "phit"
wep.phit = Val(commands$(2))
Case "ghit"
wep.ghit = Val(commands$(2))
Case "life"
wep.life = Val(commands$(2))
Case "lifeacc"
wep.lifeacc = Val(commands$(2))
Case "fragid"
wep.fragid = Val(commands$(2))
Case "force"
wep.force = Val#(commands$(2))
Case "trans"
wep.trans = Val#(commands$(2))
Case "endwep"
ExitDo
EndSelect
Loop
Sync
Cls 0
EndIf
Loop
; ---------------------------------------------------------------------]
; ---------------------------------------------------------------------]
; ---------------------------------------------------------------------]
;Main loop ------------------------------------------------------------]
; ---------------------------------------------------------------------]
Dim weaponid As Integer
plr = New player
plr.wepid = 1
For Each wep()
If wep.id = wepid Then ExitFor
Next
plr.rof = wep.rof
plr.dir = -1
plr.xpos# = 100
plr.ypos# = 100
Ink RGB(255,255,255)
Do
Cls 0
If EscKey() Then End
changed = 0
If LeftKey()
plr.wepid = plr.wepid + 1
changed = 1
Wait 200
EndIf
If RightKey()
plr.wepid = plr.wepid - 1
changed = 1
Wait 200
EndIf
If KeyState(17) Then plr.ypos# = plr.ypos# - 1
If KeyState(31) Then plr.ypos# = plr.ypos# + 1
olddir = plr.dir
If KeyState(30)
plr.xpos# = plr.xpos# - 1
plr.dir = 1
EndIf
If KeyState(32)
plr.xpos# = plr.xpos# + 1
plr.dir = -1
EndIf
plr.angle# = AngleFlip(plr.angle#,plr.dir,olddir)
If UpKey() Then plr.angle# = NewAngle(plr.angle#,plr.dir,-3)
If DownKey() Then plr.angle# = NewAngle(plr.angle#,plr.dir,3)
If EnterKey() Then Wait 10
If plr.wepid < 1 Then plr.wepid = 1
For Each wep()
If wep.id = plr.wepid Then ExitFor
Next
If changed
plr.clip = wep.clipsize
plr.rof = wep.rldtime
EndIf
Text 30,30,wep.rof
Text 0,20,wep.id
If plr.clip = 0 And wep.reload = 1
plr.clip = wep.clipsize
plr.rof = wep.rldtime
EndIf
Text 0,40,plr.clip
Text 30,40,wep.clipsize
If SpaceKey() And plr.rof = 0 And plr.clip > 0
plr.rof = wep.rof
plr.clip = plr.clip - 1
makebullet(plr.xpos#,plr.ypos#,0,0,plr.angle#,plr.wepid)
EndIf
plr.rof = plr.rof - 1
If plr.rof < 0 Then plr.rof = 0
Text 0,0,"Arrows change weapon ID"
Text 0,10,wep.name
Text 30,20,plr.wepid
Text 0,30,plr.rof
Text 350,0,FPS()
Dot Cos(plr.angle#)*10+plr.xpos#,Sin(plr.angle#)*10+plr.ypos#
Circle plr.xpos#,plr.ypos#,6,0
UpdateBullets()
Sync
Loop
; ---------------------------------------------------------------------]
; ---------------------------------------------------------------------]
Function NewAngle(Tangle#,Tdir,Tmove#)
Tangle# = Tangle# + 90
If Tdir = -1
Tangle# = Tangle# + Tmove#
If Tangle# <= 5 Then Tangle# = 5
If Tangle# >= 175 Then Tangle# = 175
EndIf
If Tdir = 1
Tangle# = Tangle# - Tmove#
If Tangle# >= -5 Then Tangle# = -5
If Tangle# <= -175 Then Tangle# = -175
EndIf
Tangle# = Tangle# - 90
EndFunction Tangle#
Function AngleFlip(Tangle#,Tdir,Tolddir)
If Tolddir <> Tdir
Tangle# = Tangle# + 90
Tangle# = -Tangle#
Tangle# = Tangle# - 90
EndIf
EndFunction Tangle#
Psub MakeBullet(x#,y#,speedx#,speedy#,angle#,wepid)
For Each wep()
If wep.id = wepid Then ExitFor
Next
For i = 1 To wep.bullets
bul = New bullet
bul.life = wep.life + RndRange(-wep.lifeacc,wep.lifeacc)
bul.angle# = angle#+RndRange#(-wep.spread#,wep.spread#)
bul.xspeed# = Cos(bul.angle#)*(wep.bes#+RndRange#(-wep.besacc#,wep.besacc#)) + speedx#
bul.yspeed# = Sin(bul.angle#)*(wep.bes#+RndRange#(-wep.besacc#,wep.besacc#)) + speedy#
bul.obj = wep.bulshape
bul.xpos = x#
bul.ypos = y#
bul.bulsize = wep.bulsize
bul.bulshape = wep.bulshape
bul.damage = wep.damage
bul.swarm# = wep.swarm#
bul.weight# = wep.weight#
bul.phit = wep.phit
bul.ghit = wep.ghit
bul.fragID = wep.fragID
bul.force# = wep.force#
bul.trans = wep.trans
Next
EndPsub
Psub UpdateBullets()
For Each bul()
bul.lived = bul.lived + 1
If bul.force# <> 0
bul.angle# = bul.angle# + RndRange#(-bul.swarm#,bul.swarm#)
bul.xspeed# = Cos(bul.angle#) * bul.force#
bul.yspeed# = Sin(bul.angle#) * bul.force#
Else
bul.yspeed# = bul.yspeed# + bul.weight#
EndIf
ssx = GetScreenWidth()
ssy = GetScreenHeight()
h = 0
If Not bul.stuck
If bul.xpos# > ssx Or bul.xpos# < 0 Or bul.ypos# > ssy Or bul.ypos# < 0
If bul.ghit = 1
destroy(1)
h = 1
EndIf
If bul.ghit = 2
bul.stuck = On
bul.xpos# = bul.xpos# - bul.xspeed#
bul.ypos# = bul.ypos# - bul.yspeed#
EndIf
EndIf
bul.xpos# = bul.xpos# + bul.xspeed#
bul.ypos# = bul.ypos# + bul.yspeed#
EndIf
DrawBullet(bul.xpos#,bul.ypos#,bul.bulshape,bul.bulsize,bul.angle#)
If bul.lived = bul.life And h = 0 And bul.stuck
destroy(1)
h = 1
EndIf
If bul.lived = bul.life And h = 0
If bul.trans Then destroy(0)
If Not bul.trans Then destroy(1)
EndIf
Next
EndPsub
Function Read(FI)
readline$ = Lower$(ReadString$(FI))
EndFunction readline$
Psub Destroy(Mode)
If Mode = 0
tbul = GetListPos(bul())
MakeBullet(bul.xpos#,bul.ypos#,bul.xspeed#,bul.yspeed#,bul.angle,bul.fragid)
SetListPos bul(), tbul
bul = NULL
EndIf
If Mode = 1
tbul = GetListPos(bul())
bul.angle# = bul.angle# + 180
MakeBullet(bul.xpos#,bul.ypos#,0,0,bul.angle#,bul.fragid)
SetListPos bul(), tbul
bul = NULL
EndIf
EndPsub
Psub DrawBullet(x#,y#,Shape,Size,Angle#)
Select Shape
Case 0
Line x#,y#,Cos(Angle#)*Size+x#,Sin(Angle#)*Size+y#
Case 1
qx1# = Cos(Angle#+20)*Size + x#
qy1# = Sin(Angle#+20)*Size + y#
qx2# = Cos(Angle#-20)*Size + x#
qy2# = Sin(Angle#-20)*Size + y#
qx3# = Cos(Angle#+20+180)*Size + x#
qy3# = Sin(Angle#+20+180)*Size + y#
qx4# = Cos(Angle#-20+180)*Size + x#
qy4# = Sin(Angle#-20+180)*Size + y#
Quad qx1#,qy1#,qx2#,qy2#,qx3#,qy3#,qx4#,qy4#
Case 2
Circle x#,y#,Size,Off
EndSelect
EndPsub