remover bulletMoveSpeed de inimigos
This commit is contained in:
parent
1ddc892c70
commit
7fdf53b7ad
1 changed files with 76 additions and 27 deletions
99
main.go
99
main.go
|
|
@ -40,6 +40,8 @@ type player struct {
|
||||||
bulletMoveSpeed float32
|
bulletMoveSpeed float32
|
||||||
hitBoxRadius float32
|
hitBoxRadius float32
|
||||||
bulletSize float32
|
bulletSize float32
|
||||||
|
focusMode bool
|
||||||
|
focusSpeedDecrease float32
|
||||||
}
|
}
|
||||||
|
|
||||||
type enemy struct {
|
type enemy struct {
|
||||||
|
|
@ -48,7 +50,6 @@ type enemy struct {
|
||||||
move movementPattern
|
move movementPattern
|
||||||
shoot shootingPattern
|
shoot shootingPattern
|
||||||
hitBoxRadius float32
|
hitBoxRadius float32
|
||||||
bulletMoveSpeed float32
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g game) insideArena(v rl.Vector2) bool {
|
func (g game) insideArena(v rl.Vector2) bool {
|
||||||
|
|
@ -72,8 +73,29 @@ func (b *bullet) update(g *game, index int) {
|
||||||
rl.DrawCircleV(b.pos, b.size, rl.Yellow)
|
rl.DrawCircleV(b.pos, b.size, rl.Yellow)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ShootAtPlayer(g *game, p *player, rate int,
|
||||||
|
bulletMoveSpeed float32) shootingPattern {
|
||||||
|
return func(e *enemy) {
|
||||||
|
if g.frame % rate != 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
direction := rl.Vector2Subtract(p.pos, e.pos)
|
||||||
|
direction = rl.Vector2Normalize(direction)
|
||||||
|
direction = rl.Vector2Scale(direction, bulletMoveSpeed)
|
||||||
|
|
||||||
func burstShootAtPlayer(g *game, p *player) shootingPattern {
|
g.bullets = append(g.bullets, &bullet{
|
||||||
|
speed: direction,
|
||||||
|
size: 12,
|
||||||
|
dmg: 1,
|
||||||
|
enemy: true,
|
||||||
|
pos: e.pos,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func burstShootAtPlayer(g *game, p *player,
|
||||||
|
rate int, bulletMoveSpeed float32) shootingPattern {
|
||||||
flag := true
|
flag := true
|
||||||
return func(e *enemy) {
|
return func(e *enemy) {
|
||||||
if g.frame % 100 == 0 {
|
if g.frame % 100 == 0 {
|
||||||
|
|
@ -84,13 +106,13 @@ func burstShootAtPlayer(g *game, p *player) shootingPattern {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if g.frame % 2 == 0 {
|
if g.frame % rate != 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
direction := rl.Vector2Subtract(p.pos, e.pos)
|
direction := rl.Vector2Subtract(p.pos, e.pos)
|
||||||
direction = rl.Vector2Normalize(direction)
|
direction = rl.Vector2Normalize(direction)
|
||||||
direction = rl.Vector2Scale(direction, e.bulletMoveSpeed)
|
direction = rl.Vector2Scale(direction, bulletMoveSpeed)
|
||||||
|
|
||||||
g.bullets = append(g.bullets, &bullet{
|
g.bullets = append(g.bullets, &bullet{
|
||||||
speed: direction,
|
speed: direction,
|
||||||
|
|
@ -225,6 +247,14 @@ func (e *enemy) update(g *game, index int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *player) move(g *game) {
|
func (p *player) move(g *game) {
|
||||||
|
|
||||||
|
var moveSpeed float32
|
||||||
|
if p.focusMode {
|
||||||
|
moveSpeed = p.moveSpeed * p.focusSpeedDecrease
|
||||||
|
} else {
|
||||||
|
moveSpeed = p.moveSpeed
|
||||||
|
}
|
||||||
|
|
||||||
p.speed = rl.Vector2{X: 0, Y: 0}
|
p.speed = rl.Vector2{X: 0, Y: 0}
|
||||||
|
|
||||||
if rl.IsKeyDown(rl.KeyW) { p.speed.Y -= 1 }
|
if rl.IsKeyDown(rl.KeyW) { p.speed.Y -= 1 }
|
||||||
|
|
@ -235,7 +265,7 @@ func (p *player) move(g *game) {
|
||||||
if !(p.speed.X == 0 && p.speed.Y == 0) {
|
if !(p.speed.X == 0 && p.speed.Y == 0) {
|
||||||
// jogador se move mais rapido na diagonal caso o contrario
|
// jogador se move mais rapido na diagonal caso o contrario
|
||||||
p.speed = rl.Vector2Normalize(p.speed)
|
p.speed = rl.Vector2Normalize(p.speed)
|
||||||
p.speed = rl.Vector2Scale(p.speed, p.moveSpeed)
|
p.speed = rl.Vector2Scale(p.speed, moveSpeed)
|
||||||
}
|
}
|
||||||
|
|
||||||
result := rl.Vector2Add(p.pos, p.speed)
|
result := rl.Vector2Add(p.pos, p.speed)
|
||||||
|
|
@ -253,6 +283,10 @@ func (p *player) move(g *game) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *player) shoot(g *game){
|
func (p *player) shoot(g *game){
|
||||||
|
if p.focusMode {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if g.frame % 5 != 0 {
|
if g.frame % 5 != 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -288,8 +322,19 @@ func (p *player) checkHit(g *game) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *player) checkFocus() {
|
||||||
|
// raylib não entende keybindings customizadas através do xmodmap?
|
||||||
|
if rl.IsKeyDown(rl.KeyLeftShift) || rl.IsKeyDown(rl.KeyRightShift) {
|
||||||
|
p.focusMode = true
|
||||||
|
} else {
|
||||||
|
p.focusMode = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (p *player) update(g *game) {
|
func (p *player) update(g *game) {
|
||||||
|
|
||||||
|
p.checkFocus()
|
||||||
|
|
||||||
p.move(g)
|
p.move(g)
|
||||||
|
|
||||||
p.shoot(g)
|
p.shoot(g)
|
||||||
|
|
@ -299,6 +344,9 @@ func (p *player) update(g *game) {
|
||||||
// hitbox
|
// hitbox
|
||||||
rl.DrawCircleV(p.pos, p.hitBoxRadius, rl.Red)
|
rl.DrawCircleV(p.pos, p.hitBoxRadius, rl.Red)
|
||||||
|
|
||||||
|
if p.focusMode {
|
||||||
|
return
|
||||||
|
}
|
||||||
// mira
|
// mira
|
||||||
mouse := rl.GetMousePosition()
|
mouse := rl.GetMousePosition()
|
||||||
inverted := rl.Vector2Subtract(p.pos, mouse)
|
inverted := rl.Vector2Subtract(p.pos, mouse)
|
||||||
|
|
@ -314,8 +362,12 @@ func main() {
|
||||||
state := &game{arenaWidth: 450, arenaHeight: 700, interfaceWidth: 300}
|
state := &game{arenaWidth: 450, arenaHeight: 700, interfaceWidth: 300}
|
||||||
|
|
||||||
player := player{
|
player := player{
|
||||||
pos: rl.Vector2{X: 100, Y: 100},
|
pos: rl.Vector2{
|
||||||
|
X: float32(state.arenaWidth) / 2,
|
||||||
|
Y: float32(state.arenaHeight) * 0.8,
|
||||||
|
},
|
||||||
moveSpeed: 4,
|
moveSpeed: 4,
|
||||||
|
focusSpeedDecrease: 0.5,
|
||||||
bulletMoveSpeed: 13,
|
bulletMoveSpeed: 13,
|
||||||
bulletSize: 8,
|
bulletSize: 8,
|
||||||
hitBoxRadius: 5,
|
hitBoxRadius: 5,
|
||||||
|
|
@ -328,22 +380,19 @@ func main() {
|
||||||
state.enemies = []*enemy{
|
state.enemies = []*enemy{
|
||||||
{
|
{
|
||||||
pos: rl.Vector2{X: 200, Y: 200},
|
pos: rl.Vector2{X: 200, Y: 200},
|
||||||
|
health: 100,
|
||||||
|
hitBoxRadius: 20,
|
||||||
|
move: horizonalPattern(state),
|
||||||
|
shoot: burstShootAtPlayer(state, &player, 8, 4),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: rl.Vector2{X: 169, Y: 285},
|
||||||
health: 10,
|
health: 10,
|
||||||
hitBoxRadius:10,
|
hitBoxRadius:10,
|
||||||
bulletMoveSpeed: 6,
|
|
||||||
move: horizonalPattern(state),
|
move: horizonalPattern(state),
|
||||||
// shoot: shootStraightDown(state),
|
shoot: ShootAtPlayer(state, &player, 16, 3),
|
||||||
shoot: burstShootAtPlayer(state, &player),
|
|
||||||
},
|
},
|
||||||
// {
|
// {
|
||||||
// pos: rl.Vector2{X: 169, Y: 222},
|
|
||||||
// health: 10,
|
|
||||||
// hitBoxRadius:10,
|
|
||||||
// bulletMoveSpeed: 6,
|
|
||||||
// move: horizonalPattern(state),
|
|
||||||
// shoot: shootStraightDown(state),
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// pos: rl.Vector2{X: 400, Y: 400},
|
// pos: rl.Vector2{X: 400, Y: 400},
|
||||||
// health: 10,
|
// health: 10,
|
||||||
// hitBoxRadius:10,
|
// hitBoxRadius:10,
|
||||||
|
|
@ -351,14 +400,14 @@ func main() {
|
||||||
// move: foobarPattern(state),
|
// move: foobarPattern(state),
|
||||||
// shoot: shootStraightDown(state),
|
// shoot: shootStraightDown(state),
|
||||||
// },
|
// },
|
||||||
{
|
// {
|
||||||
pos: rl.Vector2{X: 200, Y: 200},
|
// pos: rl.Vector2{X: 200, Y: 200},
|
||||||
health: 10,
|
// health: 10,
|
||||||
hitBoxRadius:10,
|
// hitBoxRadius:10,
|
||||||
bulletMoveSpeed: 6,
|
// bulletMoveSpeed: 6,
|
||||||
move: shootStill(),
|
// move: shootStill(),
|
||||||
shoot: shootStraightDown(state),
|
// shoot: shootStraightDown(state),
|
||||||
},
|
// },
|
||||||
}
|
}
|
||||||
|
|
||||||
currectScore := 0
|
currectScore := 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue