-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelectricwall.go
50 lines (42 loc) · 1.1 KB
/
electricwall.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
package main
import (
"math"
"github.com/jakecoffman/cp"
"github.com/lafriks/go-tiled"
"github.com/yohamta/ganim8/v2"
)
type electricWall struct {
shape *cp.Shape
drawOptions ganim8.DrawOptions
anim *ganim8.Animation
}
func newElectricWall(obj *tiled.Object, space *cp.Space) *electricWall {
radius := math.Min(obj.Width, obj.Height) / 2.0
x2 := obj.X + obj.Width - radius
y2 := obj.Y + obj.Height - radius
shape := space.AddShape(cp.NewSegment(space.StaticBody, cp.Vector{X: obj.X + radius, Y: obj.Y + radius}, cp.Vector{X: x2, Y: y2}, radius))
shape.SetElasticity(wallElasticity)
shape.SetFriction(wallFriction)
anim := animElectricBlue
if obj.Properties.GetBool("isOrange") {
anim = animElectricOrange
}
return &electricWall{
shape: shape,
drawOptions: ganim8.DrawOptions{
X: obj.X + obj.Width/2.0,
Y: obj.Y + obj.Height/2.0,
OriginX: 0.5,
OriginY: 0.5,
ScaleX: 1.0,
ScaleY: 3.0,
},
anim: anim,
}
}
func (e *electricWall) update() {
e.anim.Update(animDeltaTime)
}
func (e *electricWall) draw() {
e.anim.Draw(imageObjects, &e.drawOptions)
}