performance
This commit is contained in:
parent
5f7c6f7b85
commit
2c2eaf9507
1 changed files with 34 additions and 19 deletions
53
main.go
53
main.go
|
|
@ -73,12 +73,14 @@ type emitter struct {
|
||||||
particleAmount int
|
particleAmount int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var city *scene
|
var city *scene
|
||||||
|
|
||||||
func update_emitters() {
|
func update_emitters() {
|
||||||
for _, e := range city.emitters {
|
for i, e := range city.emitters {
|
||||||
e.update()
|
if remainingParticles := e.update(); remainingParticles == 0 {
|
||||||
|
city.emitters[i] = city.emitters[len(city.emitters)-1]
|
||||||
|
city.emitters = city.emitters[:len(city.emitters)-1]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,7 +99,7 @@ func newEmitter(pos rl.Vector3, particleAmount int) *emitter {
|
||||||
direction = rl.Vector3Normalize(direction)
|
direction = rl.Vector3Normalize(direction)
|
||||||
direction = rl.Vector3Scale(direction, 0.3 + rand.Float32()/3)
|
direction = rl.Vector3Scale(direction, 0.3 + rand.Float32()/3)
|
||||||
particle := particle{
|
particle := particle{
|
||||||
lifetime: rl.GetTime() + 1,
|
lifetime: rl.GetTime() + 2,
|
||||||
speed: direction,
|
speed: direction,
|
||||||
pos: pos,
|
pos: pos,
|
||||||
}
|
}
|
||||||
|
|
@ -107,20 +109,34 @@ func newEmitter(pos rl.Vector3, particleAmount int) *emitter {
|
||||||
return &emitter
|
return &emitter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *emitter) update() {
|
func (e *emitter) update() int {
|
||||||
gravity := rl.NewVector3(0, -0.02, 0)
|
gravity := rl.NewVector3(0, -0.02, 0)
|
||||||
for _, particle := range e.particles {
|
|
||||||
if rl.GetTime() > particle.lifetime {
|
remainingParticles := 0
|
||||||
continue
|
|
||||||
|
rl.BeginBlendMode(rl.BlendAdditive)
|
||||||
|
{
|
||||||
|
for _, particle := range e.particles {
|
||||||
|
if rl.GetTime() > particle.lifetime {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
particle.speed = rl.Vector3Add(particle.speed, gravity)
|
||||||
|
newPos := rl.Vector3Add(particle.pos, particle.speed)
|
||||||
|
if newPos.Y <= 0 {
|
||||||
|
particle.pos.Y = 0
|
||||||
|
} else {
|
||||||
|
particle.pos = newPos
|
||||||
|
}
|
||||||
|
|
||||||
|
rl.DrawCubeV(particle.pos, rl.NewVector3(.1, .1, .1), rl.Yellow)
|
||||||
|
|
||||||
|
remainingParticles += 1
|
||||||
}
|
}
|
||||||
particle.pos = rl.Vector3Add(particle.pos, particle.speed)
|
|
||||||
particle.speed = rl.Vector3Add(particle.speed, gravity)
|
|
||||||
rl.BeginBlendMode(rl.BlendAdditive)
|
|
||||||
{
|
|
||||||
rl.DrawSphere(particle.pos, 0.2, rl.Red)
|
|
||||||
}
|
|
||||||
rl.EndBlendMode()
|
|
||||||
}
|
}
|
||||||
|
rl.EndBlendMode()
|
||||||
|
|
||||||
|
return remainingParticles
|
||||||
}
|
}
|
||||||
|
|
||||||
// retona true caso projétil precise ser destruido
|
// retona true caso projétil precise ser destruido
|
||||||
|
|
@ -130,12 +146,11 @@ func (p *projectile) isHit() bool {
|
||||||
p.pos = rl.Vector3Add(p.pos, p.speed)
|
p.pos = rl.Vector3Add(p.pos, p.speed)
|
||||||
|
|
||||||
if p.pos.Y < 0 {
|
if p.pos.Y < 0 {
|
||||||
city.emitters = append(city.emitters, newEmitter(p.pos, 100))
|
city.emitters = append(city.emitters, newEmitter(p.pos, 500))
|
||||||
for _, building := range city.buildings {
|
for _, building := range city.buildings {
|
||||||
if dist := rl.Vector3Distance(p.pos, building.pos); dist < 10 {
|
if dist := rl.Vector3Distance(p.pos, building.pos); dist < 10 {
|
||||||
building.causeDamage(3)
|
building.causeDamage(3)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
@ -256,7 +271,7 @@ func (hb *healthBar) update() {
|
||||||
|
|
||||||
func newHealthBar(buildings []*building) *healthBar {
|
func newHealthBar(buildings []*building) *healthBar {
|
||||||
return &healthBar{
|
return &healthBar{
|
||||||
life: 3 * len(buildings),
|
life: buildingsHealth * len(buildings),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -266,7 +281,7 @@ func (b *building) causeDamage(damage int) {
|
||||||
}
|
}
|
||||||
b.animate = shakeBuilding(b)
|
b.animate = shakeBuilding(b)
|
||||||
b.life -= damage
|
b.life -= damage
|
||||||
fmt.Println("damage:", damage, "life:", b.life)
|
// fmt.Println("damage:", damage, "life:", b.life)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newBuilding(x, z float32) *building {
|
func newBuilding(x, z float32) *building {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue