First pass of multibot support
This commit is contained in:
+22
-18
@@ -12,7 +12,7 @@ type Projectile struct {
|
||||
Radius int `json:"-"`
|
||||
Speed float32 `json:"-"`
|
||||
Damage int `json:"-"`
|
||||
Owner *player `json:"-"`
|
||||
Owner *Robot `json:"-"`
|
||||
}
|
||||
|
||||
func (p *Projectile) Tick(g *game) {
|
||||
@@ -23,21 +23,23 @@ func (p *Projectile) Tick(g *game) {
|
||||
|
||||
hit_player := false
|
||||
for player := range g.players {
|
||||
if player == p.Owner {
|
||||
continue
|
||||
}
|
||||
for _, r := range player.Robots {
|
||||
if &r == p.Owner {
|
||||
continue
|
||||
}
|
||||
|
||||
player_rect := v.RectFromPoint(player.Robot.Position, 3)
|
||||
collision, _, _ := v.RectIntersection(player_rect, p.Position, v_scaled)
|
||||
if collision {
|
||||
hit_player = true
|
||||
player_rect := v.RectFromPoint(r.Position, 3)
|
||||
collision, _, _ := v.RectIntersection(player_rect, p.Position, v_scaled)
|
||||
if collision {
|
||||
hit_player = true
|
||||
|
||||
if player.Robot.Health > 0 {
|
||||
// Direct hit causes more damage
|
||||
log.Printf("Direct Hit %v, Dmg:%v", player.Robot.Id, p.Damage)
|
||||
if r.Health > 0 {
|
||||
// Direct hit causes more damage
|
||||
log.Printf("Direct Hit %v, Dmg:%v", r.Id, p.Damage)
|
||||
|
||||
player.Robot.Health -= p.Damage
|
||||
player.Robot.Hit = true
|
||||
r.Health -= p.Damage
|
||||
r.Hit = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,11 +75,13 @@ func (p *Projectile) Tick(g *game) {
|
||||
g.splosions[splo] = true
|
||||
|
||||
for player := range g.players {
|
||||
dist := v.Distance(player.Robot.Position, p.Position)
|
||||
if dist < float32(p.Radius) {
|
||||
if player.Robot.Health > 0 {
|
||||
player.Robot.Health -= p.Damage
|
||||
player.Robot.Hit = true
|
||||
for _, r := range player.Robots {
|
||||
dist := v.Distance(r.Position, p.Position)
|
||||
if dist < float32(p.Radius) {
|
||||
if r.Health > 0 {
|
||||
r.Health -= p.Damage
|
||||
r.Hit = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user