func (f *fire) Think(ent game.Ent, g *game.Game) { player := ent.(*game.PlayerEnt) proc, ok := player.Processes[f.id].(*multiDrain) if !ok { return } if f.trigger && f.draining && proc.Stored > 1 { proc.Stored -= 0.1 // TODO: This is assuming 60fps - maybe that should be checked somewhere? for f.xFrac += f.xps / 60.0; f.xFrac > 0.0; f.xFrac-- { g.Processes = append(g.Processes, &asplosionProc{ StartRadius: f.startRadius, EndRadius: f.endRadius, DurationThinks: f.durationThinks, Dps: f.dps, Pos: f.getPos(ent, g), }) } if proc.Stored <= 1.0 { f.draining = false f.xFrac = 0 } } }
func (a *asplode) Input(ent game.Ent, g *game.Game, pressAmt float64, trigger bool) { if trigger && !ent.Dead() { // Kill ent and put down explosion ent.Suicide() g.Processes = append(g.Processes, &asplosionProc{ StartRadius: a.startRadius, EndRadius: a.endRadius, DurationThinks: a.durationThinks, Dps: a.dps, Pos: ent.Pos(), }) } }
func (l *lightning) Think(ent game.Ent, g *game.Game) { player := ent.(*game.PlayerEnt) proc, ok := player.Processes[l.id].(*multiDrain) if !ok { return } if l.trigger && proc.Stored > 1 { delete(player.Processes, l.id) // find the endpoits of the lightning forward := (linear.Vec2{1, 0}).Rotate(player.Angle()).Scale(10000) bounds := [2]linear.Seg2{ linear.Seg2{ player.Pos(), player.Pos().Add(forward), }, linear.Seg2{ player.Pos(), player.Pos().Sub(forward), }, } mag2s := [2]float64{-1.0, -1.0} var isects [2]linear.Vec2 isects[0] = bounds[0].Q isects[1] = bounds[1].Q for _, wall := range g.Level.Room.Walls { for i := range wall { seg := wall.Seg(i) for j := range bounds { if bounds[j].DoesIsect(seg) { isect := bounds[j].Isect(seg) isectMag2 := isect.Sub(player.Pos()).Mag2() if isectMag2 < mag2s[j] || mag2s[j] == -1 { mag2s[j] = isectMag2 isects[j] = isect } } } } } g.Processes = append(g.Processes, &lightningBoltProc{ BuildThinks: l.buildThinks, DurationThinks: l.durationThinks, Width: l.width * math.Sqrt(proc.Stored), Dps: l.dps, Power: proc.Stored, Seg: linear.Seg2{isects[0], isects[1]}, }) } }