implementar explosão de balas
This commit is contained in:
parent
7fdf53b7ad
commit
c90fd3d14a
1 changed files with 51 additions and 25 deletions
76
main.go
76
main.go
|
|
@ -2,13 +2,17 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
// diz para um inimigo como ele deve se mover
|
||||
type movementPattern func(*enemy)rl.Vector2
|
||||
// diz para um inimigo em que condições atirar. acionado pelo movementPattern
|
||||
type shootingPattern func(*enemy)
|
||||
// diz para uma bala como ela deve se mover.
|
||||
type bulletMovementPattern func(*bullet)rl.Vector2
|
||||
|
||||
type hazard interface { // inimigos e projéteis
|
||||
|
|
@ -73,6 +77,36 @@ func (b *bullet) update(g *game, index int) {
|
|||
rl.DrawCircleV(b.pos, b.size, rl.Yellow)
|
||||
}
|
||||
|
||||
func bulletExplosion(g *game, rate, amount int, bulletSpeed, size float32) shootingPattern {
|
||||
return func(e *enemy) {
|
||||
if g.frame % rate != 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// radius := e.hitBoxRadius
|
||||
|
||||
var bullets []*bullet
|
||||
|
||||
for i := 0; i < amount; i++ {
|
||||
angle := 2.0 * math.Pi * float64(i) / float64(amount)
|
||||
cos := math.Cos(angle)
|
||||
sin := math.Sin(angle)
|
||||
direction := rl.Vector2{X: float32(cos), Y: float32(sin)}
|
||||
direction = rl.Vector2Scale(direction, bulletSpeed)
|
||||
|
||||
bullets = append(bullets, &bullet{
|
||||
speed: direction,
|
||||
size: size,
|
||||
dmg: 1,
|
||||
enemy: true,
|
||||
pos: e.pos,
|
||||
})
|
||||
}
|
||||
|
||||
g.bullets = append(g.bullets, bullets...)
|
||||
}
|
||||
}
|
||||
|
||||
func ShootAtPlayer(g *game, p *player, rate int,
|
||||
bulletMoveSpeed float32) shootingPattern {
|
||||
return func(e *enemy) {
|
||||
|
|
@ -93,7 +127,6 @@ bulletMoveSpeed float32) shootingPattern {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
func burstShootAtPlayer(g *game, p *player,
|
||||
rate int, bulletMoveSpeed float32) shootingPattern {
|
||||
flag := true
|
||||
|
|
@ -287,7 +320,7 @@ func (p *player) shoot(g *game){
|
|||
return
|
||||
}
|
||||
|
||||
if g.frame % 5 != 0 {
|
||||
if g.frame % 3 != 0 {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -368,8 +401,8 @@ func main() {
|
|||
},
|
||||
moveSpeed: 4,
|
||||
focusSpeedDecrease: 0.5,
|
||||
bulletMoveSpeed: 13,
|
||||
bulletSize: 8,
|
||||
bulletMoveSpeed: 6,
|
||||
bulletSize: 9,
|
||||
hitBoxRadius: 5,
|
||||
}
|
||||
|
||||
|
|
@ -383,31 +416,22 @@ func main() {
|
|||
health: 100,
|
||||
hitBoxRadius: 20,
|
||||
move: horizonalPattern(state),
|
||||
shoot: burstShootAtPlayer(state, &player, 8, 4),
|
||||
shoot: bulletExplosion(state, 60, 20, 2, 11),
|
||||
},
|
||||
{
|
||||
pos: rl.Vector2{X: 169, Y: 285},
|
||||
health: 10,
|
||||
hitBoxRadius:10,
|
||||
pos: rl.Vector2{X: 100, Y: 100},
|
||||
health: 100,
|
||||
hitBoxRadius: 20,
|
||||
move: horizonalPattern(state),
|
||||
shoot: ShootAtPlayer(state, &player, 16, 3),
|
||||
shoot: burstShootAtPlayer(state, &player, 20, 4),
|
||||
},
|
||||
{
|
||||
pos: rl.Vector2{X: 50, Y: 250},
|
||||
health: 100,
|
||||
hitBoxRadius: 20,
|
||||
move: horizonalPattern(state),
|
||||
shoot: bulletExplosion(state, 60, 20, 2, 11),
|
||||
},
|
||||
// {
|
||||
// pos: rl.Vector2{X: 400, Y: 400},
|
||||
// health: 10,
|
||||
// hitBoxRadius:10,
|
||||
// bulletMoveSpeed: 6,
|
||||
// move: foobarPattern(state),
|
||||
// shoot: shootStraightDown(state),
|
||||
// },
|
||||
// {
|
||||
// pos: rl.Vector2{X: 200, Y: 200},
|
||||
// health: 10,
|
||||
// hitBoxRadius:10,
|
||||
// bulletMoveSpeed: 6,
|
||||
// move: shootStill(),
|
||||
// shoot: shootStraightDown(state),
|
||||
// },
|
||||
}
|
||||
|
||||
currectScore := 0
|
||||
|
|
@ -437,6 +461,8 @@ func main() {
|
|||
currectScore += (state.score - currectScore) / 11
|
||||
rl.DrawText(strconv.Itoa(currectScore), state.arenaWidth, 0, 50, rl.White)
|
||||
|
||||
rl.DrawText(strconv.Itoa(len(state.bullets)), state.arenaWidth, 50, 50, rl.White)
|
||||
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue