scanners for projectiles
This commit is contained in:
parent
14f6c65e86
commit
5c77e373c3
28
player.go
28
player.go
@ -97,7 +97,7 @@ func (p *player) checkCollisions(g *game, move_vector v.Vector2d) (bool, v.Point
|
||||
|
||||
func (p *player) Tick(g *game) {
|
||||
p.Robot.Collision = false
|
||||
p.scan(g.players)
|
||||
p.scan(g)
|
||||
|
||||
// Adjust Speed
|
||||
if p.Robot.Speed < p.Robot.TargetSpeed {
|
||||
@ -169,9 +169,9 @@ func (p *player) Tick(g *game) {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *player) scan(players map[*player]bool) {
|
||||
func (p *player) scan(g *game) {
|
||||
p.Robot.Scanners = p.Robot.Scanners[:0]
|
||||
for player, _ := range players {
|
||||
for player, _ := range g.players {
|
||||
if player.Robot.Id == p.Robot.Id || player.Robot.Health <= 0 {
|
||||
continue
|
||||
}
|
||||
@ -183,10 +183,31 @@ func (p *player) scan(players map[*player]bool) {
|
||||
X: player.Robot.Position.X,
|
||||
Y: player.Robot.Position.Y,
|
||||
},
|
||||
Type: "robot",
|
||||
}
|
||||
p.Robot.Scanners = append(p.Robot.Scanners, s)
|
||||
}
|
||||
}
|
||||
|
||||
for proj, _ := range g.projectiles {
|
||||
if proj.Owner.Robot.Id == p.Robot.Id {
|
||||
continue
|
||||
}
|
||||
|
||||
dist := v.Distance(proj.Position, p.Robot.Position)
|
||||
if dist < float32(p.Robot.Stats.ScannerRadius) {
|
||||
s := Scanner{
|
||||
Id: proj.Id,
|
||||
Position: v.Point2d{
|
||||
X: proj.Position.X,
|
||||
Y: proj.Position.Y,
|
||||
},
|
||||
Type: "projectile",
|
||||
}
|
||||
p.Robot.Scanners = append(p.Robot.Scanners, s)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (p *player) fire(projectiles map[*Projectile]bool, turn int) *Projectile {
|
||||
@ -205,6 +226,7 @@ func (p *player) fire(projectiles map[*Projectile]bool, turn int) *Projectile {
|
||||
Damage: 10,
|
||||
Radius: p.Robot.Stats.WeaponRadius,
|
||||
Speed: float32(p.Robot.Stats.Speed * 3),
|
||||
Owner: p,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ type Projectile struct {
|
||||
Radius int `json:"radius"`
|
||||
Speed float32 `json:"-"`
|
||||
Damage int `json:"-"`
|
||||
Owner *player `json:"-"`
|
||||
}
|
||||
|
||||
func (p *Projectile) Tick(g *game) {
|
||||
|
Loading…
Reference in New Issue
Block a user