implementar padrões de movimentos diferentes
This commit is contained in:
parent
aa2bd3fbfd
commit
8ea76d27ca
1 changed files with 30 additions and 3 deletions
33
main.go
33
main.go
|
|
@ -39,8 +39,8 @@ type player struct {
|
||||||
type enemy struct {
|
type enemy struct {
|
||||||
pos rl.Vector2
|
pos rl.Vector2
|
||||||
health int
|
health int
|
||||||
movePattern movementPattern
|
movePattern func(*enemy)rl.Vector2
|
||||||
shootPattern shootingPattern
|
shootPattern func()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g game) insideArena(v rl.Vector2) bool {
|
func (g game) insideArena(v rl.Vector2) bool {
|
||||||
|
|
@ -74,9 +74,29 @@ func (e *enemy) shoot(g *game) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func horizonalPattern(g *game) (func(*enemy)rl.Vector2) {
|
||||||
|
direction := rl.Vector2{X: 4, Y: 0}
|
||||||
|
|
||||||
|
return func(e *enemy) rl.Vector2 {
|
||||||
|
result := rl.Vector2Add(direction, e.pos)
|
||||||
|
|
||||||
|
if !g.insideArena(result) {
|
||||||
|
direction = rl.Vector2Negate(direction)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func (e *enemy) update(g *game) {
|
func (e *enemy) update(g *game) {
|
||||||
rl.DrawCircleV(e.pos, 5, rl.Blue)
|
|
||||||
|
if e.movePattern != nil {
|
||||||
|
e.pos = e.movePattern(e)
|
||||||
|
}
|
||||||
|
|
||||||
e.shoot(g)
|
e.shoot(g)
|
||||||
|
|
||||||
|
rl.DrawCircleV(e.pos, 5, rl.Blue)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *player) move() {
|
func (p *player) move() {
|
||||||
|
|
@ -87,6 +107,10 @@ func (p *player) move() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *player) shoot(g *game){
|
func (p *player) shoot(g *game){
|
||||||
|
if g.time % 10 != 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
||||||
// não leva em consideração a velocidade do jogador
|
// não leva em consideração a velocidade do jogador
|
||||||
mouse := rl.GetMousePosition()
|
mouse := rl.GetMousePosition()
|
||||||
|
|
@ -154,14 +178,17 @@ func main() {
|
||||||
state.enemies = append(state.enemies, &enemy{
|
state.enemies = append(state.enemies, &enemy{
|
||||||
pos: rl.Vector2{X: 200, Y: 200},
|
pos: rl.Vector2{X: 200, Y: 200},
|
||||||
health: 10,
|
health: 10,
|
||||||
|
movePattern: horizonalPattern(state),
|
||||||
})
|
})
|
||||||
state.enemies = append(state.enemies, &enemy{
|
state.enemies = append(state.enemies, &enemy{
|
||||||
pos: rl.Vector2{X: 169, Y: 222},
|
pos: rl.Vector2{X: 169, Y: 222},
|
||||||
health: 10,
|
health: 10,
|
||||||
|
movePattern: horizonalPattern(state),
|
||||||
})
|
})
|
||||||
state.enemies = append(state.enemies, &enemy{
|
state.enemies = append(state.enemies, &enemy{
|
||||||
pos: rl.Vector2{X: 219, Y: 195},
|
pos: rl.Vector2{X: 219, Y: 195},
|
||||||
health: 10,
|
health: 10,
|
||||||
|
movePattern: horizonalPattern(state),
|
||||||
})
|
})
|
||||||
|
|
||||||
for ; !rl.WindowShouldClose(); state.time += 1 {
|
for ; !rl.WindowShouldClose(); state.time += 1 {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue