-
Notifications
You must be signed in to change notification settings - Fork 1
/
basic_parts.go
138 lines (119 loc) · 2.36 KB
/
basic_parts.go
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package main
import (
"github.com/ByteArena/box2d"
)
type BasicPart struct {
*GameObj
}
func (p *BasicPart) GetBody() *box2d.B2Body {
return p.body
}
func (p *BasicPart) Update(Keys) {}
func ConstructBasicPart(
world *box2d.B2World,
_ Tank,
_ *ParticleSystem,
shipPos box2d.B2Vec2, // TODO: create interface: IHavePosAndSize
shipSize box2d.B2Vec2,
pos box2d.B2Vec2,
sprite Sprite,
ang float64) Part {
shipHalfSize := box2d.B2Vec2MulScalar(0.5, shipSize)
worldPos := box2d.B2Vec2Add(shipPos, pos)
worldPos = box2d.B2Vec2Add(worldPos, shipHalfSize.OperatorNegate())
worldPos = box2d.B2Vec2Add(worldPos, box2d.MakeB2Vec2(0.5, 0.5))
// TODO: fix ship pos. now we use ship pos twice
//pos.OperatorPlusInplace(shipPos)
//pos.OperatorPlusInplace(shipHalfSize.OperatorNegate())
//pos.OperatorPlusInplace(box2d.MakeB2Vec2(0.5, 0.5))
////x := box2d.B2Vec2Add(shipPos, pos)
//x := pos
part := &BasicPart{GameObj: NewGameObj(
world,
sprite,
worldPos,
ang,
0,
box2d.B2Vec2_zero,
DefaultFriction, DefaultFixtureDensity, DefaultFixtureRestitution, true)}
part.GetBody().SetUserData(part)
return part
}
type CabinDef struct {
Dir Direction
}
func (d CabinDef) Construct(
world *box2d.B2World,
tanker Tank,
ps *ParticleSystem,
shipPos box2d.B2Vec2,
shipSize box2d.B2Vec2,
pos box2d.B2Vec2) Part {
return ConstructBasicPart(
world,
tanker,
ps,
shipPos,
shipSize,
pos,
cabinSprite,
d.Dir.GetAng())
}
type BoxDef struct {
}
func (d BoxDef) Construct(
world *box2d.B2World,
tanker Tank,
ps *ParticleSystem,
shipPos box2d.B2Vec2,
shipSize box2d.B2Vec2,
pos box2d.B2Vec2) Part {
return ConstructBasicPart(
world,
tanker,
ps,
shipPos,
shipSize,
pos,
boxSprite,
0)
}
type LegDef struct {
Dir Direction
}
func (d LegDef) Construct(
world *box2d.B2World,
tanker Tank,
ps *ParticleSystem,
shipPos box2d.B2Vec2, // TODO: remove. use ship
shipSize box2d.B2Vec2,
pos box2d.B2Vec2) Part {
return ConstructBasicPart(
world,
tanker,
ps,
shipPos,
shipSize,
pos,
legSprite,
d.Dir.GetAng())
}
type LegFasteningDef struct {
Dir Direction
}
func (d LegFasteningDef) Construct(
world *box2d.B2World,
tanker Tank,
ps *ParticleSystem,
shipPos box2d.B2Vec2,
shipSize box2d.B2Vec2,
pos box2d.B2Vec2) Part {
return ConstructBasicPart(
world,
tanker,
ps, shipPos,
shipSize,
pos,
legFasteningSprite,
d.Dir.GetAng())
}