Backup
This commit is contained in:
parent
a411573a06
commit
d50bed0777
2 changed files with 292 additions and 143 deletions
186
player.go
186
player.go
|
|
@ -1,9 +1,36 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
type player struct {
|
||||
pos rl.Vector2
|
||||
speed rl.Vector2
|
||||
direction rl.Vector2
|
||||
moveSpeed float32
|
||||
bulletMoveSpeed float32
|
||||
hitBoxRadius float32
|
||||
shoot shootingPattern
|
||||
bulletSize float32
|
||||
focusMode bool
|
||||
focusSpeedDecrease float32
|
||||
}
|
||||
|
||||
func (p *player) Pos() rl.Vector2 {
|
||||
return p.pos
|
||||
}
|
||||
|
||||
func (p *player) SetPos(x rl.Vector2) {
|
||||
p.pos = x
|
||||
}
|
||||
|
||||
func (p *player) Direction() rl.Vector2 {
|
||||
return p.direction
|
||||
}
|
||||
|
||||
func (p *player) move(g *game) {
|
||||
|
||||
var moveSpeed float32
|
||||
|
|
@ -34,7 +61,7 @@ func (p *player) move(g *game) {
|
|||
p.speed = rl.Vector2Scale(p.speed, moveSpeed)
|
||||
}
|
||||
|
||||
result := rl.Vector2Add(p.pos, p.speed)
|
||||
result := rl.Vector2Add(p.pos, rl.Vector2Scale(p.speed, rl.GetFrameTime()))
|
||||
|
||||
if result.Y-p.hitBoxRadius < 0 || result.Y+p.hitBoxRadius > float32(g.arenaHeight) {
|
||||
p.speed.Y = 0
|
||||
|
|
@ -43,38 +70,39 @@ func (p *player) move(g *game) {
|
|||
p.speed.X = 0
|
||||
}
|
||||
|
||||
p.pos = rl.Vector2Add(p.pos, p.speed)
|
||||
p.pos = rl.Vector2Add(p.pos, rl.Vector2Scale(p.speed, rl.GetFrameTime()))
|
||||
}
|
||||
|
||||
func (p *player) shoot(g *game) {
|
||||
if p.focusMode {
|
||||
return
|
||||
}
|
||||
|
||||
if int(g.frame)%3 != 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
||||
mouse := rl.GetMousePosition()
|
||||
direction := rl.Vector2Subtract(mouse, p.pos)
|
||||
direction = rl.Vector2Add(direction, p.speed)
|
||||
direction = rl.Vector2Normalize(direction)
|
||||
direction = rl.Vector2Scale(direction, p.bulletMoveSpeed)
|
||||
|
||||
g.bullets = append(g.bullets, &bullet{
|
||||
pos: p.pos,
|
||||
size: p.bulletSize,
|
||||
speed: direction,
|
||||
dmg: 1,
|
||||
enemy: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
// func (p *player) shoot(g *game) {
|
||||
// if p.focusMode {
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// if int(g.frame)%3 != 0 {
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// if rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
||||
// mouse := rl.GetMousePosition()
|
||||
// direction := rl.Vector2Subtract(mouse, p.pos)
|
||||
// direction = rl.Vector2Add(direction, p.speed)
|
||||
// direction = rl.Vector2Normalize(direction)
|
||||
// direction = rl.Vector2Scale(direction, p.bulletMoveSpeed)
|
||||
//
|
||||
// g.bullets = append(g.bullets, &bullet{
|
||||
// pos: p.pos,
|
||||
// size: p.bulletSize,
|
||||
// speed: direction,
|
||||
// dmg: 1,
|
||||
// enemy: false,
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
|
||||
func (p *player) checkHit(g *game) {
|
||||
for _, bullet := range g.bullets {
|
||||
if !bullet.enemy {
|
||||
_, playerBullet := bullet.owner.(*player)
|
||||
if playerBullet {
|
||||
continue
|
||||
}
|
||||
distance := rl.Vector2Distance(p.pos, bullet.pos) - bullet.size
|
||||
|
|
@ -96,7 +124,9 @@ func (p *player) update(g *game) {
|
|||
|
||||
p.move(g)
|
||||
|
||||
p.shoot(g)
|
||||
if !p.focusMode && p.shoot != nil {
|
||||
p.shoot(p)
|
||||
}
|
||||
|
||||
p.checkHit(g)
|
||||
|
||||
|
|
@ -112,6 +142,102 @@ func (p *player) update(g *game) {
|
|||
inverted = rl.Vector2Negate(inverted)
|
||||
inverted = rl.Vector2Normalize(inverted)
|
||||
inverted = rl.Vector2Scale(inverted, 2000)
|
||||
rl.DrawLineV(p.pos, rl.Vector2Add(mouse, inverted), rl.NewColor(255, 0, 0, 100))
|
||||
rl.DrawLineEx(p.pos, rl.Vector2Add(mouse, inverted), 3, rl.NewColor(255, 0, 0, 100))
|
||||
|
||||
}
|
||||
|
||||
func tripleFire(g *game) shootingPattern {
|
||||
t := newTimer(second * 0.05)
|
||||
return func(b body) {
|
||||
|
||||
if !t.isTimeout() {
|
||||
t.tick(g)
|
||||
return
|
||||
}
|
||||
t.reset()
|
||||
|
||||
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
||||
|
||||
g.bullets = append(g.bullets, &bullet{
|
||||
pos: b.Pos(),
|
||||
size: 9,
|
||||
speed: rl.Vector2Scale(
|
||||
rl.Mat2MultiplyVector2(rl.Mat2Radians(0.3), b.Direction()),
|
||||
600,
|
||||
),
|
||||
dmg: 1,
|
||||
owner: b,
|
||||
})
|
||||
g.bullets = append(g.bullets, &bullet{
|
||||
pos: b.Pos(),
|
||||
size: 9,
|
||||
speed: rl.Vector2Scale(
|
||||
rl.Mat2MultiplyVector2(rl.Mat2Radians(0), b.Direction()),
|
||||
600,
|
||||
),
|
||||
dmg: 1,
|
||||
owner: b,
|
||||
})
|
||||
g.bullets = append(g.bullets, &bullet{
|
||||
pos: b.Pos(),
|
||||
size: 9,
|
||||
speed: rl.Vector2Scale(
|
||||
rl.Mat2MultiplyVector2(rl.Mat2Radians(-0.3), b.Direction()),
|
||||
600,
|
||||
),
|
||||
dmg: 1,
|
||||
owner: b,
|
||||
})
|
||||
}
|
||||
|
||||
// rl.matrix
|
||||
}
|
||||
}
|
||||
|
||||
func snipe(g *game) shootingPattern {
|
||||
t := newTimer(1)
|
||||
hits := 0
|
||||
return func(b body) {
|
||||
|
||||
p, ok := b.(*player)
|
||||
if !ok {
|
||||
panic(b)
|
||||
}
|
||||
|
||||
if !t.isTimeout() {
|
||||
t.tick(g)
|
||||
return
|
||||
}
|
||||
|
||||
if !rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||
return
|
||||
}
|
||||
|
||||
t.reset()
|
||||
|
||||
mouse := rl.GetMousePosition()
|
||||
direction := rl.Vector2Subtract(mouse, p.pos)
|
||||
direction = rl.Vector2Add(direction, rl.Vector2Scale(p.speed, rl.GetFrameTime()*g.gameSpeed))
|
||||
direction = rl.Vector2Normalize(direction)
|
||||
direction = rl.Vector2Scale(direction, p.bulletMoveSpeed*700)
|
||||
|
||||
g.bullets = append(g.bullets, &bullet{
|
||||
pos: b.Pos(),
|
||||
size: p.bulletSize,
|
||||
speed: direction,
|
||||
dmg: 10 * hits,
|
||||
owner: b,
|
||||
onHit: func(b body) {
|
||||
hits += 2
|
||||
fmt.Println("hit!", hits)
|
||||
},
|
||||
onDestroy: func() {
|
||||
hits--
|
||||
hits = max(hits, 0)
|
||||
fmt.Println("hit!", hits)
|
||||
},
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue