From 7fdf53b7ad38b83c776cf50097ccad8217da49f1 Mon Sep 17 00:00:00 2001 From: silva guimaraes Date: Sun, 23 Jul 2023 14:21:36 -0300 Subject: [PATCH] remover bulletMoveSpeed de inimigos --- main.go | 103 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 76 insertions(+), 27 deletions(-) diff --git a/main.go b/main.go index 3b56283..412ec92 100644 --- a/main.go +++ b/main.go @@ -40,6 +40,8 @@ type player struct { bulletMoveSpeed float32 hitBoxRadius float32 bulletSize float32 + focusMode bool + focusSpeedDecrease float32 } type enemy struct { @@ -48,7 +50,6 @@ type enemy struct { move movementPattern shoot shootingPattern hitBoxRadius float32 - bulletMoveSpeed float32 } 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) } +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 return func(e *enemy) { if g.frame % 100 == 0 { @@ -84,13 +106,13 @@ func burstShootAtPlayer(g *game, p *player) shootingPattern { return } - if g.frame % 2 == 0 { + if g.frame % rate != 0 { return } direction := rl.Vector2Subtract(p.pos, e.pos) direction = rl.Vector2Normalize(direction) - direction = rl.Vector2Scale(direction, e.bulletMoveSpeed) + direction = rl.Vector2Scale(direction, bulletMoveSpeed) g.bullets = append(g.bullets, &bullet{ speed: direction, @@ -225,6 +247,14 @@ func (e *enemy) update(g *game, index int) { } 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} 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) { // jogador se move mais rapido na diagonal caso o contrario 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) @@ -253,6 +283,10 @@ func (p *player) move(g *game) { } func (p *player) shoot(g *game){ + if p.focusMode { + return + } + if g.frame % 5 != 0 { 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) { + p.checkFocus() + p.move(g) p.shoot(g) @@ -299,6 +344,9 @@ func (p *player) update(g *game) { // hitbox rl.DrawCircleV(p.pos, p.hitBoxRadius, rl.Red) + if p.focusMode { + return + } // mira mouse := rl.GetMousePosition() inverted := rl.Vector2Subtract(p.pos, mouse) @@ -314,8 +362,12 @@ func main() { state := &game{arenaWidth: 450, arenaHeight: 700, interfaceWidth: 300} 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, + focusSpeedDecrease: 0.5, bulletMoveSpeed: 13, bulletSize: 8, hitBoxRadius: 5, @@ -328,21 +380,18 @@ func main() { state.enemies = []*enemy{ { pos: rl.Vector2{X: 200, Y: 200}, - health: 10, - hitBoxRadius: 10, - bulletMoveSpeed: 6, + health: 100, + hitBoxRadius: 20, move: horizonalPattern(state), - // shoot: shootStraightDown(state), - shoot: burstShootAtPlayer(state, &player), + shoot: burstShootAtPlayer(state, &player, 8, 4), + }, + { + pos: rl.Vector2{X: 169, Y: 285}, + health: 10, + hitBoxRadius:10, + move: horizonalPattern(state), + shoot: ShootAtPlayer(state, &player, 16, 3), }, - // { - // 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}, // health: 10, @@ -351,14 +400,14 @@ func main() { // move: foobarPattern(state), // shoot: shootStraightDown(state), // }, - { - pos: rl.Vector2{X: 200, Y: 200}, - health: 10, - hitBoxRadius:10, - bulletMoveSpeed: 6, - move: shootStill(), - shoot: shootStraightDown(state), - }, + // { + // pos: rl.Vector2{X: 200, Y: 200}, + // health: 10, + // hitBoxRadius:10, + // bulletMoveSpeed: 6, + // move: shootStill(), + // shoot: shootStraightDown(state), + // }, } currectScore := 0