-
Notifications
You must be signed in to change notification settings - Fork 10
/
boof_oop_example.txt
61 lines (49 loc) · 2.16 KB
/
boof_oop_example.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
@name boof oop example
@inputs
@outputs
@persist Objs:table
@trigger
#[ ]#
## E2 Example: boof oop example ##
## ##
## Small object-oriented programming example ##
## for expression 2. ##
## ##
## Press E to spawn bubbles at your aimpos. ##
#[ ]#
# github users: make sure you download these too:
#include "betterhololib"
#include "bettersoundlib"
if( first() ){
runOnTick(1)
function boof(Pos:vector){
local Holo = holoAlloc(Pos) # allocate a holo for this boof object
Sound = holoEntity(Holo):betterSoundPlay("ambient/water/drip"+randint(1,4)+".wav",1) # play a sound
holoMaterial(Holo,"phoenix_storms/pack2/glass")
soundPitch(Sound,random(40,60))
holoModel(Holo,"hq_icosphere")
Boof = table(
"time" = 10,
"scale" = 0,
"scale_vel" = 0,
"holo" = Holo,
"maxscale" = random(4,10)
)
Objs:pushTable(Boof) # push our boof object into our table of objects
}
}
if(changed(owner():keyUse()) & owner():keyUse()){
boof(owner():aimPos()) # spawn a boof
}
for(I=Objs:count(),1,-1){ # iterate over all objects, but backwards so we don't skip any when we delete them
local Boof = Objs[I,table] # get our object
Boof["time",number] = Boof["time",number] - 0.1 # decrease this object's "time" every tick
Boof["scale_vel",number] = Boof["scale_vel",number]*0.7 + ( Boof["maxscale",number]*(Boof["time",number]>2) - Boof["scale",number] )*0.2
Boof["scale",number] = Boof["scale",number] + Boof["scale_vel",number]
if( Boof["time",number] < 0 ){ # time to delete this object
Boof["holo",number]:holoFree() # free up this holo
Objs:remove(I) # remove table entry
continue # nothing else to do here
}
holoScale(Boof["holo",number],vec(Boof["scale",number])) # scale this object's holo according its time
}